3 * by Frank Cusack <frank@google.com>
6 * Implemented from the description in _Applied Cryptography_, 2nd ed.
8 * ** Distribution ** of this software is unlimited and unrestricted.
10 * ** Use ** of this software is almost certainly legal; however, refer
11 * to <http://theory.lcs.mit.edu/~rivest/faq.html>.
18 unsigned char t = b; \
24 * Initialize arcfour from a key.
27 arcfour_setkey(arcfour_context *context, const unsigned char *key,
33 context->i = context->j = 0;
35 for (i = 0; i < 256; i++) {
37 K[i] = key[i % keylen];
41 for (i = 0; i < 256; i++) {
42 j = (j + context->S[i] + K[i]) % 256;
43 swap(context->S[i], context->S[j]);
46 memset(K, 0, sizeof(K));
50 * plaintext -> ciphertext (or vice versa)
53 arcfour_encrypt(arcfour_context *context, const unsigned char *in, unsigned len,
56 unsigned i = context->i;
57 unsigned j = context->j;
58 unsigned char *S = context->S;
65 K = S[(S[i] + S[j]) % 256];