3 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
4 * Copyright (c) 2006 CACE Technologies, Davis (California)
7 * SPDX-License-Identifier: BSD-3-Clause
12 /************************************************************************/
18 /************************************************************************/
19 /* Note: copied from net80211/ieee80211_airpdcap_tkip.c */
20 #define S_SWAP(a,b) { guint8 t = S[a]; S[a] = S[b]; S[b] = t; }
22 /* Note: copied from FreeBSD source code, RELENG 6, */
23 /* sys/net80211/ieee80211_crypto_wep.c, 391 */
24 int Dot11DecryptWepDecrypt(
26 const size_t seed_len,
28 const size_t data_len)
35 /* Generate key stream (RC4 Pseudo-Random Number Generator) */
36 for (i = 0; i < 256; i++)
38 for (j = i = 0; i < 256; i++) {
39 j = (j + S[i] + seed[i % seed_len]) & 0xff;
43 /* Apply RC4 to data and compute CRC32 over decrypted data */
47 for (i = j = k = 0; k < buflen; k++) {
49 j = (j + S[i]) & 0xff;
51 *cypher_text ^= S[(S[i] + S[j]) & 0xff];
52 crc = crc32_ccitt_table_lookup((crc ^ *cypher_text) & 0xff) ^ (crc >> 8);
58 /* Encrypt little-endian CRC32 and verify that it matches with the received ICV */
60 icv[1] = (guint8)(crc >> 8);
61 icv[2] = (guint8)(crc >> 16);
62 icv[3] = (guint8)(crc >> 24);
63 for (k = 0; k < 4; k++) {
65 j = (j + S[i]) & 0xff;
67 if ((icv[k] ^ S[(S[i] + S[j]) & 0xff]) != *cypher_text++) {
68 /* ICV mismatch - drop frame */
69 return 1/*DOT11DECRYPT_RET_UNSUCCESS*/;
73 return 0/*DOT11DECRYPT_RET_SUCCESS*/;
77 * Editor modelines - http://www.wireshark.org/tools/modelines.html
85 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
86 * :indentSize=8:tabSize=8:noTabs=false: