3 * Copyright (c) 2002-2005, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
20 #define S_SWAP(a,b) do { u8 t = S[a]; S[a] = S[b]; S[b] = t; } while(0)
22 int rc4_skip(const u8 *key, size_t keylen, size_t skip,
23 u8 *data, size_t data_len)
30 for (i = 0; i < 256; i++)
34 for (i = 0; i < 256; i++) {
35 j = (j + S[i] + key[kpos]) & 0xff;
42 /* Skip the start of the stream */
44 for (k = 0; k < skip; k++) {
46 j = (j + S[i]) & 0xff;
50 /* Apply RC4 to data */
52 for (k = 0; k < data_len; k++) {
54 j = (j + S[i]) & 0xff;
56 *pos++ ^= S[(S[i] + S[j]) & 0xff];