tests: Move AES-128 EAX mode test cases into hwsim framework

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2015-01-05 16:24:22 +02:00
parent 6c33962dd1
commit e438fb0d3a
2 changed files with 51 additions and 47 deletions

View file

@ -286,13 +286,63 @@ static int test_omac1(void)
}
static int test_eax(void)
{
#ifdef EAP_PSK
u8 msg[] = { 0xF7, 0xFB };
u8 key[] = { 0x91, 0x94, 0x5D, 0x3F, 0x4D, 0xCB, 0xEE, 0x0B,
0xF4, 0x5E, 0xF5, 0x22, 0x55, 0xF0, 0x95, 0xA4 };
u8 nonce[] = { 0xBE, 0xCA, 0xF0, 0x43, 0xB0, 0xA2, 0x3D, 0x84,
0x31, 0x94, 0xBA, 0x97, 0x2C, 0x66, 0xDE, 0xBD };
u8 hdr[] = { 0xFA, 0x3B, 0xFD, 0x48, 0x06, 0xEB, 0x53, 0xFA };
u8 cipher[] = { 0x19, 0xDD, 0x5C, 0x4C, 0x93, 0x31, 0x04, 0x9D,
0x0B, 0xDA, 0xB0, 0x27, 0x74, 0x08, 0xF6, 0x79,
0x67, 0xE5 };
u8 data[sizeof(msg)], tag[AES_BLOCK_SIZE];
os_memcpy(data, msg, sizeof(msg));
if (aes_128_eax_encrypt(key, nonce, sizeof(nonce), hdr, sizeof(hdr),
data, sizeof(data), tag)) {
wpa_printf(MSG_ERROR, "AES-128 EAX mode encryption failed");
return 1;
}
if (os_memcmp(data, cipher, sizeof(data)) != 0) {
wpa_printf(MSG_ERROR,
"AES-128 EAX mode encryption returned invalid cipher text");
return 1;
}
if (os_memcmp(tag, cipher + sizeof(data), AES_BLOCK_SIZE) != 0) {
wpa_printf(MSG_ERROR,
"AES-128 EAX mode encryption returned invalid tag");
return 1;
}
if (aes_128_eax_decrypt(key, nonce, sizeof(nonce), hdr, sizeof(hdr),
data, sizeof(data), tag)) {
wpa_printf(MSG_ERROR, "AES-128 EAX mode decryption failed");
return 1;
}
if (os_memcmp(data, msg, sizeof(data)) != 0) {
wpa_printf(MSG_ERROR,
"AES-128 EAX mode decryption returned invalid plain text");
return 1;
}
wpa_printf(MSG_INFO, "AES-128 EAX mode test cases passed");
#endif /* EAP_PSK */
return 0;
}
int crypto_module_tests(void)
{
int ret = 0;
wpa_printf(MSG_INFO, "crypto module tests");
if (test_siv() ||
test_omac1())
test_omac1() ||
test_eax())
ret = -1;
return ret;