3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
4 * Copyright (c) 2006 CACE Technologies, Davis (California)
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * Alternatively, this software may be distributed under the terms of the
19 * GNU General Public License ("GPL") version 2 as published by the Free
20 * Software Foundation.
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 /************************************************************************/
42 /************************************************************************/
43 /* Note: copied from net80211/ieee80211_airpdcap_tkip.c */
44 #define S_SWAP(a,b) { guint8 t = S[a]; S[a] = S[b]; S[b] = t; }
46 /* Note: copied from FreeBSD source code, RELENG 6, */
47 /* sys/net80211/ieee80211_crypto_wep.c, 391 */
48 int AirPDcapWepDecrypt(
50 const size_t seed_len,
52 const size_t data_len)
59 /* Generate key stream (RC4 Pseudo-Random Number Generator) */
60 for (i = 0; i < 256; i++)
62 for (j = i = 0; i < 256; i++) {
63 j = (j + S[i] + seed[i % seed_len]) & 0xff;
67 /* Apply RC4 to data and compute CRC32 over decrypted data */
71 for (i = j = k = 0; k < buflen; k++) {
73 j = (j + S[i]) & 0xff;
75 *cypher_text ^= S[(S[i] + S[j]) & 0xff];
76 crc = crc32_ccitt_table_lookup((crc ^ *cypher_text) & 0xff) ^ (crc >> 8);
82 /* Encrypt little-endian CRC32 and verify that it matches with the received ICV */
84 icv[1] = (guint8)(crc >> 8);
85 icv[2] = (guint8)(crc >> 16);
86 icv[3] = (guint8)(crc >> 24);
87 for (k = 0; k < 4; k++) {
89 j = (j + S[i]) & 0xff;
91 if ((icv[k] ^ S[(S[i] + S[j]) & 0xff]) != *cypher_text++) {
92 /* ICV mismatch - drop frame */
93 return 1/*AIRPDCAP_RET_UNSUCCESS*/;
97 return 0/*AIRPDCAP_RET_SUCCESS*/;
101 * Editor modelines - http://www.wireshark.org/tools/modelines.html
106 * indent-tabs-mode: t
109 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
110 * :indentSize=8:tabSize=8:noTabs=false: