mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-12-01 00:49:43 +00:00
467382ca03
After some header file cleanups to add missing include files, remove common.h from all files in the lib directory. This primarily means just dropping the line but in a few cases we need to add in other header files now. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Tom Rini <trini@konsulko.com>
45 lines
782 B
C
45 lines
782 B
C
// SPDX-License-Identifier: GPL-2.0+
|
|
/*
|
|
* (C) Copyright 2015 Google, Inc
|
|
*
|
|
* (C) Copyright 2008-2014 Rockchip Electronics
|
|
*
|
|
* Rivest Cipher 4 (RC4) implementation
|
|
*/
|
|
|
|
#include <rc4.h>
|
|
|
|
void rc4_encode(unsigned char *buf, unsigned int len, const 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];
|
|
}
|
|
}
|