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>.
15 #if defined(__linux__)
16 #include <linux/string.h>
21 unsigned char t = b; \
27 * Initialize arcfour from a key.
30 arcfour_setkey(arcfour_context
*context
, const unsigned char *key
,
36 context
->i
= context
->j
= 0;
38 for (i
= 0; i
< 256; i
++) {
40 K
[i
] = key
[i
% keylen
];
44 for (i
= 0; i
< 256; i
++) {
45 j
= (j
+ context
->S
[i
] + K
[i
]) % 256;
46 swap(context
->S
[i
], context
->S
[j
]);
49 memset(K
, 0, sizeof(K
));
53 * plaintext -> ciphertext (or vice versa)
56 arcfour_encrypt(arcfour_context
*context
, const unsigned char *in
, unsigned len
,
59 unsigned i
= context
->i
;
60 unsigned j
= context
->j
;
61 unsigned char *S
= context
->S
;
68 K
= S
[(S
[i
] + S
[j
]) % 256];