eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

test-eapol.c (146268B)


      1 /*
      2  *
      3  *  Wireless daemon for Linux
      4  *
      5  *  Copyright (C) 2013-2019  Intel Corporation. All rights reserved.
      6  *
      7  *  This library is free software; you can redistribute it and/or
      8  *  modify it under the terms of the GNU Lesser General Public
      9  *  License as published by the Free Software Foundation; either
     10  *  version 2.1 of the License, or (at your option) any later version.
     11  *
     12  *  This library is distributed in the hope that it will be useful,
     13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     15  *  Lesser General Public License for more details.
     16  *
     17  *  You should have received a copy of the GNU Lesser General Public
     18  *  License along with this library; if not, write to the Free Software
     19  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
     20  *
     21  */
     22 
     23 #ifdef HAVE_CONFIG_H
     24 #include <config.h>
     25 #endif
     26 
     27 #include <stdio.h>
     28 #include <string.h>
     29 #include <assert.h>
     30 #include <sys/stat.h>
     31 #include <linux/if_ether.h>
     32 #include <ell/ell.h>
     33 
     34 #include "src/util.h"
     35 #include "src/eapol.h"
     36 #include "src/crypto.h"
     37 #include "src/ie.h"
     38 #include "src/eap.h"
     39 #include "src/eap-private.h"
     40 #include "src/handshake.h"
     41 
     42 /* Our nonce to use + its size */
     43 static const uint8_t *snonce;
     44 
     45 /* Whether step2 was called with the right info */
     46 static bool verify_step2_called;
     47 /* PTK Handshake 2-of-4 frame we are expected to generate + its size */
     48 static const uint8_t *expected_step2_frame;
     49 static size_t expected_step2_frame_size;
     50 
     51 /* Whether step4 was called with the right info */
     52 static bool verify_step4_called;
     53 /* Whether install_tk was called with the right info */
     54 static bool verify_install_tk_called;
     55 static bool verify_install_gtk_called;
     56 /* PTK Handshake 4-of-4 frame we are expected to generate + its size */
     57 static const uint8_t *expected_step4_frame;
     58 static size_t expected_step4_frame_size;
     59 
     60 /* Whether GTK step2 was called with the right info */
     61 static bool verify_gtk_step2_called;
     62 /* GTK Handshake 2-of-2 frame we are expected to generate + its size */
     63 static const uint8_t *expected_gtk_step2_frame;
     64 static size_t expected_gtk_step2_frame_size;
     65 
     66 /* Authenticator Address */
     67 static const uint8_t *aa;
     68 /* Supplicant Address */
     69 static const uint8_t *spa;
     70 
     71 static void tls_debug(const char *str, void *user_data)
     72 {
     73 	l_info("%s", str);
     74 }
     75 
     76 struct test_handshake_state {
     77 	struct handshake_state super;
     78 	const uint8_t *tk;
     79 	bool handshake_failed;
     80 };
     81 
     82 static void test_handshake_state_free(struct handshake_state *hs)
     83 {
     84 	struct test_handshake_state *ths =
     85 			l_container_of(hs, struct test_handshake_state, super);
     86 
     87 	l_free(ths);
     88 }
     89 
     90 static struct handshake_state *test_handshake_state_new(uint32_t ifindex)
     91 {
     92 	struct test_handshake_state *ths;
     93 
     94 	ths = l_new(struct test_handshake_state, 1);
     95 
     96 	ths->super.ifindex = ifindex;
     97 	ths->super.free = test_handshake_state_free;
     98 	ths->super.refcount = 1;
     99 
    100 	return &ths->super;
    101 }
    102 
    103 struct eapol_key_data {
    104 	const unsigned char *frame;
    105 	size_t frame_len;
    106 	enum eapol_protocol_version protocol_version;
    107 	uint16_t packet_len;
    108 	enum eapol_descriptor_type descriptor_type;
    109 	enum eapol_key_descriptor_version key_descriptor_version;
    110 	bool key_type:1;
    111 	uint8_t wpa_key_id:2;
    112 	bool install:1;
    113 	bool key_ack:1;
    114 	bool key_mic:1;
    115 	bool secure:1;
    116 	bool error:1;
    117 	bool request:1;
    118 	bool encrypted_key_data:1;
    119 	bool smk_message:1;
    120 	uint16_t key_length;
    121 	uint64_t key_replay_counter;
    122 	uint8_t key_nonce[32];
    123 	uint8_t eapol_key_iv[16];
    124 	uint8_t key_rsc[8];
    125 	uint8_t key_mic_data[16];
    126 	uint16_t key_data_len;
    127 };
    128 
    129 /* Random WPA EAPoL frame, using 2001 protocol */
    130 static const unsigned char eapol_key_data_1[] = {
    131 	0x01, 0x03, 0x00, 0x5f, 0xfe, 0x00, 0x89, 0x00, 0x20, 0x00, 0x00, 0x00,
    132 	0x00, 0x00, 0x00, 0x00, 0x01, 0xd5, 0xe2, 0x13, 0x9b, 0x1b, 0x1c, 0x1e,
    133 	0xcb, 0xf4, 0xc7, 0x9d, 0xb3, 0x70, 0xcd, 0x1c, 0xea, 0x07, 0xf1, 0x61,
    134 	0x76, 0xed, 0xa6, 0x78, 0x8a, 0xc6, 0x8c, 0x2c, 0xf4, 0xd7, 0x6f, 0x2b,
    135 	0xf7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    136 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    137 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    138 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    139 	0x00, 0x00, 0x00,
    140 };
    141 
    142 static struct eapol_key_data eapol_key_test_1 = {
    143 	.frame = eapol_key_data_1,
    144 	.frame_len = sizeof(eapol_key_data_1),
    145 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
    146 	.packet_len = 95,
    147 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
    148 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
    149 	.key_type = true,
    150 	.install = false,
    151 	.key_ack = true,
    152 	.key_mic = false,
    153 	.secure = false,
    154 	.error = false,
    155 	.request = false,
    156 	.encrypted_key_data = false,
    157 	.smk_message = false,
    158 	.key_length = 32,
    159 	.key_replay_counter = 1,
    160 	.key_nonce = { 0xd5, 0xe2, 0x13, 0x9b, 0x1b, 0x1c, 0x1e, 0xcb, 0xf4,
    161 			0xc7, 0x9d, 0xb3, 0x70, 0xcd, 0x1c, 0xea, 0x07, 0xf1,
    162 			0x61, 0x76, 0xed, 0xa6, 0x78, 0x8a, 0xc6, 0x8c, 0x2c,
    163 			0xf4, 0xd7, 0x6f, 0x2b, 0xf7 },
    164 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    165 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    166 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    167 	.key_mic_data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    168 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    169 	.key_data_len = 0,
    170 };
    171 
    172 /* Random WPA2 EAPoL frame, using 2004 protocol */
    173 static const unsigned char eapol_key_data_2[] = {
    174 	0x02, 0x03, 0x00, 0x75, 0x02, 0x00, 0x8a, 0x00, 0x10, 0x00, 0x00, 0x00,
    175 	0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x6a, 0xce, 0x64, 0xc1, 0xa6, 0x44,
    176 	0xd2, 0x7b, 0x84, 0xe0, 0x39, 0x26, 0x3b, 0x63, 0x3b, 0xc3, 0x74, 0xe3,
    177 	0x29, 0x9d, 0x7d, 0x45, 0xe1, 0xc4, 0x25, 0x44, 0x05, 0x48, 0x05, 0xbf,
    178 	0xe5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    179 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    180 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    181 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    182 	0x00, 0x00, 0x16, 0xdd, 0x14, 0x00, 0x0f, 0xac, 0x04, 0x05, 0xb1, 0xb6,
    183 	0x8b, 0x5a, 0x91, 0xfc, 0x04, 0x06, 0x83, 0x84, 0x06, 0xe8, 0xd1, 0x5f,
    184 	0xdb,
    185 };
    186 
    187 static struct eapol_key_data eapol_key_test_2 = {
    188 	.frame = eapol_key_data_2,
    189 	.frame_len = sizeof(eapol_key_data_2),
    190 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    191 	.packet_len = 117,
    192 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    193 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    194 	.key_type = true,
    195 	.install = false,
    196 	.key_ack = true,
    197 	.key_mic = false,
    198 	.secure = false,
    199 	.error = false,
    200 	.request = false,
    201 	.encrypted_key_data = false,
    202 	.smk_message = false,
    203 	.key_length = 16,
    204 	.key_replay_counter = 0,
    205 	.key_nonce = { 0x12, 0x6a, 0xce, 0x64, 0xc1, 0xa6, 0x44, 0xd2, 0x7b,
    206 			0x84, 0xe0, 0x39, 0x26, 0x3b, 0x63, 0x3b, 0xc3, 0x74,
    207 			0xe3, 0x29, 0x9d, 0x7d, 0x45, 0xe1, 0xc4, 0x25, 0x44,
    208 			0x05, 0x48, 0x05, 0xbf, 0xe5 },
    209 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    210 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    211 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    212 	.key_mic_data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    213 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    214 	.key_data_len = 22,
    215 };
    216 
    217 /* WPA2 frame, 1 of 4.  For parameters see eapol_4way_test */
    218 static const unsigned char eapol_key_data_3[] = {
    219 	0x02, 0x03, 0x00, 0x5f, 0x02, 0x00, 0x8a, 0x00, 0x10, 0x00, 0x00, 0x00,
    220 	0x00, 0x00, 0x00, 0x00, 0x00, 0xc2, 0xbb, 0x57, 0xab, 0x58, 0x8f, 0x92,
    221 	0xeb, 0xbd, 0x44, 0xe8, 0x11, 0x09, 0x4f, 0x60, 0x1c, 0x08, 0x79, 0x86,
    222 	0x03, 0x0c, 0x3a, 0xc7, 0x49, 0xcc, 0x61, 0xd6, 0x3e, 0x33, 0x83, 0x2e,
    223 	0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    224 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    225 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    226 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    227 	0x00, 0x00, 0x00
    228 };
    229 
    230 static struct eapol_key_data eapol_key_test_3 = {
    231 	.frame = eapol_key_data_3,
    232 	.frame_len = sizeof(eapol_key_data_3),
    233 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    234 	.packet_len = 95,
    235 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    236 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    237 	.key_type = true,
    238 	.install = false,
    239 	.key_ack = true,
    240 	.key_mic = false,
    241 	.secure = false,
    242 	.error = false,
    243 	.request = false,
    244 	.encrypted_key_data = false,
    245 	.smk_message = false,
    246 	.key_length = 16,
    247 	.key_replay_counter = 0,
    248 	.key_nonce = { 0xc2, 0xbb, 0x57, 0xab, 0x58, 0x8f, 0x92, 0xeb, 0xbd,
    249 			0x44, 0xe8, 0x11, 0x09, 0x4f, 0x60, 0x1c, 0x08, 0x79,
    250 			0x86, 0x03, 0x0c, 0x3a, 0xc7, 0x49, 0xcc, 0x61, 0xd6,
    251 			0x3e, 0x33, 0x83, 0x2e, 0x50, },
    252 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    253 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    254 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    255 	.key_mic_data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    256 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    257 	.key_data_len = 0,
    258 };
    259 
    260 /* WPA2 frame, 2 of 4.  For parameters see eapol_4way_test */
    261 static const unsigned char eapol_key_data_4[] = {
    262 	0x01, 0x03, 0x00, 0x75, 0x02, 0x01, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
    263 	0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x89, 0xe9, 0x15, 0x65, 0x09, 0x4f,
    264 	0x32, 0x9a, 0x9c, 0xd5, 0x4a, 0x4a, 0x09, 0x0d, 0x2c, 0xf4, 0x34, 0x46,
    265 	0x83, 0xbf, 0x50, 0xef, 0xee, 0x36, 0x08, 0xb6, 0x48, 0x56, 0x80, 0x0e,
    266 	0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    267 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    268 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xc3, 0x1b,
    269 	0x82, 0xff, 0x62, 0xa3, 0x79, 0xb0, 0x8d, 0xd1, 0xfc, 0x82, 0xc2, 0xf7,
    270 	0x68, 0x00, 0x16, 0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01,
    271 	0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x02, 0x00,
    272 	0x00
    273 };
    274 
    275 static struct eapol_key_data eapol_key_test_4 = {
    276 	.frame = eapol_key_data_4,
    277 	.frame_len = sizeof(eapol_key_data_4),
    278 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
    279 	.packet_len = 117,
    280 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    281 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    282 	.key_type = true,
    283 	.install = false,
    284 	.key_ack = false,
    285 	.key_mic = true,
    286 	.secure = false,
    287 	.error = false,
    288 	.request = false,
    289 	.encrypted_key_data = false,
    290 	.smk_message = false,
    291 	.key_length = 0,
    292 	.key_replay_counter = 0,
    293 	.key_nonce = { 0x32, 0x89, 0xe9, 0x15, 0x65, 0x09, 0x4f, 0x32, 0x9a,
    294 			0x9c, 0xd5, 0x4a, 0x4a, 0x09, 0x0d, 0x2c, 0xf4, 0x34,
    295 			0x46, 0x83, 0xbf, 0x50, 0xef, 0xee, 0x36, 0x08, 0xb6,
    296 			0x48, 0x56, 0x80, 0x0e, 0x84, },
    297 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    298 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    299 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    300 	.key_mic_data = { 0x01, 0xc3, 0x1b, 0x82, 0xff, 0x62, 0xa3, 0x79, 0xb0,
    301 				0x8d, 0xd1, 0xfc, 0x82, 0xc2, 0xf7, 0x68 },
    302 	.key_data_len = 22,
    303 };
    304 
    305 /* WPA2 frame, 3 of 4.  For parameters see eapol_4way_test */
    306 static const unsigned char eapol_key_data_5[] = {
    307 	0x02, 0x03, 0x00, 0x97, 0x02, 0x13, 0xca, 0x00, 0x10, 0x00, 0x00, 0x00,
    308 	0x00, 0x00, 0x00, 0x00, 0x01, 0xc2, 0xbb, 0x57, 0xab, 0x58, 0x8f, 0x92,
    309 	0xeb, 0xbd, 0x44, 0xe8, 0x11, 0x09, 0x4f, 0x60, 0x1c, 0x08, 0x79, 0x86,
    310 	0x03, 0x0c, 0x3a, 0xc7, 0x49, 0xcc, 0x61, 0xd6, 0x3e, 0x33, 0x83, 0x2e,
    311 	0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    312 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    313 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf5, 0x35, 0xd9,
    314 	0x18, 0x09, 0x73, 0x1a, 0x1d, 0x29, 0x08, 0x94, 0x70, 0x5e, 0x91, 0x9c,
    315 	0x8e, 0x00, 0x38, 0x19, 0x18, 0xdf, 0x1e, 0xf0, 0xe7, 0x69, 0x66, 0x52,
    316 	0xe2, 0x57, 0x93, 0x80, 0x34, 0xe1, 0x70, 0x38, 0xb9, 0x8b, 0x4c, 0x45,
    317 	0xa9, 0x23, 0xb7, 0xb6, 0xfa, 0x8c, 0x33, 0xe3, 0x7b, 0xdc, 0xd4, 0x7f,
    318 	0xea, 0xb1, 0x1c, 0x22, 0x6a, 0x2c, 0x5e, 0x38, 0xd5, 0xad, 0x79, 0x94,
    319 	0x05, 0xd6, 0x10, 0xa6, 0x95, 0x51, 0xd6, 0x0b, 0xe6, 0x0a, 0x5b,
    320 };
    321 
    322 static struct eapol_key_data eapol_key_test_5 = {
    323 	.frame = eapol_key_data_5,
    324 	.frame_len = sizeof(eapol_key_data_5),
    325 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    326 	.packet_len = 151,
    327 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    328 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    329 	.key_type = true,
    330 	.install = true,
    331 	.key_ack = true,
    332 	.key_mic = true,
    333 	.secure = true,
    334 	.error = false,
    335 	.request = false,
    336 	.encrypted_key_data = true,
    337 	.smk_message = false,
    338 	.key_length = 16,
    339 	.key_replay_counter = 1,
    340 	.key_nonce = { 0xc2, 0xbb, 0x57, 0xab, 0x58, 0x8f, 0x92, 0xeb, 0xbd,
    341 			0x44, 0xe8, 0x11, 0x09, 0x4f, 0x60, 0x1c, 0x08, 0x79,
    342 			0x86, 0x03, 0x0c, 0x3a, 0xc7, 0x49, 0xcc, 0x61, 0xd6,
    343 			0x3e, 0x33, 0x83, 0x2e, 0x50, },
    344 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    345 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    346 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    347 	.key_mic_data = { 0xf5, 0x35, 0xd9, 0x18, 0x09, 0x73, 0x1a, 0x1d, 0x29,
    348 				0x08, 0x94, 0x70, 0x5e, 0x91, 0x9c, 0x8e },
    349 	.key_data_len = 56,
    350 };
    351 
    352 /* WPA2 frame, 4 of 4.  For parameters see eapol_4way_test */
    353 static const unsigned char eapol_key_data_6[] = {
    354 	0x01, 0x03, 0x00, 0x5f, 0x02, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
    355 	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    356 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    357 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    358 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    359 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    360 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9e, 0x57, 0xa4,
    361 	0xc0, 0x9b, 0xaf, 0xb3, 0x37, 0x5e, 0x46, 0xd3, 0x86, 0xcf, 0x87, 0x27,
    362 	0x53, 0x00, 0x00,
    363 };
    364 
    365 static struct eapol_key_data eapol_key_test_6 = {
    366 	.frame = eapol_key_data_6,
    367 	.frame_len = sizeof(eapol_key_data_6),
    368 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
    369 	.packet_len = 95,
    370 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    371 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    372 	.key_type = true,
    373 	.install = false,
    374 	.key_ack = false,
    375 	.key_mic = true,
    376 	.secure = true,
    377 	.error = false,
    378 	.request = false,
    379 	.encrypted_key_data = false,
    380 	.smk_message = false,
    381 	.key_length = 0,
    382 	.key_replay_counter = 1,
    383 	.key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    384 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    385 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    386 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    387 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    388 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    389 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    390 	.key_mic_data = { 0x9e, 0x57, 0xa4, 0xc0, 0x9b, 0xaf, 0xb3, 0x37, 0x5e,
    391 				0x46, 0xd3, 0x86, 0xcf, 0x87, 0x27, 0x53, },
    392 	.key_data_len = 0,
    393 };
    394 
    395 /* WPA2 frame, 1 of 4.  For parameters see eapol_wpa2_handshake_test */
    396 static const unsigned char eapol_key_data_7[] = {
    397 	0x02, 0x03, 0x00, 0x5f, 0x02, 0x00, 0x8a, 0x00, 0x10, 0x00, 0x00, 0x00,
    398 	0x00, 0x00, 0x00, 0x00, 0x01, 0x2b, 0x58, 0x52, 0xb8, 0x8e, 0x4c, 0xa3,
    399 	0x4d, 0xc5, 0x99, 0xed, 0x20, 0x2c, 0x63, 0x95, 0x7c, 0x53, 0x5e, 0x3e,
    400 	0xfa, 0x92, 0x89, 0x87, 0x34, 0x11, 0x12, 0x7c, 0xba, 0xf3, 0x58, 0x84,
    401 	0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    402 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    403 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    404 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    405 	0x00, 0x00, 0x00
    406 };
    407 
    408 static struct eapol_key_data eapol_key_test_7 = {
    409 	.frame = eapol_key_data_7,
    410 	.frame_len = sizeof(eapol_key_data_7),
    411 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    412 	.packet_len = 95,
    413 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    414 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    415 	.key_type = true,
    416 	.wpa_key_id = 0,
    417 	.install = false,
    418 	.key_ack = true,
    419 	.key_mic = false,
    420 	.secure = false,
    421 	.error = false,
    422 	.request = false,
    423 	.encrypted_key_data = false,
    424 	.smk_message = false,
    425 	.key_length = 16,
    426 	.key_replay_counter = 1,
    427 	.key_nonce = { 0x2b, 0x58, 0x52, 0xb8, 0x8e, 0x4c, 0xa3, 0x4d, 0xc5,
    428 			0x99, 0xed, 0x20, 0x2c, 0x63, 0x95, 0x7c, 0x53, 0x5e,
    429 			0x3e, 0xfa, 0x92, 0x89, 0x87, 0x34, 0x11, 0x12, 0x7c,
    430 			0xba, 0xf3, 0x58, 0x84, 0x25 },
    431 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    432 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    433 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    434 	.key_mic_data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    435 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    436 	.key_data_len = 0,
    437 };
    438 
    439 /* WPA2 frame, 2 of 4.  For parameters see eapol_wpa2_handshake_test */
    440 static const unsigned char eapol_key_data_8[] = {
    441 	0x02, 0x03, 0x00, 0x73, 0x02, 0x01, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
    442 	0x00, 0x00, 0x00, 0x00, 0x01, 0x72, 0x7c, 0x65, 0x6c, 0x5e, 0xd6, 0x42,
    443 	0xd7, 0xf4, 0x7f, 0x48, 0x43, 0x51, 0xd8, 0x08, 0x94, 0x51, 0x18, 0xda,
    444 	0x6a, 0x49, 0x33, 0xac, 0x7e, 0x29, 0x3f, 0x2f, 0x2a, 0xc0, 0x88, 0x34,
    445 	0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    446 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    447 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7d, 0x7c, 0x45,
    448 	0x98, 0x9f, 0x49, 0x2b, 0x4a, 0x36, 0x58, 0x35, 0x29, 0x28, 0x2d, 0x8f,
    449 	0xed, 0x00, 0x14, 0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01,
    450 	0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x02
    451 };
    452 
    453 static struct eapol_key_data eapol_key_test_8 = {
    454 	.frame = eapol_key_data_8,
    455 	.frame_len = sizeof(eapol_key_data_8),
    456 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    457 	.packet_len = 115,
    458 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    459 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    460 	.key_type = true,
    461 	.wpa_key_id = 0,
    462 	.install = false,
    463 	.key_ack = false,
    464 	.key_mic = true,
    465 	.secure = false,
    466 	.error = false,
    467 	.request = false,
    468 	.encrypted_key_data = false,
    469 	.smk_message = false,
    470 	.key_length = 0,
    471 	.key_replay_counter = 1,
    472 	.key_nonce = { 0x72, 0x7c, 0x65, 0x6c, 0x5e, 0xd6, 0x42, 0xd7, 0xf4,
    473 			0x7f, 0x48, 0x43, 0x51, 0xd8, 0x08, 0x94, 0x51, 0x18,
    474 			0xda, 0x6a, 0x49, 0x33, 0xac, 0x7e, 0x29, 0x3f, 0x2f,
    475 			0x2a, 0xc0, 0x88, 0x34, 0x8c },
    476 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    477 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    478 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    479 	.key_mic_data = { 0x7d, 0x7c, 0x45, 0x98, 0x9f, 0x49, 0x2b, 0x4a,
    480 			0x36, 0x58, 0x35, 0x29, 0x28, 0x2d, 0x8f, 0xed },
    481 	.key_data_len = 20,
    482 };
    483 
    484 /* WPA2 frame, 3 of 4.  For parameters see eapol_wpa2_handshake_test */
    485 static const unsigned char eapol_key_data_9[] = {
    486 	0x02, 0x03, 0x00, 0x97, 0x02, 0x13, 0xca, 0x00, 0x10, 0x00, 0x00, 0x00,
    487 	0x00, 0x00, 0x00, 0x00, 0x02, 0x2b, 0x58, 0x52, 0xb8, 0x8e, 0x4c, 0xa3,
    488 	0x4d, 0xc5, 0x99, 0xed, 0x20, 0x2c, 0x63, 0x95, 0x7c, 0x53, 0x5e, 0x3e,
    489 	0xfa, 0x92, 0x89, 0x87, 0x34, 0x11, 0x12, 0x7c, 0xba, 0xf3, 0x58, 0x84,
    490 	0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    491 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    492 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x62, 0x6a,
    493 	0x57, 0x76, 0xc7, 0x33, 0xbf, 0xc0, 0x71, 0xde, 0x62, 0xeb, 0xf7, 0xa7,
    494 	0xc5, 0x00, 0x38, 0x14, 0xdd, 0x52, 0x80, 0x3d, 0xc8, 0x3d, 0xf7, 0xba,
    495 	0x7e, 0xb6, 0x48, 0x29, 0x6d, 0x65, 0x0e, 0x88, 0xcc, 0xc8, 0xdd, 0x67,
    496 	0x62, 0x04, 0xa2, 0xc7, 0xc1, 0xf2, 0x65, 0x0b, 0xca, 0xf9, 0x6b, 0x66,
    497 	0xf5, 0xb4, 0x3d, 0x99, 0x26, 0xad, 0xc5, 0xce, 0x18, 0xc0, 0xa9, 0x9b,
    498 	0xe5, 0x0e, 0x50, 0x85, 0x84, 0xb1, 0x57, 0xe3, 0x7a, 0x5e, 0x0f
    499 };
    500 
    501 static struct eapol_key_data eapol_key_test_9 = {
    502 	.frame = eapol_key_data_9,
    503 	.frame_len = sizeof(eapol_key_data_9),
    504 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    505 	.packet_len = 151,
    506 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    507 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    508 	.key_type = true,
    509 	.wpa_key_id = 0,
    510 	.install = true,
    511 	.key_ack = true,
    512 	.key_mic = true,
    513 	.secure = true,
    514 	.error = false,
    515 	.request = false,
    516 	.encrypted_key_data = true,
    517 	.smk_message = false,
    518 	.key_length = 16,
    519 	.key_replay_counter = 2,
    520 	.key_nonce = { 0x2b, 0x58, 0x52, 0xb8, 0x8e, 0x4c, 0xa3, 0x4d, 0xc5,
    521 			0x99, 0xed, 0x20, 0x2c, 0x63, 0x95, 0x7c, 0x53, 0x5e,
    522 			0x3e, 0xfa, 0x92, 0x89, 0x87, 0x34, 0x11, 0x12, 0x7c,
    523 			0xba, 0xf3, 0x58, 0x84, 0x25 },
    524 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    525 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    526 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    527 	.key_mic_data = { 0xf8, 0x62, 0x6a, 0x57, 0x76, 0xc7, 0x33, 0xbf,
    528 			0xc0, 0x71, 0xde, 0x62, 0xeb, 0xf7, 0xa7, 0xc5 },
    529 	.key_data_len = 56,
    530 };
    531 
    532 /* WPA2 frame, 4 of 4.  For parameters see eapol_wpa2_handshake_test */
    533 static const unsigned char eapol_key_data_10[] = {
    534 	0x02, 0x03, 0x00, 0x5f, 0x02, 0x03, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00,
    535 	0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    536 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    537 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    538 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    539 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    540 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8b, 0x0f, 0x34,
    541 	0x23, 0x49, 0xf0, 0x85, 0x03, 0xe5, 0xfc, 0x54, 0xb7, 0x2c, 0xb5, 0x32,
    542 	0x66, 0x00, 0x00
    543 };
    544 
    545 static struct eapol_key_data eapol_key_test_10 = {
    546 	.frame = eapol_key_data_10,
    547 	.frame_len = sizeof(eapol_key_data_10),
    548 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    549 	.packet_len = 95,
    550 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    551 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    552 	.key_type = true,
    553 	.wpa_key_id = 0,
    554 	.install = false,
    555 	.key_ack = false,
    556 	.key_mic = true,
    557 	.secure = true,
    558 	.error = false,
    559 	.request = false,
    560 	.encrypted_key_data = false,
    561 	.smk_message = false,
    562 	.key_length = 0,
    563 	.key_replay_counter = 2,
    564 	.key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    565 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    566 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    567 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    568 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    569 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    570 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    571 	.key_mic_data = { 0x8b, 0x0f, 0x34, 0x23, 0x49, 0xf0, 0x85, 0x03,
    572 			0xe5, 0xfc, 0x54, 0xb7, 0x2c, 0xb5, 0x32, 0x66 },
    573 	.key_data_len = 0,
    574 };
    575 
    576 /* WPA2 frame, 1 of 2.  For parameters see eapol_wpa2_handshake_test */
    577 static const unsigned char eapol_key_data_11[] = {
    578 	0x02, 0x03, 0x00, 0x7f, 0x02, 0x13, 0x82, 0x00, 0x10, 0x00, 0x00, 0x00,
    579 	0x00, 0x00, 0x00, 0x00, 0x03, 0xef, 0x6d, 0xc2, 0x0c, 0x57, 0x27, 0xe8,
    580 	0x25, 0x07, 0x75, 0x1e, 0x67, 0x36, 0x9d, 0xc9, 0x1e, 0xf1, 0x71, 0x8e,
    581 	0xb1, 0x35, 0xb2, 0x12, 0xdf, 0x9f, 0xcb, 0x0a, 0x65, 0xa2, 0xd5, 0x67,
    582 	0x1d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    583 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    584 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0x6a, 0xb0,
    585 	0x75, 0xbc, 0x8e, 0xd1, 0x92, 0x11, 0xcd, 0xc3, 0xb0, 0xe2, 0xd6, 0x7e,
    586 	0xcf, 0x00, 0x20, 0xe9, 0x96, 0x5b, 0x46, 0x85, 0xd5, 0x8b, 0x88, 0xbd,
    587 	0x57, 0x48, 0x57, 0xe4, 0xf0, 0xdf, 0xdd, 0xf7, 0x2a, 0x7a, 0xa8, 0xeb,
    588 	0x68, 0xa9, 0xef, 0x44, 0x04, 0xa6, 0x6f, 0xaa, 0x48, 0x51, 0x1b
    589 };
    590 
    591 static struct eapol_key_data eapol_key_test_11 = {
    592 	.frame = eapol_key_data_11,
    593 	.frame_len = sizeof(eapol_key_data_11),
    594 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    595 	.packet_len = 127,
    596 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    597 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    598 	.key_type = false,
    599 	.wpa_key_id = 0,
    600 	.install = false,
    601 	.key_ack = true,
    602 	.key_mic = true,
    603 	.secure = true,
    604 	.error = false,
    605 	.request = false,
    606 	.encrypted_key_data = true,
    607 	.smk_message = false,
    608 	.key_length = 16,
    609 	.key_replay_counter = 3,
    610 	.key_nonce = { 0xef, 0x6d, 0xc2, 0x0c, 0x57, 0x27, 0xe8, 0x25,
    611 			0x07, 0x75, 0x1e, 0x67, 0x36, 0x9d, 0xc9, 0x1e,
    612 			0xf1, 0x71, 0x8e, 0xb1, 0x35, 0xb2, 0x12, 0xdf,
    613 			0x9f, 0xcb, 0x0a, 0x65, 0xa2, 0xd5, 0x67, 0x1d },
    614 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    615 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    616 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    617 	.key_mic_data = { 0x0f, 0x6a, 0xb0, 0x75, 0xbc, 0x8e, 0xd1, 0x92,
    618 			0x11, 0xcd, 0xc3, 0xb0, 0xe2, 0xd6, 0x7e, 0xcf },
    619 	.key_data_len = 32,
    620 };
    621 
    622 /* WPA2 frame, 2 of 2.  For parameters see eapol_wpa2_handshake_test */
    623 static const unsigned char eapol_key_data_12[] = {
    624 	0x02, 0x03, 0x00, 0x5f, 0x02, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
    625 	0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    626 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    627 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    628 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    629 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    630 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc9, 0xbd, 0x17,
    631 	0xf1, 0x54, 0xb7, 0x32, 0xcf, 0xbc, 0x01, 0xdb, 0x0c, 0x37, 0xe6, 0x33,
    632 	0x9f, 0x00, 0x00
    633 };
    634 
    635 static struct eapol_key_data eapol_key_test_12 = {
    636 	.frame = eapol_key_data_12,
    637 	.frame_len = sizeof(eapol_key_data_12),
    638 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    639 	.packet_len = 95,
    640 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
    641 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
    642 	.key_type = false,
    643 	.wpa_key_id = 0,
    644 	.install = false,
    645 	.key_ack = false,
    646 	.key_mic = true,
    647 	.secure = true,
    648 	.error = false,
    649 	.request = false,
    650 	.encrypted_key_data = false,
    651 	.smk_message = false,
    652 	.key_length = 0,
    653 	.key_replay_counter = 3,
    654 	.key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    655 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    656 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    657 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    658 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    659 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    660 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    661 	.key_mic_data = { 0xc9, 0xbd, 0x17, 0xf1, 0x54, 0xb7, 0x32, 0xcf,
    662 			0xbc, 0x01, 0xdb, 0x0c, 0x37, 0xe6, 0x33, 0x9f },
    663 	.key_data_len = 0,
    664 };
    665 
    666 /* WPA frame, 1 of 4.  For parameters see eapol_wpa_handshake_test */
    667 static const unsigned char eapol_key_data_13[] = {
    668 	0x02, 0x03, 0x00, 0x5f, 0xfe, 0x00, 0x89, 0x00, 0x20, 0x00, 0x00, 0x00,
    669 	0x00, 0x00, 0x00, 0x00, 0x01, 0x66, 0xbe, 0x99, 0x48, 0x44, 0xe0, 0xf5,
    670 	0x40, 0x78, 0x13, 0x91, 0x37, 0x6f, 0x47, 0x99, 0x56, 0xa3, 0xec, 0x36,
    671 	0x32, 0xe4, 0x12, 0x13, 0x64, 0xec, 0x7e, 0x75, 0x37, 0xef, 0xf6, 0x2a,
    672 	0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    673 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    674 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    675 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    676 	0x00, 0x00, 0x00
    677 };
    678 
    679 static struct eapol_key_data eapol_key_test_13 = {
    680 	.frame = eapol_key_data_13,
    681 	.frame_len = sizeof(eapol_key_data_13),
    682 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    683 	.packet_len = 95,
    684 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
    685 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
    686 	.key_type = true,
    687 	.wpa_key_id = 0,
    688 	.install = false,
    689 	.key_ack = true,
    690 	.key_mic = false,
    691 	.secure = false,
    692 	.error = false,
    693 	.request = false,
    694 	.encrypted_key_data = false,
    695 	.smk_message = false,
    696 	.key_length = 32,
    697 	.key_replay_counter = 1,
    698 	.key_nonce = { 0x66, 0xbe, 0x99, 0x48, 0x44, 0xe0, 0xf5, 0x40,
    699 			0x78, 0x13, 0x91, 0x37, 0x6f, 0x47, 0x99, 0x56,
    700 			0xa3, 0xec, 0x36, 0x32, 0xe4, 0x12, 0x13, 0x64,
    701 			0xec, 0x7e, 0x75, 0x37, 0xef, 0xf6, 0x2a, 0xc5 },
    702 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    703 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    704 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    705 	.key_mic_data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    706 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    707 	.key_data_len = 0,
    708 };
    709 
    710 /* WPA frame, 2 of 4.  For parameters see eapol_wpa_handshake_test */
    711 static const unsigned char eapol_key_data_14[] = {
    712 	0x02, 0x03, 0x00, 0x77, 0xfe, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
    713 	0x00, 0x00, 0x00, 0x00, 0x01, 0x3b, 0x7f, 0x85, 0x0a, 0x03, 0x9c, 0xa4,
    714 	0x71, 0x42, 0x9d, 0x0f, 0xc3, 0xce, 0x9f, 0xff, 0x48, 0xdb, 0x89, 0x2e,
    715 	0xf7, 0xa7, 0xff, 0x80, 0xf6, 0x22, 0xc4, 0x6e, 0x32, 0x97, 0x05, 0xc3,
    716 	0x7d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    717 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    718 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xe6, 0x82,
    719 	0x94, 0xdc, 0x88, 0x07, 0x18, 0xa7, 0xd3, 0x08, 0xfa, 0xb4, 0x39, 0x95,
    720 	0x36, 0x00, 0x18, 0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, 0x01, 0x00, 0x00,
    721 	0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00,
    722 	0x50, 0xf2, 0x02
    723 };
    724 
    725 static struct eapol_key_data eapol_key_test_14 = {
    726 	.frame = eapol_key_data_14,
    727 	.frame_len = sizeof(eapol_key_data_14),
    728 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    729 	.packet_len = 119,
    730 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
    731 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
    732 	.key_type = true,
    733 	.wpa_key_id = 0,
    734 	.install = false,
    735 	.key_ack = false,
    736 	.key_mic = true,
    737 	.secure = false,
    738 	.error = false,
    739 	.request = false,
    740 	.encrypted_key_data = false,
    741 	.smk_message = false,
    742 	.key_length = 0,
    743 	.key_replay_counter = 1,
    744 	.key_nonce = { 0x3b, 0x7f, 0x85, 0x0a, 0x03, 0x9c, 0xa4, 0x71,
    745 			0x42, 0x9d, 0x0f, 0xc3, 0xce, 0x9f, 0xff, 0x48,
    746 			0xdb, 0x89, 0x2e, 0xf7, 0xa7, 0xff, 0x80, 0xf6,
    747 			0x22, 0xc4, 0x6e, 0x32, 0x97, 0x05, 0xc3, 0x7d },
    748 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    749 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    750 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    751 	.key_mic_data = { 0x01, 0xe6, 0x82, 0x94, 0xdc, 0x88, 0x07, 0x18,
    752 			0xa7, 0xd3, 0x08, 0xfa, 0xb4, 0x39, 0x95, 0x36 },
    753 	.key_data_len = 24,
    754 };
    755 
    756 /* WPA frame, 3 of 4.  For parameters see eapol_wpa_handshake_test */
    757 static const unsigned char eapol_key_data_15[] = {
    758 	0x02, 0x03, 0x00, 0x77, 0xfe, 0x01, 0xc9, 0x00, 0x20, 0x00, 0x00, 0x00,
    759 	0x00, 0x00, 0x00, 0x00, 0x02, 0x66, 0xbe, 0x99, 0x48, 0x44, 0xe0, 0xf5,
    760 	0x40, 0x78, 0x13, 0x91, 0x37, 0x6f, 0x47, 0x99, 0x56, 0xa3, 0xec, 0x36,
    761 	0x32, 0xe4, 0x12, 0x13, 0x64, 0xec, 0x7e, 0x75, 0x37, 0xef, 0xf6, 0x2a,
    762 	0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    763 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    764 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96, 0xc2, 0x97,
    765 	0xf6, 0xc1, 0x93, 0x72, 0x19, 0x3e, 0x40, 0xd9, 0xc8, 0xb9, 0xaa, 0x7c,
    766 	0x94, 0x00, 0x18, 0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, 0x01, 0x00, 0x00,
    767 	0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00,
    768 	0x50, 0xf2, 0x02
    769 };
    770 
    771 static struct eapol_key_data eapol_key_test_15 = {
    772 	.frame = eapol_key_data_15,
    773 	.frame_len = sizeof(eapol_key_data_15),
    774 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    775 	.packet_len = 119,
    776 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
    777 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
    778 	.key_type = true,
    779 	.wpa_key_id = 0,
    780 	.install = true,
    781 	.key_ack = true,
    782 	.key_mic = true,
    783 	.secure = false,
    784 	.error = false,
    785 	.request = false,
    786 	.encrypted_key_data = false,
    787 	.smk_message = false,
    788 	.key_length = 32,
    789 	.key_replay_counter = 2,
    790 	.key_nonce = { 0x66, 0xbe, 0x99, 0x48, 0x44, 0xe0, 0xf5, 0x40,
    791 			0x78, 0x13, 0x91, 0x37, 0x6f, 0x47, 0x99, 0x56,
    792 			0xa3, 0xec, 0x36, 0x32, 0xe4, 0x12, 0x13, 0x64,
    793 			0xec, 0x7e, 0x75, 0x37, 0xef, 0xf6, 0x2a, 0xc5 },
    794 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    795 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    796 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    797 	.key_mic_data = { 0x96, 0xc2, 0x97, 0xf6, 0xc1, 0x93, 0x72, 0x19,
    798 			0x3e, 0x40, 0xd9, 0xc8, 0xb9, 0xaa, 0x7c, 0x94 },
    799 	.key_data_len = 24,
    800 };
    801 
    802 /* WPA frame, 4 of 4.  For parameters see eapol_wpa_handshake_test */
    803 static const unsigned char eapol_key_data_16[] = {
    804 	0x02, 0x03, 0x00, 0x5f, 0xfe, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
    805 	0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    806 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    807 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    808 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    809 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    810 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x65, 0xf3,
    811 	0x33, 0xa3, 0x5b, 0x4f, 0xda, 0xc3, 0x66, 0xb3, 0x1a, 0x43, 0xb5, 0x31,
    812 	0x95, 0x00, 0x00
    813 };
    814 
    815 static struct eapol_key_data eapol_key_test_16 = {
    816 	.frame = eapol_key_data_16,
    817 	.frame_len = sizeof(eapol_key_data_16),
    818 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    819 	.packet_len = 95,
    820 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
    821 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
    822 	.key_type = true,
    823 	.wpa_key_id = 0,
    824 	.install = false,
    825 	.key_ack = false,
    826 	.key_mic = true,
    827 	.secure = false,
    828 	.error = false,
    829 	.request = false,
    830 	.encrypted_key_data = false,
    831 	.smk_message = false,
    832 	.key_length = 0,
    833 	.key_replay_counter = 2,
    834 	.key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    835 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    836 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    837 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    838 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    839 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    840 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    841 	.key_mic_data = { 0xe0, 0x65, 0xf3, 0x33, 0xa3, 0x5b, 0x4f, 0xda,
    842 			0xc3, 0x66, 0xb3, 0x1a, 0x43, 0xb5, 0x31, 0x95 },
    843 	.key_data_len = 0,
    844 };
    845 
    846 /* WPA frame, 1 of 2.  For parameters see eapol_wpa_handshake_test */
    847 static const unsigned char eapol_key_data_17[] = {
    848 	0x02, 0x03, 0x00, 0x7f, 0xfe, 0x03, 0xa1, 0x00, 0x20, 0x00, 0x00, 0x00,
    849 	0x00, 0x00, 0x00, 0x00, 0x03, 0xc3, 0xa7, 0xe0, 0x14, 0x10, 0xea, 0xe6,
    850 	0xe5, 0xfb, 0x79, 0xfc, 0xf5, 0xe5, 0x55, 0x08, 0x44, 0xd9, 0xbd, 0xd2,
    851 	0x80, 0x5d, 0x81, 0x1c, 0x0a, 0x9c, 0x48, 0x0a, 0xe9, 0x86, 0xca, 0x87,
    852 	0xa1, 0xd9, 0xbd, 0xd2, 0x80, 0x5d, 0x81, 0x1c, 0x0a, 0x9c, 0x48, 0x0a,
    853 	0xe9, 0x86, 0xca, 0x87, 0xa2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    854 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb, 0x78, 0xf8,
    855 	0xf3, 0xff, 0x1f, 0xec, 0x97, 0x98, 0x67, 0xe8, 0x25, 0x0a, 0xf2, 0x9d,
    856 	0x61, 0x00, 0x20, 0x9f, 0x46, 0x72, 0x04, 0x83, 0xd7, 0xf6, 0xa3, 0x5b,
    857 	0xbd, 0xa6, 0x80, 0x32, 0xe0, 0x44, 0x92, 0x5e, 0x90, 0xe5, 0x7f, 0xd8,
    858 	0x5d, 0xfc, 0xd0, 0xdb, 0xcd, 0x7f, 0xf7, 0x48, 0xdf, 0x33, 0x75
    859 };
    860 
    861 static struct eapol_key_data eapol_key_test_17 = {
    862 	.frame = eapol_key_data_17,
    863 	.frame_len = sizeof(eapol_key_data_17),
    864 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    865 	.packet_len = 127,
    866 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
    867 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
    868 	.key_type = false,
    869 	.wpa_key_id = 2,
    870 	.install = false,
    871 	.key_ack = true,
    872 	.key_mic = true,
    873 	.secure = true,
    874 	.error = false,
    875 	.request = false,
    876 	.encrypted_key_data = false,
    877 	.smk_message = false,
    878 	.key_length = 32,
    879 	.key_replay_counter = 3,
    880 	.key_nonce = { 0xc3, 0xa7, 0xe0, 0x14, 0x10, 0xea, 0xe6, 0xe5,
    881 			0xfb, 0x79, 0xfc, 0xf5, 0xe5, 0x55, 0x08, 0x44,
    882 			0xd9, 0xbd, 0xd2, 0x80, 0x5d, 0x81, 0x1c, 0x0a,
    883 			0x9c, 0x48, 0x0a, 0xe9, 0x86, 0xca, 0x87, 0xa1 },
    884 	.eapol_key_iv = { 0xd9, 0xbd, 0xd2, 0x80, 0x5d, 0x81, 0x1c, 0x0a,
    885 			0x9c, 0x48, 0x0a, 0xe9, 0x86, 0xca, 0x87, 0xa2 },
    886 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    887 	.key_mic_data = { 0xfb, 0x78, 0xf8, 0xf3, 0xff, 0x1f, 0xec, 0x97,
    888 			0x98, 0x67, 0xe8, 0x25, 0x0a, 0xf2, 0x9d, 0x61 },
    889 	.key_data_len = 32,
    890 };
    891 
    892 /* WPA frame, 2 of 2.  For parameters see eapol_wpa_handshake_test */
    893 static const unsigned char eapol_key_data_18[] = {
    894 	0x02, 0x03, 0x00, 0x5f, 0xfe, 0x03, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00,
    895 	0x00, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    896 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    897 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    898 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    899 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    900 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe9, 0x92, 0xb9,
    901 	0x33, 0x25, 0xa9, 0xdc, 0x46, 0xe3, 0xb2, 0xa1, 0x5c, 0xf7, 0x2f, 0x82,
    902 	0x52, 0x00, 0x00,
    903 };
    904 
    905 static struct eapol_key_data eapol_key_test_18 = {
    906 	.frame = eapol_key_data_18,
    907 	.frame_len = sizeof(eapol_key_data_18),
    908 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
    909 	.packet_len = 95,
    910 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
    911 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
    912 	.key_type = false,
    913 	.wpa_key_id = 2,
    914 	.install = false,
    915 	.key_ack = false,
    916 	.key_mic = true,
    917 	.secure = true,
    918 	.error = false,
    919 	.request = false,
    920 	.encrypted_key_data = false,
    921 	.smk_message = false,
    922 	.key_length = 0,
    923 	.key_replay_counter = 3,
    924 	.key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    925 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    926 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    927 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    928 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    929 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    930 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    931 	.key_mic_data = { 0xe9, 0x92, 0xb9, 0x33, 0x25, 0xa9, 0xdc, 0x46, 0xe3,
    932 				0xb2, 0xa1, 0x5c, 0xf7, 0x2f, 0x82, 0x52 },
    933 	.key_data_len = 0,
    934 };
    935 
    936 /* WPA frame, 1 of 4.  For parameters see eapol_wpa2_handshake_test */
    937 static const unsigned char eapol_key_data_19[] = {
    938 	0x01, 0x03, 0x00, 0x5f, 0xfe, 0x00, 0x89, 0x00, 0x20, 0x00, 0x00, 0x00,
    939 	0x00, 0x00, 0x00, 0x00, 0x00, 0x26, 0x56, 0x9b, 0x2a, 0x6e, 0x90, 0xad,
    940 	0x21, 0x91, 0x86, 0x6d, 0x86, 0xe9, 0xfd, 0xf8, 0xb7, 0x9a, 0x12, 0xcb,
    941 	0xab, 0x1a, 0xc3, 0xe0, 0x2d, 0xa6, 0xa1, 0x22, 0x43, 0x4e, 0x76, 0x9d,
    942 	0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    943 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    944 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    945 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    946 	0x00, 0x00, 0x00,
    947 };
    948 
    949 static struct eapol_key_data eapol_key_test_19 = {
    950 	.frame = eapol_key_data_19,
    951 	.frame_len = sizeof(eapol_key_data_19),
    952 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
    953 	.packet_len = 95,
    954 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
    955 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
    956 	.key_type = true,
    957 	.wpa_key_id = 0,
    958 	.install = false,
    959 	.key_ack = true,
    960 	.key_mic = false,
    961 	.secure = false,
    962 	.error = false,
    963 	.request = false,
    964 	.encrypted_key_data = false,
    965 	.smk_message = false,
    966 	.key_length = 32,
    967 	.key_replay_counter = 0,
    968 	.key_nonce = { 0x26, 0x56, 0x9b, 0x2a, 0x6e, 0x90, 0xad, 0x21, 0x91,
    969 			0x86, 0x6d, 0x86, 0xe9, 0xfd, 0xf8, 0xb7, 0x9a, 0x12,
    970 			0xcb, 0xab, 0x1a, 0xc3, 0xe0, 0x2d, 0xa6, 0xa1, 0x22,
    971 			0x43, 0x4e, 0x76, 0x9d, 0x75 },
    972 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    973 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    974 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    975 	.key_mic_data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    976 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
    977 	.key_data_len = 0,
    978 };
    979 
    980 /* WPA frame, 2 of 4.  For parameters see eapol_wpa2_handshake_test */
    981 static const unsigned char eapol_key_data_20[] = {
    982 	0x01, 0x03, 0x00, 0x77, 0xfe, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
    983 	0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x88, 0xe2, 0x61, 0x2d, 0xf3, 0xe3,
    984 	0x66, 0x3d, 0x35, 0xf7, 0xd3, 0x70, 0x17, 0x87, 0x92, 0x92, 0x4a, 0x35,
    985 	0xc8, 0x2d, 0x67, 0x45, 0x56, 0xe6, 0x98, 0x9e, 0x75, 0x79, 0x9e, 0x25,
    986 	0x6b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    987 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    988 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32, 0x5c, 0x17,
    989 	0xb7, 0xbc, 0x6d, 0x2c, 0x0f, 0x7c, 0xc0, 0x32, 0xec, 0xa6, 0x31, 0xbd,
    990 	0x8d, 0x00, 0x18, 0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, 0x01, 0x00, 0x00,
    991 	0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00,
    992 	0x50, 0xf2, 0x02,
    993 };
    994 
    995 static struct eapol_key_data eapol_key_test_20 = {
    996 	.frame = eapol_key_data_20,
    997 	.frame_len = sizeof(eapol_key_data_20),
    998 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
    999 	.packet_len = 119,
   1000 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
   1001 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1002 	.key_type = true,
   1003 	.wpa_key_id = 0,
   1004 	.install = false,
   1005 	.key_ack = false,
   1006 	.key_mic = true,
   1007 	.secure = false,
   1008 	.error = false,
   1009 	.request = false,
   1010 	.encrypted_key_data = false,
   1011 	.smk_message = false,
   1012 	.key_length = 0,
   1013 	.key_replay_counter = 0,
   1014 	.key_nonce = { 0x04, 0x88, 0xe2, 0x61, 0x2d, 0xf3, 0xe3, 0x66, 0x3d,
   1015 			0x35, 0xf7, 0xd3, 0x70, 0x17, 0x87, 0x92, 0x92, 0x4a,
   1016 			0x35, 0xc8, 0x2d, 0x67, 0x45, 0x56, 0xe6, 0x98, 0x9e,
   1017 			0x75, 0x79, 0x9e, 0x25, 0x6b },
   1018 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1019 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1020 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1021 	.key_mic_data = { 0x32, 0x5c, 0x17, 0xb7, 0xbc, 0x6d, 0x2c, 0x0f, 0x7c,
   1022 				0xc0, 0x32, 0xec, 0xa6, 0x31, 0xbd, 0x8d },
   1023 	.key_data_len = 24,
   1024 };
   1025 
   1026 /* WPA frame, 3 of 4.  For parameters see eapol_wpa2_handshake_test */
   1027 static const unsigned char eapol_key_data_21[] = {
   1028 	0x01, 0x03, 0x00, 0x77, 0xfe, 0x01, 0xc9, 0x00, 0x20, 0x00, 0x00, 0x00,
   1029 	0x00, 0x00, 0x00, 0x00, 0x01, 0x26, 0x56, 0x9b, 0x2a, 0x6e, 0x90, 0xad,
   1030 	0x21, 0x91, 0x86, 0x6d, 0x86, 0xe9, 0xfd, 0xf8, 0xb7, 0x9a, 0x12, 0xcb,
   1031 	0xab, 0x1a, 0xc3, 0xe0, 0x2d, 0xa6, 0xa1, 0x22, 0x43, 0x4e, 0x76, 0x9d,
   1032 	0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1033 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1034 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xcd, 0x76, 0x63,
   1035 	0x43, 0xe1, 0xc7, 0x6b, 0x59, 0x34, 0xa4, 0x23, 0x42, 0xc0, 0xb9, 0x98,
   1036 	0x02, 0x00, 0x18, 0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, 0x01, 0x00, 0x00,
   1037 	0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00,
   1038 	0x50, 0xf2, 0x02,
   1039 };
   1040 
   1041 static struct eapol_key_data eapol_key_test_21 = {
   1042 	.frame = eapol_key_data_21,
   1043 	.frame_len = sizeof(eapol_key_data_21),
   1044 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
   1045 	.packet_len = 119,
   1046 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
   1047 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1048 	.key_type = true,
   1049 	.wpa_key_id = 0,
   1050 	.install = true,
   1051 	.key_ack = true,
   1052 	.key_mic = true,
   1053 	.secure = false,
   1054 	.error = false,
   1055 	.request = false,
   1056 	.encrypted_key_data = false,
   1057 	.smk_message = false,
   1058 	.key_length = 32,
   1059 	.key_replay_counter = 1,
   1060 	.key_nonce = { 0x26, 0x56, 0x9b, 0x2a, 0x6e, 0x90, 0xad, 0x21, 0x91,
   1061 			0x86, 0x6d, 0x86, 0xe9, 0xfd, 0xf8, 0xb7, 0x9a, 0x12,
   1062 			0xcb, 0xab, 0x1a, 0xc3, 0xe0, 0x2d, 0xa6, 0xa1, 0x22,
   1063 			0x43, 0x4e, 0x76, 0x9d, 0x75 },
   1064 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1065 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1066 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1067 	.key_mic_data = { 0xcd, 0x76, 0x63, 0x43, 0xe1, 0xc7, 0x6b, 0x59, 0x34,
   1068 				0xa4, 0x23, 0x42, 0xc0, 0xb9, 0x98, 0x02 },
   1069 	.key_data_len = 24,
   1070 };
   1071 
   1072 /* WPA frame, 4 of 4.  For parameters see eapol_wpa2_handshake_test */
   1073 static const unsigned char eapol_key_data_22[] = {
   1074 	0x01, 0x03, 0x00, 0x5f, 0xfe, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
   1075 	0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1076 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1077 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1078 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1079 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1080 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x37, 0xbc, 0x08,
   1081 	0x98, 0x99, 0x33, 0x1a, 0x70, 0xed, 0xa5, 0xb5, 0xb7, 0x54, 0xf5, 0x5f,
   1082 	0x06, 0x00, 0x00,
   1083 };
   1084 
   1085 static struct eapol_key_data eapol_key_test_22 = {
   1086 	.frame = eapol_key_data_22,
   1087 	.frame_len = sizeof(eapol_key_data_22),
   1088 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
   1089 	.packet_len = 95,
   1090 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
   1091 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1092 	.key_type = true,
   1093 	.wpa_key_id = 0,
   1094 	.install = false,
   1095 	.key_ack = false,
   1096 	.key_mic = true,
   1097 	.secure = false,
   1098 	.error = false,
   1099 	.request = false,
   1100 	.encrypted_key_data = false,
   1101 	.smk_message = false,
   1102 	.key_length = 0,
   1103 	.key_replay_counter = 1,
   1104 	.key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1105 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1106 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1107 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1108 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1109 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1110 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1111 	.key_mic_data = { 0x37, 0xbc, 0x08, 0x98, 0x99, 0x33, 0x1a, 0x70, 0xed,
   1112 				0xa5, 0xb5, 0xb7, 0x54, 0xf5, 0x5f, 0x06 },
   1113 	.key_data_len = 0,
   1114 };
   1115 
   1116 /*
   1117  * WPA Group Handshake frame, 1 of 2.  For parameters
   1118  * see eapol_wpa2_handshake_test
   1119  */
   1120 static const unsigned char eapol_key_data_23[] = {
   1121 	0x01, 0x03, 0x00, 0x7f, 0xfe, 0x03, 0xa1, 0x00, 0x20, 0x00, 0x00, 0x00,
   1122 	0x00, 0x00, 0x00, 0x00, 0x02, 0x6a, 0x65, 0xcf, 0x21, 0x0d, 0x51, 0xeb,
   1123 	0xd6, 0xca, 0x3e, 0xc9, 0xee, 0xc9, 0xd9, 0xad, 0x2f, 0x14, 0x13, 0x8d,
   1124 	0xb9, 0x33, 0xa1, 0xbb, 0xed, 0x94, 0x26, 0xa1, 0x73, 0x48, 0xc8, 0x4d,
   1125 	0x4a, 0x0d, 0x8c, 0xe1, 0x3f, 0x1c, 0x0c, 0x52, 0x55, 0x00, 0xe5, 0x04,
   1126 	0xe5, 0xbd, 0x46, 0x94, 0xdb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1127 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe5, 0xa3, 0x27,
   1128 	0x7c, 0x85, 0x47, 0xd5, 0x3f, 0x35, 0xaf, 0x86, 0xc2, 0x2c, 0xcb, 0xb3,
   1129 	0x87, 0x00, 0x20, 0xc8, 0xb3, 0x61, 0xc0, 0x71, 0x5d, 0x2e, 0x9a, 0x6a,
   1130 	0x78, 0xdf, 0xfe, 0x0d, 0x64, 0x11, 0x23, 0xd9, 0xcc, 0xc6, 0x44, 0x65,
   1131 	0x76, 0xba, 0x82, 0xd5, 0x08, 0x4b, 0x4e, 0x51, 0xc2, 0x6a, 0x3f,
   1132 };
   1133 
   1134 static struct eapol_key_data eapol_key_test_23 = {
   1135 	.frame = eapol_key_data_23,
   1136 	.frame_len = sizeof(eapol_key_data_23),
   1137 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
   1138 	.packet_len = 127,
   1139 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
   1140 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1141 	.key_type = false,
   1142 	.wpa_key_id = 2,
   1143 	.install = false,
   1144 	.key_ack = true,
   1145 	.key_mic = true,
   1146 	.secure = true,
   1147 	.error = false,
   1148 	.request = false,
   1149 	.encrypted_key_data = false,
   1150 	.smk_message = false,
   1151 	.key_length = 32,
   1152 	.key_replay_counter = 2,
   1153 	.key_nonce = { 0x6a, 0x65, 0xcf, 0x21, 0x0d, 0x51, 0xeb, 0xd6, 0xca,
   1154 			0x3e, 0xc9, 0xee, 0xc9, 0xd9, 0xad, 0x2f, 0x14, 0x13,
   1155 			0x8d, 0xb9, 0x33, 0xa1, 0xbb, 0xed, 0x94, 0x26, 0xa1,
   1156 			0x73, 0x48, 0xc8, 0x4d, 0x4a },
   1157 	.eapol_key_iv = { 0x0d, 0x8c, 0xe1, 0x3f, 0x1c, 0x0c, 0x52, 0x55, 0x00,
   1158 				0xe5, 0x04, 0xe5, 0xbd, 0x46, 0x94, 0xdb },
   1159 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1160 	.key_mic_data = { 0xe5, 0xa3, 0x27, 0x7c, 0x85, 0x47, 0xd5, 0x3f, 0x35,
   1161 				0xaf, 0x86, 0xc2, 0x2c, 0xcb, 0xb3, 0x87 },
   1162 	.key_data_len = 32,
   1163 };
   1164 
   1165 /*
   1166  * WPA Group Handshake frame, 2 of 2.  For parameters
   1167  * see eapol_wpa2_handshake_test
   1168  */
   1169 static const unsigned char eapol_key_data_24[] = {
   1170 	0x01, 0x03, 0x00, 0x5f, 0xfe, 0x03, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00,
   1171 	0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1172 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1173 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1174 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1175 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1176 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x06, 0x47,
   1177 	0x53, 0x9a, 0x1d, 0x3f, 0x9c, 0x02, 0x50, 0xb5, 0xc0, 0x40, 0x6b, 0x97,
   1178 	0xf8, 0x00, 0x00,
   1179 };
   1180 
   1181 static struct eapol_key_data eapol_key_test_24 = {
   1182 	.frame = eapol_key_data_24,
   1183 	.frame_len = sizeof(eapol_key_data_24),
   1184 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
   1185 	.packet_len = 95,
   1186 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_WPA,
   1187 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1188 	.key_type = false,
   1189 	.wpa_key_id = 2,
   1190 	.install = false,
   1191 	.key_ack = false,
   1192 	.key_mic = true,
   1193 	.secure = true,
   1194 	.error = false,
   1195 	.request = false,
   1196 	.encrypted_key_data = false,
   1197 	.smk_message = false,
   1198 	.key_length = 0,
   1199 	.key_replay_counter = 2,
   1200 	.key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1201 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1202 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1203 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1204 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1205 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1206 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1207 	.key_mic_data = { 0x4f, 0x06, 0x47, 0x53, 0x9a, 0x1d, 0x3f, 0x9c, 0x02,
   1208 				0x50, 0xb5, 0xc0, 0x40, 0x6b, 0x97, 0xf8 },
   1209 	.key_data_len = 0,
   1210 };
   1211 
   1212 /* FT frame, 1 of 4.  For parameters see eapol_ft_handshake_test */
   1213 static const unsigned char eapol_key_data_25[] = {
   1214 	0x02, 0x03, 0x00, 0x5f, 0x02, 0x00, 0x8b, 0x00, 0x10, 0x00, 0x00, 0x00,
   1215 	0x00, 0x00, 0x00, 0x00, 0x01, 0x33, 0xb2, 0x74, 0xa0, 0xae, 0xc9, 0xe8,
   1216 	0x5d, 0x61, 0x11, 0x8f, 0x1b, 0x6b, 0x97, 0x77, 0x4e, 0x5b, 0x75, 0x08,
   1217 	0x37, 0x45, 0x77, 0xdc, 0x14, 0x08, 0xa5, 0xf1, 0x80, 0xc5, 0xd2, 0xe9,
   1218 	0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1219 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1220 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1221 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1222 	0x00, 0x00, 0x00,
   1223 };
   1224 
   1225 static struct eapol_key_data eapol_key_test_25 = {
   1226 	.frame = eapol_key_data_25,
   1227 	.frame_len = sizeof(eapol_key_data_25),
   1228 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
   1229 	.packet_len = 95,
   1230 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
   1231 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES,
   1232 	.key_type = true,
   1233 	.install = false,
   1234 	.key_ack = true,
   1235 	.key_mic = false,
   1236 	.secure = false,
   1237 	.error = false,
   1238 	.request = false,
   1239 	.encrypted_key_data = false,
   1240 	.smk_message = false,
   1241 	.key_length = 16,
   1242 	.key_replay_counter = 1,
   1243 	.key_nonce = { 0x33, 0xb2, 0x74, 0xa0, 0xae, 0xc9, 0xe8, 0x5d, 0x61,
   1244 			0x11, 0x8f, 0x1b, 0x6b, 0x97, 0x77, 0x4e, 0x5b, 0x75,
   1245 			0x08, 0x37, 0x45, 0x77, 0xdc, 0x14, 0x08, 0xa5, 0xf1,
   1246 			0x80, 0xc5, 0xd2, 0xe9, 0xfd },
   1247 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1248 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1249 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1250 	.key_mic_data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1251 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1252 	.key_data_len = 0,
   1253 };
   1254 
   1255 /* FT frame, 2 of 4.  For parameters see eapol_ft_handshake_test */
   1256 static const unsigned char eapol_key_data_26[] = {
   1257 	0x02, 0x03, 0x00, 0xf0, 0x02, 0x01, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00,
   1258 	0x00, 0x00, 0x00, 0x00, 0x01, 0xac, 0x1e, 0xb2, 0xc7, 0x0b, 0x20, 0x8c,
   1259 	0xe6, 0x0a, 0xe2, 0x07, 0xb2, 0x38, 0x9e, 0x44, 0x1f, 0xff, 0x39, 0x86,
   1260 	0x3d, 0x44, 0x9f, 0x81, 0x24, 0x6f, 0xe3, 0x6e, 0xde, 0x0f, 0x1f, 0x56,
   1261 	0xce, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1262 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1263 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x79, 0xa1, 0x95,
   1264 	0x19, 0xe8, 0x5f, 0xcf, 0x2e, 0x60, 0x7d, 0x6f, 0xfb, 0xd9, 0xe8, 0x04,
   1265 	0xb0, 0x00, 0x91, 0x30, 0x26, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01,
   1266 	0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x00,
   1267 	0x00, 0x01, 0x00, 0xde, 0xce, 0x50, 0xa0, 0x9e, 0xf0, 0x8c, 0x4e, 0xbe,
   1268 	0xf2, 0xf1, 0xdb, 0xe9, 0x67, 0xb4, 0xd4, 0x36, 0x03, 0x12, 0x34, 0x01,
   1269 	0x37, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1270 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1271 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1272 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1273 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1274 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1275 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1276 	0x01, 0x06, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x64, 0x75,
   1277 	0x6d, 0x6d, 0x79, 0x30,
   1278 };
   1279 
   1280 static struct eapol_key_data eapol_key_test_26 = {
   1281 	.frame = eapol_key_data_26,
   1282 	.frame_len = sizeof(eapol_key_data_26),
   1283 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
   1284 	.packet_len = 240,
   1285 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
   1286 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES,
   1287 	.key_type = true,
   1288 	.install = false,
   1289 	.key_ack = false,
   1290 	.key_mic = true,
   1291 	.secure = false,
   1292 	.error = false,
   1293 	.request = false,
   1294 	.encrypted_key_data = false,
   1295 	.smk_message = false,
   1296 	.key_length = 0,
   1297 	.key_replay_counter = 1,
   1298 	.key_nonce = { 0xac, 0x1e, 0xb2, 0xc7, 0x0b, 0x20, 0x8c, 0xe6, 0x0a,
   1299 			0xe2, 0x07, 0xb2, 0x38, 0x9e, 0x44, 0x1f, 0xff, 0x39,
   1300 			0x86, 0x3d, 0x44, 0x9f, 0x81, 0x24, 0x6f, 0xe3, 0x6e,
   1301 			0xde, 0x0f, 0x1f, 0x56, 0xce },
   1302 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1303 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1304 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1305 	.key_mic_data = { 0x79, 0xa1, 0x95, 0x19, 0xe8, 0x5f, 0xcf, 0x2e, 0x60,
   1306 			0x7d, 0x6f, 0xfb, 0xd9, 0xe8, 0x04, 0xb0 },
   1307 	.key_data_len = 145,
   1308 };
   1309 
   1310 /* FT frame, 3 of 4.  For parameters see eapol_ft_handshake_test */
   1311 static const unsigned char eapol_key_data_27[] = {
   1312 	0x02, 0x03, 0x01, 0x1f, 0x02, 0x13, 0xcb, 0x00, 0x10, 0x00, 0x00, 0x00,
   1313 	0x00, 0x00, 0x00, 0x00, 0x02, 0x33, 0xb2, 0x74, 0xa0, 0xae, 0xc9, 0xe8,
   1314 	0x5d, 0x61, 0x11, 0x8f, 0x1b, 0x6b, 0x97, 0x77, 0x4e, 0x5b, 0x75, 0x08,
   1315 	0x37, 0x45, 0x77, 0xdc, 0x14, 0x08, 0xa5, 0xf1, 0x80, 0xc5, 0xd2, 0xe9,
   1316 	0xfd, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1317 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1318 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xe3, 0x6d,
   1319 	0xef, 0x96, 0x5b, 0x07, 0xaa, 0x58, 0xce, 0xed, 0xb1, 0x57, 0x83, 0x51,
   1320 	0x7e, 0x00, 0xc0, 0x1d, 0x41, 0x1c, 0xf6, 0x35, 0x4e, 0x5c, 0x0f, 0x4d,
   1321 	0x03, 0x08, 0xe7, 0x3b, 0x33, 0x04, 0xde, 0x5e, 0x01, 0x77, 0x1c, 0xb8,
   1322 	0x91, 0xef, 0x4f, 0x24, 0x64, 0x84, 0xaa, 0x94, 0x42, 0xc3, 0xcb, 0x63,
   1323 	0x2d, 0xed, 0x5e, 0x5f, 0xcb, 0x1a, 0xff, 0x53, 0x58, 0x45, 0xd5, 0xc2,
   1324 	0x11, 0x52, 0x40, 0x06, 0x08, 0x70, 0xd8, 0xd1, 0xf7, 0x79, 0xfe, 0x37,
   1325 	0xb8, 0x6d, 0xd6, 0x27, 0x45, 0xbc, 0x11, 0x2a, 0x69, 0x05, 0x2c, 0x40,
   1326 	0x3a, 0x06, 0x24, 0x5a, 0x7a, 0xa6, 0x79, 0x4b, 0x18, 0xc8, 0xbf, 0x21,
   1327 	0x10, 0xa0, 0x7d, 0x80, 0x89, 0x77, 0x85, 0x27, 0x88, 0x74, 0x07, 0x00,
   1328 	0x14, 0xe0, 0x91, 0xa2, 0xe0, 0xa2, 0x25, 0x3c, 0x26, 0xce, 0xd6, 0x9f,
   1329 	0x33, 0x20, 0x99, 0xc6, 0xc0, 0x46, 0x91, 0x8a, 0x68, 0x5b, 0xa0, 0xa1,
   1330 	0x30, 0xcd, 0x76, 0x58, 0x26, 0x81, 0x03, 0xe6, 0x79, 0x3b, 0xf6, 0x4b,
   1331 	0x2f, 0x1d, 0x73, 0x8f, 0x62, 0xda, 0x22, 0xa9, 0xb4, 0xac, 0x77, 0xcc,
   1332 	0xd4, 0xd4, 0x6f, 0x80, 0x31, 0xfb, 0x3d, 0x21, 0xde, 0x41, 0x09, 0x70,
   1333 	0xcc, 0x18, 0xa6, 0xa5, 0x3e, 0xda, 0x1b, 0x6b, 0x30, 0xce, 0xd4, 0xde,
   1334 	0xd4, 0x86, 0x7e, 0x71, 0xd0, 0x97, 0x85, 0xcc, 0xa2, 0xd3, 0x4c, 0x56,
   1335 	0xcf, 0x1a, 0xd3, 0xff, 0xf8, 0x18, 0xfd, 0x52, 0x77, 0x21, 0xe9, 0x87,
   1336 	0x3f, 0x14, 0x30,
   1337 };
   1338 
   1339 static struct eapol_key_data eapol_key_test_27 = {
   1340 	.frame = eapol_key_data_27,
   1341 	.frame_len = sizeof(eapol_key_data_27),
   1342 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
   1343 	.packet_len = 287,
   1344 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
   1345 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES,
   1346 	.key_type = true,
   1347 	.install = true,
   1348 	.key_ack = true,
   1349 	.key_mic = true,
   1350 	.secure = true,
   1351 	.error = false,
   1352 	.request = false,
   1353 	.encrypted_key_data = true,
   1354 	.smk_message = false,
   1355 	.key_length = 16,
   1356 	.key_replay_counter = 2,
   1357 	.key_nonce = { 0x33, 0xb2, 0x74, 0xa0, 0xae, 0xc9, 0xe8, 0x5d, 0x61,
   1358 			0x11, 0x8f, 0x1b, 0x6b, 0x97, 0x77, 0x4e, 0x5b, 0x75,
   1359 			0x08, 0x37, 0x45, 0x77, 0xdc, 0x14, 0x08, 0xa5, 0xf1,
   1360 			0x80, 0xc5, 0xd2, 0xe9, 0xfd },
   1361 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1362 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1363 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1364 	.key_mic_data = { 0x12, 0xe3, 0x6d, 0xef, 0x96, 0x5b, 0x07, 0xaa, 0x58,
   1365 			0xce, 0xed, 0xb1, 0x57, 0x83, 0x51, 0x7e },
   1366 	.key_data_len = 192,
   1367 };
   1368 
   1369 /* FT frame, 4 of 4.  For parameters see eapol_ft_handshake_test */
   1370 static const unsigned char eapol_key_data_28[] = {
   1371 	0x02, 0x03, 0x00, 0x5f, 0x02, 0x03, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00,
   1372 	0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1373 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1374 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1375 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1376 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1377 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3e, 0x85, 0x3a,
   1378 	0x3c, 0x83, 0x71, 0x4a, 0x94, 0xe4, 0x30, 0xdf, 0xb2, 0x06, 0x65, 0xa1,
   1379 	0xd4, 0x00, 0x00,
   1380 };
   1381 
   1382 static struct eapol_key_data eapol_key_test_28 = {
   1383 	.frame = eapol_key_data_28,
   1384 	.frame_len = sizeof(eapol_key_data_28),
   1385 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
   1386 	.packet_len = 95,
   1387 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
   1388 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES,
   1389 	.key_type = true,
   1390 	.install = false,
   1391 	.key_ack = false,
   1392 	.key_mic = true,
   1393 	.secure = true,
   1394 	.error = false,
   1395 	.request = false,
   1396 	.encrypted_key_data = false,
   1397 	.smk_message = false,
   1398 	.key_length = 0,
   1399 	.key_replay_counter = 2,
   1400 	.key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1401 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1402 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1403 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1404 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1405 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1406 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1407 	.key_mic_data = { 0x3e, 0x85, 0x3a, 0x3c, 0x83, 0x71, 0x4a, 0x94, 0xe4,
   1408 			0x30, 0xdf, 0xb2, 0x06, 0x65, 0xa1, 0xd4 },
   1409 	.key_data_len = 0,
   1410 };
   1411 
   1412 /* WPA frame, 1 of 4.  For parameters see eapol_sm_test_igtk */
   1413 static const unsigned char eapol_key_data_29[] = {
   1414 	0x02, 0x03, 0x00, 0x5f, 0x02, 0x00, 0x89, 0x00, 0x20, 0x00,
   1415 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x30, 0x37, 0x86,
   1416 	0x8d, 0x6c, 0xd2, 0x38, 0xb2, 0xfe, 0xb4, 0x5b, 0xd3, 0xc6,
   1417 	0x4b, 0xa1, 0x3e, 0x26, 0xd9, 0xa4, 0x89, 0x8b, 0x43, 0xf6,
   1418 	0x66, 0x51, 0x26, 0x99, 0x5e, 0x62, 0xce, 0x8e, 0x9d, 0x00,
   1419 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1420 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1421 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1422 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1423 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1424 };
   1425 
   1426 static struct eapol_key_data eapol_key_test_29 = {
   1427 	.frame = eapol_key_data_29,
   1428 	.frame_len = sizeof(eapol_key_data_29),
   1429 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
   1430 	.packet_len = 95,
   1431 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
   1432 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1433 	.key_type = true,
   1434 	.install = false,
   1435 	.key_ack = true,
   1436 	.key_mic = false,
   1437 	.secure = false,
   1438 	.error = false,
   1439 	.request = false,
   1440 	.encrypted_key_data = false,
   1441 	.smk_message = false,
   1442 	.key_length = 32,
   1443 	.key_replay_counter = 1,
   1444 	.key_nonce = { 0x30, 0x37, 0x86, 0x8d, 0x6c, 0xd2, 0x38, 0xb2, 0xfe,
   1445 			0xb4, 0x5b, 0xd3, 0xc6, 0x4b, 0xa1, 0x3e, 0x26, 0xd9,
   1446 			0xa4, 0x89, 0x8b, 0x43, 0xf6, 0x66, 0x51, 0x26, 0x99,
   1447 			0x5e, 0x62, 0xce, 0x8e, 0x9d},
   1448 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1449 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1450 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1451 	.key_mic_data = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1452 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, },
   1453 	.key_data_len = 0,
   1454 };
   1455 
   1456 /* WPA frame, 2 of 4.  For parameters see eapol_sm_test_igtk */
   1457 static const unsigned char eapol_key_data_30[] = {
   1458 	0x01, 0x03, 0x00, 0x7b, 0x02, 0x01, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
   1459 	0x00, 0x00, 0x00, 0x00, 0x01, 0x3e, 0x5e, 0xb7, 0x47, 0x91, 0xf4, 0x2a,
   1460 	0x39, 0x3a, 0x6a, 0xbc, 0xeb, 0x9c, 0x25, 0x27, 0x0f, 0x61, 0xb4, 0x24,
   1461 	0x8c, 0xf2, 0x97, 0xdf, 0x22, 0xef, 0x67, 0x15, 0x87, 0xad, 0x22, 0xc3,
   1462 	0xd8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1463 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1464 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92, 0x76, 0xec,
   1465 	0x87, 0x1e, 0x42, 0x7a, 0x66, 0x3f, 0x45, 0xb2, 0x7f, 0x7c, 0xd7, 0xe3,
   1466 	0xb9, 0x00, 0x1c, 0x30, 0x1a, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x02, 0x01,
   1467 	0x00, 0x00, 0x0f, 0xac, 0x02, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x02, 0x80,
   1468 	0x00, 0x00, 0x00, 0x00, 0x0f, 0xac, 0x06,
   1469 };
   1470 
   1471 static struct eapol_key_data eapol_key_test_30 = {
   1472 	.frame = eapol_key_data_30,
   1473 	.frame_len = sizeof(eapol_key_data_30),
   1474 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
   1475 	.packet_len = 123,
   1476 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
   1477 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1478 	.key_type = true,
   1479 	.install = false,
   1480 	.key_ack = false,
   1481 	.key_mic = true,
   1482 	.secure = false,
   1483 	.error = false,
   1484 	.request = false,
   1485 	.encrypted_key_data = false,
   1486 	.smk_message = false,
   1487 	.key_length = 0,
   1488 	.key_replay_counter = 1,
   1489 	.key_nonce = { 0x3e, 0x5e, 0xb7, 0x47, 0x91, 0xf4, 0x2a, 0x39, 0x3a,
   1490 			0x6a, 0xbc, 0xeb, 0x9c, 0x25, 0x27, 0x0f, 0x61, 0xb4,
   1491 			0x24, 0x8c, 0xf2, 0x97, 0xdf, 0x22, 0xef, 0x67, 0x15,
   1492 			0x87, 0xad, 0x22, 0xc3, 0xd8 },
   1493 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1494 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1495 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1496 	.key_mic_data = { 0x92, 0x76, 0xec, 0x87, 0x1e, 0x42, 0x7a, 0x66, 0x3f,
   1497 			0x45, 0xb2, 0x7f, 0x7c, 0xd7, 0xe3, 0xb9 },
   1498 	.key_data_len = 28,
   1499 };
   1500 
   1501 /* WPA frame, 3 of 4.  For parameters see eapol_sm_test_igtk */
   1502 static const unsigned char eapol_key_data_31[] = {
   1503 	0x02, 0x03, 0x00, 0xd3, 0x02, 0x13, 0xc9, 0x00, 0x20, 0x00, 0x00, 0x00,
   1504 	0x00, 0x00, 0x00, 0x00, 0x02, 0x30, 0x37, 0x86, 0x8d, 0x6c, 0xd2, 0x38,
   1505 	0xb2, 0xfe, 0xb4, 0x5b, 0xd3, 0xc6, 0x4b, 0xa1, 0x3e, 0x26, 0xd9, 0xa4,
   1506 	0x89, 0x8b, 0x43, 0xf6, 0x66, 0x51, 0x26, 0x99, 0x5e, 0x62, 0xce, 0x8e,
   1507 	0x9d, 0x92, 0xcf, 0x64, 0xa6, 0xf5, 0xea, 0x95, 0xf7, 0xf9, 0xeb, 0x6a,
   1508 	0x54, 0x8a, 0x85, 0x6c, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1509 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x80, 0xb3,
   1510 	0x14, 0x1f, 0xfa, 0x11, 0x47, 0xcd, 0x6d, 0xd0, 0x20, 0x7e, 0x9e, 0x68,
   1511 	0x65, 0x00, 0x74, 0x39, 0xf4, 0xc9, 0x3a, 0xf3, 0xac, 0xf5, 0xd3, 0x98,
   1512 	0xeb, 0xaf, 0x3c, 0x0f, 0xf1, 0xb5, 0x33, 0xff, 0xb2, 0x00, 0x1b, 0xe4,
   1513 	0x2c, 0x61, 0xaf, 0xff, 0x1c, 0x22, 0x76, 0x07, 0x3b, 0xbc, 0x0d, 0x0c,
   1514 	0xeb, 0x8a, 0xdc, 0xcd, 0x47, 0x01, 0xa5, 0x6e, 0x76, 0x77, 0x85, 0x6f,
   1515 	0x09, 0x43, 0x83, 0xee, 0x50, 0x6e, 0x5e, 0xb1, 0x24, 0xe3, 0x47, 0xef,
   1516 	0x20, 0x5e, 0x5c, 0x10, 0x7a, 0xe3, 0x61, 0x69, 0x7b, 0xb0, 0xf6, 0xdd,
   1517 	0x42, 0x1a, 0xe1, 0xc9, 0x33, 0xd6, 0xd3, 0x88, 0x40, 0xcc, 0x72, 0x28,
   1518 	0x86, 0xce, 0xec, 0xea, 0xc0, 0xea, 0xc9, 0xcf, 0xe1, 0x93, 0x8b, 0x15,
   1519 	0x5e, 0xbb, 0x1f, 0xf9, 0x6f, 0x10, 0x34, 0xa5, 0xfc, 0x61, 0x78, 0x77,
   1520 	0xa7, 0xb1, 0x4d, 0xc4, 0x36, 0xea, 0x2f, 0x1d, 0xda, 0x31, 0xa1,
   1521 };
   1522 
   1523 static struct eapol_key_data eapol_key_test_31 = {
   1524 	.frame = eapol_key_data_31,
   1525 	.frame_len = sizeof(eapol_key_data_31),
   1526 	.protocol_version = EAPOL_PROTOCOL_VERSION_2004,
   1527 	.packet_len = 211,
   1528 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
   1529 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1530 	.key_type = true,
   1531 	.install = true,
   1532 	.key_ack = true,
   1533 	.key_mic = true,
   1534 	.secure = true,
   1535 	.error = false,
   1536 	.request = false,
   1537 	.encrypted_key_data = true,
   1538 	.smk_message = false,
   1539 	.key_length = 32,
   1540 	.key_replay_counter = 2,
   1541 	.key_nonce = { 0x30, 0x37, 0x86, 0x8d, 0x6c, 0xd2, 0x38, 0xb2, 0xfe,
   1542 			0xb4, 0x5b, 0xd3, 0xc6, 0x4b, 0xa1, 0x3e, 0x26, 0xd9,
   1543 			0xa4, 0x89, 0x8b, 0x43, 0xf6, 0x66, 0x51, 0x26, 0x99,
   1544 			0x5e, 0x62, 0xce, 0x8e, 0x9d },
   1545 	.eapol_key_iv = { 0x92, 0xcf, 0x64, 0xa6, 0xf5, 0xea, 0x95, 0xf7, 0xf9,
   1546 			0xeb, 0x6a, 0x54, 0x8a, 0x85, 0x6c, 0x1c},
   1547 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1548 	.key_mic_data = { 0x1f, 0x80, 0xb3, 0x14, 0x1f, 0xfa, 0x11, 0x47, 0xcd,
   1549 			0x6d, 0xd0, 0x20, 0x7e, 0x9e, 0x68, 0x65 },
   1550 	.key_data_len = 116,
   1551 };
   1552 
   1553 /* WPA frame, 4 of 4.  For parameters see eapol_sm_test_igtk */
   1554 static const unsigned char eapol_key_data_32[] = {
   1555 	0x01, 0x03, 0x00, 0x5f, 0x02, 0x03, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00,
   1556 	0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1557 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1558 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1559 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1560 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1561 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x66, 0x2c, 0x07,
   1562 	0x9b, 0x73, 0xb6, 0x94, 0xb9, 0x4b, 0x7f, 0xa1, 0x99, 0x2f, 0x7a, 0x92,
   1563 	0xe2, 0x00, 0x00
   1564 };
   1565 
   1566 static struct eapol_key_data eapol_key_test_32 = {
   1567 	.frame = eapol_key_data_32,
   1568 	.frame_len = sizeof(eapol_key_data_32),
   1569 	.protocol_version = EAPOL_PROTOCOL_VERSION_2001,
   1570 	.packet_len = 95,
   1571 	.descriptor_type = EAPOL_DESCRIPTOR_TYPE_80211,
   1572 	.key_descriptor_version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1573 	.key_type = true,
   1574 	.install = false,
   1575 	.key_ack = false,
   1576 	.key_mic = true,
   1577 	.secure = true,
   1578 	.error = false,
   1579 	.request = false,
   1580 	.encrypted_key_data = false,
   1581 	.smk_message = false,
   1582 	.key_length = 0,
   1583 	.key_replay_counter = 2,
   1584 	.key_nonce = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1585 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1586 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1587 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1588 	.eapol_key_iv = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1589 			0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1590 	.key_rsc = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
   1591 	.key_mic_data = { 0x66, 0x2c, 0x07, 0x9b, 0x73, 0xb6, 0x94, 0xb9,
   1592 			0x4b, 0x7f, 0xa1, 0x99, 0x2f, 0x7a, 0x92, 0xe2  },
   1593 	.key_data_len = 0,
   1594 };
   1595 
   1596 static void eapol_key_test(const void *data)
   1597 {
   1598 	const struct eapol_key_data *test = data;
   1599 	const struct eapol_key *packet;
   1600 
   1601 	packet = eapol_key_validate(test->frame, test->frame_len, 16);
   1602 	assert(packet);
   1603 
   1604 	assert(packet->header.protocol_version == test->protocol_version);
   1605 	assert(packet->header.packet_type == 0x03);
   1606 	assert(L_BE16_TO_CPU(packet->header.packet_len) == test->packet_len);
   1607 	assert(packet->descriptor_type == test->descriptor_type);
   1608 	assert(packet->key_descriptor_version == test->key_descriptor_version);
   1609 	assert(packet->key_type == test->key_type);
   1610 	assert(packet->wpa_key_id == test->wpa_key_id);
   1611 	assert(packet->install == test->install);
   1612 	assert(packet->key_ack == test->key_ack);
   1613 	assert(packet->key_mic == test->key_mic);
   1614 	assert(packet->secure == test->secure);
   1615 	assert(packet->error == test->error);
   1616 	assert(packet->request == test->request);
   1617 	assert(packet->encrypted_key_data == test->encrypted_key_data);
   1618 	assert(packet->smk_message == test->smk_message);
   1619 	assert(L_BE16_TO_CPU(packet->key_length) == test->key_length);
   1620 	assert(L_BE64_TO_CPU(packet->key_replay_counter) ==
   1621 			test->key_replay_counter);
   1622 	assert(!memcmp(packet->key_nonce, test->key_nonce,
   1623 			sizeof(packet->key_nonce)));
   1624 	assert(!memcmp(packet->eapol_key_iv, test->eapol_key_iv,
   1625 			sizeof(packet->eapol_key_iv)));
   1626 	assert(!memcmp(EAPOL_KEY_MIC(packet), test->key_mic_data,
   1627 			sizeof(test->key_mic_data)));
   1628 	assert(!memcmp(packet->key_rsc, test->key_rsc,
   1629 			sizeof(packet->key_rsc)));
   1630 	assert(EAPOL_KEY_DATA_LEN(packet, 16) == test->key_data_len);
   1631 }
   1632 
   1633 struct eapol_key_mic_test {
   1634 	const uint8_t *frame;
   1635 	size_t frame_len;
   1636 	enum eapol_key_descriptor_version version;
   1637 	const uint8_t *kck;
   1638 	const uint8_t *mic;
   1639 };
   1640 
   1641 static const uint8_t eapol_key_mic_data_1[] = {
   1642 	0x01, 0x03, 0x00, 0x75, 0x02, 0x01, 0x0a, 0x00,
   1643 	0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1644 	0x01, 0x59, 0x16, 0x8b, 0xc3, 0xa5, 0xdf, 0x18,
   1645 	0xd7, 0x1e, 0xfb, 0x64, 0x23, 0xf3, 0x40, 0x08,
   1646 	0x8d, 0xab, 0x9e, 0x1b, 0xa2, 0xbb, 0xc5, 0x86,
   1647 	0x59, 0xe0, 0x7b, 0x37, 0x64, 0xb0, 0xde, 0x85,
   1648 	0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1649 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1650 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1651 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1652 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1653 	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1654 	0x00, 0x00, 0x16, 0x30, 0x14, 0x01, 0x00, 0x00,
   1655 	0x0f, 0xac, 0x04, 0x01, 0x00, 0x00, 0x0f, 0xac,
   1656 	0x04, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x02, 0x01,
   1657 	0x00,
   1658 };
   1659 
   1660 static const uint8_t eapol_key_mic_1[] = {
   1661 	0x9c, 0xc3, 0xfa, 0xa0, 0xc6, 0x85, 0x96, 0x1d,
   1662 	0x84, 0x06, 0xbb, 0x65, 0x77, 0x45, 0x13, 0x5d,
   1663 };
   1664 
   1665 static unsigned char kck_data_1[] = {
   1666 	0x9a, 0x75, 0xef, 0x0b, 0xde, 0x7c, 0x20, 0x9c,
   1667 	0xca, 0xe1, 0x3f, 0x54, 0xb1, 0xb3, 0x3e, 0xa3,
   1668 };
   1669 
   1670 static const struct eapol_key_mic_test eapol_key_mic_test_1 = {
   1671 	.frame = eapol_key_mic_data_1,
   1672 	.frame_len = sizeof(eapol_key_mic_data_1),
   1673 	.version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   1674 	.kck = kck_data_1,
   1675 	.mic = eapol_key_mic_1,
   1676 };
   1677 
   1678 static const uint8_t eapol_key_mic_2[] = {
   1679 	0x6f, 0x04, 0x89, 0xcf, 0x74, 0x06, 0xac, 0xf0,
   1680 	0xae, 0x8f, 0xcb, 0x32, 0xbc, 0xe5, 0x7c, 0x37,
   1681 };
   1682 
   1683 static const struct eapol_key_mic_test eapol_key_mic_test_2 = {
   1684 	.frame = eapol_key_mic_data_1,
   1685 	.frame_len = sizeof(eapol_key_mic_data_1),
   1686 	.version = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
   1687 	.kck = kck_data_1,
   1688 	.mic = eapol_key_mic_2,
   1689 };
   1690 
   1691 static void eapol_key_mic_test(const void *data)
   1692 {
   1693 	const struct eapol_key_mic_test *test = data;
   1694 	uint8_t mic[16];
   1695 
   1696 	memset(mic, 0, sizeof(mic));
   1697 
   1698 	switch (test->version) {
   1699 	case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4:
   1700 		assert(hmac_md5(test->kck, 16, test->frame, test->frame_len,
   1701 				mic, 16));
   1702 		break;
   1703 	case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES:
   1704 		assert(hmac_sha1(test->kck, 16, test->frame, test->frame_len,
   1705 				mic, 16));
   1706 		break;
   1707 	default:
   1708 		assert(false);
   1709 	}
   1710 
   1711 	assert(!memcmp(test->mic, mic, sizeof(mic)));
   1712 }
   1713 
   1714 struct eapol_calculate_mic_test {
   1715 	const uint8_t *frame;
   1716 	size_t frame_len;
   1717 	const uint8_t *kck;
   1718 	const uint8_t *mic;
   1719 };
   1720 
   1721 static const struct eapol_calculate_mic_test eapol_calculate_mic_test_1 = {
   1722 	.frame = eapol_key_mic_data_1,
   1723 	.frame_len = sizeof(eapol_key_mic_data_1),
   1724 	.kck = kck_data_1,
   1725 	.mic = eapol_key_mic_2,
   1726 };
   1727 
   1728 static void eapol_calculate_mic_test(const void *data)
   1729 {
   1730 	const struct eapol_calculate_mic_test *test = data;
   1731 	struct eapol_key *frame;
   1732 	uint8_t mic[16];
   1733 	bool ret;
   1734 
   1735 	memset(mic, 0, sizeof(mic));
   1736 	frame = (struct eapol_key *) test->frame;
   1737 
   1738 	ret = eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, test->kck, frame,
   1739 					mic, 16);
   1740 	assert(ret);
   1741 	assert(!memcmp(test->mic, mic, sizeof(mic)));
   1742 }
   1743 
   1744 static void eapol_4way_test(const void *data)
   1745 {
   1746 	uint8_t anonce[32];
   1747 	uint8_t snonce[32];
   1748 	uint8_t mic[16];
   1749 	struct eapol_key *frame;
   1750 	uint8_t aa[] = { 0x24, 0xa2, 0xe1, 0xec, 0x17, 0x04 };
   1751 	uint8_t spa[] = { 0xa0, 0xa8, 0xcd, 0x1c, 0x7e, 0xc9 };
   1752 	const char *passphrase = "EasilyGuessedPassword";
   1753 	const char *ssid = "TestWPA";
   1754 	const unsigned char expected_psk[] = {
   1755 		0xbf, 0x9a, 0xa3, 0x15, 0x53, 0x00, 0x12, 0x5e,
   1756 		0x7a, 0x5e, 0xbb, 0x2a, 0x54, 0x9f, 0x8c, 0xd4,
   1757 		0xed, 0xab, 0x8e, 0xe1, 0x2e, 0x94, 0xbf, 0xc2,
   1758 		0x4b, 0x33, 0x57, 0xad, 0x04, 0x96, 0x65, 0xd9 };
   1759 	unsigned char psk[32];
   1760 	uint8_t *ptk;
   1761 	size_t ptk_len;
   1762 	bool ret;
   1763 	const struct eapol_key *step1;
   1764 	const struct eapol_key *step2;
   1765 	const struct eapol_key *step3;
   1766 	const struct eapol_key *step4;
   1767 	uint8_t *decrypted_key_data;
   1768 	size_t decrypted_key_data_len;
   1769 
   1770 	step1 = eapol_key_validate(eapol_key_data_3,
   1771 					sizeof(eapol_key_data_3), 16);
   1772 	assert(step1);
   1773 	assert(eapol_verify_ptk_1_of_4(step1, 16, false));
   1774 	memcpy(anonce, step1->key_nonce, sizeof(step1->key_nonce));
   1775 
   1776 	step2 = eapol_key_validate(eapol_key_data_4,
   1777 					sizeof(eapol_key_data_4), 16);
   1778 	assert(step2);
   1779 	assert(eapol_verify_ptk_2_of_4(step2, false));
   1780 	memcpy(snonce, step2->key_nonce, sizeof(step2->key_nonce));
   1781 
   1782 	assert(!crypto_psk_from_passphrase(passphrase, (uint8_t *) ssid,
   1783 						strlen(ssid), psk));
   1784 	assert(!memcmp(expected_psk, psk, sizeof(psk)));
   1785 
   1786 	ptk_len = 32 + crypto_cipher_key_len(CRYPTO_CIPHER_CCMP);
   1787 	ptk = l_malloc(ptk_len);
   1788 	ret = crypto_derive_pairwise_ptk(psk, sizeof(psk), aa, spa, anonce,
   1789 						snonce, ptk, ptk_len,
   1790 						L_CHECKSUM_SHA1);
   1791 	assert(ret);
   1792 
   1793 	frame = eapol_create_ptk_2_of_4(EAPOL_PROTOCOL_VERSION_2001,
   1794 				EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
   1795 				eapol_key_test_4.key_replay_counter,
   1796 				snonce, eapol_key_test_4.key_data_len,
   1797 				eapol_key_data_4 + EAPOL_FRAME_LEN(16),
   1798 				false, 16, false);
   1799 	assert(frame);
   1800 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
   1801 					mic, 16));
   1802 	memcpy(EAPOL_KEY_MIC(frame), mic, sizeof(mic));
   1803 	assert(!memcmp(frame, eapol_key_data_4, sizeof(eapol_key_data_4)));
   1804 	l_free(frame);
   1805 
   1806 	step3 = eapol_key_validate(eapol_key_data_5,
   1807 					sizeof(eapol_key_data_5), 16);
   1808 	assert(step3);
   1809 	assert(eapol_verify_ptk_3_of_4(step3, false, 16));
   1810 	assert(!memcmp(anonce, step3->key_nonce, sizeof(step3->key_nonce)));
   1811 
   1812 	assert(eapol_verify_mic(IE_RSN_AKM_SUITE_PSK, ptk, step3, 16));
   1813 	decrypted_key_data = eapol_decrypt_key_data(IE_RSN_AKM_SUITE_PSK,
   1814 						ptk + 16, step3,
   1815 						&decrypted_key_data_len, 16);
   1816 	assert(decrypted_key_data[0] == 48);  // RSNE
   1817 	l_free(decrypted_key_data);
   1818 
   1819 	step4 = eapol_key_validate(eapol_key_data_6,
   1820 					sizeof(eapol_key_data_6), 16);
   1821 	assert(step4);
   1822 	assert(eapol_verify_ptk_4_of_4(step4, false));
   1823 
   1824 	l_free(ptk);
   1825 }
   1826 
   1827 static void eapol_wpa2_handshake_test(const void *data)
   1828 {
   1829 	uint8_t anonce[32];
   1830 	uint8_t snonce[32];
   1831 	uint8_t mic[16];
   1832 	struct eapol_key *frame;
   1833 	uint8_t aa[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   1834 	uint8_t spa[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 };
   1835 	const char *passphrase = "EasilyGuessedPassword";
   1836 	const char *ssid = "TestWPA";
   1837 	const unsigned char expected_psk[] = {
   1838 		0xbf, 0x9a, 0xa3, 0x15, 0x53, 0x00, 0x12, 0x5e,
   1839 		0x7a, 0x5e, 0xbb, 0x2a, 0x54, 0x9f, 0x8c, 0xd4,
   1840 		0xed, 0xab, 0x8e, 0xe1, 0x2e, 0x94, 0xbf, 0xc2,
   1841 		0x4b, 0x33, 0x57, 0xad, 0x04, 0x96, 0x65, 0xd9 };
   1842 	unsigned char psk[32];
   1843 	uint8_t *ptk;
   1844 	size_t ptk_len;
   1845 	bool ret;
   1846 	const struct eapol_key *ptk_step1;
   1847 	const struct eapol_key *ptk_step2;
   1848 	const struct eapol_key *ptk_step3;
   1849 	const struct eapol_key *ptk_step4;
   1850 	const struct eapol_key *gtk_step1;
   1851 	const struct eapol_key *gtk_step2;
   1852 	uint8_t *decrypted_key_data;
   1853 	size_t decrypted_key_data_len;
   1854 
   1855 	ptk_step1 = eapol_key_validate(eapol_key_data_7,
   1856 					sizeof(eapol_key_data_7), 16);
   1857 	assert(ptk_step1);
   1858 	assert(eapol_verify_ptk_1_of_4(ptk_step1, 16, false));
   1859 	memcpy(anonce, ptk_step1->key_nonce, sizeof(ptk_step1->key_nonce));
   1860 
   1861 	ptk_step2 = eapol_key_validate(eapol_key_data_8,
   1862 					sizeof(eapol_key_data_8), 16);
   1863 	assert(ptk_step2);
   1864 	assert(eapol_verify_ptk_2_of_4(ptk_step2, false));
   1865 	memcpy(snonce, ptk_step2->key_nonce, sizeof(ptk_step2->key_nonce));
   1866 
   1867 	assert(!crypto_psk_from_passphrase(passphrase, (uint8_t *) ssid,
   1868 						strlen(ssid), psk));
   1869 	assert(!memcmp(expected_psk, psk, sizeof(psk)));
   1870 
   1871 	ptk_len = 32 + crypto_cipher_key_len(CRYPTO_CIPHER_CCMP);
   1872 	ptk = l_malloc(ptk_len);
   1873 	ret = crypto_derive_pairwise_ptk(psk, sizeof(psk), aa, spa, anonce,
   1874 						snonce, ptk, ptk_len,
   1875 						L_CHECKSUM_SHA1);
   1876 	assert(ret);
   1877 
   1878 	frame = eapol_create_ptk_2_of_4(EAPOL_PROTOCOL_VERSION_2004,
   1879 				EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
   1880 				eapol_key_test_8.key_replay_counter,
   1881 				snonce, eapol_key_test_8.key_data_len,
   1882 				eapol_key_data_8 + EAPOL_FRAME_LEN(16),
   1883 				false, 16, false);
   1884 	assert(frame);
   1885 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
   1886 					mic, 16));
   1887 	memcpy(EAPOL_KEY_MIC(frame), mic, sizeof(mic));
   1888 	assert(!memcmp(frame, eapol_key_data_8, sizeof(eapol_key_data_8)));
   1889 	l_free(frame);
   1890 
   1891 	ptk_step3 = eapol_key_validate(eapol_key_data_9,
   1892 					sizeof(eapol_key_data_9), 16);
   1893 	assert(ptk_step3);
   1894 	assert(eapol_verify_ptk_3_of_4(ptk_step3, false, 16));
   1895 	assert(!memcmp(anonce, ptk_step3->key_nonce,
   1896 				sizeof(ptk_step3->key_nonce)));
   1897 
   1898 	assert(eapol_verify_mic(IE_RSN_AKM_SUITE_PSK, ptk, ptk_step3, 16));
   1899 
   1900 	decrypted_key_data = eapol_decrypt_key_data(IE_RSN_AKM_SUITE_PSK,
   1901 						ptk + 16, ptk_step3,
   1902 						&decrypted_key_data_len, 16);
   1903 	assert(decrypted_key_data[0] == 48);  // RSNE
   1904 	l_free(decrypted_key_data);
   1905 
   1906 	ptk_step4 = eapol_key_validate(eapol_key_data_10,
   1907 					sizeof(eapol_key_data_10), 16);
   1908 	assert(ptk_step4);
   1909 	assert(eapol_verify_ptk_4_of_4(ptk_step4, false));
   1910 
   1911 	frame = eapol_create_ptk_4_of_4(EAPOL_PROTOCOL_VERSION_2004,
   1912 				EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
   1913 				eapol_key_test_10.key_replay_counter,
   1914 				false, 16);
   1915 	assert(frame);
   1916 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
   1917 					mic, 16));
   1918 	memcpy(EAPOL_KEY_MIC(frame), mic, sizeof(mic));
   1919 	assert(!memcmp(frame, eapol_key_data_10, sizeof(eapol_key_data_10)));
   1920 	l_free(frame);
   1921 
   1922 	gtk_step1 = eapol_key_validate(eapol_key_data_11,
   1923 					sizeof(eapol_key_data_11), 16);
   1924 	assert(gtk_step1);
   1925 	assert(eapol_verify_gtk_1_of_2(gtk_step1, false, 16));
   1926 
   1927 	decrypted_key_data = eapol_decrypt_key_data(IE_RSN_AKM_SUITE_PSK,
   1928 						ptk + 16, gtk_step1,
   1929 						&decrypted_key_data_len, 16);
   1930 	assert(decrypted_key_data[0] == 221);  /* GTK KDE */
   1931 	assert(decrypted_key_data[2] == 0x00);
   1932 	assert(decrypted_key_data[3] == 0x0f);
   1933 	assert(decrypted_key_data[4] == 0xac);
   1934 	assert(decrypted_key_data[5] == 0x01);
   1935 	l_free(decrypted_key_data);
   1936 
   1937 	gtk_step2 = eapol_key_validate(eapol_key_data_12,
   1938 					sizeof(eapol_key_data_12), 16);
   1939 	assert(gtk_step2);
   1940 	assert(eapol_verify_gtk_2_of_2(gtk_step2, false));
   1941 
   1942 	frame = eapol_create_gtk_2_of_2(EAPOL_PROTOCOL_VERSION_2004,
   1943 				EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES,
   1944 				eapol_key_test_12.key_replay_counter,
   1945 				0, NULL,
   1946 				false, 0, 16);
   1947 	assert(frame);
   1948 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
   1949 					mic, 16));
   1950 	memcpy(EAPOL_KEY_MIC(frame), mic, sizeof(mic));
   1951 	assert(!memcmp(frame, eapol_key_data_12, sizeof(eapol_key_data_12)));
   1952 	l_free(frame);
   1953 
   1954 	l_free(ptk);
   1955 }
   1956 
   1957 static void eapol_wpa_handshake_test(const void *data)
   1958 {
   1959 	uint8_t anonce[32];
   1960 	uint8_t snonce[32];
   1961 	uint8_t mic[16];
   1962 	struct eapol_key *frame;
   1963 	uint8_t aa[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   1964 	uint8_t spa[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 };
   1965 	const char *passphrase = "EasilyGuessedPassword";
   1966 	const char *ssid = "TestWPA";
   1967 	const unsigned char expected_psk[] = {
   1968 		0xbf, 0x9a, 0xa3, 0x15, 0x53, 0x00, 0x12, 0x5e,
   1969 		0x7a, 0x5e, 0xbb, 0x2a, 0x54, 0x9f, 0x8c, 0xd4,
   1970 		0xed, 0xab, 0x8e, 0xe1, 0x2e, 0x94, 0xbf, 0xc2,
   1971 		0x4b, 0x33, 0x57, 0xad, 0x04, 0x96, 0x65, 0xd9 };
   1972 	unsigned char psk[32];
   1973 	uint8_t *ptk;
   1974 	size_t ptk_len;
   1975 	bool ret;
   1976 	const struct eapol_key *ptk_step1;
   1977 	const struct eapol_key *ptk_step2;
   1978 	const struct eapol_key *ptk_step3;
   1979 	const struct eapol_key *ptk_step4;
   1980 	const struct eapol_key *gtk_step1;
   1981 	const struct eapol_key *gtk_step2;
   1982 	uint8_t *decrypted_key_data;
   1983 	size_t decrypted_key_data_len;
   1984 
   1985 	ptk_step1 = eapol_key_validate(eapol_key_data_13,
   1986 					sizeof(eapol_key_data_13), 16);
   1987 	assert(ptk_step1);
   1988 	assert(eapol_verify_ptk_1_of_4(ptk_step1, 16, false));
   1989 	memcpy(anonce, ptk_step1->key_nonce, sizeof(ptk_step1->key_nonce));
   1990 
   1991 	ptk_step2 = eapol_key_validate(eapol_key_data_14,
   1992 					sizeof(eapol_key_data_14), 16);
   1993 	assert(ptk_step2);
   1994 	assert(eapol_verify_ptk_2_of_4(ptk_step2, false));
   1995 	memcpy(snonce, ptk_step2->key_nonce, sizeof(ptk_step2->key_nonce));
   1996 
   1997 	assert(!crypto_psk_from_passphrase(passphrase, (uint8_t *) ssid,
   1998 						strlen(ssid), psk));
   1999 	assert(!memcmp(expected_psk, psk, sizeof(psk)));
   2000 
   2001 	ptk_len = 32 + crypto_cipher_key_len(CRYPTO_CIPHER_TKIP);
   2002 	ptk = l_malloc(ptk_len);
   2003 	ret = crypto_derive_pairwise_ptk(psk, sizeof(psk), aa, spa, anonce,
   2004 						snonce, ptk, ptk_len,
   2005 						L_CHECKSUM_SHA1);
   2006 	assert(ret);
   2007 
   2008 	frame = eapol_create_ptk_2_of_4(EAPOL_PROTOCOL_VERSION_2004,
   2009 				EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   2010 				eapol_key_test_14.key_replay_counter,
   2011 				snonce, eapol_key_test_14.key_data_len,
   2012 				eapol_key_data_14 + EAPOL_FRAME_LEN(16),
   2013 				true, 16, false);
   2014 	assert(frame);
   2015 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
   2016 					mic, 16));
   2017 	memcpy(EAPOL_KEY_MIC(frame), mic, sizeof(mic));
   2018 	assert(!memcmp(frame, eapol_key_data_14, sizeof(eapol_key_data_14)));
   2019 	l_free(frame);
   2020 
   2021 	ptk_step3 = eapol_key_validate(eapol_key_data_15,
   2022 					sizeof(eapol_key_data_15), 16);
   2023 	assert(ptk_step3);
   2024 	assert(eapol_verify_ptk_3_of_4(ptk_step3, true, 16));
   2025 	assert(!memcmp(anonce, ptk_step3->key_nonce,
   2026 				sizeof(ptk_step3->key_nonce)));
   2027 
   2028 	assert(eapol_verify_mic(IE_RSN_AKM_SUITE_PSK, ptk, ptk_step3, 16));
   2029 
   2030 	assert(EAPOL_KEY_DATA(ptk_step3, 16)[0] == IE_TYPE_VENDOR_SPECIFIC);
   2031 	assert(is_ie_wpa_ie(EAPOL_KEY_DATA(ptk_step3, 16) + 2,
   2032 				EAPOL_KEY_DATA_LEN(ptk_step3, 16) - 2));
   2033 
   2034 	ptk_step4 = eapol_key_validate(eapol_key_data_16,
   2035 					sizeof(eapol_key_data_16), 16);
   2036 	assert(ptk_step4);
   2037 	assert(eapol_verify_ptk_4_of_4(ptk_step4, true));
   2038 
   2039 	frame = eapol_create_ptk_4_of_4(EAPOL_PROTOCOL_VERSION_2004,
   2040 				EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   2041 				eapol_key_test_16.key_replay_counter, true, 16);
   2042 	assert(frame);
   2043 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
   2044 					mic, 16));
   2045 	memcpy(EAPOL_KEY_MIC(frame), mic, sizeof(mic));
   2046 	assert(!memcmp(frame, eapol_key_data_16, sizeof(eapol_key_data_16)));
   2047 	l_free(frame);
   2048 
   2049 	gtk_step1 = eapol_key_validate(eapol_key_data_17,
   2050 					sizeof(eapol_key_data_17), 16);
   2051 	assert(gtk_step1);
   2052 	assert(eapol_verify_gtk_1_of_2(gtk_step1, true, 16));
   2053 
   2054 	decrypted_key_data = eapol_decrypt_key_data(IE_RSN_AKM_SUITE_PSK,
   2055 						ptk + 16, gtk_step1,
   2056 						&decrypted_key_data_len, 16);
   2057 	assert(decrypted_key_data_len == 32);
   2058 	l_free(decrypted_key_data);
   2059 
   2060 	gtk_step2 = eapol_key_validate(eapol_key_data_18,
   2061 					sizeof(eapol_key_data_18), 16);
   2062 	assert(gtk_step2);
   2063 	assert(eapol_verify_gtk_2_of_2(gtk_step2, true));
   2064 
   2065 	frame = eapol_create_gtk_2_of_2(EAPOL_PROTOCOL_VERSION_2004,
   2066 				EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4,
   2067 				eapol_key_test_18.key_replay_counter, 0, NULL,
   2068 				true, gtk_step1->wpa_key_id, 16);
   2069 	assert(frame);
   2070 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, frame,
   2071 					mic, 16));
   2072 	memcpy(EAPOL_KEY_MIC(frame), mic, sizeof(mic));
   2073 	assert(!memcmp(frame, eapol_key_data_18, sizeof(eapol_key_data_18)));
   2074 	l_free(frame);
   2075 
   2076 	l_free(ptk);
   2077 }
   2078 
   2079 static int verify_step2(uint32_t ifindex,
   2080 			const uint8_t *aa_addr, uint16_t proto,
   2081 			const struct eapol_frame *ef, bool noencrypt,
   2082 			void *user_data)
   2083 {
   2084 	const struct eapol_key *ek = (const struct eapol_key *) ef;
   2085 	size_t ek_len = EAPOL_FRAME_LEN(16) + EAPOL_KEY_DATA_LEN(ek, 16);
   2086 
   2087 	assert(ifindex == 1);
   2088 	assert(proto == ETH_P_PAE);
   2089 	assert(!memcmp(aa_addr, aa, 6));
   2090 	assert(ek_len == expected_step2_frame_size);
   2091 	assert(!memcmp(ek, expected_step2_frame, expected_step2_frame_size));
   2092 
   2093 	verify_step2_called = true;
   2094 
   2095 	return 0;
   2096 }
   2097 
   2098 static int verify_step4(uint32_t ifindex,
   2099 			const uint8_t *aa_addr, uint16_t proto,
   2100 			const struct eapol_frame *ef, bool noencrypt,
   2101 			void *user_data)
   2102 {
   2103 	const struct eapol_key *ek = (const struct eapol_key *) ef;
   2104 	size_t ek_len = EAPOL_FRAME_LEN(16) + EAPOL_KEY_DATA_LEN(ek, 16);
   2105 
   2106 	assert(ifindex == 1);
   2107 	assert(!memcmp(aa_addr, aa, 6));
   2108 	assert(proto == ETH_P_PAE);
   2109 	assert(ek_len == expected_step4_frame_size);
   2110 	assert(!memcmp(ek, expected_step4_frame, expected_step4_frame_size));
   2111 
   2112 	verify_step4_called = true;
   2113 
   2114 	return 0;
   2115 }
   2116 
   2117 static int verify_step2_gtk(uint32_t ifindex,
   2118 				const uint8_t *aa_addr, uint16_t proto,
   2119 				const struct eapol_frame *ef, bool noencrypt,
   2120 				void *user_data)
   2121 {
   2122 	const struct eapol_key *ek = (const struct eapol_key *) ef;
   2123 	size_t ek_len = EAPOL_FRAME_LEN(16) + EAPOL_KEY_DATA_LEN(ek, 16);
   2124 
   2125 	assert(ifindex == 1);
   2126 	assert(!memcmp(aa_addr, aa, 6));
   2127 	assert(proto == ETH_P_PAE);
   2128 	assert(ek_len == expected_gtk_step2_frame_size);
   2129 	assert(!memcmp(ek, expected_gtk_step2_frame,
   2130 			expected_gtk_step2_frame_size));
   2131 
   2132 	verify_gtk_step2_called = true;
   2133 
   2134 	return 0;
   2135 }
   2136 
   2137 static bool test_nonce(uint8_t nonce[])
   2138 {
   2139 	memcpy(nonce, snonce, 32);
   2140 
   2141 	return true;
   2142 }
   2143 
   2144 static void eapol_sm_test_ptk(const void *data)
   2145 {
   2146 	const unsigned char psk[] = {
   2147 		0xbf, 0x9a, 0xa3, 0x15, 0x53, 0x00, 0x12, 0x5e,
   2148 		0x7a, 0x5e, 0xbb, 0x2a, 0x54, 0x9f, 0x8c, 0xd4,
   2149 		0xed, 0xab, 0x8e, 0xe1, 0x2e, 0x94, 0xbf, 0xc2,
   2150 		0x4b, 0x33, 0x57, 0xad, 0x04, 0x96, 0x65, 0xd9 };
   2151 	const unsigned char ap_rsne[] = {
   2152 		0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   2153 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   2154 		0x00, 0x0f, 0xac, 0x02, 0x00, 0x00 };
   2155 	static uint8_t ap_address[] = { 0x24, 0xa2, 0xe1, 0xec, 0x17, 0x04 };
   2156 	static uint8_t sta_address[] = { 0xa0, 0xa8, 0xcd, 0x1c, 0x7e, 0xc9 };
   2157 	bool r;
   2158 	struct handshake_state *hs;
   2159 	struct eapol_sm *sm;
   2160 
   2161 	eapol_init();
   2162 
   2163 	snonce = eapol_key_test_4.key_nonce;
   2164 	__handshake_set_get_nonce_func(test_nonce);
   2165 
   2166 	aa = ap_address;
   2167 	spa = sta_address;
   2168 	verify_step2_called = false;
   2169 	expected_step2_frame = eapol_key_data_4;
   2170 	expected_step2_frame_size = sizeof(eapol_key_data_4);
   2171 	verify_step4_called = false;
   2172 	expected_step4_frame = eapol_key_data_6;
   2173 	expected_step4_frame_size = sizeof(eapol_key_data_6);
   2174 
   2175 	hs = test_handshake_state_new(1);
   2176 	/* key_data_3 uses 2004 while key_data_3 uses 2001, so force 2001 */
   2177 	handshake_state_set_protocol_version(hs, EAPOL_PROTOCOL_VERSION_2001);
   2178 
   2179 	sm = eapol_sm_new(hs);
   2180 	eapol_register(sm);
   2181 
   2182 	handshake_state_set_pmk(hs, psk, sizeof(psk));
   2183 	handshake_state_set_authenticator_address(hs, aa);
   2184 	handshake_state_set_supplicant_address(hs, spa);
   2185 
   2186 	r =  handshake_state_set_supplicant_ie(hs,
   2187 				eapol_key_data_4 + EAPOL_FRAME_LEN(16));
   2188 	assert(r);
   2189 
   2190 	handshake_state_set_authenticator_ie(hs, ap_rsne);
   2191 	eapol_start(sm);
   2192 
   2193 	__eapol_set_tx_packet_func(verify_step2);
   2194 	__eapol_rx_packet(1, aa, ETH_P_PAE, eapol_key_data_3,
   2195 					sizeof(eapol_key_data_3), false);
   2196 	assert(verify_step2_called);
   2197 
   2198 	__eapol_set_tx_packet_func(verify_step4);
   2199 	__eapol_rx_packet(1, aa, ETH_P_PAE, eapol_key_data_5,
   2200 					sizeof(eapol_key_data_5), false);
   2201 	assert(verify_step4_called);
   2202 
   2203 	eapol_sm_free(sm);
   2204 	handshake_state_unref(hs);
   2205 	eapol_exit();
   2206 }
   2207 
   2208 static void eapol_sm_test_igtk(const void *data)
   2209 {
   2210 	const unsigned char psk[] = {
   2211 		0xbf, 0x9a, 0xa3, 0x15, 0x53, 0x00, 0x12, 0x5e,
   2212 		0x7a, 0x5e, 0xbb, 0x2a, 0x54, 0x9f, 0x8c, 0xd4,
   2213 		0xed, 0xab, 0x8e, 0xe1, 0x2e, 0x94, 0xbf, 0xc2,
   2214 		0x4b, 0x33, 0x57, 0xad, 0x04, 0x96, 0x65, 0xd9 };
   2215 	const unsigned char ap_rsne[] = {
   2216 		0x30, 0x1a, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x02, 0x01, 0x00,
   2217 		0x00, 0x0f, 0xac, 0x02, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x02,
   2218 		0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xac, 0x06 };
   2219 	static uint8_t ap_address[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   2220 	static uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 };
   2221 	bool r;
   2222 	struct handshake_state *hs;
   2223 	struct eapol_sm *sm;
   2224 
   2225 	eapol_init();
   2226 
   2227 	snonce = eapol_key_test_30.key_nonce;
   2228 	__handshake_set_get_nonce_func(test_nonce);
   2229 
   2230 	aa = ap_address;
   2231 	spa = sta_address;
   2232 	verify_step2_called = false;
   2233 	expected_step2_frame = eapol_key_data_30;
   2234 	expected_step2_frame_size = sizeof(eapol_key_data_30);
   2235 	verify_step4_called = false;
   2236 	expected_step4_frame = eapol_key_data_32;
   2237 	expected_step4_frame_size = sizeof(eapol_key_data_32);
   2238 
   2239 	hs = test_handshake_state_new(1);
   2240 	/* key_data_29 uses 2004 while key_data_30 uses 2001, so force 2001 */
   2241 	handshake_state_set_protocol_version(hs, EAPOL_PROTOCOL_VERSION_2001);
   2242 
   2243 	sm = eapol_sm_new(hs);
   2244 	eapol_register(sm);
   2245 
   2246 	handshake_state_set_pmk(hs, psk, sizeof(psk));
   2247 	handshake_state_set_authenticator_address(hs, aa);
   2248 	handshake_state_set_supplicant_address(hs, spa);
   2249 
   2250 	r =  handshake_state_set_supplicant_ie(hs,
   2251 				eapol_key_data_30 + EAPOL_FRAME_LEN(16));
   2252 	assert(r);
   2253 
   2254 	handshake_state_set_authenticator_ie(hs, ap_rsne);
   2255 	eapol_start(sm);
   2256 
   2257 	__eapol_set_tx_packet_func(verify_step2);
   2258 	__eapol_rx_packet(1, aa, ETH_P_PAE, eapol_key_data_29,
   2259 					sizeof(eapol_key_data_29), false);
   2260 	assert(verify_step2_called);
   2261 
   2262 	__eapol_set_tx_packet_func(verify_step4);
   2263 	__eapol_rx_packet(1, aa, ETH_P_PAE, eapol_key_data_31,
   2264 					sizeof(eapol_key_data_31), false);
   2265 	assert(verify_step4_called);
   2266 
   2267 	eapol_sm_free(sm);
   2268 	handshake_state_unref(hs);
   2269 	eapol_exit();
   2270 }
   2271 
   2272 static void eapol_sm_test_wpa2_ptk_gtk(const void *data)
   2273 {
   2274 	const unsigned char psk[] = {
   2275 		0xbf, 0x9a, 0xa3, 0x15, 0x53, 0x00, 0x12, 0x5e,
   2276 		0x7a, 0x5e, 0xbb, 0x2a, 0x54, 0x9f, 0x8c, 0xd4,
   2277 		0xed, 0xab, 0x8e, 0xe1, 0x2e, 0x94, 0xbf, 0xc2,
   2278 		0x4b, 0x33, 0x57, 0xad, 0x04, 0x96, 0x65, 0xd9 };
   2279 	const unsigned char ap_rsne[] = {
   2280 		0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   2281 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   2282 		0x00, 0x0f, 0xac, 0x02 };
   2283 	static uint8_t ap_address[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   2284 	static uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 };
   2285 	bool r;
   2286 	struct handshake_state *hs;
   2287 	struct eapol_sm *sm;
   2288 
   2289 	eapol_init();
   2290 
   2291 	snonce = eapol_key_test_8.key_nonce;
   2292 	__handshake_set_get_nonce_func(test_nonce);
   2293 
   2294 	aa = ap_address;
   2295 	spa = sta_address;
   2296 	verify_step2_called = false;
   2297 	expected_step2_frame = eapol_key_data_8;
   2298 	expected_step2_frame_size = sizeof(eapol_key_data_8);
   2299 	verify_step4_called = false;
   2300 	expected_step4_frame = eapol_key_data_10;
   2301 	expected_step4_frame_size = sizeof(eapol_key_data_10);
   2302 	verify_gtk_step2_called = false;
   2303 	expected_gtk_step2_frame = eapol_key_data_12;
   2304 	expected_gtk_step2_frame_size = sizeof(eapol_key_data_12);
   2305 
   2306 	hs = test_handshake_state_new(1);
   2307 	sm = eapol_sm_new(hs);
   2308 	eapol_register(sm);
   2309 
   2310 	handshake_state_set_pmk(hs, psk, sizeof(psk));
   2311 	handshake_state_set_authenticator_address(hs, aa);
   2312 	handshake_state_set_supplicant_address(hs, spa);
   2313 
   2314 	r = handshake_state_set_supplicant_ie(hs,
   2315 				eapol_key_data_8 + EAPOL_FRAME_LEN(16));
   2316 	assert(r);
   2317 
   2318 	handshake_state_set_authenticator_ie(hs, ap_rsne);
   2319 	eapol_start(sm);
   2320 
   2321 	__eapol_set_tx_packet_func(verify_step2);
   2322 	__eapol_rx_packet(1, aa, ETH_P_PAE, eapol_key_data_7,
   2323 				sizeof(eapol_key_data_7), false);
   2324 	assert(verify_step2_called);
   2325 
   2326 	__eapol_set_tx_packet_func(verify_step4);
   2327 	__eapol_rx_packet(1, aa, ETH_P_PAE, eapol_key_data_9,
   2328 					sizeof(eapol_key_data_9), false);
   2329 	assert(verify_step4_called);
   2330 
   2331 	__eapol_set_tx_packet_func(verify_step2_gtk);
   2332 	__eapol_rx_packet(1, aa, ETH_P_PAE, eapol_key_data_11,
   2333 					sizeof(eapol_key_data_11), false);
   2334 	assert(verify_gtk_step2_called);
   2335 
   2336 	eapol_sm_free(sm);
   2337 	handshake_state_unref(hs);
   2338 	eapol_exit();
   2339 }
   2340 
   2341 static void eapol_sm_test_wpa_ptk_gtk(const void *data)
   2342 {
   2343 	const unsigned char psk[] = {
   2344 		0xbf, 0x9a, 0xa3, 0x15, 0x53, 0x00, 0x12, 0x5e,
   2345 		0x7a, 0x5e, 0xbb, 0x2a, 0x54, 0x9f, 0x8c, 0xd4,
   2346 		0xed, 0xab, 0x8e, 0xe1, 0x2e, 0x94, 0xbf, 0xc2,
   2347 		0x4b, 0x33, 0x57, 0xad, 0x04, 0x96, 0x65, 0xd9 };
   2348 	const unsigned char ap_wpa_ie[] = {
   2349 		0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, 0x01, 0x00,
   2350 		0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50,
   2351 		0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02 };
   2352 	static uint8_t ap_address[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   2353 	static uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 };
   2354 	bool r;
   2355 	struct handshake_state *hs;
   2356 	struct eapol_sm *sm;
   2357 
   2358 	eapol_init();
   2359 	snonce = eapol_key_test_14.key_nonce;
   2360 	__handshake_set_get_nonce_func(test_nonce);
   2361 
   2362 	aa = ap_address;
   2363 	spa = sta_address;
   2364 	verify_step2_called = false;
   2365 	expected_step2_frame = eapol_key_data_14;
   2366 	expected_step2_frame_size = sizeof(eapol_key_data_14);
   2367 	verify_step4_called = false;
   2368 	expected_step4_frame = eapol_key_data_16;
   2369 	expected_step4_frame_size = sizeof(eapol_key_data_16);
   2370 	verify_gtk_step2_called = false;
   2371 	expected_gtk_step2_frame = eapol_key_data_18;
   2372 	expected_gtk_step2_frame_size = sizeof(eapol_key_data_18);
   2373 
   2374 	hs = test_handshake_state_new(1);
   2375 	sm = eapol_sm_new(hs);
   2376 	eapol_register(sm);
   2377 
   2378 	handshake_state_set_pmk(hs, psk, sizeof(psk));
   2379 	handshake_state_set_authenticator_address(hs, ap_address);
   2380 	handshake_state_set_supplicant_address(hs, sta_address);
   2381 	r = handshake_state_set_supplicant_ie(hs,
   2382 				eapol_key_data_14 + EAPOL_FRAME_LEN(16));
   2383 	assert(r);
   2384 
   2385 	handshake_state_set_authenticator_ie(hs, ap_wpa_ie);
   2386 	eapol_start(sm);
   2387 
   2388 	__eapol_set_tx_packet_func(verify_step2);
   2389 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eapol_key_data_13,
   2390 					sizeof(eapol_key_data_13), false);
   2391 	assert(verify_step2_called);
   2392 
   2393 	__eapol_set_tx_packet_func(verify_step4);
   2394 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eapol_key_data_15,
   2395 					sizeof(eapol_key_data_15), false);
   2396 	assert(verify_step4_called);
   2397 
   2398 	__eapol_set_tx_packet_func(verify_step2_gtk);
   2399 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eapol_key_data_17,
   2400 					sizeof(eapol_key_data_17), false);
   2401 	assert(verify_gtk_step2_called);
   2402 
   2403 	eapol_sm_free(sm);
   2404 	handshake_state_unref(hs);
   2405 	eapol_exit();
   2406 }
   2407 
   2408 static void eapol_sm_test_wpa_ptk_gtk_2(const void *data)
   2409 {
   2410 	const unsigned char psk[] = {
   2411 		0xbf, 0x9a, 0xa3, 0x15, 0x53, 0x00, 0x12, 0x5e,
   2412 		0x7a, 0x5e, 0xbb, 0x2a, 0x54, 0x9f, 0x8c, 0xd4,
   2413 		0xed, 0xab, 0x8e, 0xe1, 0x2e, 0x94, 0xbf, 0xc2,
   2414 		0x4b, 0x33, 0x57, 0xad, 0x04, 0x96, 0x65, 0xd9 };
   2415 	const unsigned char ap_wpa_ie[] = {
   2416 		0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, 0x01, 0x00,
   2417 		0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50,
   2418 		0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02 };
   2419 	static uint8_t ap_address[] = { 0x24, 0xa2, 0xe1, 0xec, 0x17, 0x04 };
   2420 	static uint8_t sta_address[] = { 0xa0, 0xa8, 0xcd, 0x1c, 0x7e, 0xc9 };
   2421 	bool r;
   2422 	struct handshake_state *hs;
   2423 	struct eapol_sm *sm;
   2424 
   2425 	eapol_init();
   2426 	snonce = eapol_key_test_20.key_nonce;
   2427 	__handshake_set_get_nonce_func(test_nonce);
   2428 
   2429 	aa = ap_address;
   2430 	spa = sta_address;
   2431 	verify_step2_called = false;
   2432 	expected_step2_frame = eapol_key_data_20;
   2433 	expected_step2_frame_size = sizeof(eapol_key_data_20);
   2434 	verify_step4_called = false;
   2435 	expected_step4_frame = eapol_key_data_22;
   2436 	expected_step4_frame_size = sizeof(eapol_key_data_22);
   2437 	verify_gtk_step2_called = false;
   2438 	expected_gtk_step2_frame = eapol_key_data_24;
   2439 	expected_gtk_step2_frame_size = sizeof(eapol_key_data_24);
   2440 
   2441 	hs = test_handshake_state_new(1);
   2442 	sm = eapol_sm_new(hs);
   2443 	eapol_register(sm);
   2444 
   2445 	handshake_state_set_pmk(hs, psk, sizeof(psk));
   2446 	handshake_state_set_authenticator_address(hs, ap_address);
   2447 	handshake_state_set_supplicant_address(hs, sta_address);
   2448 
   2449 	r = handshake_state_set_supplicant_ie(hs,
   2450 				eapol_key_data_20 + EAPOL_FRAME_LEN(16));
   2451 	assert(r);
   2452 
   2453 	handshake_state_set_authenticator_ie(hs, ap_wpa_ie);
   2454 	eapol_start(sm);
   2455 
   2456 	__eapol_set_tx_packet_func(verify_step2);
   2457 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eapol_key_data_19,
   2458 					sizeof(eapol_key_data_19), false);
   2459 	assert(verify_step2_called);
   2460 
   2461 	__eapol_set_tx_packet_func(verify_step4);
   2462 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eapol_key_data_21,
   2463 					sizeof(eapol_key_data_21), false);
   2464 	assert(verify_step4_called);
   2465 
   2466 	__eapol_set_tx_packet_func(verify_step2_gtk);
   2467 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eapol_key_data_23,
   2468 					sizeof(eapol_key_data_23), false);
   2469 	assert(verify_gtk_step2_called);
   2470 
   2471 	eapol_sm_free(sm);
   2472 	handshake_state_unref(hs);
   2473 	eapol_exit();
   2474 }
   2475 
   2476 static void verify_install_tk(struct handshake_state *hs, uint8_t key_index,
   2477 				const uint8_t *tk, uint32_t cipher)
   2478 {
   2479 	struct test_handshake_state *ths =
   2480 			l_container_of(hs, struct test_handshake_state, super);
   2481 
   2482 	assert(hs->ifindex == 1);
   2483 	assert(!memcmp(hs->aa, aa, 6));
   2484 
   2485 	if (ths->tk) {
   2486 		assert(!memcmp(tk, ths->tk, 32));
   2487 		assert(cipher == CRYPTO_CIPHER_TKIP);
   2488 	}
   2489 
   2490 	verify_install_tk_called = true;
   2491 }
   2492 
   2493 static void verify_install_gtk(struct handshake_state *hs, uint16_t key_index,
   2494 				const uint8_t *gtk, uint8_t gtk_len,
   2495 				const uint8_t *rsc, uint8_t rsc_len,
   2496 				uint32_t cipher)
   2497 {
   2498 	assert(hs->ifindex == 1);
   2499 	verify_install_gtk_called = true;
   2500 }
   2501 
   2502 static inline size_t EKL(const struct eapol_key *frame)
   2503 {
   2504 	return EAPOL_FRAME_LEN(16) + EAPOL_KEY_DATA_LEN(frame, 16);
   2505 }
   2506 
   2507 static struct eapol_key *UPDATED_REPLAY_COUNTER(const struct eapol_key *frame,
   2508 							uint64_t replay_counter,
   2509 							uint8_t *ptk)
   2510 {
   2511 	struct eapol_key *ret = l_memdup(frame, EKL(frame));
   2512 	uint8_t mic[16];
   2513 
   2514 	ret->key_replay_counter = L_CPU_TO_BE64(replay_counter);
   2515 	memset(EAPOL_KEY_MIC(ret), 0, 16);
   2516 	eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, ret, mic, 16);
   2517 	memcpy(EAPOL_KEY_MIC(ret), mic, sizeof(mic));
   2518 
   2519 	return ret;
   2520 }
   2521 
   2522 static void eapol_sm_wpa2_retransmit_test(const void *data)
   2523 {
   2524 	static uint8_t ap_address[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   2525 	static uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 };
   2526 	const char *passphrase = "EasilyGuessedPassword";
   2527 	const char *ssid = "TestWPA";
   2528 	unsigned char psk[32];
   2529 	const unsigned char ap_rsne[] = {
   2530 		0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   2531 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   2532 		0x00, 0x0f, 0xac, 0x02 };
   2533 	uint8_t new_snonce[32];
   2534 	uint8_t *ptk;
   2535 	size_t ptk_len;
   2536 	struct eapol_key *expect;
   2537 	struct eapol_key *retransmit;
   2538 	bool r;
   2539 	const struct eapol_key *ptk_step1;
   2540 	const struct eapol_key *ptk_step2;
   2541 	const struct eapol_key *ptk_step3;
   2542 	const struct eapol_key *ptk_step4;
   2543 	const struct eapol_key *gtk_step1;
   2544 	const struct eapol_key *gtk_step2;
   2545 	struct handshake_state *hs;
   2546 	struct eapol_sm *sm;
   2547 	uint64_t replay_counter;
   2548 
   2549 	aa = ap_address;
   2550 	spa = sta_address;
   2551 
   2552 	crypto_psk_from_passphrase(passphrase, (uint8_t *) ssid,
   2553 							strlen(ssid), psk);
   2554 
   2555 	eapol_init();
   2556 	hs = test_handshake_state_new(1);
   2557 	sm = eapol_sm_new(hs);
   2558 	eapol_register(sm);
   2559 
   2560 	handshake_state_set_pmk(hs, psk, 32);
   2561 	handshake_state_set_authenticator_address(hs, ap_address);
   2562 	handshake_state_set_supplicant_address(hs, sta_address);
   2563 
   2564 	r = handshake_state_set_supplicant_ie(hs,
   2565 				eapol_key_data_8 + EAPOL_FRAME_LEN(16));
   2566 	assert(r);
   2567 
   2568 	handshake_state_set_authenticator_ie(hs, ap_rsne);
   2569 	eapol_start(sm);
   2570 
   2571 	ptk_step1 = eapol_key_validate(eapol_key_data_7,
   2572 					sizeof(eapol_key_data_7), 16);
   2573 	assert(ptk_step1);
   2574 
   2575 	ptk_step2 = eapol_key_validate(eapol_key_data_8,
   2576 					sizeof(eapol_key_data_8), 16);
   2577 	assert(ptk_step2);
   2578 
   2579 	replay_counter = L_BE64_TO_CPU(ptk_step1->key_replay_counter);
   2580 	snonce = ptk_step2->key_nonce;
   2581 	__handshake_set_get_nonce_func(test_nonce);
   2582 	__handshake_set_install_tk_func(verify_install_tk);
   2583 	__handshake_set_install_gtk_func(verify_install_gtk);
   2584 
   2585 	ptk_len = 32 + crypto_cipher_key_len(CRYPTO_CIPHER_CCMP);
   2586 	ptk = l_malloc(ptk_len);
   2587 	assert(crypto_derive_pairwise_ptk(psk, sizeof(psk), aa, spa,
   2588 						ptk_step1->key_nonce,
   2589 						ptk_step2->key_nonce,
   2590 						ptk, ptk_len, L_CHECKSUM_SHA1));
   2591 
   2592 	verify_step2_called = false;
   2593 	expected_step2_frame = (const uint8_t *) ptk_step2;
   2594 	expected_step2_frame_size = EKL(ptk_step2);
   2595 	__eapol_set_tx_packet_func(verify_step2);
   2596 	__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   2597 				(const uint8_t *) ptk_step1, EKL(ptk_step1),
   2598 				false);
   2599 	assert(verify_step2_called);
   2600 
   2601 	/* Detect whether we generate a new snonce when we shouldn't */
   2602 	memset(new_snonce, 0xff, sizeof(new_snonce));
   2603 	snonce = new_snonce;
   2604 
   2605 	/*
   2606 	 * Now retransmit frame 1 again without updating the counter.  This
   2607 	 * seems to be legal since the STA should not update the replay counter
   2608 	 * unless the packet has a MIC.
   2609 	 */
   2610 	verify_step2_called = false;
   2611 	__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   2612 				(const uint8_t *) ptk_step1, EKL(ptk_step1),
   2613 				false);
   2614 	assert(verify_step2_called);
   2615 
   2616 	/* Now retransmit frame 1 with an updated counter */
   2617 	replay_counter += 1;
   2618 	retransmit = l_memdup(ptk_step1, EKL(ptk_step1));
   2619 	retransmit->key_replay_counter = L_CPU_TO_BE64(replay_counter);
   2620 
   2621 	expect = UPDATED_REPLAY_COUNTER(ptk_step2, replay_counter, ptk);
   2622 
   2623 	verify_step2_called = false;
   2624 	expected_step2_frame = (const uint8_t *) expect;
   2625 	expected_step2_frame_size = EKL(expect);
   2626 	__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   2627 				(const uint8_t *) retransmit, EKL(retransmit),
   2628 				false);
   2629 	assert(verify_step2_called);
   2630 
   2631 	l_free(expect);
   2632 	l_free(retransmit);
   2633 
   2634 	ptk_step3 = eapol_key_validate(eapol_key_data_9,
   2635 					sizeof(eapol_key_data_9), 16);
   2636 	assert(ptk_step3);
   2637 
   2638 	ptk_step4 = eapol_key_validate(eapol_key_data_10,
   2639 					sizeof(eapol_key_data_10), 16);
   2640 	assert(ptk_step4);
   2641 
   2642 	verify_install_tk_called = false;
   2643 	verify_step4_called = false;
   2644 	expected_step4_frame = (const uint8_t *) ptk_step4;
   2645 	expected_step4_frame_size = EKL(ptk_step4);
   2646 	__eapol_set_tx_packet_func(verify_step4);
   2647 	__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   2648 				(const uint8_t *) ptk_step3, EKL(ptk_step3),
   2649 				false);
   2650 	assert(verify_step4_called);
   2651 	assert(verify_install_tk_called);
   2652 
   2653 	/*
   2654 	 * Now retransmit message 3.  Make sure install_tk_called is false
   2655 	 * this time.  This prevents KRACK style attacks.
   2656 	 */
   2657 	replay_counter += 1;
   2658 	retransmit = UPDATED_REPLAY_COUNTER(ptk_step3, replay_counter, ptk);
   2659 	expect = UPDATED_REPLAY_COUNTER(ptk_step4, replay_counter, ptk);
   2660 
   2661 	verify_install_tk_called = false;
   2662 	verify_step4_called = false;
   2663 	expected_step4_frame = (const uint8_t *) expect;
   2664 	expected_step4_frame_size = EKL(expect);
   2665 	__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   2666 				(const uint8_t *) retransmit, EKL(retransmit),
   2667 				false);
   2668 	assert(verify_step4_called);
   2669 	assert(!verify_install_tk_called);
   2670 
   2671 	l_free(expect);
   2672 	l_free(retransmit);
   2673 
   2674 	gtk_step1 = eapol_key_validate(eapol_key_data_11,
   2675 					sizeof(eapol_key_data_11), 16);
   2676 	assert(gtk_step1);
   2677 
   2678 	gtk_step2 = eapol_key_validate(eapol_key_data_12,
   2679 					sizeof(eapol_key_data_12), 16);
   2680 	assert(gtk_step2);
   2681 
   2682 	/*
   2683 	 * Now run the GTK handshake.  Since we retransmitted Step 3 above,
   2684 	 * update the replay counter and perform the initial transmission
   2685 	 */
   2686 	replay_counter += 1;
   2687 	retransmit = UPDATED_REPLAY_COUNTER(gtk_step1, replay_counter, ptk);
   2688 	expect = UPDATED_REPLAY_COUNTER(gtk_step2, replay_counter, ptk);
   2689 
   2690 	verify_install_gtk_called = false;
   2691 	verify_gtk_step2_called = false;
   2692 	expected_gtk_step2_frame = (const uint8_t *) expect;
   2693 	expected_gtk_step2_frame_size = EKL(expect);
   2694 	__eapol_set_tx_packet_func(verify_step2_gtk);
   2695 	__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   2696 				(const uint8_t *) retransmit, EKL(retransmit),
   2697 				false);
   2698 	assert(verify_gtk_step2_called);
   2699 	assert(verify_install_gtk_called);
   2700 
   2701 	l_free(retransmit);
   2702 	l_free(expect);
   2703 
   2704 	/* Now send a retransmit, make sure GTK isn't installed again */
   2705 	replay_counter += 1;
   2706 	retransmit = UPDATED_REPLAY_COUNTER(gtk_step1, replay_counter, ptk);
   2707 	expect = UPDATED_REPLAY_COUNTER(gtk_step2, replay_counter, ptk);
   2708 
   2709 	verify_install_gtk_called = false;
   2710 	verify_gtk_step2_called = false;
   2711 	expected_gtk_step2_frame = (const uint8_t *) expect;
   2712 	expected_gtk_step2_frame_size = EKL(expect);
   2713 	__eapol_set_tx_packet_func(verify_step2_gtk);
   2714 	__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   2715 				(const uint8_t *) retransmit, EKL(retransmit),
   2716 				false);
   2717 	assert(verify_gtk_step2_called);
   2718 	assert(!verify_install_gtk_called);
   2719 
   2720 	l_free(retransmit);
   2721 	l_free(expect);
   2722 
   2723 	l_free(ptk);
   2724 
   2725 	eapol_sm_free(sm);
   2726 	handshake_state_unref(hs);
   2727 	eapol_exit();
   2728 }
   2729 
   2730 static const uint8_t eap_identity_req[] = {
   2731 	0x02, 0x00, 0x00, 0x05, 0x01, 0x01, 0x00, 0x05, 0x01
   2732 };
   2733 static const uint8_t eap_identity_resp[] = {
   2734 	0x02, 0x00, 0x00, 0x14, 0x02, 0x01, 0x00, 0x14, 0x01, 0x61, 0x62, 0x63,
   2735 	0x40, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d
   2736 };
   2737 
   2738 struct eapol_8021x_tls_test_state {
   2739 	l_tls_write_cb_t app_data_cb;
   2740 	l_tls_ready_cb_t ready_cb;
   2741 	l_tls_disconnect_cb_t disconnect_cb;
   2742 
   2743 	uint8_t method;
   2744 	bool expect_handshake_fail;
   2745 
   2746 	struct l_tls *tls;
   2747 	uint8_t last_id;
   2748 
   2749 	bool success;
   2750 	bool pending_req;
   2751 	bool tx_ack;
   2752 	bool disconnected;
   2753 
   2754 	uint8_t tx_buf[16384];
   2755 	unsigned int tx_buf_len, tx_buf_offset;
   2756 
   2757 	uint8_t pmk[32];
   2758 };
   2759 
   2760 static int verify_8021x_identity_resp(uint32_t ifindex,
   2761 					const uint8_t *aa_addr, uint16_t proto,
   2762 					const struct eapol_frame *ef,
   2763 					bool noencrypt,
   2764 					void *user_data)
   2765 {
   2766 	struct eapol_8021x_tls_test_state *s = user_data;
   2767 	size_t len = sizeof(struct eapol_header) +
   2768 		L_BE16_TO_CPU(ef->header.packet_len);
   2769 
   2770 	assert(ifindex == 1);
   2771 	assert(!memcmp(aa_addr, aa, 6));
   2772 	assert(proto == ETH_P_PAE);
   2773 	assert(len == sizeof(eap_identity_resp));
   2774 	assert(!memcmp(ef, eap_identity_resp, sizeof(eap_identity_resp)));
   2775 
   2776 	assert(s->pending_req);
   2777 	s->pending_req = 0;
   2778 
   2779 	return 0;
   2780 }
   2781 
   2782 static int verify_8021x_tls_resp(uint32_t ifindex,
   2783 					const uint8_t *aa_addr, uint16_t proto,
   2784 					const struct eapol_frame *ef,
   2785 					bool noencrypt,
   2786 					void *user_data)
   2787 {
   2788 	struct eapol_8021x_tls_test_state *s = user_data;
   2789 	size_t len = sizeof(struct eapol_header) +
   2790 		L_BE16_TO_CPU(ef->header.packet_len);
   2791 	size_t fragment_len, header_len;
   2792 
   2793 	assert(ifindex == 1);
   2794 	assert(!memcmp(aa_addr, aa, 6));
   2795 	assert(proto == ETH_P_PAE);
   2796 	assert(len >= 10);
   2797 	assert(ef->header.protocol_version == EAPOL_PROTOCOL_VERSION_2004);
   2798 	assert(ef->header.packet_type == 0x00); /* EAPoL-EAP */
   2799 
   2800 	assert(ef->data[0] == EAP_CODE_RESPONSE);
   2801 	assert(ef->data[1] == s->last_id);
   2802 	assert(ef->data[4] == s->method);
   2803 	assert((ef->data[5] & 0x3f) == 0); /* Flags */
   2804 
   2805 	/* Expecting an ACK? */
   2806 	if (s->tx_buf_len || s->success) {
   2807 		assert(ef->data[5] == 0);
   2808 		assert(len == 10);
   2809 	}
   2810 
   2811 	header_len = 6;
   2812 	fragment_len = l_get_be16(ef->data + 2) - header_len;
   2813 
   2814 	if (ef->data[5] & 0x80) { /* L flag */
   2815 		assert(len >= 14);
   2816 		header_len += 4;
   2817 		fragment_len -= 4;
   2818 		assert(ef->data[5] & 0x40); /* M flag */
   2819 		assert(l_get_be32(ef->data + 6) > fragment_len);
   2820 	}
   2821 	s->tx_ack = !!(ef->data[5] & 0x40); /* M flag */
   2822 
   2823 	assert(len == 4 + header_len + fragment_len);
   2824 
   2825 	assert(s->pending_req);
   2826 	s->pending_req = 0;
   2827 
   2828 	if (fragment_len)
   2829 		l_tls_handle_rx(s->tls, ef->data + header_len, fragment_len);
   2830 
   2831 	return 0;
   2832 }
   2833 
   2834 static void eapol_sm_test_tls_new_data(const uint8_t *data, size_t len,
   2835 						void *user_data)
   2836 {
   2837 	assert(false);
   2838 }
   2839 
   2840 static void eapol_sm_test_tls_test_write(const uint8_t *data, size_t len,
   2841 						void *user_data)
   2842 {
   2843 	struct eapol_8021x_tls_test_state *s = user_data;
   2844 
   2845 	assert(!s->tx_ack);
   2846 	assert(!s->tx_buf_offset);
   2847 
   2848 	memcpy(s->tx_buf + s->tx_buf_len, data, len);
   2849 	s->tx_buf_len += len;
   2850 }
   2851 
   2852 static void eapol_sm_test_tls_test_ready(const char *peer_identity,
   2853 						void *user_data)
   2854 {
   2855 	struct eapol_8021x_tls_test_state *s = user_data;
   2856 
   2857 	assert(!s->tx_ack);
   2858 
   2859 	s->success = true;
   2860 
   2861 	assert(l_tls_prf_get_bytes(s->tls, true, "client EAP encryption",
   2862 					s->pmk, 32));
   2863 }
   2864 
   2865 static void eapol_sm_test_tls_test_disconnected(enum l_tls_alert_desc reason,
   2866 						bool remote, void *user_data)
   2867 {
   2868 	struct eapol_8021x_tls_test_state *s = user_data;
   2869 
   2870 	l_info("TLS alert: %s (%d)", l_tls_alert_to_str(reason), reason);
   2871 	assert(s->expect_handshake_fail);
   2872 	s->disconnected = true;
   2873 }
   2874 
   2875 static void test_handshake_event(struct handshake_state *hs,
   2876 					enum handshake_event event,
   2877 					void *user_data, ...)
   2878 {
   2879 	struct test_handshake_state *ths =
   2880 			l_container_of(hs, struct test_handshake_state, super);
   2881 
   2882 	switch (event) {
   2883 	case HANDSHAKE_EVENT_FAILED:
   2884 		ths->handshake_failed = true;
   2885 		break;
   2886 	default:
   2887 		break;
   2888 	}
   2889 }
   2890 
   2891 static void eapol_sm_test_tls(struct eapol_8021x_tls_test_state *s,
   2892 				struct l_settings *config)
   2893 {
   2894 	static const unsigned char ap_wpa_ie[] = {
   2895 		0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, 0x01, 0x00,
   2896 		0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50,
   2897 		0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02 };
   2898 	static uint8_t ap_address[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   2899 	static uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 };
   2900 	bool r;
   2901 	struct handshake_state *hs;
   2902 	struct test_handshake_state *ths;
   2903 	struct eapol_sm *sm;
   2904 	uint8_t tx_buf[2000];
   2905 	size_t header_len, data_len, tx_len;
   2906 	bool start;
   2907 	uint8_t step1_buf[256], step2_buf[256], step3_buf[256], step4_buf[256];
   2908 	struct eapol_key *step1, *step2, *step3, *step4;
   2909 	uint8_t ptk_buf[64];
   2910 	uint8_t *ptk;
   2911 	struct l_certchain *server_cert;
   2912 	struct l_key *server_key;
   2913 	struct l_queue *ca_cert;
   2914 
   2915 	aa = ap_address;
   2916 	spa = sta_address;
   2917 
   2918 	eap_init();
   2919 	eapol_init();
   2920 	__handshake_set_get_nonce_func(test_nonce);
   2921 
   2922 	hs = test_handshake_state_new(1);
   2923 	ths = l_container_of(hs, struct test_handshake_state, super);
   2924 	sm = eapol_sm_new(hs);
   2925 	eapol_register(sm);
   2926 
   2927 	handshake_state_set_authenticator_address(hs, ap_address);
   2928 	handshake_state_set_supplicant_address(hs, sta_address);
   2929 	handshake_state_set_event_func(hs, test_handshake_event, NULL);
   2930 	__eapol_set_tx_user_data(s);
   2931 
   2932 	r = handshake_state_set_supplicant_ie(hs,
   2933 				eapol_key_data_14 + EAPOL_FRAME_LEN(16));
   2934 	assert(r);
   2935 
   2936 	handshake_state_set_authenticator_ie(hs, ap_wpa_ie);
   2937 
   2938 	handshake_state_set_8021x_config(hs, config);
   2939 	eapol_start(sm);
   2940 
   2941 	__eapol_set_tx_packet_func(verify_8021x_identity_resp);
   2942 	s->pending_req = 1;
   2943 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eap_identity_req,
   2944 					sizeof(eap_identity_req), false);
   2945 	assert(!s->pending_req);
   2946 
   2947 	s->tls = l_tls_new(true, s->app_data_cb, eapol_sm_test_tls_test_write,
   2948 				s->ready_cb, s->disconnect_cb, s);
   2949 	assert(s->tls);
   2950 
   2951 	if (getenv("IWD_TLS_DEBUG"))
   2952 		l_tls_set_debug(s->tls, tls_debug, NULL, NULL);
   2953 
   2954 	s->last_id = 1;
   2955 	s->success = false;
   2956 	s->tx_buf_len = 0;
   2957 	s->tx_buf_offset = 0;
   2958 
   2959 	server_cert = l_pem_load_certificate_chain(CERTDIR "cert-server.pem");
   2960 	assert(server_cert);
   2961 
   2962 	server_key = l_pem_load_private_key(CERTDIR "cert-server-key-pkcs8.pem",
   2963 						NULL, NULL);
   2964 	assert(server_key);
   2965 
   2966 	ca_cert = l_pem_load_certificate_list(CERTDIR "cert-ca.pem");
   2967 	assert(ca_cert);
   2968 
   2969 	assert(l_tls_set_auth_data(s->tls, server_cert, server_key));
   2970 	assert(l_tls_set_cacert(s->tls, ca_cert));
   2971 	assert(l_tls_start(s->tls));
   2972 
   2973 	ths->handshake_failed = false;
   2974 	start = 1;
   2975 	__eapol_set_tx_packet_func(verify_8021x_tls_resp);
   2976 	while ((!s->success || s->tx_buf_len) &&
   2977 			!ths->handshake_failed && !s->disconnected) {
   2978 		tx_len = 0;
   2979 		data_len = 1024 < s->tx_buf_len ? 1024 : s->tx_buf_len;
   2980 		header_len = 6;
   2981 		if (data_len < s->tx_buf_len && !s->tx_buf_offset)
   2982 			header_len += 4;
   2983 		tx_buf[tx_len++] = EAPOL_PROTOCOL_VERSION_2004;
   2984 		tx_buf[tx_len++] = 0x00; /* EAPoL-EAP */
   2985 		tx_buf[tx_len++] = (data_len + header_len) >> 8;
   2986 		tx_buf[tx_len++] = (data_len + header_len) >> 0;
   2987 
   2988 		tx_buf[tx_len++] = EAP_CODE_REQUEST;
   2989 		tx_buf[tx_len++] = ++s->last_id;
   2990 		tx_buf[tx_len++] = (data_len + header_len) >> 8;
   2991 		tx_buf[tx_len++] = (data_len + header_len) >> 0;
   2992 		tx_buf[tx_len++] = s->method;
   2993 		tx_buf[tx_len++] = 0x00; /* Flags */
   2994 
   2995 		if (start) {
   2996 			tx_buf[tx_len - 1] |= 0x20; /* S flag */
   2997 			start = 0;
   2998 		}
   2999 
   3000 		if (data_len < s->tx_buf_len)
   3001 			tx_buf[tx_len - 1] |= 0x40; /* M flag */
   3002 
   3003 		if (data_len < s->tx_buf_len && !s->tx_buf_offset) {
   3004 			tx_buf[tx_len - 1] |= 0x80; /* L flag */
   3005 
   3006 			tx_buf[tx_len++] = s->tx_buf_len >> 24;
   3007 			tx_buf[tx_len++] = s->tx_buf_len >> 16;
   3008 			tx_buf[tx_len++] = s->tx_buf_len >>  8;
   3009 			tx_buf[tx_len++] = s->tx_buf_len >>  0;
   3010 		}
   3011 
   3012 		memcpy(tx_buf + tx_len, s->tx_buf + s->tx_buf_offset, data_len);
   3013 		tx_len += data_len;
   3014 		s->tx_buf_offset += data_len;
   3015 		s->tx_buf_len -= data_len;
   3016 
   3017 		if (!s->tx_buf_len)
   3018 			s->tx_buf_offset = 0;
   3019 
   3020 		s->pending_req = 1;
   3021 
   3022 		__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   3023 					tx_buf, tx_len, false);
   3024 
   3025 		if (ths->handshake_failed || s->disconnected)
   3026 			break;
   3027 
   3028 		assert(!s->pending_req);
   3029 
   3030 		while (s->tx_ack) {
   3031 			tx_len = 0;
   3032 			tx_buf[tx_len++] = EAPOL_PROTOCOL_VERSION_2004;
   3033 			tx_buf[tx_len++] = 0x00; /* EAPoL-EAP */
   3034 			tx_buf[tx_len++] = 0x00;
   3035 			tx_buf[tx_len++] = 0x06; /* Length */
   3036 
   3037 			tx_buf[tx_len++] = EAP_CODE_REQUEST;
   3038 			tx_buf[tx_len++] = ++s->last_id;
   3039 			tx_buf[tx_len++] = 0x00;
   3040 			tx_buf[tx_len++] = 0x06; /* Length */
   3041 			tx_buf[tx_len++] = s->method;
   3042 			tx_buf[tx_len++] = 0x00; /* Flags */
   3043 
   3044 			s->pending_req = 1;
   3045 
   3046 			__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   3047 						tx_buf, tx_len, false);
   3048 
   3049 			if (ths->handshake_failed || s->disconnected)
   3050 				break;
   3051 
   3052 			assert(!s->pending_req);
   3053 		}
   3054 	}
   3055 
   3056 	l_tls_free(s->tls);
   3057 
   3058 	if (ths->handshake_failed || s->disconnected) {
   3059 		assert(s->expect_handshake_fail);
   3060 
   3061 		if (ths->handshake_failed)
   3062 			sm = NULL;
   3063 
   3064 		goto done;
   3065 	}
   3066 
   3067 	assert(!s->expect_handshake_fail);
   3068 
   3069 	tx_len = 0;
   3070 	tx_buf[tx_len++] = EAPOL_PROTOCOL_VERSION_2004;
   3071 	tx_buf[tx_len++] = 0x00; /* EAPoL-EAP */
   3072 	tx_buf[tx_len++] = 0x00;
   3073 	tx_buf[tx_len++] = 0x04; /* Length */
   3074 
   3075 	tx_buf[tx_len++] = EAP_CODE_SUCCESS;
   3076 	tx_buf[tx_len++] = s->last_id;
   3077 	tx_buf[tx_len++] = 0x00;
   3078 	tx_buf[tx_len++] = 0x04; /* Length */
   3079 
   3080 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, tx_buf, tx_len, false);
   3081 
   3082 	memcpy(step1_buf, eapol_key_data_13, sizeof(eapol_key_data_13));
   3083 	step1 = (struct eapol_key *)
   3084 		eapol_key_validate(step1_buf, sizeof(eapol_key_data_13), 16);
   3085 
   3086 	memcpy(step2_buf, eapol_key_data_14, sizeof(eapol_key_data_14));
   3087 	step2 = (struct eapol_key *)
   3088 		eapol_key_validate(step2_buf, sizeof(eapol_key_data_14), 16);
   3089 
   3090 	memcpy(step3_buf, eapol_key_data_15, sizeof(eapol_key_data_15));
   3091 	step3 = (struct eapol_key *)
   3092 		eapol_key_validate(step3_buf, sizeof(eapol_key_data_15), 16);
   3093 
   3094 	memcpy(step4_buf, eapol_key_data_16, sizeof(eapol_key_data_16));
   3095 	step4 = (struct eapol_key *)
   3096 		eapol_key_validate(step4_buf, sizeof(eapol_key_data_16), 16);
   3097 
   3098 	ptk = ptk_buf;
   3099 	crypto_derive_pairwise_ptk(s->pmk, sizeof(s->pmk), sta_address,
   3100 					ap_address, step1->key_nonce,
   3101 					step2->key_nonce, ptk, 64,
   3102 					L_CHECKSUM_SHA1);
   3103 
   3104 	memset(EAPOL_KEY_MIC(step2), 0, 16);
   3105 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, step2,
   3106 					EAPOL_KEY_MIC(step2), 16));
   3107 
   3108 	memset(EAPOL_KEY_MIC(step3), 0, 16);
   3109 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, step3,
   3110 					EAPOL_KEY_MIC(step3), 16));
   3111 
   3112 	memset(EAPOL_KEY_MIC(step4), 0, 16);
   3113 	assert(eapol_calculate_mic(IE_RSN_AKM_SUITE_PSK, ptk, step4,
   3114 					EAPOL_KEY_MIC(step4), 16));
   3115 
   3116 	snonce = step2->key_nonce;
   3117 
   3118 	verify_step2_called = false;
   3119 	expected_step2_frame = step2_buf;
   3120 	expected_step2_frame_size = sizeof(eapol_key_data_14);
   3121 
   3122 	__eapol_set_tx_packet_func(verify_step2);
   3123 	__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   3124 				step1_buf, sizeof(eapol_key_data_13), false);
   3125 	assert(verify_step2_called);
   3126 
   3127 	verify_step4_called = false;
   3128 	verify_install_tk_called = false;
   3129 	expected_step4_frame = step4_buf;
   3130 	expected_step4_frame_size = sizeof(eapol_key_data_16);
   3131 
   3132 	__eapol_set_tx_packet_func(verify_step4);
   3133 	__handshake_set_install_tk_func(verify_install_tk);
   3134 	ths->tk = ptk + 16 + 16;
   3135 	__eapol_rx_packet(1, ap_address, ETH_P_PAE,
   3136 				step3_buf, sizeof(eapol_key_data_15), false);
   3137 	assert(verify_step4_called);
   3138 	assert(verify_install_tk_called);
   3139 
   3140 done:
   3141 	__handshake_set_install_tk_func(NULL);
   3142 
   3143 	if (sm)
   3144 		eapol_sm_free(sm);
   3145 
   3146 	handshake_state_unref(hs);
   3147 	eapol_exit();
   3148 	eap_exit();
   3149 }
   3150 
   3151 static void eapol_sm_test_eap_tls(const void *data)
   3152 {
   3153 	static const char *config_8021x = "[Security]\n"
   3154 		"EAP-Method=TLS\n"
   3155 		"EAP-Identity=abc@example.com\n"
   3156 		"EAP-TLS-CACert=" CERTDIR "cert-ca.pem\n"
   3157 		"EAP-TLS-ClientCert=" CERTDIR "cert-client.pem\n"
   3158 		"EAP-TLS-ClientKey=" CERTDIR "cert-client-key-pkcs8.pem";
   3159 	struct eapol_8021x_tls_test_state s = {};
   3160 	struct l_settings* config = l_settings_new();
   3161 
   3162 	l_settings_load_from_data(config, config_8021x, strlen(config_8021x));
   3163 
   3164 	s.app_data_cb = eapol_sm_test_tls_new_data;
   3165 	s.ready_cb = eapol_sm_test_tls_test_ready;
   3166 	s.disconnect_cb = eapol_sm_test_tls_test_disconnected;
   3167 	s.method = EAP_TYPE_TLS;
   3168 
   3169 	eapol_sm_test_tls(&s, config);
   3170 
   3171 	l_settings_free(config);
   3172 }
   3173 
   3174 static void eapol_sm_test_eap_tls_embedded(const void *data)
   3175 {
   3176 	struct eapol_8021x_tls_test_state s = {};
   3177 	struct l_settings *config;
   3178 
   3179 	config = l_settings_new();
   3180 	assert(config);
   3181 
   3182 	assert(l_settings_load_from_file(config, CERTDIR "tls-settings.8021x"));
   3183 
   3184 	s.app_data_cb = eapol_sm_test_tls_new_data;
   3185 	s.ready_cb = eapol_sm_test_tls_test_ready;
   3186 	s.disconnect_cb = eapol_sm_test_tls_test_disconnected;
   3187 	s.method = EAP_TYPE_TLS;
   3188 
   3189 	eapol_sm_test_tls(&s, config);
   3190 
   3191 	l_settings_free(config);
   3192 }
   3193 
   3194 static void eapol_sm_test_eap_tls_subject_good(const void *data)
   3195 {
   3196 	static const char *config_8021x = "[Security]\n"
   3197 		"EAP-Method=TLS\n"
   3198 		"EAP-Identity=abc@example.com\n"
   3199 		"EAP-TLS-CACert=" CERTDIR "cert-ca.pem\n"
   3200 		"EAP-TLS-ClientCert=" CERTDIR "cert-client.pem\n"
   3201 		"EAP-TLS-ClientKey=" CERTDIR "cert-client-key-pkcs8.pem\n"
   3202 		"EAP-TLS-ServerDomainMask=bad.example.org;*.example.org";
   3203 	struct eapol_8021x_tls_test_state s = {};
   3204 	struct l_settings* config = l_settings_new();
   3205 
   3206 	l_settings_load_from_data(config, config_8021x, strlen(config_8021x));
   3207 
   3208 	s.app_data_cb = eapol_sm_test_tls_new_data;
   3209 	s.ready_cb = eapol_sm_test_tls_test_ready;
   3210 	s.disconnect_cb = eapol_sm_test_tls_test_disconnected;
   3211 	s.method = EAP_TYPE_TLS;
   3212 
   3213 	eapol_sm_test_tls(&s, config);
   3214 
   3215 	l_settings_free(config);
   3216 }
   3217 
   3218 static void eapol_sm_test_eap_tls_subject_bad(const void *data)
   3219 {
   3220 	static const char *config_8021x = "[Security]\n"
   3221 		"EAP-Method=TLS\n"
   3222 		"EAP-Identity=abc@example.com\n"
   3223 		"EAP-TLS-CACert=" CERTDIR "cert-ca.pem\n"
   3224 		"EAP-TLS-ClientCert=" CERTDIR "cert-client.pem\n"
   3225 		"EAP-TLS-ClientKey=" CERTDIR "cert-client-key-pkcs8.pem\n"
   3226 		"EAP-TLS-ServerDomainMask=bad.example.org";
   3227 	struct eapol_8021x_tls_test_state s = {};
   3228 	struct l_settings* config = l_settings_new();
   3229 
   3230 	l_settings_load_from_data(config, config_8021x, strlen(config_8021x));
   3231 
   3232 	s.app_data_cb = eapol_sm_test_tls_new_data;
   3233 	s.ready_cb = eapol_sm_test_tls_test_ready;
   3234 	s.disconnect_cb = eapol_sm_test_tls_test_disconnected;
   3235 	s.method = EAP_TYPE_TLS;
   3236 	s.expect_handshake_fail = true;
   3237 
   3238 	eapol_sm_test_tls(&s, config);
   3239 
   3240 	l_settings_free(config);
   3241 }
   3242 
   3243 static const uint8_t eap_ttls_eap_identity_avp[] = {
   3244 	0x00, 0x00, 0x00, 0x4f, 0x40, 0x00, 0x00, 0x1c, 0x02, 0x00, 0x00, 0x14,
   3245 	0x01, 0x61, 0x62, 0x63, 0x40, 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65,
   3246 	0x2e, 0x63, 0x6f, 0x6d
   3247 };
   3248 
   3249 static const uint8_t eap_ttls_eap_md5_challenge_avp[] = {
   3250 	0x00, 0x00, 0x00, 0x4f, 0x40, 0x00, 0x00, 0x1e, 0x01, 0xbb, 0x00, 0x16,
   3251 	0x04, 0x10, 0x3a, 0x34, 0x58, 0xc4, 0xf1, 0xa3, 0xdc, 0x45, 0xd0, 0xca,
   3252 	0x96, 0x33, 0x9b, 0x95, 0xb8, 0xd6, 0x00, 0x00
   3253 };
   3254 
   3255 static const uint8_t eap_ttls_eap_md5_response_avp[] = {
   3256 	0x00, 0x00, 0x00, 0x4f, 0x40, 0x00, 0x00, 0x1e, 0x02, 0xbb, 0x00, 0x16,
   3257 	0x04, 0x10, 0x10, 0xcc, 0x62, 0x4c, 0x98, 0x2b, 0x82, 0xbd, 0x13, 0x4a,
   3258 	0x81, 0xcb, 0x70, 0x78, 0xcd, 0xc2,
   3259 };
   3260 
   3261 struct eapol_8021x_eap_ttls_test_state {
   3262 	struct eapol_8021x_tls_test_state tls;
   3263 	bool challenge_sent;
   3264 };
   3265 
   3266 static void eapol_sm_test_eap_ttls_new_data(const uint8_t *data, size_t len,
   3267 						void *user_data)
   3268 {
   3269 	struct eapol_8021x_eap_ttls_test_state *s = user_data;
   3270 
   3271 	if (!s->challenge_sent) {
   3272 		assert(len == sizeof(eap_ttls_eap_identity_avp));
   3273 		assert(!memcmp(data, eap_ttls_eap_identity_avp, len));
   3274 
   3275 		l_tls_write(s->tls.tls, eap_ttls_eap_md5_challenge_avp,
   3276 				sizeof(eap_ttls_eap_md5_challenge_avp));
   3277 
   3278 		s->challenge_sent = true;
   3279 	} else {
   3280 		assert(len == sizeof(eap_ttls_eap_md5_response_avp));
   3281 		assert(!memcmp(data, eap_ttls_eap_md5_response_avp, len));
   3282 
   3283 		s->tls.success = true;
   3284 	}
   3285 }
   3286 
   3287 static void eapol_sm_test_eap_ttls_test_ready(const char *peer_identity,
   3288 						void *user_data)
   3289 {
   3290 	struct eapol_8021x_eap_ttls_test_state *s = user_data;
   3291 
   3292 	assert(!s->tls.tx_ack);
   3293 	/* TODO: require the right peer_identity */
   3294 
   3295 	assert(l_tls_prf_get_bytes(s->tls.tls, true, "ttls keying material",
   3296 					s->tls.pmk, 32));
   3297 
   3298 	s->challenge_sent = false;
   3299 }
   3300 
   3301 static void eapol_sm_test_eap_ttls_md5(const void *data)
   3302 {
   3303 	static const char *config_8021x = "[Security]\n"
   3304 		"EAP-Method=TTLS\n"
   3305 		"EAP-Identity=abc@example.com\n"
   3306 		"EAP-TTLS-CACert=" CERTDIR "cert-ca.pem\n"
   3307 		"EAP-TTLS-ClientCert=" CERTDIR "cert-client.pem\n"
   3308 		"EAP-TTLS-ClientKey=" CERTDIR "cert-client-key-pkcs8.pem\n"
   3309 		"EAP-TTLS-Phase2-Method=MD5\n"
   3310 		"EAP-TTLS-Phase2-Identity=abc@example.com\n"
   3311 		"EAP-TTLS-Phase2-Password=testpasswd";
   3312 	struct eapol_8021x_eap_ttls_test_state s = {};
   3313 	struct l_settings* config = l_settings_new();
   3314 
   3315 	l_settings_load_from_data(config, config_8021x, strlen(config_8021x));
   3316 
   3317 	s.tls.app_data_cb = eapol_sm_test_eap_ttls_new_data;
   3318 	s.tls.ready_cb = eapol_sm_test_eap_ttls_test_ready;
   3319 	s.tls.disconnect_cb = eapol_sm_test_tls_test_disconnected;
   3320 	s.tls.method = EAP_TYPE_TTLS;
   3321 
   3322 	eapol_sm_test_tls(&s.tls, config);
   3323 
   3324 	l_settings_free(config);
   3325 }
   3326 
   3327 static const uint8_t eap_ttls_start_req[] = {
   3328 	0x02, 0x00, 0x00, 0x06, 0x01, 0x02, 0x00, 0x06, 0x15, 0x20
   3329 };
   3330 static const uint8_t eap_nak_tls[] = {
   3331 	0x02, 0x00, 0x00, 0x06, 0x02, 0x02, 0x00, 0x06, 0x03, 0x0d
   3332 };
   3333 static const uint8_t eap_failure[] = {
   3334 	0x02, 0x00, 0x00, 0x04, 0x04, 0x02, 0x00, 0x04
   3335 };
   3336 
   3337 static int verify_8021x_eap_nak(uint32_t ifindex,
   3338 				const uint8_t *aa_addr, uint16_t proto,
   3339 				const struct eapol_frame *ef, bool noencrypt,
   3340 				void *user_data)
   3341 {
   3342 	struct eapol_8021x_tls_test_state *s = user_data;
   3343 	size_t len = sizeof(struct eapol_header) +
   3344 		L_BE16_TO_CPU(ef->header.packet_len);
   3345 
   3346 	assert(ifindex == 1);
   3347 	assert(!memcmp(aa_addr, aa, 6));
   3348 	assert(proto == ETH_P_PAE);
   3349 	assert(len == sizeof(eap_nak_tls));
   3350 	assert(!memcmp(ef, eap_nak_tls, sizeof(eap_nak_tls)));
   3351 
   3352 	assert(s->pending_req);
   3353 	s->pending_req = 0;
   3354 
   3355 	return 0;
   3356 }
   3357 
   3358 static void eapol_sm_test_eap_nak(const void *data)
   3359 {
   3360 	static const char *eapol_8021x_config = "[Security]\n"
   3361 		"EAP-Method=TLS\n"
   3362 		"EAP-Identity=abc@example.com\n"
   3363 		"EAP-TLS-CACert=" CERTDIR "cert-ca.pem\n"
   3364 		"EAP-TLS-ClientCert=" CERTDIR "cert-client.pem\n"
   3365 		"EAP-TLS-ClientKey=" CERTDIR "cert-client-key-pkcs8.pem";
   3366 	static const unsigned char ap_wpa_ie[] = {
   3367 		0xdd, 0x16, 0x00, 0x50, 0xf2, 0x01, 0x01, 0x00,
   3368 		0x00, 0x50, 0xf2, 0x02, 0x01, 0x00, 0x00, 0x50,
   3369 		0xf2, 0x02, 0x01, 0x00, 0x00, 0x50, 0xf2, 0x02 };
   3370 	static uint8_t ap_address[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   3371 	static uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x01, 0x00 };
   3372 	bool r;
   3373 	struct handshake_state *hs;
   3374 	struct test_handshake_state *ths;
   3375 
   3376 	struct eapol_sm *sm;
   3377 	struct l_settings *settings;
   3378 	struct eapol_8021x_tls_test_state s = {};
   3379 
   3380 	aa = ap_address;
   3381 	spa = sta_address;
   3382 
   3383 	eap_init();
   3384 	eapol_init();
   3385 	__handshake_set_get_nonce_func(test_nonce);
   3386 
   3387 	hs = test_handshake_state_new(1);
   3388 	ths = l_container_of(hs, struct test_handshake_state, super);
   3389 
   3390 	sm = eapol_sm_new(hs);
   3391 	eapol_register(sm);
   3392 
   3393 	handshake_state_set_authenticator_address(hs, ap_address);
   3394 	handshake_state_set_supplicant_address(hs, sta_address);
   3395 	handshake_state_set_event_func(hs, test_handshake_event, NULL);
   3396 	__eapol_set_tx_user_data(&s);
   3397 
   3398 	r = handshake_state_set_supplicant_ie(hs,
   3399 				eapol_key_data_20 + EAPOL_FRAME_LEN(16));
   3400 	assert(r);
   3401 
   3402 	handshake_state_set_authenticator_ie(hs, ap_wpa_ie);
   3403 
   3404 	settings = l_settings_new();
   3405 	l_settings_load_from_data(settings, eapol_8021x_config,
   3406 					strlen(eapol_8021x_config));
   3407 	handshake_state_set_8021x_config(hs, settings);
   3408 	eapol_start(sm);
   3409 
   3410 	l_settings_free(settings);
   3411 
   3412 	__eapol_set_tx_packet_func(verify_8021x_identity_resp);
   3413 	s.pending_req = 1;
   3414 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eap_identity_req,
   3415 				sizeof(eap_identity_req), false);
   3416 	assert(!s.pending_req);
   3417 
   3418 	s.pending_req = 1;
   3419 	__eapol_set_tx_packet_func(verify_8021x_eap_nak);
   3420 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eap_ttls_start_req,
   3421 				sizeof(eap_ttls_start_req), false);
   3422 	assert(!s.pending_req);
   3423 
   3424 	ths->handshake_failed = false;
   3425 	__eapol_rx_packet(1, ap_address, ETH_P_PAE, eap_failure,
   3426 				sizeof(eap_failure), false);
   3427 	assert(ths->handshake_failed);
   3428 
   3429 	handshake_state_unref(hs);
   3430 	eapol_exit();
   3431 	eap_exit();
   3432 }
   3433 
   3434 static void eapol_ft_handshake_test(const void *data)
   3435 {
   3436 	const unsigned char psk[] = {
   3437 		0xbc, 0xcd, 0x17, 0x98, 0xef, 0x6c, 0xb8, 0x7f,
   3438 		0x2b, 0x54, 0x75, 0xfb, 0x98, 0x06, 0x57, 0xd2,
   3439 		0xea, 0x02, 0x6c, 0xe3, 0x68, 0xef, 0x3f, 0xca,
   3440 		0xda, 0x31, 0x48, 0x54, 0x3f, 0xee, 0x94, 0xf0 };
   3441 	const unsigned char ap_rsne[] = {
   3442 		0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3443 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3444 		0x00, 0x0f, 0xac, 0x04, 0x81, 0x00 };
   3445 	const unsigned char own_rsne[] = {
   3446 		0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3447 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3448 		0x00, 0x0f, 0xac, 0x04 };
   3449 	const uint8_t mde[] = { 0x36, 0x03, 0x12, 0x34, 0x01 };
   3450 	const uint8_t fte[] = {
   3451 		0x37, 0x62, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3452 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3453 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3454 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3455 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3456 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3457 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3458 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3459 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3460 		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   3461 		0x00, 0x00, 0x00, 0x00, 0x01, 0x06, 0x02, 0x00,
   3462 		0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x64, 0x75,
   3463 		0x6d, 0x6d, 0x79, 0x30 };
   3464 	const uint8_t r0khid[] = "dummy0";
   3465 	const uint8_t r1khid[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   3466 	const uint8_t ap_address[] = { 0x02, 0x00, 0x00, 0x00, 0x00, 0x00 };
   3467 	const uint8_t sta_address[] = { 0x02, 0x00, 0x00, 0x00, 0x02, 0x00 };
   3468 	const char *ssid = "TestFT";
   3469 	struct handshake_state *hs;
   3470 	struct eapol_sm *sm;
   3471 
   3472 	eapol_init();
   3473 
   3474 	snonce = eapol_key_test_26.key_nonce;
   3475 	__handshake_set_get_nonce_func(test_nonce);
   3476 
   3477 	aa = ap_address;
   3478 	spa = sta_address;
   3479 	verify_step2_called = false;
   3480 	expected_step2_frame = eapol_key_data_26;
   3481 	expected_step2_frame_size = sizeof(eapol_key_data_26);
   3482 	verify_step4_called = false;
   3483 	expected_step4_frame = eapol_key_data_28;
   3484 	expected_step4_frame_size = sizeof(eapol_key_data_28);
   3485 
   3486 	hs = test_handshake_state_new(1);
   3487 	sm = eapol_sm_new(hs);
   3488 	eapol_register(sm);
   3489 
   3490 	handshake_state_set_pmk(hs, psk, sizeof(psk));
   3491 	handshake_state_set_authenticator_address(hs, aa);
   3492 	handshake_state_set_supplicant_address(hs, spa);
   3493 	handshake_state_set_ssid(hs, (void *) ssid, strlen(ssid));
   3494 
   3495 	handshake_state_set_supplicant_ie(hs, own_rsne);
   3496 	handshake_state_set_authenticator_ie(hs, ap_rsne);
   3497 	handshake_state_set_mde(hs, mde);
   3498 	handshake_state_set_authenticator_fte(hs, fte);
   3499 	handshake_state_set_kh_ids(hs, r0khid, strlen((void *) r0khid), r1khid);
   3500 	eapol_start(sm);
   3501 
   3502 	__eapol_set_tx_packet_func(verify_step2);
   3503 	__eapol_rx_packet(1, aa, ETH_P_PAE,
   3504 				eapol_key_data_25, sizeof(eapol_key_data_25),
   3505 				false);
   3506 	assert(verify_step2_called);
   3507 
   3508 	__eapol_set_tx_packet_func(verify_step4);
   3509 	__eapol_rx_packet(1, aa, ETH_P_PAE,
   3510 				eapol_key_data_27, sizeof(eapol_key_data_27),
   3511 				false);
   3512 	assert(verify_step4_called);
   3513 
   3514 	eapol_sm_free(sm);
   3515 	handshake_state_unref(hs);
   3516 	eapol_exit();
   3517 }
   3518 
   3519 struct test_ap_sta_data {
   3520 	struct handshake_state *ap_hs;
   3521 	struct handshake_state *sta_hs;
   3522 	const uint8_t ap_address[6];
   3523 	const uint8_t sta_address[6];
   3524 
   3525 	uint8_t to_sta_data[1024];
   3526 	int to_sta_data_len;
   3527 	uint8_t ap_tk[32];
   3528 	uint8_t sta_tk[32];
   3529 	bool ap_success;
   3530 	bool sta_success;
   3531 	int to_sta_msg_cnt;
   3532 	int to_ap_msg_cnt;
   3533 	struct eapol_sm *ap_sm;
   3534 	struct eapol_sm *sta_sm;
   3535 };
   3536 
   3537 static int test_ap_sta_eapol_tx(uint32_t ifindex,
   3538 					const uint8_t *dest, uint16_t proto,
   3539 					const struct eapol_frame *ef,
   3540 					bool noencrypt, void *user_data)
   3541 {
   3542 	struct test_ap_sta_data *s = user_data;
   3543 	size_t len = sizeof(struct eapol_header) +
   3544 		L_BE16_TO_CPU(ef->header.packet_len);
   3545 
   3546 	assert(ifindex == s->ap_hs->ifindex || ifindex == s->sta_hs->ifindex);
   3547 	assert(proto == ETH_P_PAE && !noencrypt);
   3548 
   3549 	if (ifindex == s->ap_hs->ifindex) {	/* From AP to STA */
   3550 		assert(!memcmp(dest, s->sta_address, 6));
   3551 		assert(len < sizeof(s->to_sta_data));
   3552 		memcpy(s->to_sta_data, ef, len);
   3553 		s->to_sta_data_len = len;
   3554 		s->to_sta_msg_cnt++;
   3555 		return 0;
   3556 	}
   3557 
   3558 	/* From STA to AP */
   3559 	assert(!memcmp(dest, s->ap_address, 6));
   3560 	s->to_ap_msg_cnt++;
   3561 	__eapol_rx_packet(1, s->sta_address, proto, (const void *) ef, len,
   3562 				noencrypt);
   3563 	return 0;
   3564 }
   3565 
   3566 static void test_ap_sta_run(struct test_ap_sta_data *s)
   3567 {
   3568 	eap_init();
   3569 	eapol_init();
   3570 	__eapol_set_tx_packet_func(test_ap_sta_eapol_tx);
   3571 	__eapol_set_tx_user_data(s);
   3572 
   3573 	s->ap_success = false;
   3574 	s->sta_success = false;
   3575 	s->to_sta_msg_cnt = 0;
   3576 	s->to_ap_msg_cnt = 0;
   3577 	s->to_sta_data_len = 0;
   3578 
   3579 	s->ap_sm = eapol_sm_new(s->ap_hs);
   3580 	eapol_register(s->ap_sm);
   3581 
   3582 	s->sta_sm = eapol_sm_new(s->sta_hs);
   3583 	eapol_register(s->sta_sm);
   3584 
   3585 	eapol_start(s->sta_sm);
   3586 	eapol_start(s->ap_sm);
   3587 
   3588 	while (s->to_sta_data_len) {
   3589 		int len = s->to_sta_data_len;
   3590 		s->to_sta_data_len = 0;
   3591 		__eapol_rx_packet(s->sta_hs->ifindex, s->ap_address, ETH_P_PAE,
   3592 					s->to_sta_data, len, false);
   3593 	}
   3594 
   3595 	eapol_sm_free(s->ap_sm);
   3596 	eapol_sm_free(s->sta_sm);
   3597 
   3598 	eapol_exit();
   3599 	eap_exit();
   3600 }
   3601 
   3602 struct test_ap_sta_hs {
   3603 	struct handshake_state super;
   3604 	struct test_ap_sta_data *s;
   3605 };
   3606 
   3607 static struct handshake_state *test_ap_sta_hs_new(struct test_ap_sta_data *s,
   3608 							uint32_t ifindex)
   3609 {
   3610 	struct test_ap_sta_hs *ths = l_new(struct test_ap_sta_hs, 1);
   3611 
   3612 	ths->super.ifindex = ifindex;
   3613 	ths->super.free = (void (*)(struct handshake_state *s)) l_free;
   3614 	ths->super.refcount = 1;
   3615 	ths->s = s;
   3616 
   3617 	return &ths->super;
   3618 }
   3619 
   3620 static bool random_nonce(uint8_t nonce[])
   3621 {
   3622 	return l_getrandom(nonce, 32);
   3623 }
   3624 
   3625 static void test_ap_sta_hs_event(struct handshake_state *hs,
   3626 				enum handshake_event event,
   3627 				void *user_data, ...)
   3628 {
   3629 	assert(event != HANDSHAKE_EVENT_FAILED);
   3630 }
   3631 
   3632 static void test_ap_sta_install_tk(struct handshake_state *hs, uint8_t key_idx,
   3633 					const uint8_t *tk, uint32_t cipher)
   3634 {
   3635 	struct test_ap_sta_hs *ths =
   3636 		l_container_of(hs, struct test_ap_sta_hs, super);
   3637 	assert(hs == ths->s->ap_hs || hs == ths->s->sta_hs);
   3638 	assert(cipher == CRYPTO_CIPHER_CCMP);
   3639 
   3640 	if (hs == ths->s->ap_hs) {
   3641 		assert(!ths->s->ap_success);
   3642 		memcpy(ths->s->ap_tk, tk, 16);
   3643 		ths->s->ap_success = true;
   3644 	} else {
   3645 		assert(!ths->s->sta_success);
   3646 		memcpy(ths->s->sta_tk, tk, 16);
   3647 		ths->s->sta_success = true;
   3648 	}
   3649 }
   3650 
   3651 static void eapol_ap_sta_handshake_test(const void *data)
   3652 {
   3653 	static const unsigned char ap_rsne[] = {
   3654 		0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3655 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3656 		0x00, 0x0f, 0xac, 0x02, 0x81, 0x00 };
   3657 	static const unsigned char sta_rsne[] = {
   3658 		0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3659 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3660 		0x00, 0x0f, 0xac, 0x02 };
   3661 	static const char *ssid = "TestWPA2PSK";
   3662 	static const uint8_t psk[32] = {	/* secretsecret */
   3663 		0x6a, 0xa3, 0xf0, 0x0b, 0x68, 0xbd, 0x8b, 0x46,
   3664 		0x69, 0x83, 0xa5, 0x29, 0xa3, 0xfa, 0x57, 0x1c,
   3665 		0x6c, 0x7b, 0x72, 0x41, 0x1d, 0xce, 0x33, 0x02,
   3666 		0xa2, 0x2d, 0xdf, 0x77, 0xd1, 0x93, 0xdb, 0x5f };
   3667 	struct test_ap_sta_data s = {
   3668 		.ap_hs = test_ap_sta_hs_new(&s, 1),
   3669 		.sta_hs = test_ap_sta_hs_new(&s, 2),
   3670 		.ap_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
   3671 		.sta_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x08 },
   3672 	};
   3673 
   3674 	__handshake_set_get_nonce_func(random_nonce);
   3675 	__handshake_set_install_tk_func(test_ap_sta_install_tk);
   3676 	__handshake_set_install_gtk_func(NULL);
   3677 
   3678 	handshake_state_set_authenticator(s.ap_hs, true);
   3679 	handshake_state_set_event_func(s.ap_hs, test_ap_sta_hs_event, &s);
   3680 	handshake_state_set_authenticator_address(s.ap_hs, s.ap_address);
   3681 	handshake_state_set_supplicant_address(s.ap_hs, s.sta_address);
   3682 	handshake_state_set_supplicant_ie(s.ap_hs, sta_rsne);
   3683 	handshake_state_set_authenticator_ie(s.ap_hs, ap_rsne);
   3684 	handshake_state_set_ssid(s.ap_hs, (void *) ssid, strlen(ssid));
   3685 	handshake_state_set_pmk(s.ap_hs, psk, 32);
   3686 
   3687 	handshake_state_set_authenticator(s.sta_hs, false);
   3688 	handshake_state_set_event_func(s.sta_hs, test_ap_sta_hs_event, &s);
   3689 	handshake_state_set_authenticator_address(s.sta_hs, s.ap_address);
   3690 	handshake_state_set_supplicant_address(s.sta_hs, s.sta_address);
   3691 	handshake_state_set_supplicant_ie(s.sta_hs, sta_rsne);
   3692 	handshake_state_set_authenticator_ie(s.sta_hs, ap_rsne);
   3693 	handshake_state_set_ssid(s.sta_hs, (void *) ssid, strlen(ssid));
   3694 	handshake_state_set_pmk(s.sta_hs, psk, 32);
   3695 
   3696 	test_ap_sta_run(&s);
   3697 
   3698 	l_info("freeing in eapol_ap_sta_handshake_test()");
   3699 
   3700 	handshake_state_unref(s.ap_hs);
   3701 	handshake_state_unref(s.sta_hs);
   3702 	__handshake_set_install_tk_func(NULL);
   3703 
   3704 	assert(s.ap_success && s.sta_success);
   3705 	assert(s.to_ap_msg_cnt == 2 && s.to_sta_msg_cnt == 2);
   3706 	assert(!memcmp(s.ap_tk, s.sta_tk, 16));
   3707 }
   3708 
   3709 static void eapol_ap_sta_handshake_bad_psk_test(const void *data)
   3710 {
   3711 	static const unsigned char ap_rsne[] = {
   3712 		0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3713 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3714 		0x00, 0x0f, 0xac, 0x02, 0x81, 0x00 };
   3715 	static const unsigned char sta_rsne[] = {
   3716 		0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3717 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3718 		0x00, 0x0f, 0xac, 0x02 };
   3719 	static const char *ssid = "TestWPA2PSK";
   3720 	static const uint8_t psk1[32] = {	/* secretsecret */
   3721 		0x6a, 0xa3, 0xf0, 0x0b, 0x68, 0xbd, 0x8b, 0x46,
   3722 		0x69, 0x83, 0xa5, 0x29, 0xa3, 0xfa, 0x57, 0x1c,
   3723 		0x6c, 0x7b, 0x72, 0x41, 0x1d, 0xce, 0x33, 0x02,
   3724 		0xa2, 0x2d, 0xdf, 0x77, 0xd1, 0x93, 0xdb, 0x5f };
   3725 	static const uint8_t psk2[32] = {	/* wrongpasswd */
   3726 		0x04, 0x86, 0x45, 0x37, 0x4c, 0x95, 0xdd, 0x1e,
   3727 		0x96, 0xbb, 0xdf, 0x12, 0x0a, 0x1c, 0x4c, 0x5b,
   3728 		0x6d, 0x22, 0xc1, 0x1c, 0xa2, 0xe0, 0x15, 0x99,
   3729 		0xbf, 0x82, 0x10, 0xd3, 0x59, 0x2c, 0xfb, 0x2d };
   3730 	struct test_ap_sta_data s = {
   3731 		.ap_hs = test_ap_sta_hs_new(&s, 1),
   3732 		.sta_hs = test_ap_sta_hs_new(&s, 2),
   3733 		.ap_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
   3734 		.sta_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x08 },
   3735 	};
   3736 
   3737 	__handshake_set_get_nonce_func(random_nonce);
   3738 	__handshake_set_install_tk_func(test_ap_sta_install_tk);
   3739 	__handshake_set_install_gtk_func(NULL);
   3740 
   3741 	handshake_state_set_authenticator(s.ap_hs, true);
   3742 	handshake_state_set_event_func(s.ap_hs, test_ap_sta_hs_event, &s);
   3743 	handshake_state_set_authenticator_address(s.ap_hs, s.ap_address);
   3744 	handshake_state_set_supplicant_address(s.ap_hs, s.sta_address);
   3745 	handshake_state_set_supplicant_ie(s.ap_hs, sta_rsne);
   3746 	handshake_state_set_authenticator_ie(s.ap_hs, ap_rsne);
   3747 	handshake_state_set_ssid(s.ap_hs, (void *) ssid, strlen(ssid));
   3748 	handshake_state_set_pmk(s.ap_hs, psk1, 32);
   3749 
   3750 	handshake_state_set_authenticator(s.sta_hs, false);
   3751 	handshake_state_set_event_func(s.sta_hs, test_ap_sta_hs_event, &s);
   3752 	handshake_state_set_authenticator_address(s.sta_hs, s.ap_address);
   3753 	handshake_state_set_supplicant_address(s.sta_hs, s.sta_address);
   3754 	handshake_state_set_supplicant_ie(s.sta_hs, sta_rsne);
   3755 	handshake_state_set_authenticator_ie(s.sta_hs, ap_rsne);
   3756 	handshake_state_set_ssid(s.sta_hs, (void *) ssid, strlen(ssid));
   3757 	handshake_state_set_pmk(s.sta_hs, psk2, 32);
   3758 
   3759 	test_ap_sta_run(&s);
   3760 
   3761 	handshake_state_unref(s.ap_hs);
   3762 	handshake_state_unref(s.sta_hs);
   3763 	__handshake_set_install_tk_func(NULL);
   3764 
   3765 	/*
   3766 	 * There should have been 2 EAPoL-Key frame exchanged: 1/4 and
   3767 	 * 2/4 after which the AP will have detected wrong MIC and not
   3768 	 * sent any more messages with both sides waiting for the
   3769 	 * timeout.
   3770 	 */
   3771 	assert(!s.ap_success && !s.sta_success);
   3772 	assert(s.to_ap_msg_cnt == 1 && s.to_sta_msg_cnt == 1);
   3773 }
   3774 
   3775 static void eapol_ap_sta_handshake_ip_alloc_ok_test(const void *data)
   3776 {
   3777 	static const unsigned char ap_rsne[] = {
   3778 		0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3779 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3780 		0x00, 0x0f, 0xac, 0x02, 0x81, 0x00 };
   3781 	static const unsigned char sta_rsne[] = {
   3782 		0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3783 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3784 		0x00, 0x0f, 0xac, 0x02 };
   3785 	static const char *ssid = "TestWPA2PSK";
   3786 	static const uint8_t psk[32] = {	/* secretsecret */
   3787 		0x6a, 0xa3, 0xf0, 0x0b, 0x68, 0xbd, 0x8b, 0x46,
   3788 		0x69, 0x83, 0xa5, 0x29, 0xa3, 0xfa, 0x57, 0x1c,
   3789 		0x6c, 0x7b, 0x72, 0x41, 0x1d, 0xce, 0x33, 0x02,
   3790 		0xa2, 0x2d, 0xdf, 0x77, 0xd1, 0x93, 0xdb, 0x5f };
   3791 	struct test_ap_sta_data s = {
   3792 		.ap_hs = test_ap_sta_hs_new(&s, 1),
   3793 		.sta_hs = test_ap_sta_hs_new(&s, 2),
   3794 		.ap_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
   3795 		.sta_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x08 },
   3796 	};
   3797 
   3798 	__handshake_set_get_nonce_func(random_nonce);
   3799 	__handshake_set_install_tk_func(test_ap_sta_install_tk);
   3800 	__handshake_set_install_gtk_func(NULL);
   3801 
   3802 	handshake_state_set_authenticator(s.ap_hs, true);
   3803 	handshake_state_set_event_func(s.ap_hs, test_ap_sta_hs_event, &s);
   3804 	handshake_state_set_authenticator_address(s.ap_hs, s.ap_address);
   3805 	handshake_state_set_supplicant_address(s.ap_hs, s.sta_address);
   3806 	handshake_state_set_supplicant_ie(s.ap_hs, sta_rsne);
   3807 	handshake_state_set_authenticator_ie(s.ap_hs, ap_rsne);
   3808 	handshake_state_set_ssid(s.ap_hs, (void *) ssid, strlen(ssid));
   3809 	handshake_state_set_pmk(s.ap_hs, psk, 32);
   3810 	s.ap_hs->support_ip_allocation = true;
   3811 	s.ap_hs->client_ip_addr = L_CPU_TO_BE32(0x01020304);
   3812 	s.ap_hs->subnet_mask = L_CPU_TO_BE32(0xffff0000);
   3813 	s.ap_hs->go_ip_addr = L_CPU_TO_BE32(0x01020305);
   3814 
   3815 	handshake_state_set_authenticator(s.sta_hs, false);
   3816 	handshake_state_set_event_func(s.sta_hs, test_ap_sta_hs_event, &s);
   3817 	handshake_state_set_authenticator_address(s.sta_hs, s.ap_address);
   3818 	handshake_state_set_supplicant_address(s.sta_hs, s.sta_address);
   3819 	handshake_state_set_supplicant_ie(s.sta_hs, sta_rsne);
   3820 	handshake_state_set_authenticator_ie(s.sta_hs, ap_rsne);
   3821 	handshake_state_set_ssid(s.sta_hs, (void *) ssid, strlen(ssid));
   3822 	handshake_state_set_pmk(s.sta_hs, psk, 32);
   3823 	s.sta_hs->support_ip_allocation = true;
   3824 
   3825 	test_ap_sta_run(&s);
   3826 
   3827 	assert(s.ap_hs->support_ip_allocation);
   3828 	assert(s.sta_hs->support_ip_allocation);
   3829 	assert(s.sta_hs->client_ip_addr == s.ap_hs->client_ip_addr);
   3830 	assert(s.sta_hs->subnet_mask == s.ap_hs->subnet_mask);
   3831 	assert(s.sta_hs->go_ip_addr == s.ap_hs->go_ip_addr);
   3832 
   3833 	handshake_state_unref(s.ap_hs);
   3834 	handshake_state_unref(s.sta_hs);
   3835 	__handshake_set_install_tk_func(NULL);
   3836 
   3837 	assert(s.ap_success && s.sta_success);
   3838 	assert(s.to_ap_msg_cnt == 2 && s.to_sta_msg_cnt == 2);
   3839 	assert(!memcmp(s.ap_tk, s.sta_tk, 16));
   3840 }
   3841 
   3842 static void eapol_ap_sta_handshake_ip_alloc_no_req_test(const void *data)
   3843 {
   3844 	static const unsigned char ap_rsne[] = {
   3845 		0x30, 0x14, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3846 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3847 		0x00, 0x0f, 0xac, 0x02, 0x81, 0x00 };
   3848 	static const unsigned char sta_rsne[] = {
   3849 		0x30, 0x12, 0x01, 0x00, 0x00, 0x0f, 0xac, 0x04,
   3850 		0x01, 0x00, 0x00, 0x0f, 0xac, 0x04, 0x01, 0x00,
   3851 		0x00, 0x0f, 0xac, 0x02 };
   3852 	static const char *ssid = "TestWPA2PSK";
   3853 	static const uint8_t psk[32] = {	/* secretsecret */
   3854 		0x6a, 0xa3, 0xf0, 0x0b, 0x68, 0xbd, 0x8b, 0x46,
   3855 		0x69, 0x83, 0xa5, 0x29, 0xa3, 0xfa, 0x57, 0x1c,
   3856 		0x6c, 0x7b, 0x72, 0x41, 0x1d, 0xce, 0x33, 0x02,
   3857 		0xa2, 0x2d, 0xdf, 0x77, 0xd1, 0x93, 0xdb, 0x5f };
   3858 	struct test_ap_sta_data s = {
   3859 		.ap_hs = test_ap_sta_hs_new(&s, 1),
   3860 		.sta_hs = test_ap_sta_hs_new(&s, 2),
   3861 		.ap_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 },
   3862 		.sta_address = { 0x02, 0x03, 0x04, 0x05, 0x06, 0x08 },
   3863 	};
   3864 
   3865 	__handshake_set_get_nonce_func(random_nonce);
   3866 	__handshake_set_install_tk_func(test_ap_sta_install_tk);
   3867 	__handshake_set_install_gtk_func(NULL);
   3868 
   3869 	handshake_state_set_authenticator(s.ap_hs, true);
   3870 	handshake_state_set_event_func(s.ap_hs, test_ap_sta_hs_event, &s);
   3871 	handshake_state_set_authenticator_address(s.ap_hs, s.ap_address);
   3872 	handshake_state_set_supplicant_address(s.ap_hs, s.sta_address);
   3873 	handshake_state_set_supplicant_ie(s.ap_hs, sta_rsne);
   3874 	handshake_state_set_authenticator_ie(s.ap_hs, ap_rsne);
   3875 	handshake_state_set_ssid(s.ap_hs, (void *) ssid, strlen(ssid));
   3876 	handshake_state_set_pmk(s.ap_hs, psk, 32);
   3877 	s.ap_hs->support_ip_allocation = true;
   3878 	s.ap_hs->client_ip_addr = L_CPU_TO_BE32(0x01020304);
   3879 	s.ap_hs->subnet_mask = L_CPU_TO_BE32(0xffff0000);
   3880 	s.ap_hs->go_ip_addr = L_CPU_TO_BE32(0x01020305);
   3881 
   3882 	handshake_state_set_authenticator(s.sta_hs, false);
   3883 	handshake_state_set_event_func(s.sta_hs, test_ap_sta_hs_event, &s);
   3884 	handshake_state_set_authenticator_address(s.sta_hs, s.ap_address);
   3885 	handshake_state_set_supplicant_address(s.sta_hs, s.sta_address);
   3886 	handshake_state_set_supplicant_ie(s.sta_hs, sta_rsne);
   3887 	handshake_state_set_authenticator_ie(s.sta_hs, ap_rsne);
   3888 	handshake_state_set_ssid(s.sta_hs, (void *) ssid, strlen(ssid));
   3889 	handshake_state_set_pmk(s.sta_hs, psk, 32);
   3890 	s.ap_hs->support_ip_allocation = false;
   3891 
   3892 	test_ap_sta_run(&s);
   3893 
   3894 	assert(!s.ap_hs->support_ip_allocation);
   3895 	assert(!s.sta_hs->support_ip_allocation);
   3896 
   3897 	handshake_state_unref(s.ap_hs);
   3898 	handshake_state_unref(s.sta_hs);
   3899 	__handshake_set_install_tk_func(NULL);
   3900 
   3901 	assert(s.ap_success && s.sta_success);
   3902 	assert(s.to_ap_msg_cnt == 2 && s.to_sta_msg_cnt == 2);
   3903 	assert(!memcmp(s.ap_tk, s.sta_tk, 16));
   3904 }
   3905 
   3906 #define IS_ENABLED(config_macro) _IS_ENABLED1(config_macro)
   3907 #define _IS_ENABLED1(config_macro) _IS_ENABLED2(_XXXX##config_macro)
   3908 #define _XXXX1 _YYYY,
   3909 #define _IS_ENABLED2(one_or_two_args) _IS_ENABLED3(one_or_two_args true, false)
   3910 #define _IS_ENABLED3(ignore_this, val, ...) val
   3911 
   3912 static bool hash_precheck(const void *data)
   3913 {
   3914 	return (l_checksum_is_supported(L_CHECKSUM_MD5, true) &&
   3915 		l_checksum_is_supported(L_CHECKSUM_SHA1, true));
   3916 }
   3917 
   3918 static bool aes_precheck(const void *data)
   3919 {
   3920 	return (l_cipher_is_supported(L_CIPHER_AES) &&
   3921 		l_checksum_is_supported(L_CHECKSUM_MD5, true) &&
   3922 		l_checksum_is_supported(L_CHECKSUM_SHA1, true));
   3923 }
   3924 
   3925 static bool pkcs8_precheck(const void *data)
   3926 {
   3927 	struct stat st;
   3928 
   3929 	/*
   3930 	 * Despite the path, this directory exists whether the module
   3931 	 * is external or built-in.
   3932 	 */
   3933 	if (stat("/sys/module/pkcs8_key_parser", &st) < 0)
   3934 		return false;
   3935 
   3936 	if (!S_ISDIR(st.st_mode))
   3937 		return false;
   3938 
   3939 	return (IS_ENABLED(HAVE_PKCS8_SUPPORT) &&
   3940 		l_cipher_is_supported(L_CIPHER_AES) &&
   3941 		l_cipher_is_supported(L_CIPHER_AES_CBC) &&
   3942 		l_cipher_is_supported(L_CIPHER_DES3_EDE_CBC) &&
   3943 		l_checksum_is_supported(L_CHECKSUM_MD5, true) &&
   3944 		l_checksum_is_supported(L_CHECKSUM_SHA1, true) &&
   3945 		l_key_is_supported(L_KEY_FEATURE_CRYPTO) &&
   3946 		l_key_is_supported(L_KEY_FEATURE_RESTRICT));
   3947 }
   3948 
   3949 #define add_hash_test(name, func, data) l_test_add_data_func_precheck(name, \
   3950 						data, func, hash_precheck, 0)
   3951 #define add_aes_test(name, func, data) l_test_add_data_func_precheck(name, \
   3952 						data, func, aes_precheck, 0)
   3953 #define add_pkcs8_test(name, func, data) l_test_add_data_func_precheck(name, \
   3954 						data, func, pkcs8_precheck, 0)
   3955 
   3956 int main(int argc, char *argv[])
   3957 {
   3958 	l_test_init(&argc, &argv);
   3959 
   3960 	l_test_add("/EAPoL Key/Key Frame 1",
   3961 			eapol_key_test, &eapol_key_test_1);
   3962 	l_test_add("/EAPoL Key/Key Frame 2",
   3963 			eapol_key_test, &eapol_key_test_2);
   3964 	l_test_add("/EAPoL Key/Key Frame 3",
   3965 			eapol_key_test, &eapol_key_test_3);
   3966 	l_test_add("/EAPoL Key/Key Frame 4",
   3967 			eapol_key_test, &eapol_key_test_4);
   3968 	l_test_add("/EAPoL Key/Key Frame 5",
   3969 			eapol_key_test, &eapol_key_test_5);
   3970 	l_test_add("/EAPoL Key/Key Frame 6",
   3971 			eapol_key_test, &eapol_key_test_6);
   3972 	l_test_add("/EAPoL Key/Key Frame 7",
   3973 			eapol_key_test, &eapol_key_test_7);
   3974 	l_test_add("/EAPoL Key/Key Frame 8",
   3975 			eapol_key_test, &eapol_key_test_8);
   3976 	l_test_add("/EAPoL Key/Key Frame 9",
   3977 			eapol_key_test, &eapol_key_test_9);
   3978 	l_test_add("/EAPoL Key/Key Frame 10",
   3979 			eapol_key_test, &eapol_key_test_10);
   3980 	l_test_add("/EAPoL Key/Key Frame 11",
   3981 			eapol_key_test, &eapol_key_test_11);
   3982 	l_test_add("/EAPoL Key/Key Frame 12",
   3983 			eapol_key_test, &eapol_key_test_12);
   3984 	l_test_add("/EAPoL Key/Key Frame 13",
   3985 			eapol_key_test, &eapol_key_test_13);
   3986 	l_test_add("/EAPoL Key/Key Frame 14",
   3987 			eapol_key_test, &eapol_key_test_14);
   3988 	l_test_add("/EAPoL Key/Key Frame 15",
   3989 			eapol_key_test, &eapol_key_test_15);
   3990 	l_test_add("/EAPoL Key/Key Frame 16",
   3991 			eapol_key_test, &eapol_key_test_16);
   3992 	l_test_add("/EAPoL Key/Key Frame 17",
   3993 			eapol_key_test, &eapol_key_test_17);
   3994 	l_test_add("/EAPoL Key/Key Frame 18",
   3995 			eapol_key_test, &eapol_key_test_18);
   3996 	l_test_add("/EAPoL Key/Key Frame 19",
   3997 			eapol_key_test, &eapol_key_test_19);
   3998 	l_test_add("/EAPoL Key/Key Frame 20",
   3999 			eapol_key_test, &eapol_key_test_20);
   4000 	l_test_add("/EAPoL Key/Key Frame 21",
   4001 			eapol_key_test, &eapol_key_test_21);
   4002 	l_test_add("/EAPoL Key/Key Frame 22",
   4003 			eapol_key_test, &eapol_key_test_22);
   4004 	l_test_add("/EAPoL Key/Key Frame 23",
   4005 			eapol_key_test, &eapol_key_test_23);
   4006 	l_test_add("/EAPoL Key/Key Frame 24",
   4007 			eapol_key_test, &eapol_key_test_24);
   4008 	l_test_add("/EAPoL Key/Key Frame 25",
   4009 			eapol_key_test, &eapol_key_test_25);
   4010 	l_test_add("/EAPoL Key/Key Frame 26",
   4011 			eapol_key_test, &eapol_key_test_26);
   4012 	l_test_add("/EAPoL Key/Key Frame 27",
   4013 			eapol_key_test, &eapol_key_test_27);
   4014 	l_test_add("/EAPoL Key/Key Frame 28",
   4015 			eapol_key_test, &eapol_key_test_28);
   4016 	l_test_add("/EAPoL Key/Key Frame 29",
   4017 			eapol_key_test, &eapol_key_test_29);
   4018 	l_test_add("/EAPoL Key/Key Frame 30",
   4019 			eapol_key_test, &eapol_key_test_30);
   4020 	l_test_add("/EAPoL Key/Key Frame 31",
   4021 			eapol_key_test, &eapol_key_test_31);
   4022 	l_test_add("/EAPoL Key/Key Frame 32",
   4023 			eapol_key_test, &eapol_key_test_32);
   4024 
   4025 	add_hash_test("/EAPoL Key/MIC Test 1",
   4026 			eapol_key_mic_test, &eapol_key_mic_test_1);
   4027 	add_hash_test("/EAPoL Key/MIC Test 2",
   4028 			eapol_key_mic_test, &eapol_key_mic_test_2);
   4029 	add_hash_test("/EAPoL Key/Calculate MIC Test 1",
   4030 			eapol_calculate_mic_test, &eapol_calculate_mic_test_1);
   4031 
   4032 	add_aes_test("EAPoL/WPA2 4-Way Handshake",
   4033 				eapol_4way_test, NULL);
   4034 	add_aes_test("EAPoL/WPA2 4-Way & GTK Handshake",
   4035 				eapol_wpa2_handshake_test, NULL);
   4036 	add_aes_test("EAPoL/WPA 4-Way & GTK Handshake",
   4037 				eapol_wpa_handshake_test, NULL);
   4038 	add_aes_test("EAPoL/WPA2 PTK State Machine",
   4039 				eapol_sm_test_ptk, NULL);
   4040 	add_aes_test("EAPoL IGTK & 4-Way Handshake",
   4041 				eapol_sm_test_igtk, NULL);
   4042 	add_aes_test("EAPoL/WPA2 PTK & GTK State Machine",
   4043 				eapol_sm_test_wpa2_ptk_gtk, NULL);
   4044 	add_aes_test("EAPoL/WPA PTK & GTK State Machine Test 1",
   4045 				eapol_sm_test_wpa_ptk_gtk, NULL);
   4046 	add_aes_test("EAPoL/WPA PTK & GTK State Machine Test 2",
   4047 				eapol_sm_test_wpa_ptk_gtk_2, NULL);
   4048 	add_aes_test("EAPoL/WPA2 Retransmit Test",
   4049 				eapol_sm_wpa2_retransmit_test, NULL);
   4050 
   4051 	add_pkcs8_test("EAPoL/8021x EAP-TLS & 4-Way Handshake",
   4052 				eapol_sm_test_eap_tls, NULL);
   4053 	add_pkcs8_test("EAPoL/8021x EAP-TTLS+EAP-MD5 & 4-Way Handshake",
   4054 				eapol_sm_test_eap_ttls_md5, NULL);
   4055 	add_pkcs8_test("EAPoL/8021x EAP NAK",
   4056 				eapol_sm_test_eap_nak, NULL);
   4057 	add_pkcs8_test("EAPoL/8021x EAP-TLS subject name match",
   4058 				eapol_sm_test_eap_tls_subject_good, NULL);
   4059 	add_pkcs8_test("EAPoL/8021x EAP-TLS subject name mismatch",
   4060 				eapol_sm_test_eap_tls_subject_bad, NULL);
   4061 	add_pkcs8_test("EAPoL/8021x EAP-TLS embedded certs",
   4062 				eapol_sm_test_eap_tls_embedded, NULL);
   4063 
   4064 	add_aes_test("EAPoL/FT-Using-PSK 4-Way Handshake",
   4065 			eapol_ft_handshake_test, NULL);
   4066 	add_aes_test("EAPoL/Supplicant+Authenticator 4-Way Handshake",
   4067 			eapol_ap_sta_handshake_test, NULL);
   4068 	add_aes_test("EAPoL/Supplicant+Authenticator 4-Way Handshake Bad PSK",
   4069 			eapol_ap_sta_handshake_bad_psk_test, NULL);
   4070 	add_aes_test("EAPoL/Supplicant+Authenticator IP Allocation OK",
   4071 			eapol_ap_sta_handshake_ip_alloc_ok_test, NULL);
   4072 	add_aes_test("EAPoL/Supplicant+Authenticator IP Allocation no request",
   4073 			eapol_ap_sta_handshake_ip_alloc_no_req_test, NULL);
   4074 
   4075 	return l_test_run();
   4076 }