2 * Host AP (software wireless LAN access point) user space daemon for
3 * Host AP kernel driver / RC4
4 * Copyright (c) 2002-2004, Jouni Malinen <jkmaline@cc.hut.fi>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Alternatively, this software may be distributed under the terms of BSD
13 * 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 void rc4_skip(u8 *key, size_t keylen, size_t skip, u8 *data, size_t data_len)
29 for (i = 0; i < 256; i++)
33 for (i = 0; i < 256; i++) {
34 j = (j + S[i] + key[kpos]) & 0xff;
41 /* Skip the start of the stream */
43 for (k = 0; k < skip; k++) {
45 j = (j + S[i]) & 0xff;
49 /* Apply RC4 to data */
51 for (k = 0; k < data_len; k++) {
53 j = (j + S[i]) & 0xff;
55 *pos++ ^= S[(S[i] + S[j]) & 0xff];
60 void rc4(u8 *buf, size_t len, u8 *key, size_t key_len)
62 rc4_skip(key, key_len, 0, buf, len);