1 /*********************************************************************
3 * Author: Brad Conte (brad AT bradconte.com)
5 * Disclaimer: This code is presented "as is" without any guarantees.
6 * Details: Implementation of the ARCFOUR encryption algorithm.
7 Algorithm specification can be found here:
8 * http://en.wikipedia.org/wiki/RC4
9 *********************************************************************/
11 /*************************** HEADER FILES ***************************/
15 /*********************** FUNCTION DEFINITIONS ***********************/
16 void arcfour_key_setup(BYTE state[], const BYTE key[], int len)
21 for (i = 0; i < 256; ++i)
23 for (i = 0, j = 0; i < 256; ++i) {
24 j = (j + state[i] + key[i % len]) % 256;
31 // This does not hold state between calls. It always generates the
32 // stream starting from the first output byte.
33 void arcfour_generate_stream(BYTE state[], BYTE out[], size_t len)
39 for (idx = 0, i = 0, j = 0; idx < len; ++idx) {
41 j = (j + state[i]) % 256;
45 out[idx] = state[(state[i] + state[j]) % 256];