~ubuntu-branches/ubuntu/gutsy/wireshark/gutsy-security

« back to all changes in this revision

Viewing changes to epan/crypt/airpdcap_wep.c

  • Committer: Bazaar Package Importer
  • Author(s): Frederic Peters
  • Date: 2007-04-01 08:58:40 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20070401085840-or3qhrpv8alt1bwg
Tags: 0.99.5-1
* New upstream release.
* debian/patches/09_idl2wrs.dpatch: updated to patch idl2wrs.sh.in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* airpcap_wep.c
 
2
 *
 
3
 *  $Id: airpdcap_wep.c 20401 2007-01-12 00:54:13Z gerald $
 
4
 *
 
5
 * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting
 
6
 * Copyright (c) 2006 CACE Technologies, Davis (California)
 
7
 * All rights reserved.
 
8
 *
 
9
 * Redistribution and use in source and binary forms, with or without
 
10
 * modification, are permitted provided that the following conditions
 
11
 * are met:
 
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.
 
19
 *
 
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.
 
23
 *
 
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.
 
34
 */
 
35
 
 
36
/************************************************************************/
 
37
/*      File includes                                                   */
 
38
 
 
39
#include <epan/tvbuff.h>
 
40
#include <epan/crc32.h>
 
41
 
 
42
#include "airpdcap_system.h"
 
43
#include "airpdcap_int.h"
 
44
 
 
45
#include "airpdcap_debug.h"
 
46
 
 
47
/************************************************************************/
 
48
 
 
49
/* Note: copied from FreeBSD source code, RELENG 6,                     */
 
50
/*              sys/net80211/ieee80211_crypto_wep.c, 391                */
 
51
INT AirPDcapWepDecrypt(
 
52
        const UCHAR *seed,
 
53
        const size_t seed_len,
 
54
        UCHAR *cypher_text,
 
55
        const size_t data_len)
 
56
{
 
57
        UINT32 i, j, k, crc;
 
58
        UINT8 S[256];
 
59
        UINT8 icv[4];
 
60
        size_t buflen;
 
61
 
 
62
        /* Generate key stream (RC4 Pseude-Random Number Generator) */
 
63
        for (i = 0; i < 256; i++)
 
64
                S[i] = (UINT8)i;
 
65
        for (j = i = 0; i < 256; i++) {
 
66
                j = (j + S[i] + seed[i % seed_len]) & 0xff;
 
67
                S_SWAP(i, j);
 
68
        }
 
69
 
 
70
        /* Apply RC4 to data and compute CRC32 over decrypted data */
 
71
        crc = ~(UINT32)0;
 
72
        buflen = data_len;
 
73
 
 
74
        for (i = j = k = 0; k < buflen; k++) {
 
75
                i = (i + 1) & 0xff;
 
76
                j = (j + S[i]) & 0xff;
 
77
                S_SWAP(i, j);
 
78
                *cypher_text ^= S[(S[i] + S[j]) & 0xff];
 
79
                crc = crc32_ccitt_table[(crc ^ *cypher_text) & 0xff] ^ (crc >> 8);
 
80
                cypher_text++;
 
81
        }
 
82
 
 
83
        crc = ~crc;
 
84
 
 
85
        /* Encrypt little-endian CRC32 and verify that it matches with the received ICV */
 
86
        icv[0] = (UINT8)crc;
 
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++) {
 
91
                i = (i + 1) & 0xff;
 
92
                j = (j + S[i]) & 0xff;
 
93
                S_SWAP(i, j);
 
94
                if ((icv[k] ^ S[(S[i] + S[j]) & 0xff]) != *cypher_text++) {
 
95
                        /* ICV mismatch - drop frame */
 
96
                        return AIRPDCAP_RET_UNSUCCESS;
 
97
                }
 
98
        }
 
99
 
 
100
        return AIRPDCAP_RET_SUCCESS;
 
101
}