]>
git.ipfire.org Git - thirdparty/hostap.git/blob - wlantest/bip.c
3 * Copyright (c) 2010-2012, 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"
13 #include "crypto/aes_wrap.h"
17 u8
* bip_protect(const u8
*igtk
, u8
*frame
, size_t len
, u8
*ipn
, int keyid
,
23 struct ieee80211_hdr
*hdr
;
27 prot
= os_malloc(plen
);
30 os_memcpy(prot
, frame
, len
);
32 *pos
++ = WLAN_EID_MMIE
;
34 WPA_PUT_LE16(pos
, keyid
);
36 os_memcpy(pos
, ipn
, 6);
38 os_memset(pos
, 0, 8); /* MIC */
40 buf
= os_malloc(plen
+ 20 - 24);
46 /* BIP AAD: FC(masked) A1 A2 A3 */
47 hdr
= (struct ieee80211_hdr
*) frame
;
48 fc
= le_to_host16(hdr
->frame_control
);
49 fc
&= ~(WLAN_FC_RETRY
| WLAN_FC_PWRMGT
| WLAN_FC_MOREDATA
);
50 WPA_PUT_LE16(buf
, fc
);
51 os_memcpy(buf
+ 2, hdr
->addr1
, 3 * ETH_ALEN
);
52 os_memcpy(buf
+ 20, prot
+ 24, plen
- 24);
53 wpa_hexdump(MSG_MSGDUMP
, "BIP: AAD|Body(masked)", buf
, plen
+ 20 - 24);
54 /* MIC = L(AES-128-CMAC(AAD || Frame Body(masked)), 0, 64) */
55 if (omac1_aes_128(igtk
, buf
, plen
+ 20 - 24, mic
) < 0) {
62 os_memcpy(pos
, mic
, 8);
63 wpa_hexdump(MSG_DEBUG
, "BIP MMIE MIC", pos
, 8);
70 u8
* bip_gmac_protect(const u8
*igtk
, size_t igtk_len
, u8
*frame
, size_t len
,
71 u8
*ipn
, int keyid
, size_t *prot_len
)
75 struct ieee80211_hdr
*hdr
;
80 prot
= os_malloc(plen
);
83 os_memcpy(prot
, frame
, len
);
85 *pos
++ = WLAN_EID_MMIE
;
87 WPA_PUT_LE16(pos
, keyid
);
89 os_memcpy(pos
, ipn
, 6);
91 os_memset(pos
, 0, 16); /* MIC */
93 buf
= os_malloc(plen
+ 20 - 24);
99 /* BIP AAD: FC(masked) A1 A2 A3 */
100 hdr
= (struct ieee80211_hdr
*) frame
;
101 fc
= le_to_host16(hdr
->frame_control
);
102 fc
&= ~(WLAN_FC_RETRY
| WLAN_FC_PWRMGT
| WLAN_FC_MOREDATA
);
103 WPA_PUT_LE16(buf
, fc
);
104 os_memcpy(buf
+ 2, hdr
->addr1
, 3 * ETH_ALEN
);
105 os_memcpy(buf
+ 20, prot
+ 24, plen
- 24);
106 wpa_hexdump(MSG_MSGDUMP
, "BIP-GMAC: AAD|Body(masked)",
107 buf
, plen
+ 20 - 24);
109 /* Nonce: A2 | IPN */
110 os_memcpy(nonce
, hdr
->addr2
, ETH_ALEN
);
111 npos
= nonce
+ ETH_ALEN
;
118 wpa_hexdump(MSG_EXCESSIVE
, "BIP-GMAC: Nonce", nonce
, sizeof(nonce
));
120 /* MIC = AES-GMAC(AAD || Frame Body(masked)) */
121 if (aes_gmac(igtk
, igtk_len
, nonce
, sizeof(nonce
),
122 buf
, plen
+ 20 - 24, pos
) < 0) {
129 wpa_hexdump(MSG_DEBUG
, "BIP-GMAC MMIE MIC", pos
, 16);