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
15 void rc4_encode(unsigned char *buf, unsigned int len, unsigned char key[16])
17 unsigned char s[256], k[256], temp;
18 unsigned short i, j, t;
22 for (i = 0; i < 256; i++) {
23 s[i] = (unsigned char)i;
30 for (i = 0; i < 256; i++) {
31 j = (j + s[i] + k[i]) % 256;
39 for (ptr = 0; ptr < len; ptr++) {
45 t = (s[i] + (s[j] % 256)) % 256;
46 buf[ptr] = buf[ptr] ^ s[t];