1*5b9c547cSRui Paulo /* 2*5b9c547cSRui Paulo * crypto module tests 3*5b9c547cSRui Paulo * Copyright (c) 2014-2015, Jouni Malinen <j@w1.fi> 4*5b9c547cSRui Paulo * 5*5b9c547cSRui Paulo * This software may be distributed under the terms of the BSD license. 6*5b9c547cSRui Paulo * See README for more details. 7*5b9c547cSRui Paulo */ 8*5b9c547cSRui Paulo 9*5b9c547cSRui Paulo #include "utils/includes.h" 10*5b9c547cSRui Paulo 11*5b9c547cSRui Paulo #include "utils/common.h" 12*5b9c547cSRui Paulo #include "crypto/aes_siv.h" 13*5b9c547cSRui Paulo #include "crypto/aes_wrap.h" 14*5b9c547cSRui Paulo #include "crypto/aes.h" 15*5b9c547cSRui Paulo #include "crypto/ms_funcs.h" 16*5b9c547cSRui Paulo #include "crypto/crypto.h" 17*5b9c547cSRui Paulo #include "crypto/sha1.h" 18*5b9c547cSRui Paulo #include "crypto/sha256.h" 19*5b9c547cSRui Paulo 20*5b9c547cSRui Paulo 21*5b9c547cSRui Paulo static int test_siv(void) 22*5b9c547cSRui Paulo { 23*5b9c547cSRui Paulo #ifdef CONFIG_MESH 24*5b9c547cSRui Paulo /* RFC 5297, A.1. Deterministic Authenticated Encryption Example */ 25*5b9c547cSRui Paulo u8 key[] = { 26*5b9c547cSRui Paulo 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8, 27*5b9c547cSRui Paulo 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0, 28*5b9c547cSRui Paulo 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 29*5b9c547cSRui Paulo 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff 30*5b9c547cSRui Paulo }; 31*5b9c547cSRui Paulo u8 ad[] = { 32*5b9c547cSRui Paulo 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 33*5b9c547cSRui Paulo 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 34*5b9c547cSRui Paulo 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27 35*5b9c547cSRui Paulo }; 36*5b9c547cSRui Paulo u8 plaintext[] = { 37*5b9c547cSRui Paulo 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 38*5b9c547cSRui Paulo 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee 39*5b9c547cSRui Paulo }; 40*5b9c547cSRui Paulo u8 iv_c[] = { 41*5b9c547cSRui Paulo 0x85, 0x63, 0x2d, 0x07, 0xc6, 0xe8, 0xf3, 0x7f, 42*5b9c547cSRui Paulo 0x95, 0x0a, 0xcd, 0x32, 0x0a, 0x2e, 0xcc, 0x93, 43*5b9c547cSRui Paulo 0x40, 0xc0, 0x2b, 0x96, 0x90, 0xc4, 0xdc, 0x04, 44*5b9c547cSRui Paulo 0xda, 0xef, 0x7f, 0x6a, 0xfe, 0x5c 45*5b9c547cSRui Paulo }; 46*5b9c547cSRui Paulo /* RFC 5297, A.2. Nonce-Based Authenticated Encryption Example */ 47*5b9c547cSRui Paulo u8 key_2[] = { 48*5b9c547cSRui Paulo 0x7f, 0x7e, 0x7d, 0x7c, 0x7b, 0x7a, 0x79, 0x78, 49*5b9c547cSRui Paulo 0x77, 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x70, 50*5b9c547cSRui Paulo 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 51*5b9c547cSRui Paulo 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f 52*5b9c547cSRui Paulo }; 53*5b9c547cSRui Paulo u8 ad1_2[] = { 54*5b9c547cSRui Paulo 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 55*5b9c547cSRui Paulo 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 56*5b9c547cSRui Paulo 0xde, 0xad, 0xda, 0xda, 0xde, 0xad, 0xda, 0xda, 57*5b9c547cSRui Paulo 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 58*5b9c547cSRui Paulo 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00 59*5b9c547cSRui Paulo }; 60*5b9c547cSRui Paulo u8 ad2_2[] = { 61*5b9c547cSRui Paulo 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, 62*5b9c547cSRui Paulo 0x90, 0xa0 63*5b9c547cSRui Paulo }; 64*5b9c547cSRui Paulo u8 nonce_2[] = { 65*5b9c547cSRui Paulo 0x09, 0xf9, 0x11, 0x02, 0x9d, 0x74, 0xe3, 0x5b, 66*5b9c547cSRui Paulo 0xd8, 0x41, 0x56, 0xc5, 0x63, 0x56, 0x88, 0xc0 67*5b9c547cSRui Paulo }; 68*5b9c547cSRui Paulo u8 plaintext_2[] = { 69*5b9c547cSRui Paulo 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 70*5b9c547cSRui Paulo 0x73, 0x6f, 0x6d, 0x65, 0x20, 0x70, 0x6c, 0x61, 71*5b9c547cSRui Paulo 0x69, 0x6e, 0x74, 0x65, 0x78, 0x74, 0x20, 0x74, 72*5b9c547cSRui Paulo 0x6f, 0x20, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 73*5b9c547cSRui Paulo 0x74, 0x20, 0x75, 0x73, 0x69, 0x6e, 0x67, 0x20, 74*5b9c547cSRui Paulo 0x53, 0x49, 0x56, 0x2d, 0x41, 0x45, 0x53 75*5b9c547cSRui Paulo }; 76*5b9c547cSRui Paulo u8 iv_c_2[] = { 77*5b9c547cSRui Paulo 0x7b, 0xdb, 0x6e, 0x3b, 0x43, 0x26, 0x67, 0xeb, 78*5b9c547cSRui Paulo 0x06, 0xf4, 0xd1, 0x4b, 0xff, 0x2f, 0xbd, 0x0f, 79*5b9c547cSRui Paulo 0xcb, 0x90, 0x0f, 0x2f, 0xdd, 0xbe, 0x40, 0x43, 80*5b9c547cSRui Paulo 0x26, 0x60, 0x19, 0x65, 0xc8, 0x89, 0xbf, 0x17, 81*5b9c547cSRui Paulo 0xdb, 0xa7, 0x7c, 0xeb, 0x09, 0x4f, 0xa6, 0x63, 82*5b9c547cSRui Paulo 0xb7, 0xa3, 0xf7, 0x48, 0xba, 0x8a, 0xf8, 0x29, 83*5b9c547cSRui Paulo 0xea, 0x64, 0xad, 0x54, 0x4a, 0x27, 0x2e, 0x9c, 84*5b9c547cSRui Paulo 0x48, 0x5b, 0x62, 0xa3, 0xfd, 0x5c, 0x0d 85*5b9c547cSRui Paulo }; 86*5b9c547cSRui Paulo u8 out[2 * AES_BLOCK_SIZE + sizeof(plaintext_2)]; 87*5b9c547cSRui Paulo const u8 *addr[3]; 88*5b9c547cSRui Paulo size_t len[3]; 89*5b9c547cSRui Paulo 90*5b9c547cSRui Paulo /* RFC 5297, A.1. Deterministic Authenticated Encryption Example */ 91*5b9c547cSRui Paulo addr[0] = ad; 92*5b9c547cSRui Paulo len[0] = sizeof(ad); 93*5b9c547cSRui Paulo 94*5b9c547cSRui Paulo if (aes_siv_encrypt(key, plaintext, sizeof(plaintext), 95*5b9c547cSRui Paulo 1, addr, len, out)) { 96*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-SIV mode encryption failed"); 97*5b9c547cSRui Paulo return 1; 98*5b9c547cSRui Paulo } 99*5b9c547cSRui Paulo if (os_memcmp(out, iv_c, sizeof(iv_c)) != 0) { 100*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, 101*5b9c547cSRui Paulo "AES-SIV mode encryption returned invalid cipher text"); 102*5b9c547cSRui Paulo return 1; 103*5b9c547cSRui Paulo } 104*5b9c547cSRui Paulo 105*5b9c547cSRui Paulo if (aes_siv_decrypt(key, iv_c, sizeof(iv_c), 1, addr, len, out)) { 106*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-SIV mode decryption failed"); 107*5b9c547cSRui Paulo return 1; 108*5b9c547cSRui Paulo } 109*5b9c547cSRui Paulo if (os_memcmp(out, plaintext, sizeof(plaintext)) != 0) { 110*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, 111*5b9c547cSRui Paulo "AES-SIV mode decryption returned invalid plain text"); 112*5b9c547cSRui Paulo return 1; 113*5b9c547cSRui Paulo } 114*5b9c547cSRui Paulo 115*5b9c547cSRui Paulo /* RFC 5297, A.2. Nonce-Based Authenticated Encryption Example */ 116*5b9c547cSRui Paulo addr[0] = ad1_2; 117*5b9c547cSRui Paulo len[0] = sizeof(ad1_2); 118*5b9c547cSRui Paulo addr[1] = ad2_2; 119*5b9c547cSRui Paulo len[1] = sizeof(ad2_2); 120*5b9c547cSRui Paulo addr[2] = nonce_2; 121*5b9c547cSRui Paulo len[2] = sizeof(nonce_2); 122*5b9c547cSRui Paulo 123*5b9c547cSRui Paulo if (aes_siv_encrypt(key_2, plaintext_2, sizeof(plaintext_2), 124*5b9c547cSRui Paulo 3, addr, len, out)) { 125*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-SIV mode encryption failed"); 126*5b9c547cSRui Paulo return 1; 127*5b9c547cSRui Paulo } 128*5b9c547cSRui Paulo if (os_memcmp(out, iv_c_2, sizeof(iv_c_2)) != 0) { 129*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, 130*5b9c547cSRui Paulo "AES-SIV mode encryption returned invalid cipher text"); 131*5b9c547cSRui Paulo return 1; 132*5b9c547cSRui Paulo } 133*5b9c547cSRui Paulo 134*5b9c547cSRui Paulo if (aes_siv_decrypt(key_2, iv_c_2, sizeof(iv_c_2), 3, addr, len, out)) { 135*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-SIV mode decryption failed"); 136*5b9c547cSRui Paulo return 1; 137*5b9c547cSRui Paulo } 138*5b9c547cSRui Paulo if (os_memcmp(out, plaintext_2, sizeof(plaintext_2)) != 0) { 139*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, 140*5b9c547cSRui Paulo "AES-SIV mode decryption returned invalid plain text"); 141*5b9c547cSRui Paulo return 1; 142*5b9c547cSRui Paulo } 143*5b9c547cSRui Paulo 144*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "AES-SIV test cases passed"); 145*5b9c547cSRui Paulo #endif /* CONFIG_MESH */ 146*5b9c547cSRui Paulo 147*5b9c547cSRui Paulo return 0; 148*5b9c547cSRui Paulo } 149*5b9c547cSRui Paulo 150*5b9c547cSRui Paulo 151*5b9c547cSRui Paulo /* OMAC1 AES-128 test vectors from 152*5b9c547cSRui Paulo * http://csrc.nist.gov/CryptoToolkit/modes/proposedmodes/omac/omac-ad.pdf 153*5b9c547cSRui Paulo * which are same as the examples from NIST SP800-38B 154*5b9c547cSRui Paulo * http://csrc.nist.gov/CryptoToolkit/modes/800-38_Series_Publications/SP800-38B.pdf 155*5b9c547cSRui Paulo */ 156*5b9c547cSRui Paulo 157*5b9c547cSRui Paulo struct omac1_test_vector { 158*5b9c547cSRui Paulo u8 k[16]; 159*5b9c547cSRui Paulo u8 msg[64]; 160*5b9c547cSRui Paulo int msg_len; 161*5b9c547cSRui Paulo u8 tag[16]; 162*5b9c547cSRui Paulo }; 163*5b9c547cSRui Paulo 164*5b9c547cSRui Paulo static struct omac1_test_vector omac1_test_vectors[] = 165*5b9c547cSRui Paulo { 166*5b9c547cSRui Paulo { 167*5b9c547cSRui Paulo { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 168*5b9c547cSRui Paulo 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }, 169*5b9c547cSRui Paulo { }, 170*5b9c547cSRui Paulo 0, 171*5b9c547cSRui Paulo { 0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28, 172*5b9c547cSRui Paulo 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46 } 173*5b9c547cSRui Paulo }, 174*5b9c547cSRui Paulo { 175*5b9c547cSRui Paulo { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 176*5b9c547cSRui Paulo 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }, 177*5b9c547cSRui Paulo { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 178*5b9c547cSRui Paulo 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a}, 179*5b9c547cSRui Paulo 16, 180*5b9c547cSRui Paulo { 0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44, 181*5b9c547cSRui Paulo 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c } 182*5b9c547cSRui Paulo }, 183*5b9c547cSRui Paulo { 184*5b9c547cSRui Paulo { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 185*5b9c547cSRui Paulo 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }, 186*5b9c547cSRui Paulo { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 187*5b9c547cSRui Paulo 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 188*5b9c547cSRui Paulo 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 189*5b9c547cSRui Paulo 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, 190*5b9c547cSRui Paulo 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11 }, 191*5b9c547cSRui Paulo 40, 192*5b9c547cSRui Paulo { 0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30, 193*5b9c547cSRui Paulo 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27 } 194*5b9c547cSRui Paulo }, 195*5b9c547cSRui Paulo { 196*5b9c547cSRui Paulo { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 197*5b9c547cSRui Paulo 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }, 198*5b9c547cSRui Paulo { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 199*5b9c547cSRui Paulo 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 200*5b9c547cSRui Paulo 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, 201*5b9c547cSRui Paulo 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, 202*5b9c547cSRui Paulo 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, 203*5b9c547cSRui Paulo 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, 204*5b9c547cSRui Paulo 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 205*5b9c547cSRui Paulo 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 }, 206*5b9c547cSRui Paulo 64, 207*5b9c547cSRui Paulo { 0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92, 208*5b9c547cSRui Paulo 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe } 209*5b9c547cSRui Paulo }, 210*5b9c547cSRui Paulo }; 211*5b9c547cSRui Paulo 212*5b9c547cSRui Paulo 213*5b9c547cSRui Paulo static int test_omac1_vector(struct omac1_test_vector *tv, unsigned int i) 214*5b9c547cSRui Paulo { 215*5b9c547cSRui Paulo u8 key[] = { 216*5b9c547cSRui Paulo 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 217*5b9c547cSRui Paulo 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c 218*5b9c547cSRui Paulo }; 219*5b9c547cSRui Paulo u8 msg[] = { 0x12, 0x34, 0x56 }; 220*5b9c547cSRui Paulo u8 result[24], result2[24]; 221*5b9c547cSRui Paulo const u8 *addr[3]; 222*5b9c547cSRui Paulo size_t len[3]; 223*5b9c547cSRui Paulo 224*5b9c547cSRui Paulo if (omac1_aes_128(tv->k, tv->msg, tv->msg_len, result) || 225*5b9c547cSRui Paulo os_memcmp(result, tv->tag, 16) != 0) { 226*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "OMAC1-AES-128 test vector %u failed", i); 227*5b9c547cSRui Paulo return 1; 228*5b9c547cSRui Paulo } 229*5b9c547cSRui Paulo 230*5b9c547cSRui Paulo if (tv->msg_len > 1) { 231*5b9c547cSRui Paulo 232*5b9c547cSRui Paulo addr[0] = tv->msg; 233*5b9c547cSRui Paulo len[0] = 1; 234*5b9c547cSRui Paulo addr[1] = tv->msg + 1; 235*5b9c547cSRui Paulo len[1] = tv->msg_len - 1; 236*5b9c547cSRui Paulo 237*5b9c547cSRui Paulo if (omac1_aes_128_vector(tv->k, 2, addr, len, result) || 238*5b9c547cSRui Paulo os_memcmp(result, tv->tag, 16) != 0) { 239*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, 240*5b9c547cSRui Paulo "OMAC1-AES-128(vector) test vector %u failed", 241*5b9c547cSRui Paulo i); 242*5b9c547cSRui Paulo return 1; 243*5b9c547cSRui Paulo } 244*5b9c547cSRui Paulo 245*5b9c547cSRui Paulo addr[0] = tv->msg; 246*5b9c547cSRui Paulo len[0] = tv->msg_len - 2; 247*5b9c547cSRui Paulo addr[1] = tv->msg + tv->msg_len - 2; 248*5b9c547cSRui Paulo len[1] = 1; 249*5b9c547cSRui Paulo addr[2] = tv->msg + tv->msg_len - 1; 250*5b9c547cSRui Paulo len[2] = 1; 251*5b9c547cSRui Paulo 252*5b9c547cSRui Paulo if (omac1_aes_128_vector(tv->k, 3, addr, len, result) || 253*5b9c547cSRui Paulo os_memcmp(result, tv->tag, 16) != 0) { 254*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, 255*5b9c547cSRui Paulo "OMAC1-AES-128(vector2) test vector %u failed", 256*5b9c547cSRui Paulo i); 257*5b9c547cSRui Paulo return 1; 258*5b9c547cSRui Paulo } 259*5b9c547cSRui Paulo } 260*5b9c547cSRui Paulo 261*5b9c547cSRui Paulo addr[0] = &msg[0]; 262*5b9c547cSRui Paulo len[0] = 1; 263*5b9c547cSRui Paulo addr[1] = &msg[1]; 264*5b9c547cSRui Paulo len[1] = 1; 265*5b9c547cSRui Paulo addr[2] = &msg[2]; 266*5b9c547cSRui Paulo len[2] = 1; 267*5b9c547cSRui Paulo if (omac1_aes_128(key, msg, sizeof(msg), result) || 268*5b9c547cSRui Paulo omac1_aes_128_vector(key, 3, addr, len, result2) || 269*5b9c547cSRui Paulo os_memcmp(result, result2, 16) != 0) { 270*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "OMAC1-AES-128 short test mismatch"); 271*5b9c547cSRui Paulo return 1; 272*5b9c547cSRui Paulo } 273*5b9c547cSRui Paulo 274*5b9c547cSRui Paulo return 0; 275*5b9c547cSRui Paulo } 276*5b9c547cSRui Paulo 277*5b9c547cSRui Paulo 278*5b9c547cSRui Paulo static int test_omac1(void) 279*5b9c547cSRui Paulo { 280*5b9c547cSRui Paulo unsigned int i; 281*5b9c547cSRui Paulo 282*5b9c547cSRui Paulo for (i = 0; i < ARRAY_SIZE(omac1_test_vectors); i++) { 283*5b9c547cSRui Paulo if (test_omac1_vector(&omac1_test_vectors[i], i)) 284*5b9c547cSRui Paulo return 1; 285*5b9c547cSRui Paulo } 286*5b9c547cSRui Paulo 287*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "OMAC1-AES-128 test cases passed"); 288*5b9c547cSRui Paulo 289*5b9c547cSRui Paulo return 0; 290*5b9c547cSRui Paulo } 291*5b9c547cSRui Paulo 292*5b9c547cSRui Paulo 293*5b9c547cSRui Paulo static int test_eax(void) 294*5b9c547cSRui Paulo { 295*5b9c547cSRui Paulo #ifdef EAP_PSK 296*5b9c547cSRui Paulo u8 msg[] = { 0xF7, 0xFB }; 297*5b9c547cSRui Paulo u8 key[] = { 0x91, 0x94, 0x5D, 0x3F, 0x4D, 0xCB, 0xEE, 0x0B, 298*5b9c547cSRui Paulo 0xF4, 0x5E, 0xF5, 0x22, 0x55, 0xF0, 0x95, 0xA4 }; 299*5b9c547cSRui Paulo u8 nonce[] = { 0xBE, 0xCA, 0xF0, 0x43, 0xB0, 0xA2, 0x3D, 0x84, 300*5b9c547cSRui Paulo 0x31, 0x94, 0xBA, 0x97, 0x2C, 0x66, 0xDE, 0xBD }; 301*5b9c547cSRui Paulo u8 hdr[] = { 0xFA, 0x3B, 0xFD, 0x48, 0x06, 0xEB, 0x53, 0xFA }; 302*5b9c547cSRui Paulo u8 cipher[] = { 0x19, 0xDD, 0x5C, 0x4C, 0x93, 0x31, 0x04, 0x9D, 303*5b9c547cSRui Paulo 0x0B, 0xDA, 0xB0, 0x27, 0x74, 0x08, 0xF6, 0x79, 304*5b9c547cSRui Paulo 0x67, 0xE5 }; 305*5b9c547cSRui Paulo u8 data[sizeof(msg)], tag[AES_BLOCK_SIZE]; 306*5b9c547cSRui Paulo 307*5b9c547cSRui Paulo os_memcpy(data, msg, sizeof(msg)); 308*5b9c547cSRui Paulo if (aes_128_eax_encrypt(key, nonce, sizeof(nonce), hdr, sizeof(hdr), 309*5b9c547cSRui Paulo data, sizeof(data), tag)) { 310*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-128 EAX mode encryption failed"); 311*5b9c547cSRui Paulo return 1; 312*5b9c547cSRui Paulo } 313*5b9c547cSRui Paulo if (os_memcmp(data, cipher, sizeof(data)) != 0) { 314*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, 315*5b9c547cSRui Paulo "AES-128 EAX mode encryption returned invalid cipher text"); 316*5b9c547cSRui Paulo return 1; 317*5b9c547cSRui Paulo } 318*5b9c547cSRui Paulo if (os_memcmp(tag, cipher + sizeof(data), AES_BLOCK_SIZE) != 0) { 319*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, 320*5b9c547cSRui Paulo "AES-128 EAX mode encryption returned invalid tag"); 321*5b9c547cSRui Paulo return 1; 322*5b9c547cSRui Paulo } 323*5b9c547cSRui Paulo 324*5b9c547cSRui Paulo if (aes_128_eax_decrypt(key, nonce, sizeof(nonce), hdr, sizeof(hdr), 325*5b9c547cSRui Paulo data, sizeof(data), tag)) { 326*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-128 EAX mode decryption failed"); 327*5b9c547cSRui Paulo return 1; 328*5b9c547cSRui Paulo } 329*5b9c547cSRui Paulo if (os_memcmp(data, msg, sizeof(data)) != 0) { 330*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, 331*5b9c547cSRui Paulo "AES-128 EAX mode decryption returned invalid plain text"); 332*5b9c547cSRui Paulo return 1; 333*5b9c547cSRui Paulo } 334*5b9c547cSRui Paulo 335*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "AES-128 EAX mode test cases passed"); 336*5b9c547cSRui Paulo #endif /* EAP_PSK */ 337*5b9c547cSRui Paulo 338*5b9c547cSRui Paulo return 0; 339*5b9c547cSRui Paulo } 340*5b9c547cSRui Paulo 341*5b9c547cSRui Paulo 342*5b9c547cSRui Paulo static int test_cbc(void) 343*5b9c547cSRui Paulo { 344*5b9c547cSRui Paulo struct cbc_test_vector { 345*5b9c547cSRui Paulo u8 key[16]; 346*5b9c547cSRui Paulo u8 iv[16]; 347*5b9c547cSRui Paulo u8 plain[32]; 348*5b9c547cSRui Paulo u8 cipher[32]; 349*5b9c547cSRui Paulo size_t len; 350*5b9c547cSRui Paulo } vectors[] = { 351*5b9c547cSRui Paulo { 352*5b9c547cSRui Paulo { 0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b, 353*5b9c547cSRui Paulo 0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06 }, 354*5b9c547cSRui Paulo { 0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30, 355*5b9c547cSRui Paulo 0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41 }, 356*5b9c547cSRui Paulo "Single block msg", 357*5b9c547cSRui Paulo { 0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8, 358*5b9c547cSRui Paulo 0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a }, 359*5b9c547cSRui Paulo 16 360*5b9c547cSRui Paulo }, 361*5b9c547cSRui Paulo { 362*5b9c547cSRui Paulo { 0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0, 363*5b9c547cSRui Paulo 0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a }, 364*5b9c547cSRui Paulo { 0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28, 365*5b9c547cSRui Paulo 0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58 }, 366*5b9c547cSRui Paulo { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 367*5b9c547cSRui Paulo 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 368*5b9c547cSRui Paulo 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 369*5b9c547cSRui Paulo 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, 370*5b9c547cSRui Paulo { 0xd2, 0x96, 0xcd, 0x94, 0xc2, 0xcc, 0xcf, 0x8a, 371*5b9c547cSRui Paulo 0x3a, 0x86, 0x30, 0x28, 0xb5, 0xe1, 0xdc, 0x0a, 372*5b9c547cSRui Paulo 0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9, 373*5b9c547cSRui Paulo 0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1 }, 374*5b9c547cSRui Paulo 32 375*5b9c547cSRui Paulo } 376*5b9c547cSRui Paulo }; 377*5b9c547cSRui Paulo int ret = 0; 378*5b9c547cSRui Paulo u8 *buf; 379*5b9c547cSRui Paulo unsigned int i; 380*5b9c547cSRui Paulo 381*5b9c547cSRui Paulo for (i = 0; i < ARRAY_SIZE(vectors); i++) { 382*5b9c547cSRui Paulo struct cbc_test_vector *tv = &vectors[i]; 383*5b9c547cSRui Paulo 384*5b9c547cSRui Paulo buf = os_malloc(tv->len); 385*5b9c547cSRui Paulo if (buf == NULL) { 386*5b9c547cSRui Paulo ret++; 387*5b9c547cSRui Paulo break; 388*5b9c547cSRui Paulo } 389*5b9c547cSRui Paulo 390*5b9c547cSRui Paulo os_memcpy(buf, tv->plain, tv->len); 391*5b9c547cSRui Paulo if (aes_128_cbc_encrypt(tv->key, tv->iv, buf, tv->len) || 392*5b9c547cSRui Paulo os_memcmp(buf, tv->cipher, tv->len) != 0) { 393*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-CBC encrypt %d failed", i); 394*5b9c547cSRui Paulo ret++; 395*5b9c547cSRui Paulo } 396*5b9c547cSRui Paulo 397*5b9c547cSRui Paulo os_memcpy(buf, tv->cipher, tv->len); 398*5b9c547cSRui Paulo if (aes_128_cbc_decrypt(tv->key, tv->iv, buf, tv->len) || 399*5b9c547cSRui Paulo os_memcmp(buf, tv->plain, tv->len) != 0) { 400*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-CBC decrypt %d failed", i); 401*5b9c547cSRui Paulo ret++; 402*5b9c547cSRui Paulo } 403*5b9c547cSRui Paulo 404*5b9c547cSRui Paulo os_free(buf); 405*5b9c547cSRui Paulo } 406*5b9c547cSRui Paulo 407*5b9c547cSRui Paulo return ret; 408*5b9c547cSRui Paulo } 409*5b9c547cSRui Paulo 410*5b9c547cSRui Paulo 411*5b9c547cSRui Paulo static int test_ecb(void) 412*5b9c547cSRui Paulo { 413*5b9c547cSRui Paulo #ifdef EAP_PSK 414*5b9c547cSRui Paulo struct ecb_test_vector { 415*5b9c547cSRui Paulo char *key; 416*5b9c547cSRui Paulo char *plaintext; 417*5b9c547cSRui Paulo char *ciphertext; 418*5b9c547cSRui Paulo } vectors[] = { 419*5b9c547cSRui Paulo /* CAVS 11.1 - ECBGFSbox128.rsp */ 420*5b9c547cSRui Paulo { 421*5b9c547cSRui Paulo "00000000000000000000000000000000", 422*5b9c547cSRui Paulo "f34481ec3cc627bacd5dc3fb08f273e6", 423*5b9c547cSRui Paulo "0336763e966d92595a567cc9ce537f5e" 424*5b9c547cSRui Paulo }, 425*5b9c547cSRui Paulo { 426*5b9c547cSRui Paulo "00000000000000000000000000000000", 427*5b9c547cSRui Paulo "9798c4640bad75c7c3227db910174e72", 428*5b9c547cSRui Paulo "a9a1631bf4996954ebc093957b234589" 429*5b9c547cSRui Paulo }, 430*5b9c547cSRui Paulo { 431*5b9c547cSRui Paulo "00000000000000000000000000000000", 432*5b9c547cSRui Paulo "96ab5c2ff612d9dfaae8c31f30c42168", 433*5b9c547cSRui Paulo "ff4f8391a6a40ca5b25d23bedd44a597" 434*5b9c547cSRui Paulo }, 435*5b9c547cSRui Paulo { 436*5b9c547cSRui Paulo "00000000000000000000000000000000", 437*5b9c547cSRui Paulo "6a118a874519e64e9963798a503f1d35", 438*5b9c547cSRui Paulo "dc43be40be0e53712f7e2bf5ca707209" 439*5b9c547cSRui Paulo }, 440*5b9c547cSRui Paulo { 441*5b9c547cSRui Paulo "00000000000000000000000000000000", 442*5b9c547cSRui Paulo "cb9fceec81286ca3e989bd979b0cb284", 443*5b9c547cSRui Paulo "92beedab1895a94faa69b632e5cc47ce" 444*5b9c547cSRui Paulo }, 445*5b9c547cSRui Paulo { 446*5b9c547cSRui Paulo "00000000000000000000000000000000", 447*5b9c547cSRui Paulo "b26aeb1874e47ca8358ff22378f09144", 448*5b9c547cSRui Paulo "459264f4798f6a78bacb89c15ed3d601" 449*5b9c547cSRui Paulo }, 450*5b9c547cSRui Paulo { 451*5b9c547cSRui Paulo "00000000000000000000000000000000", 452*5b9c547cSRui Paulo "58c8e00b2631686d54eab84b91f0aca1", 453*5b9c547cSRui Paulo "08a4e2efec8a8e3312ca7460b9040bbf" 454*5b9c547cSRui Paulo }, 455*5b9c547cSRui Paulo /* CAVS 11.1 - ECBKeySbox128.rsp */ 456*5b9c547cSRui Paulo { 457*5b9c547cSRui Paulo "10a58869d74be5a374cf867cfb473859", 458*5b9c547cSRui Paulo "00000000000000000000000000000000", 459*5b9c547cSRui Paulo "6d251e6944b051e04eaa6fb4dbf78465" 460*5b9c547cSRui Paulo }, 461*5b9c547cSRui Paulo { 462*5b9c547cSRui Paulo "caea65cdbb75e9169ecd22ebe6e54675", 463*5b9c547cSRui Paulo "00000000000000000000000000000000", 464*5b9c547cSRui Paulo "6e29201190152df4ee058139def610bb", 465*5b9c547cSRui Paulo } 466*5b9c547cSRui Paulo }; 467*5b9c547cSRui Paulo int ret = 0; 468*5b9c547cSRui Paulo unsigned int i; 469*5b9c547cSRui Paulo u8 key[16], plain[16], cipher[16], out[16]; 470*5b9c547cSRui Paulo 471*5b9c547cSRui Paulo for (i = 0; i < ARRAY_SIZE(vectors); i++) { 472*5b9c547cSRui Paulo struct ecb_test_vector *tv = &vectors[i]; 473*5b9c547cSRui Paulo 474*5b9c547cSRui Paulo if (hexstr2bin(tv->key, key, sizeof(key)) || 475*5b9c547cSRui Paulo hexstr2bin(tv->plaintext, plain, sizeof(plain)) || 476*5b9c547cSRui Paulo hexstr2bin(tv->ciphertext, cipher, sizeof(cipher))) { 477*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "Invalid AES-ECB test vector %u", 478*5b9c547cSRui Paulo i); 479*5b9c547cSRui Paulo ret++; 480*5b9c547cSRui Paulo continue; 481*5b9c547cSRui Paulo } 482*5b9c547cSRui Paulo 483*5b9c547cSRui Paulo if (aes_128_encrypt_block(key, plain, out) < 0 || 484*5b9c547cSRui Paulo os_memcmp(out, cipher, 16) != 0) { 485*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-ECB encrypt %u failed", i); 486*5b9c547cSRui Paulo ret++; 487*5b9c547cSRui Paulo } 488*5b9c547cSRui Paulo } 489*5b9c547cSRui Paulo 490*5b9c547cSRui Paulo if (!ret) 491*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "AES ECB mode test cases passed"); 492*5b9c547cSRui Paulo 493*5b9c547cSRui Paulo return ret; 494*5b9c547cSRui Paulo #endif /* EAP_PSK */ 495*5b9c547cSRui Paulo 496*5b9c547cSRui Paulo return 0; 497*5b9c547cSRui Paulo } 498*5b9c547cSRui Paulo 499*5b9c547cSRui Paulo 500*5b9c547cSRui Paulo static int test_key_wrap(void) 501*5b9c547cSRui Paulo { 502*5b9c547cSRui Paulo int ret = 0; 503*5b9c547cSRui Paulo 504*5b9c547cSRui Paulo /* RFC 3394 - Test vector 4.1 */ 505*5b9c547cSRui Paulo u8 kek41[] = { 506*5b9c547cSRui Paulo 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 507*5b9c547cSRui Paulo 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f 508*5b9c547cSRui Paulo }; 509*5b9c547cSRui Paulo u8 plain41[] = { 510*5b9c547cSRui Paulo 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 511*5b9c547cSRui Paulo 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff 512*5b9c547cSRui Paulo }; 513*5b9c547cSRui Paulo u8 crypt41[] = { 514*5b9c547cSRui Paulo 0x1F, 0xA6, 0x8B, 0x0A, 0x81, 0x12, 0xB4, 0x47, 515*5b9c547cSRui Paulo 0xAE, 0xF3, 0x4B, 0xD8, 0xFB, 0x5A, 0x7B, 0x82, 516*5b9c547cSRui Paulo 0x9D, 0x3E, 0x86, 0x23, 0x71, 0xD2, 0xCF, 0xE5 517*5b9c547cSRui Paulo }; 518*5b9c547cSRui Paulo /* RFC 3394 - Test vector 4.2 */ 519*5b9c547cSRui Paulo u8 kek42[] = { 520*5b9c547cSRui Paulo 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 521*5b9c547cSRui Paulo 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 522*5b9c547cSRui Paulo 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 523*5b9c547cSRui Paulo }; 524*5b9c547cSRui Paulo u8 plain42[] = { 525*5b9c547cSRui Paulo 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 526*5b9c547cSRui Paulo 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff 527*5b9c547cSRui Paulo }; 528*5b9c547cSRui Paulo u8 crypt42[] = { 529*5b9c547cSRui Paulo 0x96, 0x77, 0x8B, 0x25, 0xAE, 0x6C, 0xA4, 0x35, 530*5b9c547cSRui Paulo 0xF9, 0x2B, 0x5B, 0x97, 0xC0, 0x50, 0xAE, 0xD2, 531*5b9c547cSRui Paulo 0x46, 0x8A, 0xB8, 0xA1, 0x7A, 0xD8, 0x4E, 0x5D 532*5b9c547cSRui Paulo }; 533*5b9c547cSRui Paulo /* RFC 3394 - Test vector 4.3 */ 534*5b9c547cSRui Paulo u8 kek43[] = { 535*5b9c547cSRui Paulo 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 536*5b9c547cSRui Paulo 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 537*5b9c547cSRui Paulo 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 538*5b9c547cSRui Paulo 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F 539*5b9c547cSRui Paulo }; 540*5b9c547cSRui Paulo u8 plain43[] = { 541*5b9c547cSRui Paulo 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 542*5b9c547cSRui Paulo 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff 543*5b9c547cSRui Paulo }; 544*5b9c547cSRui Paulo u8 crypt43[] = { 545*5b9c547cSRui Paulo 0x64, 0xE8, 0xC3, 0xF9, 0xCE, 0x0F, 0x5B, 0xA2, 546*5b9c547cSRui Paulo 0x63, 0xE9, 0x77, 0x79, 0x05, 0x81, 0x8A, 0x2A, 547*5b9c547cSRui Paulo 0x93, 0xC8, 0x19, 0x1E, 0x7D, 0x6E, 0x8A, 0xE7, 548*5b9c547cSRui Paulo }; 549*5b9c547cSRui Paulo /* RFC 3394 - Test vector 4.4 */ 550*5b9c547cSRui Paulo u8 kek44[] = { 551*5b9c547cSRui Paulo 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 552*5b9c547cSRui Paulo 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 553*5b9c547cSRui Paulo 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 554*5b9c547cSRui Paulo }; 555*5b9c547cSRui Paulo u8 plain44[] = { 556*5b9c547cSRui Paulo 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 557*5b9c547cSRui Paulo 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 558*5b9c547cSRui Paulo 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 559*5b9c547cSRui Paulo }; 560*5b9c547cSRui Paulo u8 crypt44[] = { 561*5b9c547cSRui Paulo 0x03, 0x1D, 0x33, 0x26, 0x4E, 0x15, 0xD3, 0x32, 562*5b9c547cSRui Paulo 0x68, 0xF2, 0x4E, 0xC2, 0x60, 0x74, 0x3E, 0xDC, 563*5b9c547cSRui Paulo 0xE1, 0xC6, 0xC7, 0xDD, 0xEE, 0x72, 0x5A, 0x93, 564*5b9c547cSRui Paulo 0x6B, 0xA8, 0x14, 0x91, 0x5C, 0x67, 0x62, 0xD2 565*5b9c547cSRui Paulo }; 566*5b9c547cSRui Paulo /* RFC 3394 - Test vector 4.5 */ 567*5b9c547cSRui Paulo u8 kek45[] = { 568*5b9c547cSRui Paulo 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 569*5b9c547cSRui Paulo 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 570*5b9c547cSRui Paulo 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 571*5b9c547cSRui Paulo 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F 572*5b9c547cSRui Paulo }; 573*5b9c547cSRui Paulo u8 plain45[] = { 574*5b9c547cSRui Paulo 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 575*5b9c547cSRui Paulo 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 576*5b9c547cSRui Paulo 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 577*5b9c547cSRui Paulo }; 578*5b9c547cSRui Paulo u8 crypt45[] = { 579*5b9c547cSRui Paulo 0xA8, 0xF9, 0xBC, 0x16, 0x12, 0xC6, 0x8B, 0x3F, 580*5b9c547cSRui Paulo 0xF6, 0xE6, 0xF4, 0xFB, 0xE3, 0x0E, 0x71, 0xE4, 581*5b9c547cSRui Paulo 0x76, 0x9C, 0x8B, 0x80, 0xA3, 0x2C, 0xB8, 0x95, 582*5b9c547cSRui Paulo 0x8C, 0xD5, 0xD1, 0x7D, 0x6B, 0x25, 0x4D, 0xA1, 583*5b9c547cSRui Paulo }; 584*5b9c547cSRui Paulo /* RFC 3394 - Test vector 4.6 */ 585*5b9c547cSRui Paulo u8 kek46[] = { 586*5b9c547cSRui Paulo 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 587*5b9c547cSRui Paulo 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 588*5b9c547cSRui Paulo 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 589*5b9c547cSRui Paulo 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F 590*5b9c547cSRui Paulo }; 591*5b9c547cSRui Paulo u8 plain46[] = { 592*5b9c547cSRui Paulo 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 593*5b9c547cSRui Paulo 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 594*5b9c547cSRui Paulo 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 595*5b9c547cSRui Paulo 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 596*5b9c547cSRui Paulo }; 597*5b9c547cSRui Paulo u8 crypt46[] = { 598*5b9c547cSRui Paulo 0x28, 0xC9, 0xF4, 0x04, 0xC4, 0xB8, 0x10, 0xF4, 599*5b9c547cSRui Paulo 0xCB, 0xCC, 0xB3, 0x5C, 0xFB, 0x87, 0xF8, 0x26, 600*5b9c547cSRui Paulo 0x3F, 0x57, 0x86, 0xE2, 0xD8, 0x0E, 0xD3, 0x26, 601*5b9c547cSRui Paulo 0xCB, 0xC7, 0xF0, 0xE7, 0x1A, 0x99, 0xF4, 0x3B, 602*5b9c547cSRui Paulo 0xFB, 0x98, 0x8B, 0x9B, 0x7A, 0x02, 0xDD, 0x21 603*5b9c547cSRui Paulo }; 604*5b9c547cSRui Paulo u8 result[40]; 605*5b9c547cSRui Paulo 606*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "RFC 3394 - Test vector 4.1"); 607*5b9c547cSRui Paulo if (aes_wrap(kek41, sizeof(kek41), sizeof(plain41) / 8, plain41, 608*5b9c547cSRui Paulo result)) { 609*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-128 reported failure"); 610*5b9c547cSRui Paulo ret++; 611*5b9c547cSRui Paulo } 612*5b9c547cSRui Paulo if (os_memcmp(result, crypt41, sizeof(crypt41)) != 0) { 613*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-128 failed"); 614*5b9c547cSRui Paulo ret++; 615*5b9c547cSRui Paulo } 616*5b9c547cSRui Paulo if (aes_unwrap(kek41, sizeof(kek41), sizeof(plain41) / 8, crypt41, 617*5b9c547cSRui Paulo result)) { 618*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-128 reported failure"); 619*5b9c547cSRui Paulo ret++; 620*5b9c547cSRui Paulo } 621*5b9c547cSRui Paulo if (os_memcmp(result, plain41, sizeof(plain41)) != 0) { 622*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-128 failed"); 623*5b9c547cSRui Paulo ret++; 624*5b9c547cSRui Paulo } 625*5b9c547cSRui Paulo 626*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "RFC 3394 - Test vector 4.2"); 627*5b9c547cSRui Paulo if (aes_wrap(kek42, sizeof(kek42), sizeof(plain42) / 8, plain42, 628*5b9c547cSRui Paulo result)) { 629*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-192 reported failure"); 630*5b9c547cSRui Paulo ret++; 631*5b9c547cSRui Paulo } 632*5b9c547cSRui Paulo if (os_memcmp(result, crypt42, sizeof(crypt42)) != 0) { 633*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-192 failed"); 634*5b9c547cSRui Paulo ret++; 635*5b9c547cSRui Paulo } 636*5b9c547cSRui Paulo if (aes_unwrap(kek42, sizeof(kek42), sizeof(plain42) / 8, crypt42, 637*5b9c547cSRui Paulo result)) { 638*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-192 reported failure"); 639*5b9c547cSRui Paulo ret++; 640*5b9c547cSRui Paulo } 641*5b9c547cSRui Paulo if (os_memcmp(result, plain42, sizeof(plain42)) != 0) { 642*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-192 failed"); 643*5b9c547cSRui Paulo ret++; 644*5b9c547cSRui Paulo } 645*5b9c547cSRui Paulo 646*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "RFC 3394 - Test vector 4.3"); 647*5b9c547cSRui Paulo if (aes_wrap(kek43, sizeof(kek43), sizeof(plain43) / 8, plain43, 648*5b9c547cSRui Paulo result)) { 649*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-256 reported failure"); 650*5b9c547cSRui Paulo ret++; 651*5b9c547cSRui Paulo } 652*5b9c547cSRui Paulo if (os_memcmp(result, crypt43, sizeof(crypt43)) != 0) { 653*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-256 failed"); 654*5b9c547cSRui Paulo ret++; 655*5b9c547cSRui Paulo } 656*5b9c547cSRui Paulo if (aes_unwrap(kek43, sizeof(kek43), sizeof(plain43) / 8, crypt43, 657*5b9c547cSRui Paulo result)) { 658*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-256 reported failure"); 659*5b9c547cSRui Paulo ret++; 660*5b9c547cSRui Paulo } 661*5b9c547cSRui Paulo if (os_memcmp(result, plain43, sizeof(plain43)) != 0) { 662*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-256 failed"); 663*5b9c547cSRui Paulo ret++; 664*5b9c547cSRui Paulo } 665*5b9c547cSRui Paulo 666*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "RFC 3394 - Test vector 4.4"); 667*5b9c547cSRui Paulo if (aes_wrap(kek44, sizeof(kek44), sizeof(plain44) / 8, plain44, 668*5b9c547cSRui Paulo result)) { 669*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-192 reported failure"); 670*5b9c547cSRui Paulo ret++; 671*5b9c547cSRui Paulo } 672*5b9c547cSRui Paulo if (os_memcmp(result, crypt44, sizeof(crypt44)) != 0) { 673*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-192 failed"); 674*5b9c547cSRui Paulo ret++; 675*5b9c547cSRui Paulo } 676*5b9c547cSRui Paulo if (aes_unwrap(kek44, sizeof(kek44), sizeof(plain44) / 8, crypt44, 677*5b9c547cSRui Paulo result)) { 678*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-192 reported failure"); 679*5b9c547cSRui Paulo ret++; 680*5b9c547cSRui Paulo } 681*5b9c547cSRui Paulo if (os_memcmp(result, plain44, sizeof(plain44)) != 0) { 682*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-192 failed"); 683*5b9c547cSRui Paulo ret++; 684*5b9c547cSRui Paulo } 685*5b9c547cSRui Paulo 686*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "RFC 3394 - Test vector 4.5"); 687*5b9c547cSRui Paulo if (aes_wrap(kek45, sizeof(kek45), sizeof(plain45) / 8, plain45, 688*5b9c547cSRui Paulo result)) { 689*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-256 reported failure"); 690*5b9c547cSRui Paulo ret++; 691*5b9c547cSRui Paulo } 692*5b9c547cSRui Paulo if (os_memcmp(result, crypt45, sizeof(crypt45)) != 0) { 693*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-256 failed"); 694*5b9c547cSRui Paulo ret++; 695*5b9c547cSRui Paulo } 696*5b9c547cSRui Paulo if (aes_unwrap(kek45, sizeof(kek45), sizeof(plain45) / 8, crypt45, 697*5b9c547cSRui Paulo result)) { 698*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-256 reported failure"); 699*5b9c547cSRui Paulo ret++; 700*5b9c547cSRui Paulo } 701*5b9c547cSRui Paulo if (os_memcmp(result, plain45, sizeof(plain45)) != 0) { 702*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-256 failed"); 703*5b9c547cSRui Paulo ret++; 704*5b9c547cSRui Paulo } 705*5b9c547cSRui Paulo 706*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "RFC 3394 - Test vector 4.6"); 707*5b9c547cSRui Paulo if (aes_wrap(kek46, sizeof(kek46), sizeof(plain46) / 8, plain46, 708*5b9c547cSRui Paulo result)) { 709*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-256 reported failure"); 710*5b9c547cSRui Paulo ret++; 711*5b9c547cSRui Paulo } 712*5b9c547cSRui Paulo if (os_memcmp(result, crypt46, sizeof(crypt46)) != 0) { 713*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-WRAP-256 failed"); 714*5b9c547cSRui Paulo ret++; 715*5b9c547cSRui Paulo } 716*5b9c547cSRui Paulo if (aes_unwrap(kek46, sizeof(kek46), sizeof(plain46) / 8, crypt46, 717*5b9c547cSRui Paulo result)) { 718*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-256 reported failure"); 719*5b9c547cSRui Paulo ret++; 720*5b9c547cSRui Paulo } 721*5b9c547cSRui Paulo if (os_memcmp(result, plain46, sizeof(plain46)) != 0) { 722*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "AES-UNWRAP-256 failed"); 723*5b9c547cSRui Paulo ret++; 724*5b9c547cSRui Paulo } 725*5b9c547cSRui Paulo 726*5b9c547cSRui Paulo if (!ret) 727*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "AES key wrap/unwrap test cases passed"); 728*5b9c547cSRui Paulo 729*5b9c547cSRui Paulo return ret; 730*5b9c547cSRui Paulo } 731*5b9c547cSRui Paulo 732*5b9c547cSRui Paulo 733*5b9c547cSRui Paulo static int test_md5(void) 734*5b9c547cSRui Paulo { 735*5b9c547cSRui Paulo struct { 736*5b9c547cSRui Paulo char *data; 737*5b9c547cSRui Paulo char *hash; 738*5b9c547cSRui Paulo } tests[] = { 739*5b9c547cSRui Paulo { 740*5b9c547cSRui Paulo "", 741*5b9c547cSRui Paulo "\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04" 742*5b9c547cSRui Paulo "\xe9\x80\x09\x98\xec\xf8\x42\x7e" 743*5b9c547cSRui Paulo }, 744*5b9c547cSRui Paulo { 745*5b9c547cSRui Paulo "a", 746*5b9c547cSRui Paulo "\x0c\xc1\x75\xb9\xc0\xf1\xb6\xa8" 747*5b9c547cSRui Paulo "\x31\xc3\x99\xe2\x69\x77\x26\x61" 748*5b9c547cSRui Paulo }, 749*5b9c547cSRui Paulo { 750*5b9c547cSRui Paulo "abc", 751*5b9c547cSRui Paulo "\x90\x01\x50\x98\x3c\xd2\x4f\xb0" 752*5b9c547cSRui Paulo "\xd6\x96\x3f\x7d\x28\xe1\x7f\x72" 753*5b9c547cSRui Paulo }, 754*5b9c547cSRui Paulo { 755*5b9c547cSRui Paulo "message digest", 756*5b9c547cSRui Paulo "\xf9\x6b\x69\x7d\x7c\xb7\x93\x8d" 757*5b9c547cSRui Paulo "\x52\x5a\x2f\x31\xaa\xf1\x61\xd0" 758*5b9c547cSRui Paulo }, 759*5b9c547cSRui Paulo { 760*5b9c547cSRui Paulo "abcdefghijklmnopqrstuvwxyz", 761*5b9c547cSRui Paulo "\xc3\xfc\xd3\xd7\x61\x92\xe4\x00" 762*5b9c547cSRui Paulo "\x7d\xfb\x49\x6c\xca\x67\xe1\x3b" 763*5b9c547cSRui Paulo }, 764*5b9c547cSRui Paulo { 765*5b9c547cSRui Paulo "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" 766*5b9c547cSRui Paulo "0123456789", 767*5b9c547cSRui Paulo "\xd1\x74\xab\x98\xd2\x77\xd9\xf5" 768*5b9c547cSRui Paulo "\xa5\x61\x1c\x2c\x9f\x41\x9d\x9f" 769*5b9c547cSRui Paulo }, 770*5b9c547cSRui Paulo { 771*5b9c547cSRui Paulo "12345678901234567890123456789012345678901234567890" 772*5b9c547cSRui Paulo "123456789012345678901234567890", 773*5b9c547cSRui Paulo "\x57\xed\xf4\xa2\x2b\xe3\xc9\x55" 774*5b9c547cSRui Paulo "\xac\x49\xda\x2e\x21\x07\xb6\x7a" 775*5b9c547cSRui Paulo } 776*5b9c547cSRui Paulo }; 777*5b9c547cSRui Paulo unsigned int i; 778*5b9c547cSRui Paulo u8 hash[16]; 779*5b9c547cSRui Paulo const u8 *addr[2]; 780*5b9c547cSRui Paulo size_t len[2]; 781*5b9c547cSRui Paulo int errors = 0; 782*5b9c547cSRui Paulo 783*5b9c547cSRui Paulo for (i = 0; i < ARRAY_SIZE(tests); i++) { 784*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "MD5 test case %d", i); 785*5b9c547cSRui Paulo 786*5b9c547cSRui Paulo addr[0] = (u8 *) tests[i].data; 787*5b9c547cSRui Paulo len[0] = strlen(tests[i].data); 788*5b9c547cSRui Paulo if (md5_vector(1, addr, len, hash) < 0 || 789*5b9c547cSRui Paulo os_memcmp(hash, tests[i].hash, 16) != 0) { 790*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " FAIL"); 791*5b9c547cSRui Paulo errors++; 792*5b9c547cSRui Paulo } else 793*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " OK"); 794*5b9c547cSRui Paulo 795*5b9c547cSRui Paulo if (len[0]) { 796*5b9c547cSRui Paulo addr[0] = (u8 *) tests[i].data; 797*5b9c547cSRui Paulo len[0] = strlen(tests[i].data); 798*5b9c547cSRui Paulo addr[1] = (u8 *) tests[i].data + 1; 799*5b9c547cSRui Paulo len[1] = strlen(tests[i].data) - 1; 800*5b9c547cSRui Paulo if (md5_vector(1, addr, len, hash) < 0 || 801*5b9c547cSRui Paulo os_memcmp(hash, tests[i].hash, 16) != 0) { 802*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " FAIL"); 803*5b9c547cSRui Paulo errors++; 804*5b9c547cSRui Paulo } else 805*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " OK"); 806*5b9c547cSRui Paulo } 807*5b9c547cSRui Paulo } 808*5b9c547cSRui Paulo 809*5b9c547cSRui Paulo if (!errors) 810*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "MD5 test cases passed"); 811*5b9c547cSRui Paulo 812*5b9c547cSRui Paulo return errors; 813*5b9c547cSRui Paulo } 814*5b9c547cSRui Paulo 815*5b9c547cSRui Paulo 816*5b9c547cSRui Paulo static int test_eap_fast(void) 817*5b9c547cSRui Paulo { 818*5b9c547cSRui Paulo #ifdef EAP_FAST 819*5b9c547cSRui Paulo /* RFC 4851, Appendix B.1 */ 820*5b9c547cSRui Paulo const u8 pac_key[] = { 821*5b9c547cSRui Paulo 0x0B, 0x97, 0x39, 0x0F, 0x37, 0x51, 0x78, 0x09, 822*5b9c547cSRui Paulo 0x81, 0x1E, 0xFD, 0x9C, 0x6E, 0x65, 0x94, 0x2B, 823*5b9c547cSRui Paulo 0x63, 0x2C, 0xE9, 0x53, 0x89, 0x38, 0x08, 0xBA, 824*5b9c547cSRui Paulo 0x36, 0x0B, 0x03, 0x7C, 0xD1, 0x85, 0xE4, 0x14 825*5b9c547cSRui Paulo }; 826*5b9c547cSRui Paulo const u8 seed[] = { 827*5b9c547cSRui Paulo 0x3F, 0xFB, 0x11, 0xC4, 0x6C, 0xBF, 0xA5, 0x7A, 828*5b9c547cSRui Paulo 0x54, 0x40, 0xDA, 0xE8, 0x22, 0xD3, 0x11, 0xD3, 829*5b9c547cSRui Paulo 0xF7, 0x6D, 0xE4, 0x1D, 0xD9, 0x33, 0xE5, 0x93, 830*5b9c547cSRui Paulo 0x70, 0x97, 0xEB, 0xA9, 0xB3, 0x66, 0xF4, 0x2A, 831*5b9c547cSRui Paulo 0x00, 0x00, 0x00, 0x02, 0x6A, 0x66, 0x43, 0x2A, 832*5b9c547cSRui Paulo 0x8D, 0x14, 0x43, 0x2C, 0xEC, 0x58, 0x2D, 0x2F, 833*5b9c547cSRui Paulo 0xC7, 0x9C, 0x33, 0x64, 0xBA, 0x04, 0xAD, 0x3A, 834*5b9c547cSRui Paulo 0x52, 0x54, 0xD6, 0xA5, 0x79, 0xAD, 0x1E, 0x00 835*5b9c547cSRui Paulo }; 836*5b9c547cSRui Paulo const u8 master_secret[] = { 837*5b9c547cSRui Paulo 0x4A, 0x1A, 0x51, 0x2C, 0x01, 0x60, 0xBC, 0x02, 838*5b9c547cSRui Paulo 0x3C, 0xCF, 0xBC, 0x83, 0x3F, 0x03, 0xBC, 0x64, 839*5b9c547cSRui Paulo 0x88, 0xC1, 0x31, 0x2F, 0x0B, 0xA9, 0xA2, 0x77, 840*5b9c547cSRui Paulo 0x16, 0xA8, 0xD8, 0xE8, 0xBD, 0xC9, 0xD2, 0x29, 841*5b9c547cSRui Paulo 0x38, 0x4B, 0x7A, 0x85, 0xBE, 0x16, 0x4D, 0x27, 842*5b9c547cSRui Paulo 0x33, 0xD5, 0x24, 0x79, 0x87, 0xB1, 0xC5, 0xA2 843*5b9c547cSRui Paulo }; 844*5b9c547cSRui Paulo const u8 key_block[] = { 845*5b9c547cSRui Paulo 0x59, 0x59, 0xBE, 0x8E, 0x41, 0x3A, 0x77, 0x74, 846*5b9c547cSRui Paulo 0x8B, 0xB2, 0xE5, 0xD3, 0x60, 0xAC, 0x4D, 0x35, 847*5b9c547cSRui Paulo 0xDF, 0xFB, 0xC8, 0x1E, 0x9C, 0x24, 0x9C, 0x8B, 848*5b9c547cSRui Paulo 0x0E, 0xC3, 0x1D, 0x72, 0xC8, 0x84, 0x9D, 0x57, 849*5b9c547cSRui Paulo 0x48, 0x51, 0x2E, 0x45, 0x97, 0x6C, 0x88, 0x70, 850*5b9c547cSRui Paulo 0xBE, 0x5F, 0x01, 0xD3, 0x64, 0xE7, 0x4C, 0xBB, 851*5b9c547cSRui Paulo 0x11, 0x24, 0xE3, 0x49, 0xE2, 0x3B, 0xCD, 0xEF, 852*5b9c547cSRui Paulo 0x7A, 0xB3, 0x05, 0x39, 0x5D, 0x64, 0x8A, 0x44, 853*5b9c547cSRui Paulo 0x11, 0xB6, 0x69, 0x88, 0x34, 0x2E, 0x8E, 0x29, 854*5b9c547cSRui Paulo 0xD6, 0x4B, 0x7D, 0x72, 0x17, 0x59, 0x28, 0x05, 855*5b9c547cSRui Paulo 0xAF, 0xF9, 0xB7, 0xFF, 0x66, 0x6D, 0xA1, 0x96, 856*5b9c547cSRui Paulo 0x8F, 0x0B, 0x5E, 0x06, 0x46, 0x7A, 0x44, 0x84, 857*5b9c547cSRui Paulo 0x64, 0xC1, 0xC8, 0x0C, 0x96, 0x44, 0x09, 0x98, 858*5b9c547cSRui Paulo 0xFF, 0x92, 0xA8, 0xB4, 0xC6, 0x42, 0x28, 0x71 859*5b9c547cSRui Paulo }; 860*5b9c547cSRui Paulo const u8 sks[] = { 861*5b9c547cSRui Paulo 0xD6, 0x4B, 0x7D, 0x72, 0x17, 0x59, 0x28, 0x05, 862*5b9c547cSRui Paulo 0xAF, 0xF9, 0xB7, 0xFF, 0x66, 0x6D, 0xA1, 0x96, 863*5b9c547cSRui Paulo 0x8F, 0x0B, 0x5E, 0x06, 0x46, 0x7A, 0x44, 0x84, 864*5b9c547cSRui Paulo 0x64, 0xC1, 0xC8, 0x0C, 0x96, 0x44, 0x09, 0x98, 865*5b9c547cSRui Paulo 0xFF, 0x92, 0xA8, 0xB4, 0xC6, 0x42, 0x28, 0x71 866*5b9c547cSRui Paulo }; 867*5b9c547cSRui Paulo const u8 isk[] = { 868*5b9c547cSRui Paulo 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 869*5b9c547cSRui Paulo 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 870*5b9c547cSRui Paulo 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 871*5b9c547cSRui Paulo 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 872*5b9c547cSRui Paulo }; 873*5b9c547cSRui Paulo const u8 imck[] = { 874*5b9c547cSRui Paulo 0x16, 0x15, 0x3C, 0x3F, 0x21, 0x55, 0xEF, 0xD9, 875*5b9c547cSRui Paulo 0x7F, 0x34, 0xAE, 0xC8, 0x1A, 0x4E, 0x66, 0x80, 876*5b9c547cSRui Paulo 0x4C, 0xC3, 0x76, 0xF2, 0x8A, 0xA9, 0x6F, 0x96, 877*5b9c547cSRui Paulo 0xC2, 0x54, 0x5F, 0x8C, 0xAB, 0x65, 0x02, 0xE1, 878*5b9c547cSRui Paulo 0x18, 0x40, 0x7B, 0x56, 0xBE, 0xEA, 0xA7, 0xC5, 879*5b9c547cSRui Paulo 0x76, 0x5D, 0x8F, 0x0B, 0xC5, 0x07, 0xC6, 0xB9, 880*5b9c547cSRui Paulo 0x04, 0xD0, 0x69, 0x56, 0x72, 0x8B, 0x6B, 0xB8, 881*5b9c547cSRui Paulo 0x15, 0xEC, 0x57, 0x7B 882*5b9c547cSRui Paulo }; 883*5b9c547cSRui Paulo const u8 msk[] = { 884*5b9c547cSRui Paulo 0x4D, 0x83, 0xA9, 0xBE, 0x6F, 0x8A, 0x74, 0xED, 885*5b9c547cSRui Paulo 0x6A, 0x02, 0x66, 0x0A, 0x63, 0x4D, 0x2C, 0x33, 886*5b9c547cSRui Paulo 0xC2, 0xDA, 0x60, 0x15, 0xC6, 0x37, 0x04, 0x51, 887*5b9c547cSRui Paulo 0x90, 0x38, 0x63, 0xDA, 0x54, 0x3E, 0x14, 0xB9, 888*5b9c547cSRui Paulo 0x27, 0x99, 0x18, 0x1E, 0x07, 0xBF, 0x0F, 0x5A, 889*5b9c547cSRui Paulo 0x5E, 0x3C, 0x32, 0x93, 0x80, 0x8C, 0x6C, 0x49, 890*5b9c547cSRui Paulo 0x67, 0xED, 0x24, 0xFE, 0x45, 0x40, 0xA0, 0x59, 891*5b9c547cSRui Paulo 0x5E, 0x37, 0xC2, 0xE9, 0xD0, 0x5D, 0x0A, 0xE3 892*5b9c547cSRui Paulo }; 893*5b9c547cSRui Paulo const u8 emsk[] = { 894*5b9c547cSRui Paulo 0x3A, 0xD4, 0xAB, 0xDB, 0x76, 0xB2, 0x7F, 0x3B, 895*5b9c547cSRui Paulo 0xEA, 0x32, 0x2C, 0x2B, 0x74, 0xF4, 0x28, 0x55, 896*5b9c547cSRui Paulo 0xEF, 0x2D, 0xBA, 0x78, 0xC9, 0x57, 0x2F, 0x0D, 897*5b9c547cSRui Paulo 0x06, 0xCD, 0x51, 0x7C, 0x20, 0x93, 0x98, 0xA9, 898*5b9c547cSRui Paulo 0x76, 0xEA, 0x70, 0x21, 0xD7, 0x0E, 0x25, 0x54, 899*5b9c547cSRui Paulo 0x97, 0xED, 0xB2, 0x8A, 0xF6, 0xED, 0xFD, 0x0A, 900*5b9c547cSRui Paulo 0x2A, 0xE7, 0xA1, 0x58, 0x90, 0x10, 0x50, 0x44, 901*5b9c547cSRui Paulo 0xB3, 0x82, 0x85, 0xDB, 0x06, 0x14, 0xD2, 0xF9 902*5b9c547cSRui Paulo }; 903*5b9c547cSRui Paulo /* RFC 4851, Appendix B.2 */ 904*5b9c547cSRui Paulo u8 tlv[] = { 905*5b9c547cSRui Paulo 0x80, 0x0C, 0x00, 0x38, 0x00, 0x01, 0x01, 0x00, 906*5b9c547cSRui Paulo 0xD8, 0x6A, 0x8C, 0x68, 0x3C, 0x32, 0x31, 0xA8, 907*5b9c547cSRui Paulo 0x56, 0x63, 0xB6, 0x40, 0x21, 0xFE, 0x21, 0x14, 908*5b9c547cSRui Paulo 0x4E, 0xE7, 0x54, 0x20, 0x79, 0x2D, 0x42, 0x62, 909*5b9c547cSRui Paulo 0xC9, 0xBF, 0x53, 0x7F, 0x54, 0xFD, 0xAC, 0x58, 910*5b9c547cSRui Paulo 0x43, 0x24, 0x6E, 0x30, 0x92, 0x17, 0x6D, 0xCF, 911*5b9c547cSRui Paulo 0xE6, 0xE0, 0x69, 0xEB, 0x33, 0x61, 0x6A, 0xCC, 912*5b9c547cSRui Paulo 0x05, 0xC5, 0x5B, 0xB7 913*5b9c547cSRui Paulo }; 914*5b9c547cSRui Paulo const u8 compound_mac[] = { 915*5b9c547cSRui Paulo 0x43, 0x24, 0x6E, 0x30, 0x92, 0x17, 0x6D, 0xCF, 916*5b9c547cSRui Paulo 0xE6, 0xE0, 0x69, 0xEB, 0x33, 0x61, 0x6A, 0xCC, 917*5b9c547cSRui Paulo 0x05, 0xC5, 0x5B, 0xB7 918*5b9c547cSRui Paulo }; 919*5b9c547cSRui Paulo u8 buf[512]; 920*5b9c547cSRui Paulo const u8 *simck, *cmk; 921*5b9c547cSRui Paulo int errors = 0; 922*5b9c547cSRui Paulo 923*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "EAP-FAST test cases"); 924*5b9c547cSRui Paulo 925*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "- T-PRF (SHA1) test case / master_secret"); 926*5b9c547cSRui Paulo if (sha1_t_prf(pac_key, sizeof(pac_key), 927*5b9c547cSRui Paulo "PAC to master secret label hash", 928*5b9c547cSRui Paulo seed, sizeof(seed), buf, sizeof(master_secret)) < 0 || 929*5b9c547cSRui Paulo os_memcmp(master_secret, buf, sizeof(master_secret)) != 0) { 930*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "T-PRF test - FAILED!"); 931*5b9c547cSRui Paulo errors++; 932*5b9c547cSRui Paulo } 933*5b9c547cSRui Paulo 934*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "- PRF (TLS, SHA1/MD5) test case / key_block"); 935*5b9c547cSRui Paulo if (tls_prf_sha1_md5(master_secret, sizeof(master_secret), 936*5b9c547cSRui Paulo "key expansion", seed, sizeof(seed), 937*5b9c547cSRui Paulo buf, sizeof(key_block)) || 938*5b9c547cSRui Paulo os_memcmp(key_block, buf, sizeof(key_block)) != 0) { 939*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "PRF test - FAILED!"); 940*5b9c547cSRui Paulo errors++; 941*5b9c547cSRui Paulo } 942*5b9c547cSRui Paulo 943*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "- T-PRF (SHA1) test case / IMCK"); 944*5b9c547cSRui Paulo if (sha1_t_prf(sks, sizeof(sks), "Inner Methods Compound Keys", 945*5b9c547cSRui Paulo isk, sizeof(isk), buf, sizeof(imck)) < 0 || 946*5b9c547cSRui Paulo os_memcmp(imck, buf, sizeof(imck)) != 0) { 947*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "T-PRF test - FAILED!"); 948*5b9c547cSRui Paulo errors++; 949*5b9c547cSRui Paulo } 950*5b9c547cSRui Paulo 951*5b9c547cSRui Paulo simck = imck; 952*5b9c547cSRui Paulo cmk = imck + 40; 953*5b9c547cSRui Paulo 954*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "- T-PRF (SHA1) test case / MSK"); 955*5b9c547cSRui Paulo if (sha1_t_prf(simck, 40, "Session Key Generating Function", 956*5b9c547cSRui Paulo (u8 *) "", 0, buf, sizeof(msk)) < 0 || 957*5b9c547cSRui Paulo os_memcmp(msk, buf, sizeof(msk)) != 0) { 958*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "T-PRF test - FAILED!"); 959*5b9c547cSRui Paulo errors++; 960*5b9c547cSRui Paulo } 961*5b9c547cSRui Paulo 962*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "- T-PRF (SHA1) test case / EMSK"); 963*5b9c547cSRui Paulo if (sha1_t_prf(simck, 40, "Extended Session Key Generating Function", 964*5b9c547cSRui Paulo (u8 *) "", 0, buf, sizeof(msk)) < 0 || 965*5b9c547cSRui Paulo os_memcmp(emsk, buf, sizeof(emsk)) != 0) { 966*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "T-PRF test - FAILED!"); 967*5b9c547cSRui Paulo errors++; 968*5b9c547cSRui Paulo } 969*5b9c547cSRui Paulo 970*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "- Compound MAC test case"); 971*5b9c547cSRui Paulo os_memset(tlv + sizeof(tlv) - 20, 0, 20); 972*5b9c547cSRui Paulo if (hmac_sha1(cmk, 20, tlv, sizeof(tlv), tlv + sizeof(tlv) - 20) < 0 || 973*5b9c547cSRui Paulo os_memcmp(tlv + sizeof(tlv) - 20, compound_mac, 974*5b9c547cSRui Paulo sizeof(compound_mac)) != 0) { 975*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Compound MAC test - FAILED!"); 976*5b9c547cSRui Paulo errors++; 977*5b9c547cSRui Paulo } 978*5b9c547cSRui Paulo 979*5b9c547cSRui Paulo return errors; 980*5b9c547cSRui Paulo #else /* EAP_FAST */ 981*5b9c547cSRui Paulo return 0; 982*5b9c547cSRui Paulo #endif /* EAP_FAST */ 983*5b9c547cSRui Paulo } 984*5b9c547cSRui Paulo 985*5b9c547cSRui Paulo 986*5b9c547cSRui Paulo static u8 key0[] = 987*5b9c547cSRui Paulo { 988*5b9c547cSRui Paulo 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 989*5b9c547cSRui Paulo 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 990*5b9c547cSRui Paulo 0x0b, 0x0b, 0x0b, 0x0b 991*5b9c547cSRui Paulo }; 992*5b9c547cSRui Paulo static u8 data0[] = "Hi There"; 993*5b9c547cSRui Paulo static u8 prf0[] = 994*5b9c547cSRui Paulo { 995*5b9c547cSRui Paulo 0xbc, 0xd4, 0xc6, 0x50, 0xb3, 0x0b, 0x96, 0x84, 996*5b9c547cSRui Paulo 0x95, 0x18, 0x29, 0xe0, 0xd7, 0x5f, 0x9d, 0x54, 997*5b9c547cSRui Paulo 0xb8, 0x62, 0x17, 0x5e, 0xd9, 0xf0, 0x06, 0x06, 998*5b9c547cSRui Paulo 0xe1, 0x7d, 0x8d, 0xa3, 0x54, 0x02, 0xff, 0xee, 999*5b9c547cSRui Paulo 0x75, 0xdf, 0x78, 0xc3, 0xd3, 0x1e, 0x0f, 0x88, 1000*5b9c547cSRui Paulo 0x9f, 0x01, 0x21, 0x20, 0xc0, 0x86, 0x2b, 0xeb, 1001*5b9c547cSRui Paulo 0x67, 0x75, 0x3e, 0x74, 0x39, 0xae, 0x24, 0x2e, 1002*5b9c547cSRui Paulo 0xdb, 0x83, 0x73, 0x69, 0x83, 0x56, 0xcf, 0x5a 1003*5b9c547cSRui Paulo }; 1004*5b9c547cSRui Paulo 1005*5b9c547cSRui Paulo static u8 key1[] = "Jefe"; 1006*5b9c547cSRui Paulo static u8 data1[] = "what do ya want for nothing?"; 1007*5b9c547cSRui Paulo static u8 prf1[] = 1008*5b9c547cSRui Paulo { 1009*5b9c547cSRui Paulo 0x51, 0xf4, 0xde, 0x5b, 0x33, 0xf2, 0x49, 0xad, 1010*5b9c547cSRui Paulo 0xf8, 0x1a, 0xeb, 0x71, 0x3a, 0x3c, 0x20, 0xf4, 1011*5b9c547cSRui Paulo 0xfe, 0x63, 0x14, 0x46, 0xfa, 0xbd, 0xfa, 0x58, 1012*5b9c547cSRui Paulo 0x24, 0x47, 0x59, 0xae, 0x58, 0xef, 0x90, 0x09, 1013*5b9c547cSRui Paulo 0xa9, 0x9a, 0xbf, 0x4e, 0xac, 0x2c, 0xa5, 0xfa, 1014*5b9c547cSRui Paulo 0x87, 0xe6, 0x92, 0xc4, 0x40, 0xeb, 0x40, 0x02, 1015*5b9c547cSRui Paulo 0x3e, 0x7b, 0xab, 0xb2, 0x06, 0xd6, 0x1d, 0xe7, 1016*5b9c547cSRui Paulo 0xb9, 0x2f, 0x41, 0x52, 0x90, 0x92, 0xb8, 0xfc 1017*5b9c547cSRui Paulo }; 1018*5b9c547cSRui Paulo 1019*5b9c547cSRui Paulo 1020*5b9c547cSRui Paulo static u8 key2[] = 1021*5b9c547cSRui Paulo { 1022*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1023*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1024*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa 1025*5b9c547cSRui Paulo }; 1026*5b9c547cSRui Paulo static u8 data2[] = 1027*5b9c547cSRui Paulo { 1028*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1029*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1030*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1031*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1032*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1033*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1034*5b9c547cSRui Paulo 0xdd, 0xdd 1035*5b9c547cSRui Paulo }; 1036*5b9c547cSRui Paulo static u8 prf2[] = 1037*5b9c547cSRui Paulo { 1038*5b9c547cSRui Paulo 0xe1, 0xac, 0x54, 0x6e, 0xc4, 0xcb, 0x63, 0x6f, 1039*5b9c547cSRui Paulo 0x99, 0x76, 0x48, 0x7b, 0xe5, 0xc8, 0x6b, 0xe1, 1040*5b9c547cSRui Paulo 0x7a, 0x02, 0x52, 0xca, 0x5d, 0x8d, 0x8d, 0xf1, 1041*5b9c547cSRui Paulo 0x2c, 0xfb, 0x04, 0x73, 0x52, 0x52, 0x49, 0xce, 1042*5b9c547cSRui Paulo 0x9d, 0xd8, 0xd1, 0x77, 0xea, 0xd7, 0x10, 0xbc, 1043*5b9c547cSRui Paulo 0x9b, 0x59, 0x05, 0x47, 0x23, 0x91, 0x07, 0xae, 1044*5b9c547cSRui Paulo 0xf7, 0xb4, 0xab, 0xd4, 0x3d, 0x87, 0xf0, 0xa6, 1045*5b9c547cSRui Paulo 0x8f, 0x1c, 0xbd, 0x9e, 0x2b, 0x6f, 0x76, 0x07 1046*5b9c547cSRui Paulo }; 1047*5b9c547cSRui Paulo 1048*5b9c547cSRui Paulo 1049*5b9c547cSRui Paulo struct passphrase_test { 1050*5b9c547cSRui Paulo char *passphrase; 1051*5b9c547cSRui Paulo char *ssid; 1052*5b9c547cSRui Paulo char psk[32]; 1053*5b9c547cSRui Paulo }; 1054*5b9c547cSRui Paulo 1055*5b9c547cSRui Paulo static struct passphrase_test passphrase_tests[] = 1056*5b9c547cSRui Paulo { 1057*5b9c547cSRui Paulo { 1058*5b9c547cSRui Paulo "password", 1059*5b9c547cSRui Paulo "IEEE", 1060*5b9c547cSRui Paulo { 1061*5b9c547cSRui Paulo 0xf4, 0x2c, 0x6f, 0xc5, 0x2d, 0xf0, 0xeb, 0xef, 1062*5b9c547cSRui Paulo 0x9e, 0xbb, 0x4b, 0x90, 0xb3, 0x8a, 0x5f, 0x90, 1063*5b9c547cSRui Paulo 0x2e, 0x83, 0xfe, 0x1b, 0x13, 0x5a, 0x70, 0xe2, 1064*5b9c547cSRui Paulo 0x3a, 0xed, 0x76, 0x2e, 0x97, 0x10, 0xa1, 0x2e 1065*5b9c547cSRui Paulo } 1066*5b9c547cSRui Paulo }, 1067*5b9c547cSRui Paulo { 1068*5b9c547cSRui Paulo "ThisIsAPassword", 1069*5b9c547cSRui Paulo "ThisIsASSID", 1070*5b9c547cSRui Paulo { 1071*5b9c547cSRui Paulo 0x0d, 0xc0, 0xd6, 0xeb, 0x90, 0x55, 0x5e, 0xd6, 1072*5b9c547cSRui Paulo 0x41, 0x97, 0x56, 0xb9, 0xa1, 0x5e, 0xc3, 0xe3, 1073*5b9c547cSRui Paulo 0x20, 0x9b, 0x63, 0xdf, 0x70, 0x7d, 0xd5, 0x08, 1074*5b9c547cSRui Paulo 0xd1, 0x45, 0x81, 0xf8, 0x98, 0x27, 0x21, 0xaf 1075*5b9c547cSRui Paulo } 1076*5b9c547cSRui Paulo }, 1077*5b9c547cSRui Paulo { 1078*5b9c547cSRui Paulo "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 1079*5b9c547cSRui Paulo "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ", 1080*5b9c547cSRui Paulo { 1081*5b9c547cSRui Paulo 0xbe, 0xcb, 0x93, 0x86, 0x6b, 0xb8, 0xc3, 0x83, 1082*5b9c547cSRui Paulo 0x2c, 0xb7, 0x77, 0xc2, 0xf5, 0x59, 0x80, 0x7c, 1083*5b9c547cSRui Paulo 0x8c, 0x59, 0xaf, 0xcb, 0x6e, 0xae, 0x73, 0x48, 1084*5b9c547cSRui Paulo 0x85, 0x00, 0x13, 0x00, 0xa9, 0x81, 0xcc, 0x62 1085*5b9c547cSRui Paulo } 1086*5b9c547cSRui Paulo }, 1087*5b9c547cSRui Paulo }; 1088*5b9c547cSRui Paulo 1089*5b9c547cSRui Paulo #define NUM_PASSPHRASE_TESTS ARRAY_SIZE(passphrase_tests) 1090*5b9c547cSRui Paulo 1091*5b9c547cSRui Paulo 1092*5b9c547cSRui Paulo struct rfc6070_test { 1093*5b9c547cSRui Paulo char *p; 1094*5b9c547cSRui Paulo char *s; 1095*5b9c547cSRui Paulo int c; 1096*5b9c547cSRui Paulo char dk[32]; 1097*5b9c547cSRui Paulo size_t dk_len; 1098*5b9c547cSRui Paulo }; 1099*5b9c547cSRui Paulo 1100*5b9c547cSRui Paulo static struct rfc6070_test rfc6070_tests[] = 1101*5b9c547cSRui Paulo { 1102*5b9c547cSRui Paulo { 1103*5b9c547cSRui Paulo "password", 1104*5b9c547cSRui Paulo "salt", 1105*5b9c547cSRui Paulo 1, 1106*5b9c547cSRui Paulo { 1107*5b9c547cSRui Paulo 0x0c, 0x60, 0xc8, 0x0f, 0x96, 0x1f, 0x0e, 0x71, 1108*5b9c547cSRui Paulo 0xf3, 0xa9, 0xb5, 0x24, 0xaf, 0x60, 0x12, 0x06, 1109*5b9c547cSRui Paulo 0x2f, 0xe0, 0x37, 0xa6 1110*5b9c547cSRui Paulo }, 1111*5b9c547cSRui Paulo 20 1112*5b9c547cSRui Paulo }, 1113*5b9c547cSRui Paulo { 1114*5b9c547cSRui Paulo "password", 1115*5b9c547cSRui Paulo "salt", 1116*5b9c547cSRui Paulo 2, 1117*5b9c547cSRui Paulo { 1118*5b9c547cSRui Paulo 0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 1119*5b9c547cSRui Paulo 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0, 1120*5b9c547cSRui Paulo 0xd8, 0xde, 0x89, 0x57 1121*5b9c547cSRui Paulo }, 1122*5b9c547cSRui Paulo 20 1123*5b9c547cSRui Paulo }, 1124*5b9c547cSRui Paulo { 1125*5b9c547cSRui Paulo "password", 1126*5b9c547cSRui Paulo "salt", 1127*5b9c547cSRui Paulo 4096, 1128*5b9c547cSRui Paulo { 1129*5b9c547cSRui Paulo 0x4b, 0x00, 0x79, 0x01, 0xb7, 0x65, 0x48, 0x9a, 1130*5b9c547cSRui Paulo 0xbe, 0xad, 0x49, 0xd9, 0x26, 0xf7, 0x21, 0xd0, 1131*5b9c547cSRui Paulo 0x65, 0xa4, 0x29, 0xc1 1132*5b9c547cSRui Paulo }, 1133*5b9c547cSRui Paulo 20 1134*5b9c547cSRui Paulo }, 1135*5b9c547cSRui Paulo #if 0 /* This takes quite long to derive.. */ 1136*5b9c547cSRui Paulo { 1137*5b9c547cSRui Paulo "password", 1138*5b9c547cSRui Paulo "salt", 1139*5b9c547cSRui Paulo 16777216, 1140*5b9c547cSRui Paulo { 1141*5b9c547cSRui Paulo 0xee, 0xfe, 0x3d, 0x61, 0xcd, 0x4d, 0xa4, 0xe4, 1142*5b9c547cSRui Paulo 0xe9, 0x94, 0x5b, 0x3d, 0x6b, 0xa2, 0x15, 0x8c, 1143*5b9c547cSRui Paulo 0x26, 0x34, 0xe9, 0x84 1144*5b9c547cSRui Paulo }, 1145*5b9c547cSRui Paulo 20 1146*5b9c547cSRui Paulo }, 1147*5b9c547cSRui Paulo #endif 1148*5b9c547cSRui Paulo { 1149*5b9c547cSRui Paulo "passwordPASSWORDpassword", 1150*5b9c547cSRui Paulo "saltSALTsaltSALTsaltSALTsaltSALTsalt", 1151*5b9c547cSRui Paulo 4096, 1152*5b9c547cSRui Paulo { 1153*5b9c547cSRui Paulo 0x3d, 0x2e, 0xec, 0x4f, 0xe4, 0x1c, 0x84, 0x9b, 1154*5b9c547cSRui Paulo 0x80, 0xc8, 0xd8, 0x36, 0x62, 0xc0, 0xe4, 0x4a, 1155*5b9c547cSRui Paulo 0x8b, 0x29, 0x1a, 0x96, 0x4c, 0xf2, 0xf0, 0x70, 1156*5b9c547cSRui Paulo 0x38 1157*5b9c547cSRui Paulo }, 1158*5b9c547cSRui Paulo 25 1159*5b9c547cSRui Paulo }, 1160*5b9c547cSRui Paulo #if 0 /* \0 not currently supported in passphrase parameters.. */ 1161*5b9c547cSRui Paulo { 1162*5b9c547cSRui Paulo "pass\0word", 1163*5b9c547cSRui Paulo "sa\0lt", 1164*5b9c547cSRui Paulo 4096, 1165*5b9c547cSRui Paulo { 1166*5b9c547cSRui Paulo 0x56, 0xfa, 0x6a, 0xa7, 0x55, 0x48, 0x09, 0x9d, 1167*5b9c547cSRui Paulo 0xcc, 0x37, 0xd7, 0xf0, 0x34, 0x25, 0xe0, 0xc3 1168*5b9c547cSRui Paulo }, 1169*5b9c547cSRui Paulo 16 1170*5b9c547cSRui Paulo }, 1171*5b9c547cSRui Paulo #endif 1172*5b9c547cSRui Paulo }; 1173*5b9c547cSRui Paulo 1174*5b9c547cSRui Paulo #define NUM_RFC6070_TESTS ARRAY_SIZE(rfc6070_tests) 1175*5b9c547cSRui Paulo 1176*5b9c547cSRui Paulo 1177*5b9c547cSRui Paulo static int test_sha1(void) 1178*5b9c547cSRui Paulo { 1179*5b9c547cSRui Paulo u8 res[512]; 1180*5b9c547cSRui Paulo int ret = 0; 1181*5b9c547cSRui Paulo unsigned int i; 1182*5b9c547cSRui Paulo 1183*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "PRF-SHA1 test cases:"); 1184*5b9c547cSRui Paulo 1185*5b9c547cSRui Paulo if (sha1_prf(key0, sizeof(key0), "prefix", data0, sizeof(data0) - 1, 1186*5b9c547cSRui Paulo res, sizeof(prf0)) == 0 && 1187*5b9c547cSRui Paulo os_memcmp(res, prf0, sizeof(prf0)) == 0) 1188*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case 0 - OK"); 1189*5b9c547cSRui Paulo else { 1190*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case 0 - FAILED!"); 1191*5b9c547cSRui Paulo ret++; 1192*5b9c547cSRui Paulo } 1193*5b9c547cSRui Paulo 1194*5b9c547cSRui Paulo if (sha1_prf(key1, sizeof(key1) - 1, "prefix", data1, sizeof(data1) - 1, 1195*5b9c547cSRui Paulo res, sizeof(prf1)) == 0 && 1196*5b9c547cSRui Paulo os_memcmp(res, prf1, sizeof(prf1)) == 0) 1197*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case 1 - OK"); 1198*5b9c547cSRui Paulo else { 1199*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case 1 - FAILED!"); 1200*5b9c547cSRui Paulo ret++; 1201*5b9c547cSRui Paulo } 1202*5b9c547cSRui Paulo 1203*5b9c547cSRui Paulo if (sha1_prf(key2, sizeof(key2), "prefix", data2, sizeof(data2), 1204*5b9c547cSRui Paulo res, sizeof(prf2)) == 0 && 1205*5b9c547cSRui Paulo os_memcmp(res, prf2, sizeof(prf2)) == 0) 1206*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case 2 - OK"); 1207*5b9c547cSRui Paulo else { 1208*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case 2 - FAILED!"); 1209*5b9c547cSRui Paulo ret++; 1210*5b9c547cSRui Paulo } 1211*5b9c547cSRui Paulo 1212*5b9c547cSRui Paulo ret += test_eap_fast(); 1213*5b9c547cSRui Paulo 1214*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "PBKDF2-SHA1 Passphrase test cases:"); 1215*5b9c547cSRui Paulo for (i = 0; i < NUM_PASSPHRASE_TESTS; i++) { 1216*5b9c547cSRui Paulo u8 psk[32]; 1217*5b9c547cSRui Paulo struct passphrase_test *test = &passphrase_tests[i]; 1218*5b9c547cSRui Paulo 1219*5b9c547cSRui Paulo if (pbkdf2_sha1(test->passphrase, 1220*5b9c547cSRui Paulo (const u8 *) test->ssid, strlen(test->ssid), 1221*5b9c547cSRui Paulo 4096, psk, 32) == 0 && 1222*5b9c547cSRui Paulo os_memcmp(psk, test->psk, 32) == 0) 1223*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case %d - OK", i); 1224*5b9c547cSRui Paulo else { 1225*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case %d - FAILED!", i); 1226*5b9c547cSRui Paulo ret++; 1227*5b9c547cSRui Paulo } 1228*5b9c547cSRui Paulo } 1229*5b9c547cSRui Paulo 1230*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "PBKDF2-SHA1 test cases (RFC 6070):"); 1231*5b9c547cSRui Paulo for (i = 0; i < NUM_RFC6070_TESTS; i++) { 1232*5b9c547cSRui Paulo u8 dk[25]; 1233*5b9c547cSRui Paulo struct rfc6070_test *test = &rfc6070_tests[i]; 1234*5b9c547cSRui Paulo 1235*5b9c547cSRui Paulo if (pbkdf2_sha1(test->p, (const u8 *) test->s, strlen(test->s), 1236*5b9c547cSRui Paulo test->c, dk, test->dk_len) == 0 && 1237*5b9c547cSRui Paulo os_memcmp(dk, test->dk, test->dk_len) == 0) 1238*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case %d - OK", i); 1239*5b9c547cSRui Paulo else { 1240*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test case %d - FAILED!", i); 1241*5b9c547cSRui Paulo ret++; 1242*5b9c547cSRui Paulo } 1243*5b9c547cSRui Paulo } 1244*5b9c547cSRui Paulo 1245*5b9c547cSRui Paulo if (!ret) 1246*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "SHA1 test cases passed"); 1247*5b9c547cSRui Paulo return ret; 1248*5b9c547cSRui Paulo } 1249*5b9c547cSRui Paulo 1250*5b9c547cSRui Paulo 1251*5b9c547cSRui Paulo struct { 1252*5b9c547cSRui Paulo char *data; 1253*5b9c547cSRui Paulo u8 hash[32]; 1254*5b9c547cSRui Paulo } tests[] = { 1255*5b9c547cSRui Paulo { 1256*5b9c547cSRui Paulo "abc", 1257*5b9c547cSRui Paulo { 1258*5b9c547cSRui Paulo 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 1259*5b9c547cSRui Paulo 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, 1260*5b9c547cSRui Paulo 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 1261*5b9c547cSRui Paulo 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad 1262*5b9c547cSRui Paulo } 1263*5b9c547cSRui Paulo }, 1264*5b9c547cSRui Paulo { 1265*5b9c547cSRui Paulo "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1266*5b9c547cSRui Paulo { 1267*5b9c547cSRui Paulo 0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, 1268*5b9c547cSRui Paulo 0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39, 1269*5b9c547cSRui Paulo 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67, 1270*5b9c547cSRui Paulo 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1 1271*5b9c547cSRui Paulo } 1272*5b9c547cSRui Paulo } 1273*5b9c547cSRui Paulo }; 1274*5b9c547cSRui Paulo 1275*5b9c547cSRui Paulo struct hmac_test { 1276*5b9c547cSRui Paulo u8 key[80]; 1277*5b9c547cSRui Paulo size_t key_len; 1278*5b9c547cSRui Paulo u8 data[128]; 1279*5b9c547cSRui Paulo size_t data_len; 1280*5b9c547cSRui Paulo u8 hash[32]; 1281*5b9c547cSRui Paulo } hmac_tests[] = { 1282*5b9c547cSRui Paulo /* draft-ietf-ipsec-ciph-sha-256-01.txt */ 1283*5b9c547cSRui Paulo { 1284*5b9c547cSRui Paulo { 1285*5b9c547cSRui Paulo 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 1286*5b9c547cSRui Paulo 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 1287*5b9c547cSRui Paulo 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 1288*5b9c547cSRui Paulo 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 1289*5b9c547cSRui Paulo }, 1290*5b9c547cSRui Paulo 32, 1291*5b9c547cSRui Paulo "abc", 3, 1292*5b9c547cSRui Paulo { 1293*5b9c547cSRui Paulo 0xa2, 0x1b, 0x1f, 0x5d, 0x4c, 0xf4, 0xf7, 0x3a, 1294*5b9c547cSRui Paulo 0x4d, 0xd9, 0x39, 0x75, 0x0f, 0x7a, 0x06, 0x6a, 1295*5b9c547cSRui Paulo 0x7f, 0x98, 0xcc, 0x13, 0x1c, 0xb1, 0x6a, 0x66, 1296*5b9c547cSRui Paulo 0x92, 0x75, 0x90, 0x21, 0xcf, 0xab, 0x81, 0x81 1297*5b9c547cSRui Paulo } 1298*5b9c547cSRui Paulo }, 1299*5b9c547cSRui Paulo { 1300*5b9c547cSRui Paulo { 1301*5b9c547cSRui Paulo 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 1302*5b9c547cSRui Paulo 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 1303*5b9c547cSRui Paulo 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 1304*5b9c547cSRui Paulo 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 1305*5b9c547cSRui Paulo }, 1306*5b9c547cSRui Paulo 32, 1307*5b9c547cSRui Paulo "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1308*5b9c547cSRui Paulo 56, 1309*5b9c547cSRui Paulo { 1310*5b9c547cSRui Paulo 0x10, 0x4f, 0xdc, 0x12, 0x57, 0x32, 0x8f, 0x08, 1311*5b9c547cSRui Paulo 0x18, 0x4b, 0xa7, 0x31, 0x31, 0xc5, 0x3c, 0xae, 1312*5b9c547cSRui Paulo 0xe6, 0x98, 0xe3, 0x61, 0x19, 0x42, 0x11, 0x49, 1313*5b9c547cSRui Paulo 0xea, 0x8c, 0x71, 0x24, 0x56, 0x69, 0x7d, 0x30 1314*5b9c547cSRui Paulo } 1315*5b9c547cSRui Paulo }, 1316*5b9c547cSRui Paulo { 1317*5b9c547cSRui Paulo { 1318*5b9c547cSRui Paulo 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 1319*5b9c547cSRui Paulo 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 1320*5b9c547cSRui Paulo 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 1321*5b9c547cSRui Paulo 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20 1322*5b9c547cSRui Paulo }, 1323*5b9c547cSRui Paulo 32, 1324*5b9c547cSRui Paulo "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" 1325*5b9c547cSRui Paulo "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 1326*5b9c547cSRui Paulo 112, 1327*5b9c547cSRui Paulo { 1328*5b9c547cSRui Paulo 0x47, 0x03, 0x05, 0xfc, 0x7e, 0x40, 0xfe, 0x34, 1329*5b9c547cSRui Paulo 0xd3, 0xee, 0xb3, 0xe7, 0x73, 0xd9, 0x5a, 0xab, 1330*5b9c547cSRui Paulo 0x73, 0xac, 0xf0, 0xfd, 0x06, 0x04, 0x47, 0xa5, 1331*5b9c547cSRui Paulo 0xeb, 0x45, 0x95, 0xbf, 0x33, 0xa9, 0xd1, 0xa3 1332*5b9c547cSRui Paulo } 1333*5b9c547cSRui Paulo }, 1334*5b9c547cSRui Paulo { 1335*5b9c547cSRui Paulo { 1336*5b9c547cSRui Paulo 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 1337*5b9c547cSRui Paulo 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 1338*5b9c547cSRui Paulo 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 1339*5b9c547cSRui Paulo 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b 1340*5b9c547cSRui Paulo }, 1341*5b9c547cSRui Paulo 32, 1342*5b9c547cSRui Paulo "Hi There", 1343*5b9c547cSRui Paulo 8, 1344*5b9c547cSRui Paulo { 1345*5b9c547cSRui Paulo 0x19, 0x8a, 0x60, 0x7e, 0xb4, 0x4b, 0xfb, 0xc6, 1346*5b9c547cSRui Paulo 0x99, 0x03, 0xa0, 0xf1, 0xcf, 0x2b, 0xbd, 0xc5, 1347*5b9c547cSRui Paulo 0xba, 0x0a, 0xa3, 0xf3, 0xd9, 0xae, 0x3c, 0x1c, 1348*5b9c547cSRui Paulo 0x7a, 0x3b, 0x16, 0x96, 0xa0, 0xb6, 0x8c, 0xf7 1349*5b9c547cSRui Paulo } 1350*5b9c547cSRui Paulo }, 1351*5b9c547cSRui Paulo { 1352*5b9c547cSRui Paulo "Jefe", 1353*5b9c547cSRui Paulo 4, 1354*5b9c547cSRui Paulo "what do ya want for nothing?", 1355*5b9c547cSRui Paulo 28, 1356*5b9c547cSRui Paulo { 1357*5b9c547cSRui Paulo 0x5b, 0xdc, 0xc1, 0x46, 0xbf, 0x60, 0x75, 0x4e, 1358*5b9c547cSRui Paulo 0x6a, 0x04, 0x24, 0x26, 0x08, 0x95, 0x75, 0xc7, 1359*5b9c547cSRui Paulo 0x5a, 0x00, 0x3f, 0x08, 0x9d, 0x27, 0x39, 0x83, 1360*5b9c547cSRui Paulo 0x9d, 0xec, 0x58, 0xb9, 0x64, 0xec, 0x38, 0x43 1361*5b9c547cSRui Paulo } 1362*5b9c547cSRui Paulo }, 1363*5b9c547cSRui Paulo { 1364*5b9c547cSRui Paulo { 1365*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1366*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1367*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1368*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa 1369*5b9c547cSRui Paulo }, 1370*5b9c547cSRui Paulo 32, 1371*5b9c547cSRui Paulo { 1372*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1373*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1374*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1375*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1376*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1377*5b9c547cSRui Paulo 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 0xdd, 1378*5b9c547cSRui Paulo 0xdd, 0xdd 1379*5b9c547cSRui Paulo }, 1380*5b9c547cSRui Paulo 50, 1381*5b9c547cSRui Paulo { 1382*5b9c547cSRui Paulo 0xcd, 0xcb, 0x12, 0x20, 0xd1, 0xec, 0xcc, 0xea, 1383*5b9c547cSRui Paulo 0x91, 0xe5, 0x3a, 0xba, 0x30, 0x92, 0xf9, 0x62, 1384*5b9c547cSRui Paulo 0xe5, 0x49, 0xfe, 0x6c, 0xe9, 0xed, 0x7f, 0xdc, 1385*5b9c547cSRui Paulo 0x43, 0x19, 0x1f, 0xbd, 0xe4, 0x5c, 0x30, 0xb0 1386*5b9c547cSRui Paulo } 1387*5b9c547cSRui Paulo }, 1388*5b9c547cSRui Paulo { 1389*5b9c547cSRui Paulo { 1390*5b9c547cSRui Paulo 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 1391*5b9c547cSRui Paulo 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 1392*5b9c547cSRui Paulo 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 1393*5b9c547cSRui Paulo 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 1394*5b9c547cSRui Paulo 0x21, 0x22, 0x23, 0x24, 0x25 1395*5b9c547cSRui Paulo }, 1396*5b9c547cSRui Paulo 37, 1397*5b9c547cSRui Paulo { 1398*5b9c547cSRui Paulo 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 1399*5b9c547cSRui Paulo 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 1400*5b9c547cSRui Paulo 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 1401*5b9c547cSRui Paulo 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 1402*5b9c547cSRui Paulo 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 1403*5b9c547cSRui Paulo 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 0xcd, 1404*5b9c547cSRui Paulo 0xcd, 0xcd 1405*5b9c547cSRui Paulo }, 1406*5b9c547cSRui Paulo 50, 1407*5b9c547cSRui Paulo { 1408*5b9c547cSRui Paulo 0xd4, 0x63, 0x3c, 0x17, 0xf6, 0xfb, 0x8d, 0x74, 1409*5b9c547cSRui Paulo 0x4c, 0x66, 0xde, 0xe0, 0xf8, 0xf0, 0x74, 0x55, 1410*5b9c547cSRui Paulo 0x6e, 0xc4, 0xaf, 0x55, 0xef, 0x07, 0x99, 0x85, 1411*5b9c547cSRui Paulo 0x41, 0x46, 0x8e, 0xb4, 0x9b, 0xd2, 0xe9, 0x17 1412*5b9c547cSRui Paulo } 1413*5b9c547cSRui Paulo }, 1414*5b9c547cSRui Paulo { 1415*5b9c547cSRui Paulo { 1416*5b9c547cSRui Paulo 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 1417*5b9c547cSRui Paulo 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 1418*5b9c547cSRui Paulo 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 1419*5b9c547cSRui Paulo 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c, 0x0c 1420*5b9c547cSRui Paulo }, 1421*5b9c547cSRui Paulo 32, 1422*5b9c547cSRui Paulo "Test With Truncation", 1423*5b9c547cSRui Paulo 20, 1424*5b9c547cSRui Paulo { 1425*5b9c547cSRui Paulo 0x75, 0x46, 0xaf, 0x01, 0x84, 0x1f, 0xc0, 0x9b, 1426*5b9c547cSRui Paulo 0x1a, 0xb9, 0xc3, 0x74, 0x9a, 0x5f, 0x1c, 0x17, 1427*5b9c547cSRui Paulo 0xd4, 0xf5, 0x89, 0x66, 0x8a, 0x58, 0x7b, 0x27, 1428*5b9c547cSRui Paulo 0x00, 0xa9, 0xc9, 0x7c, 0x11, 0x93, 0xcf, 0x42 1429*5b9c547cSRui Paulo } 1430*5b9c547cSRui Paulo }, 1431*5b9c547cSRui Paulo { 1432*5b9c547cSRui Paulo { 1433*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1434*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1435*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1436*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1437*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1438*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1439*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1440*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1441*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1442*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa 1443*5b9c547cSRui Paulo }, 1444*5b9c547cSRui Paulo 80, 1445*5b9c547cSRui Paulo "Test Using Larger Than Block-Size Key - Hash Key First", 1446*5b9c547cSRui Paulo 54, 1447*5b9c547cSRui Paulo { 1448*5b9c547cSRui Paulo 0x69, 0x53, 0x02, 0x5e, 0xd9, 0x6f, 0x0c, 0x09, 1449*5b9c547cSRui Paulo 0xf8, 0x0a, 0x96, 0xf7, 0x8e, 0x65, 0x38, 0xdb, 1450*5b9c547cSRui Paulo 0xe2, 0xe7, 0xb8, 0x20, 0xe3, 0xdd, 0x97, 0x0e, 1451*5b9c547cSRui Paulo 0x7d, 0xdd, 0x39, 0x09, 0x1b, 0x32, 0x35, 0x2f 1452*5b9c547cSRui Paulo } 1453*5b9c547cSRui Paulo }, 1454*5b9c547cSRui Paulo { 1455*5b9c547cSRui Paulo { 1456*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1457*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1458*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1459*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1460*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1461*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1462*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1463*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1464*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 1465*5b9c547cSRui Paulo 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa 1466*5b9c547cSRui Paulo }, 1467*5b9c547cSRui Paulo 80, 1468*5b9c547cSRui Paulo "Test Using Larger Than Block-Size Key and Larger Than One " 1469*5b9c547cSRui Paulo "Block-Size Data", 1470*5b9c547cSRui Paulo 73, 1471*5b9c547cSRui Paulo { 1472*5b9c547cSRui Paulo 0x63, 0x55, 0xac, 0x22, 0xe8, 0x90, 0xd0, 0xa3, 1473*5b9c547cSRui Paulo 0xc8, 0x48, 0x1a, 0x5c, 0xa4, 0x82, 0x5b, 0xc8, 1474*5b9c547cSRui Paulo 0x84, 0xd3, 0xe7, 0xa1, 0xff, 0x98, 0xa2, 0xfc, 1475*5b9c547cSRui Paulo 0x2a, 0xc7, 0xd8, 0xe0, 0x64, 0xc3, 0xb2, 0xe6 1476*5b9c547cSRui Paulo } 1477*5b9c547cSRui Paulo } 1478*5b9c547cSRui Paulo }; 1479*5b9c547cSRui Paulo 1480*5b9c547cSRui Paulo 1481*5b9c547cSRui Paulo static int test_sha256(void) 1482*5b9c547cSRui Paulo { 1483*5b9c547cSRui Paulo unsigned int i; 1484*5b9c547cSRui Paulo u8 hash[32]; 1485*5b9c547cSRui Paulo const u8 *addr[2]; 1486*5b9c547cSRui Paulo size_t len[2]; 1487*5b9c547cSRui Paulo int errors = 0; 1488*5b9c547cSRui Paulo 1489*5b9c547cSRui Paulo for (i = 0; i < ARRAY_SIZE(tests); i++) { 1490*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "SHA256 test case %d:", i + 1); 1491*5b9c547cSRui Paulo 1492*5b9c547cSRui Paulo addr[0] = (u8 *) tests[i].data; 1493*5b9c547cSRui Paulo len[0] = strlen(tests[i].data); 1494*5b9c547cSRui Paulo sha256_vector(1, addr, len, hash); 1495*5b9c547cSRui Paulo if (memcmp(hash, tests[i].hash, 32) != 0) { 1496*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " FAIL"); 1497*5b9c547cSRui Paulo errors++; 1498*5b9c547cSRui Paulo } else 1499*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " OK"); 1500*5b9c547cSRui Paulo 1501*5b9c547cSRui Paulo if (len[0]) { 1502*5b9c547cSRui Paulo addr[0] = (u8 *) tests[i].data; 1503*5b9c547cSRui Paulo len[0] = 1; 1504*5b9c547cSRui Paulo addr[1] = (u8 *) tests[i].data + 1; 1505*5b9c547cSRui Paulo len[1] = strlen(tests[i].data) - 1; 1506*5b9c547cSRui Paulo sha256_vector(2, addr, len, hash); 1507*5b9c547cSRui Paulo if (memcmp(hash, tests[i].hash, 32) != 0) { 1508*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " FAIL"); 1509*5b9c547cSRui Paulo errors++; 1510*5b9c547cSRui Paulo } else 1511*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " OK"); 1512*5b9c547cSRui Paulo } 1513*5b9c547cSRui Paulo } 1514*5b9c547cSRui Paulo 1515*5b9c547cSRui Paulo for (i = 0; i < ARRAY_SIZE(hmac_tests); i++) { 1516*5b9c547cSRui Paulo struct hmac_test *t = &hmac_tests[i]; 1517*5b9c547cSRui Paulo 1518*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "HMAC-SHA256 test case %d:", i + 1); 1519*5b9c547cSRui Paulo 1520*5b9c547cSRui Paulo if (hmac_sha256(t->key, t->key_len, t->data, t->data_len, 1521*5b9c547cSRui Paulo hash) < 0 || 1522*5b9c547cSRui Paulo os_memcmp(hash, t->hash, 32) != 0) { 1523*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " FAIL"); 1524*5b9c547cSRui Paulo errors++; 1525*5b9c547cSRui Paulo } else 1526*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " OK"); 1527*5b9c547cSRui Paulo 1528*5b9c547cSRui Paulo addr[0] = t->data; 1529*5b9c547cSRui Paulo len[0] = t->data_len; 1530*5b9c547cSRui Paulo if (hmac_sha256_vector(t->key, t->key_len, 1, addr, len, 1531*5b9c547cSRui Paulo hash) < 0 || 1532*5b9c547cSRui Paulo os_memcmp(hash, t->hash, 32) != 0) { 1533*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " FAIL"); 1534*5b9c547cSRui Paulo errors++; 1535*5b9c547cSRui Paulo } else 1536*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " OK"); 1537*5b9c547cSRui Paulo 1538*5b9c547cSRui Paulo if (len[0]) { 1539*5b9c547cSRui Paulo addr[0] = t->data; 1540*5b9c547cSRui Paulo len[0] = 1; 1541*5b9c547cSRui Paulo addr[1] = t->data + 1; 1542*5b9c547cSRui Paulo len[1] = t->data_len - 1; 1543*5b9c547cSRui Paulo if (hmac_sha256_vector(t->key, t->key_len, 2, addr, len, 1544*5b9c547cSRui Paulo hash) < 0 || 1545*5b9c547cSRui Paulo os_memcmp(hash, t->hash, 32) != 0) { 1546*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " FAIL"); 1547*5b9c547cSRui Paulo errors++; 1548*5b9c547cSRui Paulo } else 1549*5b9c547cSRui Paulo wpa_printf(MSG_INFO, " OK"); 1550*5b9c547cSRui Paulo } 1551*5b9c547cSRui Paulo } 1552*5b9c547cSRui Paulo 1553*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "Test IEEE 802.11r KDF"); 1554*5b9c547cSRui Paulo sha256_prf((u8 *) "abc", 3, "KDF test", (u8 *) "data", 4, 1555*5b9c547cSRui Paulo hash, sizeof(hash)); 1556*5b9c547cSRui Paulo /* TODO: add proper test case for this */ 1557*5b9c547cSRui Paulo 1558*5b9c547cSRui Paulo if (!errors) 1559*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "SHA256 test cases passed"); 1560*5b9c547cSRui Paulo return errors; 1561*5b9c547cSRui Paulo } 1562*5b9c547cSRui Paulo 1563*5b9c547cSRui Paulo 1564*5b9c547cSRui Paulo static int test_ms_funcs(void) 1565*5b9c547cSRui Paulo { 1566*5b9c547cSRui Paulo /* Test vector from RFC2759 example */ 1567*5b9c547cSRui Paulo char *username = "User"; 1568*5b9c547cSRui Paulo char *password = "clientPass"; 1569*5b9c547cSRui Paulo u8 auth_challenge[] = { 1570*5b9c547cSRui Paulo 0x5B, 0x5D, 0x7C, 0x7D, 0x7B, 0x3F, 0x2F, 0x3E, 1571*5b9c547cSRui Paulo 0x3C, 0x2C, 0x60, 0x21, 0x32, 0x26, 0x26, 0x28 1572*5b9c547cSRui Paulo }; 1573*5b9c547cSRui Paulo u8 peer_challenge[] = { 1574*5b9c547cSRui Paulo 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E, 0x26, 0x2A, 1575*5b9c547cSRui Paulo 0x28, 0x29, 0x5F, 0x2B, 0x3A, 0x33, 0x7C, 0x7E 1576*5b9c547cSRui Paulo }; 1577*5b9c547cSRui Paulo u8 password_hash[] = { 1578*5b9c547cSRui Paulo 0x44, 0xEB, 0xBA, 0x8D, 0x53, 0x12, 0xB8, 0xD6, 1579*5b9c547cSRui Paulo 0x11, 0x47, 0x44, 0x11, 0xF5, 0x69, 0x89, 0xAE 1580*5b9c547cSRui Paulo }; 1581*5b9c547cSRui Paulo u8 nt_response[] = { 1582*5b9c547cSRui Paulo 0x82, 0x30, 0x9E, 0xCD, 0x8D, 0x70, 0x8B, 0x5E, 1583*5b9c547cSRui Paulo 0xA0, 0x8F, 0xAA, 0x39, 0x81, 0xCD, 0x83, 0x54, 1584*5b9c547cSRui Paulo 0x42, 0x33, 0x11, 0x4A, 0x3D, 0x85, 0xD6, 0xDF 1585*5b9c547cSRui Paulo }; 1586*5b9c547cSRui Paulo u8 password_hash_hash[] = { 1587*5b9c547cSRui Paulo 0x41, 0xC0, 0x0C, 0x58, 0x4B, 0xD2, 0xD9, 0x1C, 1588*5b9c547cSRui Paulo 0x40, 0x17, 0xA2, 0xA1, 0x2F, 0xA5, 0x9F, 0x3F 1589*5b9c547cSRui Paulo }; 1590*5b9c547cSRui Paulo u8 authenticator_response[] = { 1591*5b9c547cSRui Paulo 0x40, 0x7A, 0x55, 0x89, 0x11, 0x5F, 0xD0, 0xD6, 1592*5b9c547cSRui Paulo 0x20, 0x9F, 0x51, 0x0F, 0xE9, 0xC0, 0x45, 0x66, 1593*5b9c547cSRui Paulo 0x93, 0x2C, 0xDA, 0x56 1594*5b9c547cSRui Paulo }; 1595*5b9c547cSRui Paulo u8 master_key[] = { 1596*5b9c547cSRui Paulo 0xFD, 0xEC, 0xE3, 0x71, 0x7A, 0x8C, 0x83, 0x8C, 1597*5b9c547cSRui Paulo 0xB3, 0x88, 0xE5, 0x27, 0xAE, 0x3C, 0xDD, 0x31 1598*5b9c547cSRui Paulo }; 1599*5b9c547cSRui Paulo u8 send_start_key[] = { 1600*5b9c547cSRui Paulo 0x8B, 0x7C, 0xDC, 0x14, 0x9B, 0x99, 0x3A, 0x1B, 1601*5b9c547cSRui Paulo 0xA1, 0x18, 0xCB, 0x15, 0x3F, 0x56, 0xDC, 0xCB 1602*5b9c547cSRui Paulo }; 1603*5b9c547cSRui Paulo u8 buf[32]; 1604*5b9c547cSRui Paulo int errors = 0; 1605*5b9c547cSRui Paulo 1606*5b9c547cSRui Paulo if (nt_password_hash((u8 *) password, os_strlen(password), buf) || 1607*5b9c547cSRui Paulo os_memcmp(password_hash, buf, sizeof(password_hash)) != 0) { 1608*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "nt_password_hash failed"); 1609*5b9c547cSRui Paulo errors++; 1610*5b9c547cSRui Paulo } 1611*5b9c547cSRui Paulo 1612*5b9c547cSRui Paulo if (generate_nt_response(auth_challenge, peer_challenge, 1613*5b9c547cSRui Paulo (u8 *) username, os_strlen(username), 1614*5b9c547cSRui Paulo (u8 *) password, os_strlen(password), buf) || 1615*5b9c547cSRui Paulo os_memcmp(nt_response, buf, sizeof(nt_response)) != 0) { 1616*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "generate_nt_response failed"); 1617*5b9c547cSRui Paulo errors++; 1618*5b9c547cSRui Paulo } 1619*5b9c547cSRui Paulo 1620*5b9c547cSRui Paulo if (hash_nt_password_hash(password_hash, buf) || 1621*5b9c547cSRui Paulo os_memcmp(password_hash_hash, buf, 1622*5b9c547cSRui Paulo sizeof(password_hash_hash)) != 0) { 1623*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "hash_nt_password_hash failed"); 1624*5b9c547cSRui Paulo errors++; 1625*5b9c547cSRui Paulo } 1626*5b9c547cSRui Paulo 1627*5b9c547cSRui Paulo if (generate_authenticator_response((u8 *) password, 1628*5b9c547cSRui Paulo os_strlen(password), 1629*5b9c547cSRui Paulo peer_challenge, auth_challenge, 1630*5b9c547cSRui Paulo (u8 *) username, 1631*5b9c547cSRui Paulo os_strlen(username), 1632*5b9c547cSRui Paulo nt_response, buf) || 1633*5b9c547cSRui Paulo os_memcmp(authenticator_response, buf, 1634*5b9c547cSRui Paulo sizeof(authenticator_response)) != 0) { 1635*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "generate_authenticator_response failed"); 1636*5b9c547cSRui Paulo errors++; 1637*5b9c547cSRui Paulo } 1638*5b9c547cSRui Paulo 1639*5b9c547cSRui Paulo if (get_master_key(password_hash_hash, nt_response, buf) || 1640*5b9c547cSRui Paulo os_memcmp(master_key, buf, sizeof(master_key)) != 0) { 1641*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "get_master_key failed"); 1642*5b9c547cSRui Paulo errors++; 1643*5b9c547cSRui Paulo } 1644*5b9c547cSRui Paulo 1645*5b9c547cSRui Paulo if (get_asymetric_start_key(master_key, buf, sizeof(send_start_key), 1646*5b9c547cSRui Paulo 1, 1) || 1647*5b9c547cSRui Paulo os_memcmp(send_start_key, buf, sizeof(send_start_key)) != 0) { 1648*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "get_asymetric_start_key failed"); 1649*5b9c547cSRui Paulo errors++; 1650*5b9c547cSRui Paulo } 1651*5b9c547cSRui Paulo 1652*5b9c547cSRui Paulo if (errors) 1653*5b9c547cSRui Paulo wpa_printf(MSG_ERROR, "ms_funcs: %d errors", errors); 1654*5b9c547cSRui Paulo else 1655*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "ms_funcs test cases passed"); 1656*5b9c547cSRui Paulo 1657*5b9c547cSRui Paulo return errors; 1658*5b9c547cSRui Paulo } 1659*5b9c547cSRui Paulo 1660*5b9c547cSRui Paulo 1661*5b9c547cSRui Paulo int crypto_module_tests(void) 1662*5b9c547cSRui Paulo { 1663*5b9c547cSRui Paulo int ret = 0; 1664*5b9c547cSRui Paulo 1665*5b9c547cSRui Paulo wpa_printf(MSG_INFO, "crypto module tests"); 1666*5b9c547cSRui Paulo if (test_siv() || 1667*5b9c547cSRui Paulo test_omac1() || 1668*5b9c547cSRui Paulo test_eax() || 1669*5b9c547cSRui Paulo test_cbc() || 1670*5b9c547cSRui Paulo test_ecb() || 1671*5b9c547cSRui Paulo test_key_wrap() || 1672*5b9c547cSRui Paulo test_md5() || 1673*5b9c547cSRui Paulo test_sha1() || 1674*5b9c547cSRui Paulo test_sha256() || 1675*5b9c547cSRui Paulo test_ms_funcs()) 1676*5b9c547cSRui Paulo ret = -1; 1677*5b9c547cSRui Paulo 1678*5b9c547cSRui Paulo return ret; 1679*5b9c547cSRui Paulo } 1680