2 * wep.c - WEP functions
4 * Copyright (C) 2010, Broadcom Corporation
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
12 * $Id: wep.c,v 1.4 2007-04-29 04:36:19 Exp $
17 /* include wl driver config file if this file is compiled for driver */
22 extern void bcopy(const void *src
, void *dst
, int len
);
23 extern int bcmp(const void *b1
, const void *b2
, int len
);
24 extern void bzero(void *b
, int len
);
26 #define bcopy(src, dst, len) memcpy((dst), (src), (len))
27 #define bcmp(b1, b2, len) memcmp((b1), (b2), (len))
28 #define bzero(b, len) memset((b), 0, (len))
29 #endif /* defined(__GNUC__) */
30 #endif /* BCMDRIVER */
33 #include <bcmcrypto/rc4.h>
34 #include <bcmcrypto/wep.h>
35 #include <proto/802.11.h>
37 /* WEP-encrypt a buffer */
38 /* assumes a contiguous buffer, with IV prepended, and with enough space at
42 BCMROMFN(wep_encrypt
)(uint buf_len
, uint8
*buf
, uint sec_len
, uint8
*sec_data
)
47 uint8
*body
= buf
+ DOT11_IV_LEN
;
48 uint body_len
= buf_len
- (DOT11_IV_LEN
+ DOT11_ICV_LEN
);
49 uint8
*picv
= body
+ body_len
;
51 bcopy(buf
, key_data
, 3);
52 bcopy(sec_data
, &key_data
[3], sec_len
);
54 prepare_key(key_data
, sec_len
+ 3, &ks
);
57 ICV
= ~hndcrc32(body
, body_len
, CRC32_INIT_VALUE
);
59 picv
[1] = (ICV
>> 8) & 0xff;
60 picv
[2] = (ICV
>> 16) & 0xff;
61 picv
[3] = (ICV
>> 24) & 0xff;
63 rc4(body
, body_len
+ DOT11_ICV_LEN
, &ks
);
67 * Assumes a contigous buffer, with IV prepended.
68 * Returns TRUE if ICV check passes, FALSE otherwise
72 BCMROMFN(wep_decrypt
)(uint buf_len
, uint8
*buf
, uint sec_len
, uint8
*sec_data
)
77 bcopy(buf
, key_data
, 3);
78 bcopy(sec_data
, &key_data
[3], sec_len
);
80 prepare_key(key_data
, sec_len
+ 3, &ks
);
82 rc4(buf
+ DOT11_IV_LEN
, buf_len
- DOT11_IV_LEN
, &ks
);
84 return (hndcrc32(buf
+ DOT11_IV_LEN
, buf_len
- DOT11_IV_LEN
, CRC32_INIT_VALUE
) ==