3
* $Id: airpdcap_wep.c 20401 2007-01-12 00:54:13Z gerald $
5
* Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
6
* Copyright (c) 2006 CACE Technologies, Davis (California)
9
* Redistribution and use in source and binary forms, with or without
10
* modification, are permitted provided that the following conditions
12
* 1. Redistributions of source code must retain the above copyright
13
* notice, this list of conditions and the following disclaimer.
14
* 2. Redistributions in binary form must reproduce the above copyright
15
* notice, this list of conditions and the following disclaimer in the
16
* documentation and/or other materials provided with the distribution.
17
* 3. The name of the author may not be used to endorse or promote products
18
* derived from this software without specific prior written permission.
20
* Alternatively, this software may be distributed under the terms of the
21
* GNU General Public License ("GPL") version 2 as published by the Free
22
* Software Foundation.
24
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36
/************************************************************************/
39
#include <epan/tvbuff.h>
40
#include <epan/crc32.h>
42
#include "airpdcap_system.h"
43
#include "airpdcap_int.h"
45
#include "airpdcap_debug.h"
47
/************************************************************************/
49
/* Note: copied from FreeBSD source code, RELENG 6, */
50
/* sys/net80211/ieee80211_crypto_wep.c, 391 */
51
INT AirPDcapWepDecrypt(
53
const size_t seed_len,
55
const size_t data_len)
62
/* Generate key stream (RC4 Pseude-Random Number Generator) */
63
for (i = 0; i < 256; i++)
65
for (j = i = 0; i < 256; i++) {
66
j = (j + S[i] + seed[i % seed_len]) & 0xff;
70
/* Apply RC4 to data and compute CRC32 over decrypted data */
74
for (i = j = k = 0; k < buflen; k++) {
76
j = (j + S[i]) & 0xff;
78
*cypher_text ^= S[(S[i] + S[j]) & 0xff];
79
crc = crc32_ccitt_table[(crc ^ *cypher_text) & 0xff] ^ (crc >> 8);
85
/* Encrypt little-endian CRC32 and verify that it matches with the received ICV */
87
icv[1] = (UINT8)(crc >> 8);
88
icv[2] = (UINT8)(crc >> 16);
89
icv[3] = (UINT8)(crc >> 24);
90
for (k = 0; k < 4; k++) {
92
j = (j + S[i]) & 0xff;
94
if ((icv[k] ^ S[(S[i] + S[j]) & 0xff]) != *cypher_text++) {
95
/* ICV mismatch - drop frame */
96
return AIRPDCAP_RET_UNSUCCESS;
100
return AIRPDCAP_RET_SUCCESS;