- md5 hmac test
authorMartin Willi <martin@strongswan.org>
Tue, 22 Nov 2005 15:53:54 +0000 (15:53 -0000)
committerMartin Willi <martin@strongswan.org>
Tue, 22 Nov 2005 15:53:54 +0000 (15:53 -0000)
Source/charon/testcases/hmac_test.c
Source/charon/testcases/hmac_test.h
Source/charon/testcases/prf_plus_test.c
Source/charon/testcases/testcases.c

index bb9cce0..3dc36f5 100644 (file)
@@ -217,3 +217,191 @@ void test_hmac_sha1(tester_t *tester)
        tester->assert_true(tester, digest[3].len == 20, "chunk len append mode");
        tester->assert_false(tester, memcmp(digest[3].ptr, reference[3].ptr, 20), "hmac value append mode");
 }
+
+/* 
+ * described in Header-File
+ */
+void test_hmac_md5(tester_t *tester)
+{
+       /*
+        * Test cases from RFC2202
+        * 
+        * test_case =     1
+        * key =           0x0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b
+        * key_len =       16
+        * data =          "Hi There"
+        * data_len =      8
+        * digest =        0x9294727a3638bb1c13f48ef8158bfc9d
+        * 
+        * test_case =     2
+        * key =           "Jefe"
+        * key_len =       4
+        * data =          "what do ya want for nothing?"
+        * data_len =      28
+        * digest =        0x750c783e6ab0b503eaa86e310a5db738
+        * 
+        * test_case =     3
+        * key =           0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+        * key_len         16
+        * data =          0xdd repeated 50 times
+        * data_len =      50
+        * digest =        0x56be34521d144c88dbb8c733f0e8b3f6
+        * 
+        * test_case =     4
+        * key =           0x0102030405060708090a0b0c0d0e0f10111213141516171819
+        * key_len         25
+        * data =          0xcd repeated 50 times
+        * data_len =      50
+        * digest =        0x697eaf0aca3a3aea3a75164746ffaa79
+        * 
+        * test_case =     5
+        * key =           0x0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c
+        * key_len =       16
+        * data =          "Test With Truncation"
+        * data_len =      20
+        * digest =        0x56461ef2342edc00f9bab995690efd4c
+        * digest-96       0x56461ef2342edc00f9bab995
+        * 
+        * test_case =     6
+        * key =           0xaa repeated 80 times
+        * key_len =       80
+        * data =          "Test Using Larger Than Block-Size Key - Hash Key First"
+        * data_len =      54
+        * digest =        0x6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd
+        * 
+        * test_case =     7
+        * key =           0xaa repeated 80 times
+        * key_len =       80
+        * data =          "Test Using Larger Than Block-Size Key and Larger
+        *                 Than One Block-Size Data"
+        * data_len =      73
+        * digest =        0x6f630fad67cda0ee1fb1f562db3aa53e
+        *       
+        * 
+        *  
+        * currently performing test 1, 2, 4 and 7
+        *       
+        */
+       chunk_t keys[4];
+       chunk_t data[4];
+       chunk_t digest[4];
+       chunk_t reference[4];
+       int i;
+       
+       /*
+        * values for test 1
+        */
+       u_int8_t key1[] = {
+               0x0b,0x0b,0x0b,0x0b,
+               0x0b,0x0b,0x0b,0x0b,
+               0x0b,0x0b,0x0b,0x0b,
+               0x0b,0x0b,0x0b,0x0b,
+       };
+       keys[0].ptr = key1;
+       keys[0].len = sizeof(key1);
+       data[0].ptr = "Hi There";
+       data[0].len = 8; 
+       u_int8_t reference1[] = {
+               0x92,0x94,0x72,0x7a,
+               0x36,0x38,0xbb,0x1c,
+               0x13,0xf4,0x8e,0xf8,
+               0x15,0x8b,0xfc,0x9d
+       };
+       reference[0].ptr = reference1;
+       reference[0].len = sizeof(reference1);
+       
+       /*
+        * values for test 2
+        */
+       u_int8_t reference2[] = {
+               0x75,0x0c,0x78,0x3e,
+               0x6a,0xb0,0xb5,0x03,
+               0xea,0xa8,0x6e,0x31,
+               0x0a,0x5d,0xb7,0x38
+       };
+       keys[1].ptr = "Jefe";
+       keys[1].len = 4;
+       data[1].ptr = "what do ya want for nothing?";
+       data[1].len = 28; 
+       reference[1].ptr = reference2;
+       reference[1].len = sizeof(reference2);     
+       
+       /*
+        * values for test 7
+        */
+       u_int8_t key7[] = {
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+               0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
+       };
+       u_int8_t reference7[] = {
+               0x6f,0x63,0x0f,0xad,
+               0x67,0xcd,0xa0,0xee,
+               0x1f,0xb1,0xf5,0x62,
+               0xdb,0x3a,0xa5,0x3e
+       };
+       keys[2].ptr = key7;
+       keys[2].len = sizeof(key7);
+       data[2].ptr = "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data";
+       data[2].len = 73; 
+       reference[2].ptr = reference7;
+       reference[2].len = sizeof(reference7);
+       
+       
+       for (i=0; i<3; i++)
+       {
+               hmac_t *hmac = hmac_create(HASH_MD5);
+               hmac->set_key(hmac, keys[i]);
+               hmac->allocate_mac(hmac, data[i], &digest[i]);
+               hmac->destroy(hmac);
+               tester->assert_true(tester, digest[i].len == 16, "chunk len");
+               tester->assert_false(tester, memcmp(digest[i].ptr, reference[i].ptr, 16), "hmac value");
+               allocator_free(digest[i].ptr);
+       }
+       
+       /*
+        * test 4 is donne in append mode
+        */     
+       u_int8_t val = 0xcd;
+
+       u_int8_t key4[] = {
+               0x01,0x02,0x03,0x04,
+               0x05,0x06,0x07,0x08,
+               0x09,0x0a,0x0b,0x0c,
+               0x0d,0x0e,0x0f,0x10,
+               0x11,0x12,0x13,0x14,
+               0x15,0x16,0x17,0x18,
+               0x19
+       };
+       keys[3].ptr = key4;
+       keys[3].len = sizeof(key4);
+       u_int8_t reference4[] = {
+               0x69,0x7e,0xaf,0x0a,
+               0xca,0x3a,0x3a,0xea,
+               0x3a,0x75,0x16,0x47,
+               0x46,0xff,0xaa,0x79
+       };
+       reference[3].ptr = reference4;
+       reference[3].len = sizeof(reference4);
+       
+       hmac_t *hmac = hmac_create(HASH_MD5);
+       hmac->set_key(hmac, keys[3]);   
+       data[3].ptr = &val;
+       data[3].len = 1;
+       for (i=0; i<49; i++)
+       {       
+               hmac->get_mac(hmac, data[3], NULL);
+       }
+       hmac->allocate_mac(hmac, data[3], &digest[3]);
+       hmac->destroy(hmac);
+       
+       tester->assert_true(tester, digest[3].len == 16, "chunk len append mode");
+       tester->assert_false(tester, memcmp(digest[3].ptr, reference[3].ptr, 16), "hmac value append mode");
+}
index 6afddef..7907bd7 100644 (file)
  */
 void test_hmac_sha1(tester_t *tester);
 
+/**
+ * @brief Test function used to test the hmac functionality
+ * using md5.
+ *
+ * @param tester associated tester object
+ */
+void test_hmac_md5(tester_t *tester);
+
 #endif /*HMAC_TEST_H_*/
index ebdbbbe..eafdebf 100644 (file)
@@ -74,7 +74,7 @@ void test_prf_plus(tester_t *tester)
 
 void test_prf_plus_md5(tester_t *tester)
 {
-       /* md5 test data */
+       /* md5 test data 
        u_int8_t nonce[] = {
                0x58,0xCC,0x4C,0xA3,0x81,0x81,0xDA,0x7D,
                0x19,0xA6,0x9F,0xB1,0xE8,0xD3,0xE7,0x96,
@@ -142,5 +142,5 @@ void test_prf_plus_md5(tester_t *tester)
                0x57,0xC4,0xDE,0x65,
                0x10,0xEB,0xA7,0xB6,
                0x24,0x0D,0xEC,0xB4
-       };
+       };*/
 }
index b489a54..8fcda2f 100644 (file)
@@ -190,6 +190,7 @@ test_t hasher_md5_test = {test_hasher_md5,"MD5 hasher"};
  * Test for hmac
  */
 test_t hmac_test1 = {test_hmac_sha1, "HMAC using SHA1"};
+test_t hmac_test2 = {test_hmac_md5, "HMAC using MD5"};
 
 /**
  * Test for prf_plus
@@ -253,7 +254,7 @@ logger_manager_t *global_logger_manager;
                &sender_test,
                &receiver_test,
                &ike_sa_id_test,
-               //&ike_sa_test,
+               &ike_sa_test,
                &generator_test1,
                &generator_test2,
                &parser_test1,
@@ -267,12 +268,13 @@ logger_manager_t *global_logger_manager;
                &generator_test6,
                &generator_test7,
                &generator_test8,
-               //&ike_sa_manager_test,
+               &ike_sa_manager_test,
                &packet_test,
                &diffie_hellman_test,
                &hasher_sha1_test,
                &hasher_md5_test,
                &hmac_test1,
+               &hmac_test2,
                &prf_plus_test,
                NULL
        };
@@ -291,8 +293,8 @@ logger_manager_t *global_logger_manager;
        tester_t *tester = tester_create(test_output, FALSE);
 
 
-       //tester->perform_tests(tester,all_tests);
-       tester->perform_test(tester,&prf_plus_test); 
+       tester->perform_tests(tester,all_tests);
+       //tester->perform_test(tester,&hmac_test2);