wlantest: Add IEEE Std 802.11-2012, M.9.2 CCMP (mgmt) test vector
[mech_eap.git] / wlantest / test_vectors.c
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
16 extern int wpa_debug_level;
17 extern int wpa_debug_show_keys;
18
19
20 static 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         };
48         u8 *enc;
49         size_t enc_len;
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);
65         os_free(enc);
66 }
67
68
69 static void test_vector_ccmp(void)
70 {
71         u8 tk[] = { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85,
72                     0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f };
73         u8 pn[] = { 0xB5, 0x03, 0x97, 0x76, 0xE7, 0x0C };
74         u8 frame[] = {
75                 0x08, 0x48, 0xc3, 0x2c, 0x0f, 0xd2, 0xe1, 0x28,
76                 0xa5, 0x7c, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08,
77                 0xab, 0xae, 0xa5, 0xb8, 0xfc, 0xba, 0x80, 0x33,
78                 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae,
79                 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb,
80                 0x7e, 0x78, 0xa0, 0x50
81         };
82         u8 *enc;
83         size_t enc_len;
84         u8 fcs[4];
85
86         wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.6.4 CCMP test "
87                    "vector\n");
88
89         wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
90         wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
91         wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
92         wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
93
94         enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
95         if (enc == NULL) {
96                 wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
97                 return;
98         }
99
100         wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
101         WPA_PUT_LE32(fcs, crc32(enc, enc_len));
102         wpa_hexdump(MSG_INFO, "FCS", fcs, sizeof(fcs));
103         os_free(enc);
104 }
105
106
107 static void test_vector_ccmp_mgmt(void)
108 {
109         u8 tk[] = { 0x66, 0xed, 0x21, 0x04, 0x2f, 0x9f, 0x26, 0xd7,
110                     0x11, 0x57, 0x06, 0xe4, 0x04, 0x14, 0xcf, 0x2e };
111         u8 pn[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 };
112         u8 frame[] = {
113                 0xc0, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
114                 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
115                 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00,
116                 0x02, 0x00
117         };
118         u8 *enc;
119         size_t enc_len;
120
121         wpa_printf(MSG_INFO, "\nIEEE Std 802.11-2012, M.9.2 CCMP with unicast "
122                    "Deauthentication frame\n");
123
124         wpa_hexdump(MSG_INFO, "TK", tk, sizeof(tk));
125         wpa_hexdump(MSG_INFO, "PN", pn, sizeof(pn));
126         wpa_hexdump(MSG_INFO, "802.11 Header", frame, 24);
127         wpa_hexdump(MSG_INFO, "Plaintext Data", frame + 24, sizeof(frame) - 24);
128
129         enc = ccmp_encrypt(tk, frame, sizeof(frame), 24, NULL, pn, 0, &enc_len);
130         if (enc == NULL) {
131                 wpa_printf(MSG_ERROR, "Failed to encrypt CCMP frame");
132                 return;
133         }
134
135         wpa_hexdump(MSG_INFO, "Encrypted MPDU (without FCS)", enc, enc_len);
136         os_free(enc);
137 }
138
139
140 int main(int argc, char *argv[])
141 {
142         wpa_debug_level = MSG_EXCESSIVE;
143         wpa_debug_show_keys = 1;
144
145         if (os_program_init())
146                 return -1;
147
148         test_vector_tkip();
149         test_vector_ccmp();
150         test_vector_ccmp_mgmt();
151
152         os_program_deinit();
153
154         return 0;
155 }