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 /************************************************************************/
17 /************************************************************************/
18 /* Note: copied from net80211/ieee80211_airpdcap_tkip.c */
19 #define S_SWAP(a,b) { uint8_t t = S[a]; S[a] = S[b]; S[b] = t; }
21 /* Note: copied from FreeBSD source code, RELENG 6, */
22 /* sys/net80211/ieee80211_crypto_wep.c, 391 */
23 int Dot11DecryptWepDecrypt(
24 const unsigned char *seed
,
25 const size_t seed_len
,
26 unsigned char *cypher_text
,
27 const size_t data_len
)
29 uint32_t i
, j
, k
, crc
;
34 /* Generate key stream (RC4 Pseudo-Random Number Generator) */
35 for (i
= 0; i
< 256; i
++)
37 for (j
= i
= 0; i
< 256; i
++) {
38 j
= (j
+ S
[i
] + seed
[i
% seed_len
]) & 0xff;
42 /* Apply RC4 to data and compute CRC32 over decrypted data */
46 for (i
= j
= k
= 0; k
< buflen
; k
++) {
48 j
= (j
+ S
[i
]) & 0xff;
50 *cypher_text
^= S
[(S
[i
] + S
[j
]) & 0xff];
51 crc
= crc32_ccitt_table_lookup((crc
^ *cypher_text
) & 0xff) ^ (crc
>> 8);
57 /* Encrypt little-endian CRC32 and verify that it matches with the received ICV */
58 icv
[0] = (uint8_t)crc
;
59 icv
[1] = (uint8_t)(crc
>> 8);
60 icv
[2] = (uint8_t)(crc
>> 16);
61 icv
[3] = (uint8_t)(crc
>> 24);
62 for (k
= 0; k
< 4; k
++) {
64 j
= (j
+ S
[i
]) & 0xff;
66 if ((icv
[k
] ^ S
[(S
[i
] + S
[j
]) & 0xff]) != *cypher_text
++) {
67 /* ICV mismatch - drop frame */
68 return 1/*DOT11DECRYPT_RET_UNSUCCESS*/;
72 return 0/*DOT11DECRYPT_RET_SUCCESS*/;
76 * Editor modelines - https://www.wireshark.org/tools/modelines.html
84 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
85 * :indentSize=8:tabSize=8:noTabs=false: