blob: 0800db7f3a3adeaf0b67b1570f82320a6d4c0de5 [file] [log] [blame]
Jouni Malinen3ae89682012-09-08 14:03:43 +03001/*
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
Jouni Malinen3ae89682012-09-08 14:03:43 +030016static void test_vector_tkip(void)
17{
18 u8 tk[] = {
19 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56,
20 0x78, 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12,
21 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56, 0x78,
22 0x90, 0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34
23 };
24 u8 pn[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
25 u8 frame[] = {
26 0x08, 0x42, 0x2c, 0x00, 0x02, 0x03, 0x04, 0x05,
27 0x06, 0x08, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
28 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0xd0, 0x02,
29 /* 0x00, 0x20, 0x01, 0x20, 0x00, 0x00, 0x00, 0x00, */
30 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00, 0x08, 0x00,
31 0x45, 0x00, 0x00, 0x54, 0x00, 0x00, 0x40, 0x00,
32 0x40, 0x01, 0xa5, 0x55, 0xc0, 0xa8, 0x0a, 0x02,
33 0xc0, 0xa8, 0x0a, 0x01, 0x08, 0x00, 0x3a, 0xb0,
34 0x00, 0x00, 0x00, 0x00, 0xcd, 0x4c, 0x05, 0x00,
35 0x00, 0x00, 0x00, 0x00, 0x08, 0x09, 0x0a, 0x0b,
36 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13,
37 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
38 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,
39 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,
40 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33,
41 0x34, 0x35, 0x36, 0x37,
42 /* 0x68, 0x81, 0xa3, 0xf3, 0xd6, 0x48, 0xd0, 0x3c */
43 };
Jouni Malinen5a652e72012-09-08 16:53:45 +030044 u8 *enc, *plain;
45 size_t enc_len, plain_len;
Jouni Malinen3ae89682012-09-08 14:03:43 +030046
47 wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.6.3 TKIP test "
48 "vector\n");
49
50 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
51 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
52 wpa_hexdump(MSG_INFO, "Plaintext MPDU", frame, sizeof(frame));
53
54 enc = tkip_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
55 if (enc == NULL) {
56 wpa_printf(MSG_ERROR, "Failed to encrypt TKIP frame");
57 return;
58 }
59
60 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
Jouni Malinen5a652e72012-09-08 16:53:45 +030061
62 wpa_debug_level = MSG_INFO;
63 plain = tkip_decrypt(tk, (const struct ieee80211_hdr *) enc,
64 enc + 24, enc_len - 24, &plain_len);
65 wpa_debug_level = MSG_EXCESSIVE;
Jouni Malinen3ae89682012-09-08 14:03:43 +030066 os_free(enc);
Jouni Malinen5a652e72012-09-08 16:53:45 +030067
68 if (plain == NULL) {
69 wpa_printf(MSG_ERROR, "Failed to decrypt TKIP frame");
70 return;
71 }
72
73 if (plain_len != sizeof(frame) - 24 ||
74 os_memcmp(plain, frame + 24, plain_len) != 0) {
75 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
76 plain, plain_len);
77 }
78
79 os_free(plain);
Jouni Malinen3ae89682012-09-08 14:03:43 +030080}
81
82
83static void test_vector_ccmp(void)
84{
85 u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
86 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f };
87 u8 pn[] = { 0xB5, 0x03, 0x97, 0x76, 0xE7, 0x0C };
88 u8 frame[] = {
89 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
90 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
91 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
92 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
93 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
94 0x7e, 0x78, 0xa0, 0x50
95 };
Jouni Malinen5a652e72012-09-08 16:53:45 +030096 u8 *enc, *plain;
97 size_t enc_len, plain_len;
Jouni Malinen3ae89682012-09-08 14:03:43 +030098 u8 fcs[4];
99
100 wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.6.4 CCMP test "
101 "vector\n");
102
103 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
104 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
105 wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
106 wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
107
108 enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
109 if (enc == NULL) {
110 wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
111 return;
112 }
113
114 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
115 WPA_PUT_LE32(fcs, crc32(enc, enc_len));
116 wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
Jouni Malinen5a652e72012-09-08 16:53:45 +0300117
118 wpa_debug_level = MSG_INFO;
119 plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
120 enc + 24, enc_len - 24, &plain_len);
121 wpa_debug_level = MSG_EXCESSIVE;
Jouni Malinen3ae89682012-09-08 14:03:43 +0300122 os_free(enc);
Jouni Malinen5a652e72012-09-08 16:53:45 +0300123
124 if (plain == NULL) {
125 wpa_printf(MSG_ERROR, "Failed to decrypt CCMP frame");
126 return;
127 }
128
129 if (plain_len != sizeof(frame) - 24 ||
130 os_memcmp(plain, frame + 24, plain_len) != 0) {
131 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
132 plain, plain_len);
133 }
134
135 os_free(plain);
Jouni Malinen3ae89682012-09-08 14:03:43 +0300136}
137
138
Jouni Malinen7d682412012-09-08 16:43:11 +0300139static void test_vector_bip(void)
140{
141 u8 igtk[] = {
142 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
143 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf
144 };
145 u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
146 u8 frame[] = {
147 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
148 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
149 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
150 0x02, 0x00
151 };
152 u8 *prot;
153 size_t prot_len;
154
155 wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.9.1 BIP with broadcast "
156 "Deauthentication frame\n");
157
158 wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
159 wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
160 wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
161
162 prot = bip_protect(igtk, frame, sizeof(frame), ipn, 4, &prot_len);
163 if (prot == NULL) {
164 wpa_printf(MSG_ERROR, "Failed to protect BIP frame");
165 return;
166 }
167
168 wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
169 os_free(prot);
170}
171
172
Jouni Malinen65229842012-09-08 16:21:57 +0300173static void test_vector_ccmp_mgmt(void)
174{
175 u8 tk[] = { 0x66, 0xed, 0x21, 0x04, 0x2f, 0x9f, 0x26, 0xd7,
176 0x11, 0x57, 0x06, 0xe4, 0x04, 0x14, 0xcf, 0x2e };
177 u8 pn[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
178 u8 frame[] = {
179 0xc0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
180 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
181 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
182 0x02, 0x00
183 };
Jouni Malinen5a652e72012-09-08 16:53:45 +0300184 u8 *enc, *plain;
185 size_t enc_len, plain_len;
Jouni Malinen65229842012-09-08 16:21:57 +0300186
187 wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.9.2 CCMP with unicast "
188 "Deauthentication frame\n");
189
190 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
191 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
192 wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
193 wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
194
195 enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
196 if (enc == NULL) {
197 wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
198 return;
199 }
200
201 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
Jouni Malinen5a652e72012-09-08 16:53:45 +0300202
203 wpa_debug_level = MSG_INFO;
204 plain = ccmp_decrypt(tk, (const struct ieee80211_hdr *) enc,
205 enc + 24, enc_len - 24, &plain_len);
206 wpa_debug_level = MSG_EXCESSIVE;
Jouni Malinen65229842012-09-08 16:21:57 +0300207 os_free(enc);
Jouni Malinen5a652e72012-09-08 16:53:45 +0300208
209 if (plain == NULL) {
210 wpa_printf(MSG_ERROR, "Failed to decrypt CCMP frame");
211 return;
212 }
213
214 if (plain_len != sizeof(frame) - 24 ||
215 os_memcmp(plain, frame + 24, plain_len) != 0) {
216 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
217 plain, plain_len);
218 }
219
220 os_free(plain);
Jouni Malinen65229842012-09-08 16:21:57 +0300221}
222
223
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200224struct gcmp_test {
225 u8 tk[16];
226 u8 pn[6];
227 u8 frame[300];
228 size_t hdr_len;
229 size_t payload_len;
230 u8 mic[16];
231 u8 encr[300];
232};
233
234static struct gcmp_test gcmp_vectors[] =
Jouni Malinen455bcc02012-09-08 20:00:54 +0300235{
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200236 {
237 .tk = { 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
238 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa },
239 .pn = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
240 .frame = {
241 0x20, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
242 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
243 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
244
245 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
246 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
247 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
248 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
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 },
278 .hdr_len = 24,
279 .payload_len = 256,
280 .mic = {
281 0x80, 0xCB, 0x06, 0x62, 0xEA, 0x71, 0xAB, 0xFD,
282 0x9F, 0x04, 0xC7, 0xF8, 0x72, 0xF5, 0x80, 0x90 },
283 .encr = {
284 0x5F, 0x55, 0x78, 0xC1, 0x8F, 0x13, 0x7A, 0xD2,
285 0x79, 0xBF, 0x3F, 0x2B, 0x24, 0xC7, 0xBD, 0x8F,
286 0x27, 0x7A, 0x1B, 0xE6, 0x77, 0x0D, 0xA1, 0xD9,
287 0x8B, 0x70, 0xC6, 0xD2, 0x8A, 0xE0, 0x1C, 0x55,
288 0x9E, 0xCB, 0xA6, 0xA0, 0x1D, 0xB0, 0x67, 0xC5,
289 0xA2, 0x7E, 0x4D, 0xB0, 0x8C, 0xDA, 0xDC, 0x77,
290 0x52, 0xAD, 0x63, 0x7E, 0xAF, 0x0A, 0x18, 0xED,
291 0x13, 0xFB, 0xAA, 0x14, 0x3B, 0xAF, 0xEF, 0x18,
292 0xF8, 0xFB, 0xCE, 0x4C, 0x65, 0xE8, 0x6B, 0xD0,
293 0x2A, 0x87, 0xB6, 0x01, 0xB7, 0xEA, 0xB9, 0x3F,
294 0x2B, 0xBC, 0x87, 0x4C, 0x8A, 0x71, 0x05, 0x80,
295 0xF5, 0x02, 0x34, 0x1A, 0x6A, 0x53, 0x39, 0x31,
296 0x43, 0xDE, 0x4C, 0x9E, 0xC6, 0xA2, 0x86, 0xF1,
297 0x25, 0x71, 0x83, 0x78, 0xAE, 0xDC, 0x84, 0xEB,
298 0xA2, 0xB3, 0x0F, 0x5C, 0x28, 0xBB, 0x5D, 0x75,
299 0xC6, 0xB0, 0x25, 0x46, 0x6D, 0x06, 0x51, 0xC7,
300 0x22, 0xDC, 0x71, 0x15, 0x1F, 0x21, 0x2D, 0x68,
301 0x87, 0x82, 0x8A, 0x03, 0x82, 0xE9, 0x28, 0x8A,
302 0x7F, 0x43, 0xD5, 0x2B, 0x7D, 0x25, 0x08, 0x61,
303 0x57, 0x64, 0x69, 0x54, 0xBB, 0x43, 0xB5, 0x7E,
304 0xA5, 0x87, 0xA0, 0x25, 0xF4, 0x0C, 0xE7, 0x45,
305 0x11, 0xE4, 0xDD, 0x22, 0x85, 0xB4, 0x0B, 0xA3,
306 0xF3, 0xB9, 0x62, 0x62, 0xCB, 0xC2, 0x8C, 0x6A,
307 0xA7, 0xBE, 0x44, 0x3E, 0x7B, 0x41, 0xE1, 0xEB,
308 0xFF, 0x52, 0x48, 0x57, 0xA6, 0x81, 0x68, 0x97,
309 0x75, 0x01, 0x15, 0xB0, 0x23, 0x1A, 0xB7, 0xC2,
310 0x84, 0x72, 0xC0, 0x6D, 0xD0, 0xB4, 0x9B, 0xE9,
311 0xF3, 0x69, 0xA8, 0xC3, 0x9C, 0xCD, 0x0D, 0xB7,
312 0x98, 0x35, 0x10, 0xE1, 0xAE, 0x8F, 0x05, 0xD7,
313 0x75, 0x45, 0xE0, 0x23, 0x5C, 0xDB, 0xD6, 0x12,
314 0xF3, 0x15, 0x07, 0x54, 0xCE, 0xE5, 0xCE, 0x6A,
315 0x12, 0x25, 0xD9, 0x95, 0x25, 0x02, 0x6F, 0x74
316 }
317 },
318 {
319 .tk = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
320 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f },
321 .pn = { 0x00, 0x89, 0x5F, 0x5F, 0x2B, 0x08 },
322 .frame = {
323 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
324 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
325 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
326 0x03, 0x00,
327
328 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
329 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
330 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
331 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
332 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
333 },
334 .hdr_len = 26,
335 .payload_len = 40,
336 .mic = {
337 0xde, 0xf6, 0x19, 0xc2, 0xa3, 0x74, 0xb6, 0xdf,
338 0x66, 0xff, 0xa5, 0x3b, 0x6c, 0x69, 0xd7, 0x9e },
339 .encr = {
340 0x60, 0xe9, 0x70, 0x0c, 0xc4, 0xd4, 0x0a, 0xc6,
341 0xd2, 0x88, 0xb2, 0x01, 0xc3, 0x8f, 0x5b, 0xf0,
342 0x8b, 0x80, 0x74, 0x42, 0x64, 0x0a, 0x15, 0x96,
343 0xe5, 0xdb, 0xda, 0xd4, 0x1d, 0x1f, 0x36, 0x23,
344 0xf4, 0x5d, 0x7a, 0x12, 0xdb, 0x7a, 0xfb, 0x23
345 }
346 }
347};
348
349
350static int run_gcmp(int idx, struct gcmp_test *vector)
351{
Jouni Malinen455bcc02012-09-08 20:00:54 +0300352 u8 *enc, *plain;
353 size_t enc_len, plain_len;
354 u8 fcs[4];
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200355 int err = 0;
Jouni Malinen455bcc02012-09-08 20:00:54 +0300356
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200357 wpa_printf(MSG_INFO,
358 "\nIEEE Std 802.11ad-2012, M.11.1 GCMP test mpdu #%d\n",
359 idx);
Jouni Malinen455bcc02012-09-08 20:00:54 +0300360
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200361 wpa_hexdump(MSG_INFO, "TK", vector->tk, sizeof(vector->tk));
362 wpa_hexdump(MSG_INFO, "PN", vector->pn, sizeof(vector->pn));
363 wpa_hexdump(MSG_INFO, "802.11 Header", vector->frame, vector->hdr_len);
364 wpa_hexdump(MSG_INFO, "Plaintext Data",
365 vector->frame + vector->hdr_len,
366 vector->payload_len);
Jouni Malinen455bcc02012-09-08 20:00:54 +0300367
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200368 enc = gcmp_encrypt(vector->tk, sizeof(vector->tk),
369 vector->frame,
370 vector->hdr_len + vector->payload_len,
371 vector->hdr_len,
372 vector->hdr_len == 26 ?
373 vector->frame + vector->hdr_len - 2 : NULL,
374 vector->pn, 0, &enc_len);
Jouni Malinen455bcc02012-09-08 20:00:54 +0300375 if (enc == NULL) {
376 wpa_printf(MSG_ERROR, "Failed to encrypt GCMP frame");
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200377 return 1;
Jouni Malinen455bcc02012-09-08 20:00:54 +0300378 }
379
380 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200381 if (os_memcmp(vector->encr, enc + vector->hdr_len + 8,
382 vector->payload_len) != 0) {
383 wpa_printf(MSG_ERROR, "GCMP test mpdu #%d enctypted data mismatch",
384 idx);
385 err++;
386 }
387 if (os_memcmp(vector->mic, enc + enc_len - sizeof(vector->mic),
388 sizeof(vector->mic)) != 0) {
389 wpa_printf(MSG_ERROR, "GCMP test mpdu #%d MIC mismatch", idx);
390 err++;
391 }
Jouni Malinen455bcc02012-09-08 20:00:54 +0300392 WPA_PUT_LE32(fcs, crc32(enc, enc_len));
393 wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
394
395 wpa_debug_level = MSG_INFO;
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200396 plain = gcmp_decrypt(vector->tk, sizeof(vector->tk),
397 (const struct ieee80211_hdr *) enc,
398 enc + vector->hdr_len,
399 enc_len - vector->hdr_len, &plain_len);
Jouni Malinenf1732952012-09-09 14:01:03 +0300400 wpa_debug_level = MSG_EXCESSIVE;
401 os_free(enc);
402
403 if (plain == NULL) {
404 wpa_printf(MSG_ERROR, "Failed to decrypt GCMP frame");
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200405 return 1;
Jouni Malinenf1732952012-09-09 14:01:03 +0300406 }
407
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200408 if (plain_len != vector->payload_len ||
409 os_memcmp(plain, vector->frame + vector->hdr_len, plain_len) != 0) {
Jouni Malinenf1732952012-09-09 14:01:03 +0300410 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
411 plain, plain_len);
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200412 err++;
Jouni Malinenf1732952012-09-09 14:01:03 +0300413 }
414
415 os_free(plain);
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200416
417 return err;
418}
419
420
421static int test_vector_gcmp(void)
422{
423 int err = 0;
424 int i;
425
426 for (i = 0; i < ARRAY_SIZE(gcmp_vectors); i++) {
427 if (run_gcmp(i + 1, &gcmp_vectors[i]))
428 err++;
429
430 }
431
432 return err;
Jouni Malinenf1732952012-09-09 14:01:03 +0300433}
434
435
Jouni Malinen0e913372013-11-17 20:32:32 +0200436static int test_vector_gcmp_256(void)
Jouni Malinenf1732952012-09-09 14:01:03 +0300437{
438 u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
439 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
440 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
441 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
442 u8 pn[] = {
443 0x00, 0x89, 0x5F, 0x5F, 0x2B, 0x08
444 };
445 u8 frame[] = {
446 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
447 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
448 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
449 0x03, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
450 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
451 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
452 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d,
453 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
454 0x26, 0x27
455 };
Jouni Malinen0e913372013-11-17 20:32:32 +0200456 u8 encr[] = {
457 0x88, 0x48, 0x0b, 0x00, 0x0f, 0xd2, 0xe1, 0x28,
458 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
459 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0x80, 0x33,
460 0x03, 0x00, 0x08, 0x2b, 0x00, 0x20, 0x5f, 0x5f,
461 0x89, 0x00, 0x65, 0x83, 0x43, 0xc8, 0xb1, 0x44,
462 0x47, 0xd9, 0x21, 0x1d, 0xef, 0xd4, 0x6a, 0xd8,
463 0x9c, 0x71, 0x0c, 0x6f, 0xc3, 0x33, 0x33, 0x23,
464 0x6e, 0x39, 0x97, 0xb9, 0x17, 0x6a, 0x5a, 0x8b,
465 0xe7, 0x79, 0xb2, 0x12, 0x66, 0x55, 0x5e, 0x70,
466 0xad, 0x79, 0x11, 0x43, 0x16, 0x85, 0x90, 0x95,
467 0x47, 0x3d, 0x5b, 0x1b, 0xd5, 0x96, 0xb3, 0xde,
468 0xa3, 0xbf
469 };
Jouni Malinenf1732952012-09-09 14:01:03 +0300470 u8 *enc, *plain;
471 size_t enc_len, plain_len;
472 u8 fcs[4];
Jouni Malinen0e913372013-11-17 20:32:32 +0200473 int err = 0;
Jouni Malinenf1732952012-09-09 14:01:03 +0300474
Jouni Malinen0e913372013-11-17 20:32:32 +0200475 wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.11.1 GCMP-256 test vector\n");
Jouni Malinenf1732952012-09-09 14:01:03 +0300476
477 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
478 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
479 wpa_hexdump(MSG_INFO, "802.11 Header", frame, 26);
480 wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 26, sizeof(frame) - 26);
481
482 enc = gcmp_encrypt(tk, sizeof(tk), frame, sizeof(frame), 26, frame + 24,
483 pn, 0, &enc_len);
484 if (enc == NULL) {
485 wpa_printf(MSG_ERROR, "Failed to encrypt GCMP frame");
Jouni Malinen0e913372013-11-17 20:32:32 +0200486 return 1;
Jouni Malinenf1732952012-09-09 14:01:03 +0300487 }
488
489 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
Jouni Malinen0e913372013-11-17 20:32:32 +0200490 if (enc_len != sizeof(encr) || os_memcmp(enc, encr, enc_len) != 0) {
491 wpa_printf(MSG_ERROR, "GCMP-256 test vector mismatch");
492 err++;
493 }
Jouni Malinenf1732952012-09-09 14:01:03 +0300494 WPA_PUT_LE32(fcs, crc32(enc, enc_len));
495 wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
496
497 wpa_debug_level = MSG_INFO;
498 plain = gcmp_decrypt(tk, sizeof(tk), (const struct ieee80211_hdr *) enc,
Jouni Malinen455bcc02012-09-08 20:00:54 +0300499 enc + 26, enc_len - 26, &plain_len);
500 wpa_debug_level = MSG_EXCESSIVE;
501 os_free(enc);
502
503 if (plain == NULL) {
504 wpa_printf(MSG_ERROR, "Failed to decrypt GCMP frame");
Jouni Malinen0e913372013-11-17 20:32:32 +0200505 return 1;
Jouni Malinen455bcc02012-09-08 20:00:54 +0300506 }
507
508 if (plain_len != sizeof(frame) - 26 ||
509 os_memcmp(plain, frame + 26, plain_len) != 0) {
510 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
511 plain, plain_len);
Jouni Malinen0e913372013-11-17 20:32:32 +0200512 err++;
Jouni Malinen455bcc02012-09-08 20:00:54 +0300513 }
514
515 os_free(plain);
Jouni Malinen0e913372013-11-17 20:32:32 +0200516
517 return err;
Jouni Malinen455bcc02012-09-08 20:00:54 +0300518}
519
520
Jouni Malinen0e913372013-11-17 20:32:32 +0200521static int test_vector_ccmp_256(void)
Jouni Malinen7d19d3e2012-09-09 18:38:18 +0300522{
523 u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
524 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f,
525 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
526 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
527 u8 pn[] = { 0xB5, 0x03, 0x97, 0x76, 0xE7, 0x0C };
528 u8 frame[] = {
529 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
530 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
531 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
532 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
533 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
534 0x7e, 0x78, 0xa0, 0x50
535 };
Jouni Malinen0e913372013-11-17 20:32:32 +0200536 u8 encr[] = {
537 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
538 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
539 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
540 0x0c, 0xe7, 0x00, 0x20, 0x76, 0x97, 0x03, 0xb5,
541 0x6d, 0x15, 0x5d, 0x88, 0x32, 0x66, 0x82, 0x56,
542 0xd6, 0xa9, 0x2b, 0x78, 0xe1, 0x1d, 0x8e, 0x54,
543 0x49, 0x5d, 0xd1, 0x74, 0x80, 0xaa, 0x56, 0xc9,
544 0x49, 0x2e, 0x88, 0x2b, 0x97, 0x64, 0x2f, 0x80,
545 0xd5, 0x0f, 0xe9, 0x7b
546
547 };
Jouni Malinen7d19d3e2012-09-09 18:38:18 +0300548 u8 *enc, *plain;
549 size_t enc_len, plain_len;
550 u8 fcs[4];
Jouni Malinen0e913372013-11-17 20:32:32 +0200551 int err = 0;
Jouni Malinen7d19d3e2012-09-09 18:38:18 +0300552
Jouni Malinen0e913372013-11-17 20:32:32 +0200553 wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.6.4 CCMP-256 test vector\n");
Jouni Malinen7d19d3e2012-09-09 18:38:18 +0300554
555 wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
556 wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
557 wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
558 wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
559
560 enc = ccmp_256_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0,
561 &enc_len);
562 if (enc == NULL) {
563 wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
Jouni Malinen0e913372013-11-17 20:32:32 +0200564 return 1;
Jouni Malinen7d19d3e2012-09-09 18:38:18 +0300565 }
566
567 wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
Jouni Malinen0e913372013-11-17 20:32:32 +0200568 if (enc_len != sizeof(encr) || os_memcmp(enc, encr, enc_len) != 0) {
569 wpa_printf(MSG_ERROR, "CCMP-256 test vector mismatch");
570 err++;
571 }
Jouni Malinen7d19d3e2012-09-09 18:38:18 +0300572 WPA_PUT_LE32(fcs, crc32(enc, enc_len));
573 wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
574
575 wpa_debug_level = MSG_INFO;
576 plain = ccmp_256_decrypt(tk, (const struct ieee80211_hdr *) enc,
577 enc + 24, enc_len - 24, &plain_len);
578 wpa_debug_level = MSG_EXCESSIVE;
579 os_free(enc);
580
581 if (plain == NULL) {
582 wpa_printf(MSG_ERROR, "Failed to decrypt CCMP-256 frame");
Jouni Malinen0e913372013-11-17 20:32:32 +0200583 return 1;
Jouni Malinen7d19d3e2012-09-09 18:38:18 +0300584 }
585
586 if (plain_len != sizeof(frame) - 24 ||
587 os_memcmp(plain, frame + 24, plain_len) != 0) {
588 wpa_hexdump(MSG_ERROR, "Decryption result did not match",
589 plain, plain_len);
Jouni Malinen0e913372013-11-17 20:32:32 +0200590 err++;
Jouni Malinen7d19d3e2012-09-09 18:38:18 +0300591 }
592
593 os_free(plain);
Jouni Malinen0e913372013-11-17 20:32:32 +0200594
595 return err;
Jouni Malinen7d19d3e2012-09-09 18:38:18 +0300596}
597
598
Jouni Malinen0e913372013-11-17 20:32:32 +0200599static int test_vector_bip_gmac_128(void)
Jouni Malinene88f0902012-09-09 19:04:53 +0300600{
601 u8 igtk[] = {
602 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
603 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf
604 };
605 u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
606 u8 frame[] = {
607 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
608 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
609 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
610 0x02, 0x00
611 };
Jouni Malinen0e913372013-11-17 20:32:32 +0200612 u8 res[] = {
613 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
614 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
615 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
616 0x02, 0x00, 0x4c, 0x18, 0x04, 0x00, 0x04, 0x00,
617 0x00, 0x00, 0x00, 0x00, 0x3e, 0xd8, 0x62, 0xfb,
618 0x0f, 0x33, 0x38, 0xdd, 0x33, 0x86, 0xc8, 0x97,
619 0xe2, 0xed, 0x05, 0x3d
620 };
Jouni Malinene88f0902012-09-09 19:04:53 +0300621 u8 *prot;
622 size_t prot_len;
Jouni Malinen0e913372013-11-17 20:32:32 +0200623 int err = 0;
Jouni Malinene88f0902012-09-09 19:04:53 +0300624
Jouni Malinen0e913372013-11-17 20:32:32 +0200625 wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.9.1 BIP-GMAC-128 with broadcast "
Jouni Malinene88f0902012-09-09 19:04:53 +0300626 "Deauthentication frame\n");
627
628 wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
629 wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
630 wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
631
632 prot = bip_gmac_protect(igtk, sizeof(igtk), frame, sizeof(frame),
633 ipn, 4, &prot_len);
634 if (prot == NULL) {
635 wpa_printf(MSG_ERROR, "Failed to protect BIP-GMAC-128 frame");
Jouni Malinen0e913372013-11-17 20:32:32 +0200636 return 1;
Jouni Malinene88f0902012-09-09 19:04:53 +0300637 }
638
639 wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
Jouni Malinen0e913372013-11-17 20:32:32 +0200640 if (prot_len != sizeof(res) || os_memcmp(res, prot, prot_len) != 0) {
641 wpa_printf(MSG_ERROR, "BIP-GMAC-128 test vector mismatch");
642 err++;
643 }
Jouni Malinene88f0902012-09-09 19:04:53 +0300644 os_free(prot);
Jouni Malinen0e913372013-11-17 20:32:32 +0200645
646 return err;
Jouni Malinene88f0902012-09-09 19:04:53 +0300647}
648
649
Jouni Malinen0e913372013-11-17 20:32:32 +0200650static int test_vector_bip_gmac_256(void)
Jouni Malinene88f0902012-09-09 19:04:53 +0300651{
652 u8 igtk[] = {
653 0x4e, 0xa9, 0x54, 0x3e, 0x09, 0xcf, 0x2b, 0x1e,
654 0xca, 0x66, 0xff, 0xc5, 0x8b, 0xde, 0xcb, 0xcf,
655 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
656 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
657 };
658 u8 ipn[] = { 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };
659 u8 frame[] = {
660 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
661 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
662 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
663 0x02, 0x00
664 };
Jouni Malinen0e913372013-11-17 20:32:32 +0200665 u8 res[] = {
666 0xc0, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
667 0xff, 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
668 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x09, 0x00,
669 0x02, 0x00, 0x4c, 0x18, 0x04, 0x00, 0x04, 0x00,
670 0x00, 0x00, 0x00, 0x00, 0x23, 0xbe, 0x59, 0xdc,
671 0xc7, 0x02, 0x2e, 0xe3, 0x83, 0x62, 0x7e, 0xbb,
672 0x10, 0x17, 0xdd, 0xfc
673 };
Jouni Malinene88f0902012-09-09 19:04:53 +0300674 u8 *prot;
675 size_t prot_len;
Jouni Malinen0e913372013-11-17 20:32:32 +0200676 int err = 0;
Jouni Malinene88f0902012-09-09 19:04:53 +0300677
Jouni Malinen0e913372013-11-17 20:32:32 +0200678 wpa_printf(MSG_INFO, "\nIEEE P802.11ac/D7.0, M.9.1 BIP-GMAC-256 with broadcast Deauthentication frame\n");
Jouni Malinene88f0902012-09-09 19:04:53 +0300679
680 wpa_hexdump(MSG_INFO, "IGTK", igtk, sizeof(igtk));
681 wpa_hexdump(MSG_INFO, "IPN", ipn, sizeof(ipn));
682 wpa_hexdump(MSG_INFO, "Plaintext frame", frame, sizeof(frame));
683
684 prot = bip_gmac_protect(igtk, sizeof(igtk), frame, sizeof(frame),
685 ipn, 4, &prot_len);
686 if (prot == NULL) {
687 wpa_printf(MSG_ERROR, "Failed to protect BIP-GMAC-256 frame");
Jouni Malinen0e913372013-11-17 20:32:32 +0200688 return 1;
Jouni Malinene88f0902012-09-09 19:04:53 +0300689 }
690
691 wpa_hexdump(MSG_INFO, "Protected MPDU (without FCS)", prot, prot_len);
Jouni Malinen0e913372013-11-17 20:32:32 +0200692 if (prot_len != sizeof(res) || os_memcmp(res, prot, prot_len) != 0) {
693 wpa_printf(MSG_ERROR, "BIP-GMAC-128 test vector mismatch");
694 err++;
695 }
Jouni Malinene88f0902012-09-09 19:04:53 +0300696 os_free(prot);
Jouni Malinen0e913372013-11-17 20:32:32 +0200697
698 return err;
Jouni Malinene88f0902012-09-09 19:04:53 +0300699}
700
701
Jouni Malinen3ae89682012-09-08 14:03:43 +0300702int main(int argc, char *argv[])
703{
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200704 int errors = 0;
705
Jouni Malinen3ae89682012-09-08 14:03:43 +0300706 wpa_debug_level = MSG_EXCESSIVE;
707 wpa_debug_show_keys = 1;
708
709 if (os_program_init())
710 return -1;
711
712 test_vector_tkip();
713 test_vector_ccmp();
Jouni Malinen7d682412012-09-08 16:43:11 +0300714 test_vector_bip();
Jouni Malinen65229842012-09-08 16:21:57 +0300715 test_vector_ccmp_mgmt();
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200716 errors += test_vector_gcmp();
Jouni Malinen0e913372013-11-17 20:32:32 +0200717 errors += test_vector_gcmp_256();
718 errors += test_vector_ccmp_256();
719 errors += test_vector_bip_gmac_128();
720 errors += test_vector_bip_gmac_256();
Jouni Malinen3ae89682012-09-08 14:03:43 +0300721
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200722 if (errors)
723 wpa_printf(MSG_INFO, "One or more test vectors failed");
Jouni Malinen3ae89682012-09-08 14:03:43 +0300724 os_program_deinit();
725
Jouni Malinen84a65fd2013-11-17 20:23:51 +0200726 return errors ? -1 : 0;
Jouni Malinen3ae89682012-09-08 14:03:43 +0300727}