- AUTH_HMAC_MD5_96 and AUTH_HMAC_SHA1_96 implemented and tested...
[strongswan.git] / Source / charon / testcases / aes_cbc_crypter_test.c
index 736d6f0..7b6e844 100644 (file)
@@ -67,16 +67,15 @@ void test_aes_cbc_crypter(tester_t *tester)
        logger->log_chunk(logger,RAW,"exptected encrypted :", &expected_encrypted1);
        logger->log_chunk(logger,RAW,"encrypted :", &encrypted1);
        
+       tester->assert_true(tester, (crypter->decrypt(crypter,encrypted1,iv1_chunk,&decrypted1) == SUCCESS), "decrypt call test");
        allocator_free_chunk(&encrypted1);
 
-       tester->assert_true(tester, (crypter->decrypt(crypter,data1,iv1_chunk,&decrypted1) == SUCCESS), "decrypt call test");
-
        tester->assert_true(tester, (memcmp(decrypted1.ptr, plaintext1, 16) == 0), "decrypted value");
        
        logger->log_chunk(logger,RAW,"expected decrypted :", &data1);
        logger->log_chunk(logger,RAW,"decrypted :", &decrypted1);
        
-       allocator_free_chunk(&encrypted1);
+       allocator_free_chunk(&decrypted1);
         
        tester->assert_true(tester, (crypter->destroy(crypter) == SUCCESS), "destroy call test");
        
@@ -110,7 +109,8 @@ void test_aes_cbc_crypter(tester_t *tester)
        chunk_t data2 = {ptr: plaintext2, len : 32};
        chunk_t encrypted2;
        chunk_t decrypted2;
-                
+       
+
        crypter = (crypter_t *) aes_cbc_crypter_create(16);
        tester->assert_true(tester, (crypter != NULL), "create call test");
        
@@ -118,25 +118,89 @@ void test_aes_cbc_crypter(tester_t *tester)
        
        tester->assert_true(tester, (crypter->encrypt(crypter,data2,iv2_chunk,&encrypted2) == SUCCESS), "encrypt call test");
        
-       tester->assert_true(tester, (memcmp(encrypted2.ptr, expected_encrypted2.ptr, 26) == 0), "Encrypted value");
+       tester->assert_true(tester, (memcmp(encrypted2.ptr, expected_encrypted2.ptr, 32) == 0), "Encrypted value");
        
        logger->log_chunk(logger,RAW,"exptected encrypted :", &expected_encrypted2);
        logger->log_chunk(logger,RAW,"encrypted :", &encrypted2);
        
+       tester->assert_true(tester, (crypter->decrypt(crypter,encrypted2,iv2_chunk,&decrypted2) == SUCCESS), "decrypt call test");
        allocator_free_chunk(&encrypted2);
 
-       tester->assert_true(tester, (crypter->decrypt(crypter,data2,iv2_chunk,&decrypted2) == SUCCESS), "decrypt call test");
-
-       tester->assert_true(tester, (memcmp(decrypted2.ptr, plaintext2, 26) == 0), "decrypted value");
+       tester->assert_true(tester, (memcmp(decrypted2.ptr, plaintext2, 32) == 0), "decrypted value");
        
        logger->log_chunk(logger,RAW,"expected decrypted :", &data2);
        logger->log_chunk(logger,RAW,"decrypted :", &decrypted2);
        
-       allocator_free_chunk(&encrypted2);
+       allocator_free_chunk(&decrypted2);
+
+       tester->assert_true(tester, (crypter->destroy(crypter) == SUCCESS), "destroy call test");
         
-       tester->assert_true(tester, (crypter->destroy(crypter) == SUCCESS), "destroy call test");
+       /*
+        * Test 3 of RFC3603
+        * Key       : 0x56e47a38c5598974bc46903dba290349
+        * IV        : 0x8ce82eefbea0da3c44699ed7db51b7d9
+        * Plaintext : 0xa0a1a2a3a4a5a6a7a8a9aaabacadaeaf
+     *                b0b1b2b3b4b5b6b7b8b9babbbcbdbebf
+     *             c0c1c2c3c4c5c6c7c8c9cacbcccdcecf
+     *             d0d1d2d3d4d5d6d7d8d9dadbdcdddedf
+        * Ciphertext: 0xc30e32ffedc0774e6aff6af0869f71aa
+     *             0f3af07a9a31a9c684db207eb0ef8e4e
+     *             35907aa632c3ffdf868bb7b29d3d46ad
+     *             83ce9f9a102ee99d49a53e87f4c3da55    
+        */
+       u_int8_t key3[] = {0x56,0xe4,0x7a,0x38,0xc5,0x59,0x89,0x74,
+                                          0xbc,0x46,0x90,0x3d,0xba,0x29,0x03,0x49};
+       chunk_t key3_chunk = {ptr: key3, len : 16};
+       u_int8_t iv3[] = {0x8c,0xe8,0x2e,0xef,0xbe,0xa0,0xda,0x3c,
+                                         0x44,0x69,0x9e,0xd7,0xdb,0x51,0xb7,0xd9};
+       chunk_t iv3_chunk = {ptr: iv3, len : 16};
+       u_int8_t ciphertext3[] = { 0xc3,0x0e,0x32,0xff,0xed,0xc0,0x77,0x4e,
+                                                          0x6a,0xff,0x6a,0xf0,0x86,0x9f,0x71,0xaa,
+                                                          0x0f,0x3a,0xf0,0x7a,0x9a,0x31,0xa9,0xc6,
+                                                          0x84,0xdb,0x20,0x7e,0xb0,0xef,0x8e,0x4e,
+                                                          0x35,0x90,0x7a,0xa6,0x32,0xc3,0xff,0xdf,
+                                                          0x86,0x8b,0xb7,0xb2,0x9d,0x3d,0x46,0xad,
+                                                          0x83,0xce,0x9f,0x9a,0x10,0x2e,0xe9,0x9d,
+                                                          0x49,0xa5,0x3e,0x87,0xf4,0xc3,0xda,0x55};
+       
+       chunk_t expected_encrypted3 = {ptr: ciphertext3, len : 64};
+       u_int8_t plaintext3[] = {0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,
+                                                        0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
+                                                        0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,
+                                                        0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
+                                                        0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,
+                                                        0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
+                                                        0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,
+                                                        0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf};
+       chunk_t data3 = {ptr: plaintext3, len : 64};
+       chunk_t encrypted3;
+       chunk_t decrypted3;
+
+       crypter = (crypter_t *) aes_cbc_crypter_create(16);
+       tester->assert_true(tester, (crypter != NULL), "create call test");
+       
+       tester->assert_true(tester, (crypter->set_key(crypter,key3_chunk) == SUCCESS), "set_key call test"); 
+       
+       tester->assert_true(tester, (crypter->encrypt(crypter,data3,iv3_chunk,&encrypted3) == SUCCESS), "encrypt call test");
+       
+       tester->assert_true(tester, (memcmp(encrypted3.ptr, expected_encrypted3.ptr, 64) == 0), "Encrypted value");
+       
+       logger->log_chunk(logger,RAW,"exptected encrypted :", &expected_encrypted3);
+       logger->log_chunk(logger,RAW,"encrypted :", &encrypted3);
        
+       tester->assert_true(tester, (crypter->decrypt(crypter,encrypted3,iv3_chunk,&decrypted3) == SUCCESS), "decrypt call test");
+       allocator_free_chunk(&encrypted3);
+
+       tester->assert_true(tester, (memcmp(decrypted3.ptr, plaintext3, 64) == 0), "decrypted value");
+       
+       logger->log_chunk(logger,RAW,"expected decrypted :", &data3);
+       logger->log_chunk(logger,RAW,"decrypted :", &decrypted3);
+       
+       allocator_free_chunk(&decrypted3);
+        
+       tester->assert_true(tester, (crypter->destroy(crypter) == SUCCESS), "destroy call test");
        
+
        
        global_logger_manager->destroy_logger(global_logger_manager,logger);
 }