From e438fb0d3a99427ecbdbbf9f9173fabdc0b2411a Mon Sep 17 00:00:00 2001 From: Jouni Malinen Date: Mon, 5 Jan 2015 16:24:22 +0200 Subject: [PATCH] tests: Move AES-128 EAX mode test cases into hwsim framework Signed-off-by: Jouni Malinen --- src/crypto/crypto_module_tests.c | 52 +++++++++++++++++++++++++++++++- tests/test-aes.c | 46 ---------------------------- 2 files changed, 51 insertions(+), 47 deletions(-) diff --git a/src/crypto/crypto_module_tests.c b/src/crypto/crypto_module_tests.c index 0c6a171e5..c65ec6e37 100644 --- a/src/crypto/crypto_module_tests.c +++ b/src/crypto/crypto_module_tests.c @@ -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; diff --git a/tests/test-aes.c b/tests/test-aes.c index 4dd396273..bc4e8a2f4 100644 --- a/tests/test-aes.c +++ b/tests/test-aes.c @@ -51,50 +51,6 @@ static void test_aes_perf(void) } -static int test_eax(void) -{ - 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[BLOCK_SIZE]; - - memcpy(data, msg, sizeof(msg)); - if (aes_128_eax_encrypt(key, nonce, sizeof(nonce), hdr, sizeof(hdr), - data, sizeof(data), tag)) { - printf("AES-128 EAX mode encryption failed\n"); - return 1; - } - if (memcmp(data, cipher, sizeof(data)) != 0) { - printf("AES-128 EAX mode encryption returned invalid cipher " - "text\n"); - return 1; - } - if (memcmp(tag, cipher + sizeof(data), BLOCK_SIZE) != 0) { - printf("AES-128 EAX mode encryption returned invalid tag\n"); - return 1; - } - - if (aes_128_eax_decrypt(key, nonce, sizeof(nonce), hdr, sizeof(hdr), - data, sizeof(data), tag)) { - printf("AES-128 EAX mode decryption failed\n"); - return 1; - } - if (memcmp(data, msg, sizeof(data)) != 0) { - printf("AES-128 EAX mode decryption returned invalid plain " - "text\n"); - return 1; - } - - return 0; -} - - static int test_cbc(void) { struct cbc_test_vector { @@ -978,8 +934,6 @@ int main(int argc, char *argv[]) test_aes_perf(); - ret += test_eax(); - ret += test_cbc(); ret += test_gcm();