From af1a266670d040d2f4083ff309d732d648afba2a Mon Sep 17 00:00:00 2001 From: Angelos Mouzakitis Date: Tue, 10 Oct 2023 14:33:42 +0000 Subject: Add submodule dependency files Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec --- roms/u-boot/lib/rc4.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 roms/u-boot/lib/rc4.c (limited to 'roms/u-boot/lib/rc4.c') diff --git a/roms/u-boot/lib/rc4.c b/roms/u-boot/lib/rc4.c new file mode 100644 index 000000000..0c0043984 --- /dev/null +++ b/roms/u-boot/lib/rc4.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * (C) Copyright 2015 Google, Inc + * + * (C) Copyright 2008-2014 Rockchip Electronics + * + * Rivest Cipher 4 (RC4) implementation + */ + +#ifndef USE_HOSTCC +#include +#endif +#include + +void rc4_encode(unsigned char *buf, unsigned int len, unsigned char key[16]) +{ + unsigned char s[256], k[256], temp; + unsigned short i, j, t; + int ptr; + + j = 0; + for (i = 0; i < 256; i++) { + s[i] = (unsigned char)i; + j &= 0x0f; + k[i] = key[j]; + j++; + } + + j = 0; + for (i = 0; i < 256; i++) { + j = (j + s[i] + k[i]) % 256; + temp = s[i]; + s[i] = s[j]; + s[j] = temp; + } + + i = 0; + j = 0; + for (ptr = 0; ptr < len; ptr++) { + i = (i + 1) % 256; + j = (j + s[i]) % 256; + temp = s[i]; + s[i] = s[j]; + s[j] = temp; + t = (s[i] + (s[j] % 256)) % 256; + buf[ptr] = buf[ptr] ^ s[t]; + } +} -- cgit