From c7c6bbf831e23cb2db4b1cedcd22c8c059ab2f8f Mon Sep 17 00:00:00 2001 From: Anders Broman Date: Mon, 12 Sep 2011 08:23:15 +0000 Subject: Move airpcap_wep.c to /wsutil svn path=/trunk/; revision=38969 --- epan/crypt/Makefile.common | 1 - epan/crypt/airpdcap_int.h | 3 -- epan/crypt/airpdcap_system.h | 7 --- epan/crypt/airpdcap_tkip.c | 1 + epan/crypt/airpdcap_wep.c | 105 ------------------------------------------- wsutil/Makefile.common | 1 + wsutil/airpdcap_wep.c | 102 +++++++++++++++++++++++++++++++++++++++++ wsutil/crc32.c | 2 +- wsutil/crc32.h | 9 ++++ wsutil/libwsutil.def | 2 + 10 files changed, 116 insertions(+), 117 deletions(-) delete mode 100644 epan/crypt/airpdcap_wep.c create mode 100644 wsutil/airpdcap_wep.c diff --git a/epan/crypt/Makefile.common b/epan/crypt/Makefile.common index 93c5f65537..02d2a753fb 100644 --- a/epan/crypt/Makefile.common +++ b/epan/crypt/Makefile.common @@ -29,7 +29,6 @@ LIBAIRPDCAP_SRC = \ airpdcap_debug.c \ airpdcap_rijndael.c \ airpdcap_tkip.c \ - airpdcap_wep.c \ crypt-aes.c \ crypt-des.c \ crypt-md4.c \ diff --git a/epan/crypt/airpdcap_int.h b/epan/crypt/airpdcap_int.h index b0fcfdffdc..e6c1b20a61 100644 --- a/epan/crypt/airpdcap_int.h +++ b/epan/crypt/airpdcap_int.h @@ -88,9 +88,6 @@ #define AIRPDCAP_EAP_MIC(KeyInfo_0) (KeyInfo_0 & 0x1) #define AIRPDCAP_EAP_SEC(KeyInfo_0) ((KeyInfo_0 >> 1) & 0x1) -/* Note: copied from net80211/ieee80211_airpdcap_tkip.c */ -#define S_SWAP(a,b) { UINT8 t = S[a]; S[a] = S[b]; S[b] = t; } - /****************************************************************************/ /****************************************************************************/ diff --git a/epan/crypt/airpdcap_system.h b/epan/crypt/airpdcap_system.h index cf57201112..69ec762f4c 100644 --- a/epan/crypt/airpdcap_system.h +++ b/epan/crypt/airpdcap_system.h @@ -336,13 +336,6 @@ INT AirPDcapDestroyContext( PAIRPDCAP_CONTEXT ctx) ; - -extern INT AirPDcapWepDecrypt( - const UCHAR *seed, - const size_t seed_len, /* max AIRPDCAP_KEYBUF_SIZE */ - UCHAR *cypher_text, - const size_t data_len) - ; extern INT AirPDcapCcmpDecrypt( UINT8 *m, gint mac_header_len, diff --git a/epan/crypt/airpdcap_tkip.c b/epan/crypt/airpdcap_tkip.c index a8ba95a1d9..9920485968 100644 --- a/epan/crypt/airpdcap_tkip.c +++ b/epan/crypt/airpdcap_tkip.c @@ -36,6 +36,7 @@ /* File includes */ /* */ #include +#include #include "airpdcap_system.h" #include "airpdcap_int.h" diff --git a/epan/crypt/airpdcap_wep.c b/epan/crypt/airpdcap_wep.c deleted file mode 100644 index 9353d06f77..0000000000 --- a/epan/crypt/airpdcap_wep.c +++ /dev/null @@ -1,105 +0,0 @@ -/* airpcap_wep.c - * - * $Id$ - * - * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting - * Copyright (c) 2006 CACE Technologies, Davis (California) - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * Alternatively, this software may be distributed under the terms of the - * GNU General Public License ("GPL") version 2 as published by the Free - * Software Foundation. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -/************************************************************************/ -/* File includes */ - -#include -#include - -#include "airpdcap_system.h" -#include "airpdcap_int.h" - -#include "airpdcap_debug.h" - -/************************************************************************/ - -/* Note: copied from FreeBSD source code, RELENG 6, */ -/* sys/net80211/ieee80211_crypto_wep.c, 391 */ -INT AirPDcapWepDecrypt( - const UCHAR *seed, - const size_t seed_len, - UCHAR *cypher_text, - const size_t data_len) -{ - UINT32 i, j, k, crc; - UINT8 S[256]; - UINT8 icv[4]; - size_t buflen; - - /* Generate key stream (RC4 Pseudo-Random Number Generator) */ - for (i = 0; i < 256; i++) - S[i] = (UINT8)i; - for (j = i = 0; i < 256; i++) { - j = (j + S[i] + seed[i % seed_len]) & 0xff; - S_SWAP(i, j); - } - - /* Apply RC4 to data and compute CRC32 over decrypted data */ - crc = ~(UINT32)0; - buflen = data_len; - - for (i = j = k = 0; k < buflen; k++) { - i = (i + 1) & 0xff; - j = (j + S[i]) & 0xff; - S_SWAP(i, j); - *cypher_text ^= S[(S[i] + S[j]) & 0xff]; - crc = crc32_ccitt_table_lookup((crc ^ *cypher_text) & 0xff) ^ (crc >> 8); - cypher_text++; - } - - crc = ~crc; - - /* Encrypt little-endian CRC32 and verify that it matches with the received ICV */ - icv[0] = (UINT8)crc; - icv[1] = (UINT8)(crc >> 8); - icv[2] = (UINT8)(crc >> 16); - icv[3] = (UINT8)(crc >> 24); - for (k = 0; k < 4; k++) { - i = (i + 1) & 0xff; - j = (j + S[i]) & 0xff; - S_SWAP(i, j); - if ((icv[k] ^ S[(S[i] + S[j]) & 0xff]) != *cypher_text++) { - /* ICV mismatch - drop frame */ - return AIRPDCAP_RET_UNSUCCESS; - } - } - - return AIRPDCAP_RET_SUCCESS; -} diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index 019f50bfa7..9cef17eac7 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -29,6 +29,7 @@ # generated from YACC or Lex files (as Automake doesn't want them in # _SOURCES variables). LIBWSUTIL_SRC = \ + airpdcap_wep.c \ crc10.c \ crc16.c \ crc16-plain.c \ diff --git a/wsutil/airpdcap_wep.c b/wsutil/airpdcap_wep.c new file mode 100644 index 0000000000..57b047fab7 --- /dev/null +++ b/wsutil/airpdcap_wep.c @@ -0,0 +1,102 @@ +/* airpcap_wep.c + * + * $Id$ + * + * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting + * Copyright (c) 2006 CACE Technologies, Davis (California) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, this software may be distributed under the terms of the + * GNU General Public License ("GPL") version 2 as published by the Free + * Software Foundation. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +/************************************************************************/ +/* File includes */ + +#include +#include "crc32.h" + +/************************************************************************/ +/* Note: copied from net80211/ieee80211_airpdcap_tkip.c */ +#define S_SWAP(a,b) { guint8 t = S[a]; S[a] = S[b]; S[b] = t; } + +/* Note: copied from FreeBSD source code, RELENG 6, */ +/* sys/net80211/ieee80211_crypto_wep.c, 391 */ +int AirPDcapWepDecrypt( + const guchar *seed, + const size_t seed_len, + guchar *cypher_text, + const size_t data_len) +{ + guint32 i, j, k, crc; + guint8 S[256]; + guint8 icv[4]; + size_t buflen; + + /* Generate key stream (RC4 Pseudo-Random Number Generator) */ + for (i = 0; i < 256; i++) + S[i] = (guint8)i; + for (j = i = 0; i < 256; i++) { + j = (j + S[i] + seed[i % seed_len]) & 0xff; + S_SWAP(i, j); + } + + /* Apply RC4 to data and compute CRC32 over decrypted data */ + crc = ~(guint32)0; + buflen = data_len; + + for (i = j = k = 0; k < buflen; k++) { + i = (i + 1) & 0xff; + j = (j + S[i]) & 0xff; + S_SWAP(i, j); + *cypher_text ^= S[(S[i] + S[j]) & 0xff]; + crc = crc32_ccitt_table[(crc ^ *cypher_text) & 0xff] ^ (crc >> 8); + cypher_text++; + } + + crc = ~crc; + + /* Encrypt little-endian CRC32 and verify that it matches with the received ICV */ + icv[0] = (guint8)crc; + icv[1] = (guint8)(crc >> 8); + icv[2] = (guint8)(crc >> 16); + icv[3] = (guint8)(crc >> 24); + for (k = 0; k < 4; k++) { + i = (i + 1) & 0xff; + j = (j + S[i]) & 0xff; + S_SWAP(i, j); + if ((icv[k] ^ S[(S[i] + S[j]) & 0xff]) != *cypher_text++) { + /* ICV mismatch - drop frame */ + return 1/*AIRPDCAP_RET_UNSUCCESS*/; + } + } + + return 0/*AIRPDCAP_RET_SUCCESS*/; +} diff --git a/wsutil/crc32.c b/wsutil/crc32.c index eb4a9b1025..c40047dffe 100644 --- a/wsutil/crc32.c +++ b/wsutil/crc32.c @@ -115,7 +115,7 @@ static const guint32 crc32c_table[256] = { * x^32 + x^26 + x^23 + x^22 + x^16 + x^12 + x^11 + x^8 + x^7 + * x^5 + x^4 + x^2 + x + 1 */ -static const guint32 crc32_ccitt_table[256] = { +const guint32 crc32_ccitt_table[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, diff --git a/wsutil/crc32.h b/wsutil/crc32.h index 854f5fa035..514a437596 100644 --- a/wsutil/crc32.h +++ b/wsutil/crc32.h @@ -43,6 +43,8 @@ extern "C" { #define CRC32C(c,d) (c=(c>>8)^crc32c_table_lookup((c^(d))&0xFF)) +extern const guint32 crc32_ccitt_table[256]; + /** Lookup the crc value in the crc32c_table @param pos Position in the table. */ extern guint32 crc32c_table_lookup (guchar pos); @@ -73,6 +75,13 @@ extern guint32 crc32_ccitt(const guint8 *buf, guint len); @return The CRC32 CCITT checksum (using the given seed). */ extern guint32 crc32_ccitt_seed(const guint8 *buf, guint len, guint32 seed); + +int AirPDcapWepDecrypt( + const guchar *seed, + const size_t seed_len, + guchar *cypher_text, + const size_t data_len); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/wsutil/libwsutil.def b/wsutil/libwsutil.def index 0804860c2e..70ef7bb78e 100644 --- a/wsutil/libwsutil.def +++ b/wsutil/libwsutil.def @@ -8,6 +8,8 @@ ; NOTE: TABS DON'T WORK IN THIS FILE, USE SPACES INSTEAD!!! ; EXPORTS +; airpdcap.c +AirPDcapWepDecrypt ; crc6.c update_crc6_by_bytes -- cgit v1.2.3