2 * (C) Copyright 2015 Google, Inc
4 * (C) Copyright 2008-2014 Rockchip Electronics
6 * Rivest Cipher 4 (RC4) implementation
8 * SPDX-License-Identifier: GPL-2.0+
16 void rc4_encode(unsigned char *buf, unsigned int len, unsigned char key[16])
18 unsigned char s[256], k[256], temp;
19 unsigned short i, j, t;
23 for (i = 0; i < 256; i++) {
24 s[i] = (unsigned char)i;
31 for (i = 0; i < 256; i++) {
32 j = (j + s[i] + k[i]) % 256;
40 for (ptr = 0; ptr < len; ptr++) {
46 t = (s[i] + (s[j] % 256)) % 256;
47 buf[ptr] = buf[ptr] ^ s[t];