]>
git.ipfire.org Git - thirdparty/hostap.git/blob - wlantest/wep.c
2 * Wired Equivalent Privacy (WEP)
3 * Copyright (c) 2010, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
9 #include "utils/includes.h"
11 #include "utils/common.h"
12 #include "common/ieee802_11_defs.h"
16 void wep_crypt(u8
*key
, u8
*buf
, size_t plen
)
20 #define S_SWAP(a,b) do { u8 t = S[a]; S[a] = S[b]; S[b] = t; } while(0)
24 for (i
= 0; i
< 256; i
++)
27 for (i
= 0; i
< 256; i
++) {
28 j
= (j
+ S
[i
] + key
[i
& 0x0f]) & 0xff;
32 /* Apply RC4 to data */
35 for (k
= 0; k
< plen
; k
++) {
37 j
= (j
+ S
[i
]) & 0xff;
39 *pos
^= S
[(S
[i
] + S
[j
]) & 0xff];
45 static int try_wep(const u8
*key
, size_t key_len
, const u8
*data
,
46 size_t data_len
, u8
*plain
)
52 for (i
= 0, j
= 0; i
< sizeof(k
); i
++) {
59 os_memcpy(plain
, data
, data_len
);
60 wep_crypt(k
, plain
, data_len
);
61 icv
= crc32(plain
, data_len
- 4);
62 rx_icv
= WPA_GET_LE32(plain
+ data_len
- 4);
70 u8
* wep_decrypt(struct wlantest
*wt
, const struct ieee80211_hdr
*hdr
,
71 const u8
*data
, size_t data_len
, size_t *decrypted_len
)
74 struct wlantest_wep
*w
;
78 if (dl_list_empty(&wt
->wep
))
83 plain
= os_malloc(data_len
- 4);
87 dl_list_for_each(w
, &wt
->wep
, struct wlantest_wep
, list
) {
88 os_memcpy(key
, data
, 3);
89 os_memcpy(key
+ 3, w
->key
, w
->key_len
);
90 if (try_wep(key
, 3 + w
->key_len
, data
+ 4, data_len
- 4, plain
)
101 *decrypted_len
= data_len
- 4 - 4;