]> git.ipfire.org Git - thirdparty/hostap.git/blame - wlantest/test_vectors.c
Validate P802.11ac test vector result
[thirdparty/hostap.git] / wlantest / test_vectors.c
CommitLineData
3ae89686
JM
1/*
2 * test_vectors - IEEE 802.11 test vector generator
3 * Copyright (c) 2012, Jouni Malinen <j@w1.fi>
4 *
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
7 */
8
9#include "utils/includes.h"
10
11#include "utils/common.h"
12#include "utils/eloop.h"
13#include "wlantest.h"
14
15
16extern int wpa_debug_level;
17extern int wpa_debug_show_keys;
18
19
20static void test_vector_tkip(void)
21{
22 u8 tk[] = {
23 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56,
24 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12,
25 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78,
26 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34
27 };
28 u8 pn[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
29 u8 frame[] = {
30 0x08, 0x42, 0x2c, 0x00, 0x02, 0x03, 0x04, 0x05,
31 0x06, 0x08, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
32 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xd0, 0x02,
33 /* 0x00, 0x20, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, */
34 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00,
35 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
36 0x40, 0x01, 0xa5, 0x55, 0xc0, 0xa8, 0x0a, 0x02,
37 0xc0, 0xa8, 0x0a, 0x01, 0x08, 0x00, 0x3a, 0xb0,
38 0x00, 0x00, 0x00, 0x00, 0xcd, 0x4c, 0x05, 0x00,
39 0x00, 0x00, 0x00, 0x00, 0x08, 0x09, 0x0a, 0x0b,
40 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
41 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
42 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
43 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
44 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
45 0x34, 0x35, 0x36, 0x37,
46 /* 0x68, 0x81, 0xa3, 0xf3, 0xd6, 0x48, 0xd0, 0x3c */
47 };
5a652e71
JM
48 u8 *enc, *plain;
49 size_t enc_len, plain_len;
3ae89686
JM
50
51 wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.6.3 TKIP test "
52 "vector\n");
53
54 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
55 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
56 wpa_hexdump(MSG_INFO, "Plaintext MPDU", frame, sizeof(frame));
57
58 enc = tkip_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
59 if (enc == NULL) {
60 wpa_printf(MSG_ERROR, "Failed to encrypt TKIP frame");
61 return;
62 }
63
64 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
5a652e71
JM
65
66 wpa_debug_level = MSG_INFO;
67 plain = tkip_decrypt(tk, (const struct ieee80211_hdr *) enc,
68 enc + 24, enc_len - 24, &plain_len);
69 wpa_debug_level = MSG_EXCESSIVE;
3ae89686 70 os_free(enc);
5a652e71
JM
71
72 if (plain == NULL) {
73 wpa_printf(MSG_ERROR, "Failed to decrypt TKIP frame");
74 return;
75 }
76
77 if (plain_len != sizeof(frame) - 24 ||
78 os_memcmp(plain, frame + 24, plain_len) != 0) {
79 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
80 plain, plain_len);
81 }
82
83 os_free(plain);
3ae89686
JM
84}
85
86
87static void test_vector_ccmp(void)
88{
89 u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
90 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f };
91 u8 pn[] = { 0xB5, 0x03, 0x97, 0x76, 0xE7, 0x0C };
92 u8 frame[] = {
93 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
94 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
95 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
96 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
97 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
98 0x7e, 0x78, 0xa0, 0x50
99 };
5a652e71
JM
100 u8 *enc, *plain;
101 size_t enc_len, plain_len;
3ae89686
JM
102 u8 fcs[4];
103
104 wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.6.4 CCMP test "
105 "vector\n");
106
107 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
108 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
109 wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
110 wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
111
112 enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
113 if (enc == NULL) {
114 wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
115 return;
116 }
117
118 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
119 WPA_PUT_LE32(fcs, crc32(enc, enc_len));
120 wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
5a652e71
JM
121
122 wpa_debug_level = MSG_INFO;
123 plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
124 enc + 24, enc_len - 24, &plain_len);
125 wpa_debug_level = MSG_EXCESSIVE;
3ae89686 126 os_free(enc);
5a652e71
JM
127
128 if (plain == NULL) {
129 wpa_printf(MSG_ERROR, "Failed to decrypt CCMP frame");
130 return;
131 }
132
133 if (plain_len != sizeof(frame) - 24 ||
134 os_memcmp(plain, frame + 24, plain_len) != 0) {
135 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
136 plain, plain_len);
137 }
138
139 os_free(plain);
3ae89686
JM
140}
141
142
7d68241d
JM
143static void test_vector_bip(void)
144{
145 u8 igtk[] = {
146 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
147 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf
148 };
149 u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
150 u8 frame[] = {
151 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
152 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
153 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
154 0x02, 0x00
155 };
156 u8 *prot;
157 size_t prot_len;
158
159 wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.9.1 BIP with broadcast "
160 "Deauthentication frame\n");
161
162 wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
163 wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
164 wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
165
166 prot = bip_protect(igtk, frame, sizeof(frame), ipn, 4, &prot_len);
167 if (prot == NULL) {
168 wpa_printf(MSG_ERROR, "Failed to protect BIP frame");
169 return;
170 }
171
172 wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
173 os_free(prot);
174}
175
176
65229840
JM
177static void test_vector_ccmp_mgmt(void)
178{
179 u8 tk[] = { 0x66, 0xed, 0x21, 0x04, 0x2f, 0x9f, 0x26, 0xd7,
180 0x11, 0x57, 0x06, 0xe4, 0x04, 0x14, 0xcf, 0x2e };
181 u8 pn[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
182 u8 frame[] = {
183 0xc0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
184 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
185 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
186 0x02, 0x00
187 };
5a652e71
JM
188 u8 *enc, *plain;
189 size_t enc_len, plain_len;
65229840
JM
190
191 wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.9.2 CCMP with unicast "
192 "Deauthentication frame\n");
193
194 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
195 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
196 wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
197 wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
198
199 enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
200 if (enc == NULL) {
201 wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
202 return;
203 }
204
205 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
5a652e71
JM
206
207 wpa_debug_level = MSG_INFO;
208 plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
209 enc + 24, enc_len - 24, &plain_len);
210 wpa_debug_level = MSG_EXCESSIVE;
65229840 211 os_free(enc);
5a652e71
JM
212
213 if (plain == NULL) {
214 wpa_printf(MSG_ERROR, "Failed to decrypt CCMP frame");
215 return;
216 }
217
218 if (plain_len != sizeof(frame) - 24 ||
219 os_memcmp(plain, frame + 24, plain_len) != 0) {
220 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
221 plain, plain_len);
222 }
223
224 os_free(plain);
65229840
JM
225}
226
227
84a65fd6
JM
228struct gcmp_test {
229 u8 tk[16];
230 u8 pn[6];
231 u8 frame[300];
232 size_t hdr_len;
233 size_t payload_len;
234 u8 mic[16];
235 u8 encr[300];
236};
237
238static struct gcmp_test gcmp_vectors[] =
239{
240 {
241 .tk = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
242 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa },
243 .pn = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
244 .frame = {
245 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
247 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
248
249 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
250 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
251 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
252 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
253 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
254 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
255 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
256 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
257 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
258 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
259 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
260 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
261 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
262 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
263 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
264 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
265 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
266 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
267 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
268 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
269 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
270 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
271 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
272 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
273 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
274 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
275 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
276 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
277 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
278 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
279 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
280 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
281 },
282 .hdr_len = 24,
283 .payload_len = 256,
284 .mic = {
285 0x80, 0xCB, 0x06, 0x62, 0xEA, 0x71, 0xAB, 0xFD,
286 0x9F, 0x04, 0xC7, 0xF8, 0x72, 0xF5, 0x80, 0x90 },
287 .encr = {
288 0x5F, 0x55, 0x78, 0xC1, 0x8F, 0x13, 0x7A, 0xD2,
289 0x79, 0xBF, 0x3F, 0x2B, 0x24, 0xC7, 0xBD, 0x8F,
290 0x27, 0x7A, 0x1B, 0xE6, 0x77, 0x0D, 0xA1, 0xD9,
291 0x8B, 0x70, 0xC6, 0xD2, 0x8A, 0xE0, 0x1C, 0x55,
292 0x9E, 0xCB, 0xA6, 0xA0, 0x1D, 0xB0, 0x67, 0xC5,
293 0xA2, 0x7E, 0x4D, 0xB0, 0x8C, 0xDA, 0xDC, 0x77,
294 0x52, 0xAD, 0x63, 0x7E, 0xAF, 0x0A, 0x18, 0xED,
295 0x13, 0xFB, 0xAA, 0x14, 0x3B, 0xAF, 0xEF, 0x18,
296 0xF8, 0xFB, 0xCE, 0x4C, 0x65, 0xE8, 0x6B, 0xD0,
297 0x2A, 0x87, 0xB6, 0x01, 0xB7, 0xEA, 0xB9, 0x3F,
298 0x2B, 0xBC, 0x87, 0x4C, 0x8A, 0x71, 0x05, 0x80,
299 0xF5, 0x02, 0x34, 0x1A, 0x6A, 0x53, 0x39, 0x31,
300 0x43, 0xDE, 0x4C, 0x9E, 0xC6, 0xA2, 0x86, 0xF1,
301 0x25, 0x71, 0x83, 0x78, 0xAE, 0xDC, 0x84, 0xEB,
302 0xA2, 0xB3, 0x0F, 0x5C, 0x28, 0xBB, 0x5D, 0x75,
303 0xC6, 0xB0, 0x25, 0x46, 0x6D, 0x06, 0x51, 0xC7,
304 0x22, 0xDC, 0x71, 0x15, 0x1F, 0x21, 0x2D, 0x68,
305 0x87, 0x82, 0x8A, 0x03, 0x82, 0xE9, 0x28, 0x8A,
306 0x7F, 0x43, 0xD5, 0x2B, 0x7D, 0x25, 0x08, 0x61,
307 0x57, 0x64, 0x69, 0x54, 0xBB, 0x43, 0xB5, 0x7E,
308 0xA5, 0x87, 0xA0, 0x25, 0xF4, 0x0C, 0xE7, 0x45,
309 0x11, 0xE4, 0xDD, 0x22, 0x85, 0xB4, 0x0B, 0xA3,
310 0xF3, 0xB9, 0x62, 0x62, 0xCB, 0xC2, 0x8C, 0x6A,
311 0xA7, 0xBE, 0x44, 0x3E, 0x7B, 0x41, 0xE1, 0xEB,
312 0xFF, 0x52, 0x48, 0x57, 0xA6, 0x81, 0x68, 0x97,
313 0x75, 0x01, 0x15, 0xB0, 0x23, 0x1A, 0xB7, 0xC2,
314 0x84, 0x72, 0xC0, 0x6D, 0xD0, 0xB4, 0x9B, 0xE9,
315 0xF3, 0x69, 0xA8, 0xC3, 0x9C, 0xCD, 0x0D, 0xB7,
316 0x98, 0x35, 0x10, 0xE1, 0xAE, 0x8F, 0x05, 0xD7,
317 0x75, 0x45, 0xE0, 0x23, 0x5C, 0xDB, 0xD6, 0x12,
318 0xF3, 0x15, 0x07, 0x54, 0xCE, 0xE5, 0xCE, 0x6A,
319 0x12, 0x25, 0xD9, 0x95, 0x25, 0x02, 0x6F, 0x74
320 }
321 },
322 {
323 .tk = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
324 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f },
325 .pn = { 0x00, 0x89, 0x5F, 0x5F, 0x2B, 0x08 },
326 .frame = {
327 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
328 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
329 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
330 0x03, 0x00,
331
332 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
333 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
334 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
335 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
336 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
337 },
338 .hdr_len = 26,
339 .payload_len = 40,
340 .mic = {
341 0xde, 0xf6, 0x19, 0xc2, 0xa3, 0x74, 0xb6, 0xdf,
342 0x66, 0xff, 0xa5, 0x3b, 0x6c, 0x69, 0xd7, 0x9e },
343 .encr = {
344 0x60, 0xe9, 0x70, 0x0c, 0xc4, 0xd4, 0x0a, 0xc6,
345 0xd2, 0x88, 0xb2, 0x01, 0xc3, 0x8f, 0x5b, 0xf0,
346 0x8b, 0x80, 0x74, 0x42, 0x64, 0x0a, 0x15, 0x96,
347 0xe5, 0xdb, 0xda, 0xd4, 0x1d, 0x1f, 0x36, 0x23,
348 0xf4, 0x5d, 0x7a, 0x12, 0xdb, 0x7a, 0xfb, 0x23
349 }
350 }
351};
352
353
354static int run_gcmp(int idx, struct gcmp_test *vector)
455bcc0f 355{
455bcc0f
JM
356 u8 *enc, *plain;
357 size_t enc_len, plain_len;
358 u8 fcs[4];
84a65fd6
JM
359 int err = 0;
360
361 wpa_printf(MSG_INFO,
362 "\nIEEE Std 802.11ad-2012, M.11.1 GCMP test mpdu #%d\n",
363 idx);
364
365 wpa_hexdump(MSG_INFO, "TK", vector->tk, sizeof(vector->tk));
366 wpa_hexdump(MSG_INFO, "PN", vector->pn, sizeof(vector->pn));
367 wpa_hexdump(MSG_INFO, "802.11 Header", vector->frame, vector->hdr_len);
368 wpa_hexdump(MSG_INFO, "Plaintext Data",
369 vector->frame + vector->hdr_len,
370 vector->payload_len);
371
372 enc = gcmp_encrypt(vector->tk, sizeof(vector->tk),
373 vector->frame,
374 vector->hdr_len + vector->payload_len,
375 vector->hdr_len,
376 vector->hdr_len == 26 ?
377 vector->frame + vector->hdr_len - 2 : NULL,
378 vector->pn, 0, &enc_len);
455bcc0f
JM
379 if (enc == NULL) {
380 wpa_printf(MSG_ERROR, "Failed to encrypt GCMP frame");
84a65fd6 381 return 1;
455bcc0f
JM
382 }
383
384 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
84a65fd6
JM
385 if (os_memcmp(vector->encr, enc + vector->hdr_len + 8,
386 vector->payload_len) != 0) {
387 wpa_printf(MSG_ERROR, "GCMP test mpdu #%d enctypted data mismatch",
388 idx);
389 err++;
390 }
391 if (os_memcmp(vector->mic, enc + enc_len - sizeof(vector->mic),
392 sizeof(vector->mic)) != 0) {
393 wpa_printf(MSG_ERROR, "GCMP test mpdu #%d MIC mismatch", idx);
394 err++;
395 }
455bcc0f
JM
396 WPA_PUT_LE32(fcs, crc32(enc, enc_len));
397 wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
398
399 wpa_debug_level = MSG_INFO;
84a65fd6
JM
400 plain = gcmp_decrypt(vector->tk, sizeof(vector->tk),
401 (const struct ieee80211_hdr *) enc,
402 enc + vector->hdr_len,
403 enc_len - vector->hdr_len, &plain_len);
f1732956
JM
404 wpa_debug_level = MSG_EXCESSIVE;
405 os_free(enc);
406
407 if (plain == NULL) {
408 wpa_printf(MSG_ERROR, "Failed to decrypt GCMP frame");
84a65fd6 409 return 1;
f1732956
JM
410 }
411
84a65fd6
JM
412 if (plain_len != vector->payload_len ||
413 os_memcmp(plain, vector->frame + vector->hdr_len, plain_len) != 0) {
f1732956
JM
414 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
415 plain, plain_len);
84a65fd6 416 err++;
f1732956
JM
417 }
418
419 os_free(plain);
84a65fd6
JM
420
421 return err;
422}
423
424
425static int test_vector_gcmp(void)
426{
427 int err = 0;
428 int i;
429
430 for (i = 0; i < ARRAY_SIZE(gcmp_vectors); i++) {
431 if (run_gcmp(i + 1, &gcmp_vectors[i]))
432 err++;
433
434 }
435
436 return err;
f1732956
JM
437}
438
439
0e91337d 440static int test_vector_gcmp_256(void)
f1732956
JM
441{
442 u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
443 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
444 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
445 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
446 u8 pn[] = {
447 0x00, 0x89, 0x5F, 0x5F, 0x2B, 0x08
448 };
449 u8 frame[] = {
450 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
451 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
452 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
453 0x03, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
454 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
455 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
456 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
457 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
458 0x26, 0x27
459 };
0e91337d
JM
460 u8 encr[] = {
461 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
462 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
463 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
464 0x03, 0x00, 0x08, 0x2b, 0x00, 0x20, 0x5f, 0x5f,
465 0x89, 0x00, 0x65, 0x83, 0x43, 0xc8, 0xb1, 0x44,
466 0x47, 0xd9, 0x21, 0x1d, 0xef, 0xd4, 0x6a, 0xd8,
467 0x9c, 0x71, 0x0c, 0x6f, 0xc3, 0x33, 0x33, 0x23,
468 0x6e, 0x39, 0x97, 0xb9, 0x17, 0x6a, 0x5a, 0x8b,
469 0xe7, 0x79, 0xb2, 0x12, 0x66, 0x55, 0x5e, 0x70,
470 0xad, 0x79, 0x11, 0x43, 0x16, 0x85, 0x90, 0x95,
471 0x47, 0x3d, 0x5b, 0x1b, 0xd5, 0x96, 0xb3, 0xde,
472 0xa3, 0xbf
473 };
f1732956
JM
474 u8 *enc, *plain;
475 size_t enc_len, plain_len;
476 u8 fcs[4];
0e91337d 477 int err = 0;
f1732956 478
0e91337d 479 wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.11.1 GCMP-256 test vector\n");
f1732956
JM
480
481 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
482 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
483 wpa_hexdump(MSG_INFO, "802.11 Header", frame, 26);
484 wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 26, sizeof(frame) - 26);
485
486 enc = gcmp_encrypt(tk, sizeof(tk), frame, sizeof(frame), 26, frame + 24,
487 pn, 0, &enc_len);
488 if (enc == NULL) {
489 wpa_printf(MSG_ERROR, "Failed to encrypt GCMP frame");
0e91337d 490 return 1;
f1732956
JM
491 }
492
493 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
0e91337d
JM
494 if (enc_len != sizeof(encr) || os_memcmp(enc, encr, enc_len) != 0) {
495 wpa_printf(MSG_ERROR, "GCMP-256 test vector mismatch");
496 err++;
497 }
f1732956
JM
498 WPA_PUT_LE32(fcs, crc32(enc, enc_len));
499 wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
500
501 wpa_debug_level = MSG_INFO;
502 plain = gcmp_decrypt(tk, sizeof(tk), (const struct ieee80211_hdr *) enc,
455bcc0f
JM
503 enc + 26, enc_len - 26, &plain_len);
504 wpa_debug_level = MSG_EXCESSIVE;
505 os_free(enc);
506
507 if (plain == NULL) {
508 wpa_printf(MSG_ERROR, "Failed to decrypt GCMP frame");
0e91337d 509 return 1;
455bcc0f
JM
510 }
511
512 if (plain_len != sizeof(frame) - 26 ||
513 os_memcmp(plain, frame + 26, plain_len) != 0) {
514 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
515 plain, plain_len);
0e91337d 516 err++;
455bcc0f
JM
517 }
518
519 os_free(plain);
0e91337d
JM
520
521 return err;
455bcc0f
JM
522}
523
524
0e91337d 525static int test_vector_ccmp_256(void)
7d19d3e9
JM
526{
527 u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
528 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
529 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
530 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
531 u8 pn[] = { 0xB5, 0x03, 0x97, 0x76, 0xE7, 0x0C };
532 u8 frame[] = {
533 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
534 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
535 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
536 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
537 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
538 0x7e, 0x78, 0xa0, 0x50
539 };
0e91337d
JM
540 u8 encr[] = {
541 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
542 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
543 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
544 0x0c, 0xe7, 0x00, 0x20, 0x76, 0x97, 0x03, 0xb5,
545 0x6d, 0x15, 0x5d, 0x88, 0x32, 0x66, 0x82, 0x56,
546 0xd6, 0xa9, 0x2b, 0x78, 0xe1, 0x1d, 0x8e, 0x54,
547 0x49, 0x5d, 0xd1, 0x74, 0x80, 0xaa, 0x56, 0xc9,
548 0x49, 0x2e, 0x88, 0x2b, 0x97, 0x64, 0x2f, 0x80,
549 0xd5, 0x0f, 0xe9, 0x7b
550
551 };
7d19d3e9
JM
552 u8 *enc, *plain;
553 size_t enc_len, plain_len;
554 u8 fcs[4];
0e91337d 555 int err = 0;
7d19d3e9 556
0e91337d 557 wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.6.4 CCMP-256 test vector\n");
7d19d3e9
JM
558
559 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
560 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
561 wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
562 wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
563
564 enc = ccmp_256_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0,
565 &enc_len);
566 if (enc == NULL) {
567 wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
0e91337d 568 return 1;
7d19d3e9
JM
569 }
570
571 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
0e91337d
JM
572 if (enc_len != sizeof(encr) || os_memcmp(enc, encr, enc_len) != 0) {
573 wpa_printf(MSG_ERROR, "CCMP-256 test vector mismatch");
574 err++;
575 }
7d19d3e9
JM
576 WPA_PUT_LE32(fcs, crc32(enc, enc_len));
577 wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
578
579 wpa_debug_level = MSG_INFO;
580 plain = ccmp_256_decrypt(tk, (const struct ieee80211_hdr *) enc,
581 enc + 24, enc_len - 24, &plain_len);
582 wpa_debug_level = MSG_EXCESSIVE;
583 os_free(enc);
584
585 if (plain == NULL) {
586 wpa_printf(MSG_ERROR, "Failed to decrypt CCMP-256 frame");
0e91337d 587 return 1;
7d19d3e9
JM
588 }
589
590 if (plain_len != sizeof(frame) - 24 ||
591 os_memcmp(plain, frame + 24, plain_len) != 0) {
592 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
593 plain, plain_len);
0e91337d 594 err++;
7d19d3e9
JM
595 }
596
597 os_free(plain);
0e91337d
JM
598
599 return err;
7d19d3e9
JM
600}
601
602
0e91337d 603static int test_vector_bip_gmac_128(void)
e88f0901
JM
604{
605 u8 igtk[] = {
606 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
607 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf
608 };
609 u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
610 u8 frame[] = {
611 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
612 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
613 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
614 0x02, 0x00
615 };
0e91337d
JM
616 u8 res[] = {
617 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
618 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
619 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
620 0x02, 0x00, 0x4c, 0x18, 0x04, 0x00, 0x04, 0x00,
621 0x00, 0x00, 0x00, 0x00, 0x3e, 0xd8, 0x62, 0xfb,
622 0x0f, 0x33, 0x38, 0xdd, 0x33, 0x86, 0xc8, 0x97,
623 0xe2, 0xed, 0x05, 0x3d
624 };
e88f0901
JM
625 u8 *prot;
626 size_t prot_len;
0e91337d 627 int err = 0;
e88f0901 628
0e91337d 629 wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.9.1 BIP-GMAC-128 with broadcast "
e88f0901
JM
630 "Deauthentication frame\n");
631
632 wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
633 wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
634 wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
635
636 prot = bip_gmac_protect(igtk, sizeof(igtk), frame, sizeof(frame),
637 ipn, 4, &prot_len);
638 if (prot == NULL) {
639 wpa_printf(MSG_ERROR, "Failed to protect BIP-GMAC-128 frame");
0e91337d 640 return 1;
e88f0901
JM
641 }
642
643 wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
0e91337d
JM
644 if (prot_len != sizeof(res) || os_memcmp(res, prot, prot_len) != 0) {
645 wpa_printf(MSG_ERROR, "BIP-GMAC-128 test vector mismatch");
646 err++;
647 }
e88f0901 648 os_free(prot);
0e91337d
JM
649
650 return err;
e88f0901
JM
651}
652
653
0e91337d 654static int test_vector_bip_gmac_256(void)
e88f0901
JM
655{
656 u8 igtk[] = {
657 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
658 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf,
659 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
660 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
661 };
662 u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
663 u8 frame[] = {
664 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
665 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
666 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
667 0x02, 0x00
668 };
0e91337d
JM
669 u8 res[] = {
670 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
671 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
672 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
673 0x02, 0x00, 0x4c, 0x18, 0x04, 0x00, 0x04, 0x00,
674 0x00, 0x00, 0x00, 0x00, 0x23, 0xbe, 0x59, 0xdc,
675 0xc7, 0x02, 0x2e, 0xe3, 0x83, 0x62, 0x7e, 0xbb,
676 0x10, 0x17, 0xdd, 0xfc
677 };
e88f0901
JM
678 u8 *prot;
679 size_t prot_len;
0e91337d 680 int err = 0;
e88f0901 681
0e91337d 682 wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.9.1 BIP-GMAC-256 with broadcast Deauthentication frame\n");
e88f0901
JM
683
684 wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
685 wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
686 wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
687
688 prot = bip_gmac_protect(igtk, sizeof(igtk), frame, sizeof(frame),
689 ipn, 4, &prot_len);
690 if (prot == NULL) {
691 wpa_printf(MSG_ERROR, "Failed to protect BIP-GMAC-256 frame");
0e91337d 692 return 1;
e88f0901
JM
693 }
694
695 wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
0e91337d
JM
696 if (prot_len != sizeof(res) || os_memcmp(res, prot, prot_len) != 0) {
697 wpa_printf(MSG_ERROR, "BIP-GMAC-128 test vector mismatch");
698 err++;
699 }
e88f0901 700 os_free(prot);
0e91337d
JM
701
702 return err;
e88f0901
JM
703}
704
705
3ae89686
JM
706int main(int argc, char *argv[])
707{
84a65fd6
JM
708 int errors = 0;
709
3ae89686
JM
710 wpa_debug_level = MSG_EXCESSIVE;
711 wpa_debug_show_keys = 1;
712
713 if (os_program_init())
714 return -1;
715
716 test_vector_tkip();
717 test_vector_ccmp();
7d68241d 718 test_vector_bip();
65229840 719 test_vector_ccmp_mgmt();
84a65fd6 720 errors += test_vector_gcmp();
0e91337d
JM
721 errors += test_vector_gcmp_256();
722 errors += test_vector_ccmp_256();
723 errors += test_vector_bip_gmac_128();
724 errors += test_vector_bip_gmac_256();
3ae89686 725
84a65fd6
JM
726 if (errors)
727 wpa_printf(MSG_INFO, "One or more test vectors failed");
3ae89686
JM
728 os_program_deinit();
729
84a65fd6 730 return errors ? -1 : 0;
3ae89686 731}