1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2015 Google, Inc
5 * (C) Copyright 2008-2014 Rockchip Electronics
7 * Rivest Cipher 4 (RC4) implementation
12 void rc4_encode(unsigned char *buf, unsigned int len, const unsigned char key[16])
14 unsigned char s[256], k[256], temp;
15 unsigned short i, j, t;
19 for (i = 0; i < 256; i++) {
20 s[i] = (unsigned char)i;
27 for (i = 0; i < 256; i++) {
28 j = (j + s[i] + k[i]) % 256;
36 for (ptr = 0; ptr < len; ptr++) {
42 t = (s[i] + (s[j] % 256)) % 256;
43 buf[ptr] = buf[ptr] ^ s[t];