]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Move AES-128 EAX mode test cases into hwsim framework
authorJouni Malinen <j@w1.fi>
Mon, 5 Jan 2015 14:24:22 +0000 (16:24 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 5 Jan 2015 14:24:42 +0000 (16:24 +0200)
Signed-off-by: Jouni Malinen <j@w1.fi>
src/crypto/crypto_module_tests.c
tests/test-aes.c

index 0c6a171e52effe30160a2375e39d1a360977cc27..c65ec6e3705a2141d65611726da690bba73a8c3f 100644 (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;
index 4dd396273eec84e3a9e20b2a989369fd73c9d581..bc4e8a2f4aa085ec1fb6983ad031bf893ff1e7b0 100644 (file)
@@ -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();