From e1ef70f4f49f36d99d8b1b743e21145225de8ef6 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sat, 19 Mar 2005 01:00:29 +0000 Subject: [PATCH] Update unit tests to reflect recent API changes svn path=/trunk/kdesupport/qca/; revision=398876 --- unittest/cipherunittest.cpp | 116 +++++++++++++++--------------- unittest/kdfunittest.cpp | 2 +- unittest/macunittest.cpp | 24 +++---- unittest/symmetrickeyunittest.cpp | 2 +- 4 files changed, 72 insertions(+), 72 deletions(-) diff --git a/unittest/cipherunittest.cpp b/unittest/cipherunittest.cpp index fea8973d..c227920c 100644 --- a/unittest/cipherunittest.cpp +++ b/unittest/cipherunittest.cpp @@ -628,8 +628,8 @@ void CipherUnitTest::allTests() if (!QCA::isSupported("aes128") ) SKIP("AES128 not supported!"); else { - QCA::SymmetricKey key1(QSecureArray(QCA::hexToArray( "00010203050607080A0B0C0D0F101112" ) ) ); - QCA::AES128 cipherObj1(QCA::Cipher::ECB, QCA::Encode, key1, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key1(QCA::hexToArray( "00010203050607080A0B0C0D0F101112" ) ); + QCA::AES128 cipherObj1(QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key1); QSecureArray inter = cipherObj1.update( QCA::hexToArray( "506812A45F08C889B97F5980038B8359" ) ); CHECK( QCA::arrayToHex( inter ), QString( "d8f532538289ef7d06b506a4fd5be9c9") ); CHECK( QCA::arrayToHex( cipherObj1.final() ), QString( "" ) ); @@ -637,41 +637,41 @@ void CipherUnitTest::allTests() CHECK( cipherObj1.blockSize(), (unsigned)16 ); // From the NIST rijndael-vals.zip set, see ecb_iv.txt - QCA::SymmetricKey key2(QSecureArray(QCA::hexToArray( "000102030405060708090A0B0C0D0E0F" ) ) ); - QCA::AES128 cipherObj2(QCA::Cipher::ECB, QCA::Encode, key2, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key2(QCA::hexToArray( "000102030405060708090A0B0C0D0E0F" ) ); + QCA::AES128 cipherObj2(QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key2); CHECK( QCA::arrayToHex( cipherObj2.update( QCA::hexToArray( "000102030405060708090A0B0C0D0E0F" ) ) ), QString( "0a940bb5416ef045f1c39458c653ea5a" ) ); CHECK( QCA::arrayToHex( cipherObj2.final() ), QString( "" ) ); // From the NIST rijndael-vals.zip set, see ecb_iv.txt - QCA::AES128 cipherObj3(QCA::Cipher::ECB, QCA::Decode, key2, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::AES128 cipherObj3(QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key2); CHECK( QCA::arrayToHex( cipherObj3.update( QCA::hexToArray( "0A940BB5416EF045F1C39458C653EA5A" ) ) ), QString("000102030405060708090a0b0c0d0e0f" ) ); CHECK( QCA::arrayToHex( cipherObj3.final() ), QString( "" ) ); // From FIPS-197 Annex C.1 - QCA::AES128 cipherObj4(QCA::Cipher::ECB, QCA::Encode, key2, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::AES128 cipherObj4(QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key2); CHECK( QCA::arrayToHex( cipherObj4.update( QCA::hexToArray( "00112233445566778899aabbccddeeff" ) ) ), QString("69c4e0d86a7b0430d8cdb78070b4c55a" ) ); CHECK( QCA::arrayToHex( cipherObj4.final() ), QString( "" ) ); // From FIPS-197 Annex C.1 - QCA::AES128 cipherObj5(QCA::Cipher::ECB, QCA::Decode, key2, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::AES128 cipherObj5(QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key2); CHECK( QCA::arrayToHex( cipherObj5.update( QCA::hexToArray( "69c4e0d86a7b0430d8cdb78070b4c55a" ) ) ), QString( "00112233445566778899aabbccddeeff" ) ); CHECK( QCA::arrayToHex( cipherObj5.final() ), QString( "" ) ); for (int n = 0; (0 != aes128ecbTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( aes128ecbTestValues[n].key ) ) ); - QCA::AES128 forwardCipher( QCA::Cipher::ECB, QCA::Encode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( aes128ecbTestValues[n].key ) ); + QCA::AES128 forwardCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( aes128ecbTestValues[n].plaintext ) ) ), QString( aes128ecbTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::AES128 reverseCipher( QCA::Cipher::ECB, QCA::Decode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::AES128 reverseCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( aes128ecbTestValues[n].ciphertext ) ) ), QString( aes128ecbTestValues[n].plaintext ) ); @@ -681,16 +681,16 @@ void CipherUnitTest::allTests() } for (int n = 0; (0 != aes128cbcTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( aes128cbcTestValues[n].key ) ) ); - QCA::InitializationVector iv( QSecureArray(QCA::hexToArray( aes128cbcTestValues[n].iv ) ) ); - QCA::AES128 forwardCipher( QCA::Cipher::CBC, QCA::Encode, key, iv, QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( aes128cbcTestValues[n].key ) ); + QCA::InitializationVector iv( QCA::hexToArray( aes128cbcTestValues[n].iv ) ); + QCA::AES128 forwardCipher( QCA::Cipher::CBC, QCA::Cipher::NoPadding,QCA::Encode, key, iv); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( aes128cbcTestValues[n].plaintext ) ) ), QString( aes128cbcTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::AES128 reverseCipher( QCA::Cipher::CBC, QCA::Decode, key, iv, QCA::Cipher::NoPadding ); + QCA::AES128 reverseCipher( QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Decode, key, iv); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( aes128cbcTestValues[n].ciphertext ) ) ), QString( aes128cbcTestValues[n].plaintext ) ); @@ -700,16 +700,16 @@ void CipherUnitTest::allTests() } for (int n = 0; (0 != aes128cfbTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( aes128cfbTestValues[n].key ) ) ); - QCA::InitializationVector iv( QSecureArray(QCA::hexToArray( aes128cfbTestValues[n].iv ) ) ); - QCA::AES128 forwardCipher( QCA::Cipher::CFB, QCA::Encode, key, iv, QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( aes128cfbTestValues[n].key ) ); + QCA::InitializationVector iv( QCA::hexToArray( aes128cfbTestValues[n].iv ) ); + QCA::AES128 forwardCipher( QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( aes128cfbTestValues[n].plaintext ) ) ), QString( aes128cfbTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::AES128 reverseCipher( QCA::Cipher::CFB, QCA::Decode, key, iv, QCA::Cipher::NoPadding ); + QCA::AES128 reverseCipher( QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( aes128cfbTestValues[n].ciphertext ) ) ), QString( aes128cfbTestValues[n].plaintext ) ); @@ -723,8 +723,8 @@ void CipherUnitTest::allTests() SKIP("AES192 not supported!"); else { // FIPS 197, Appendix C.2 - QCA::SymmetricKey key1(QSecureArray(QCA::hexToArray( "000102030405060708090A0B0C0D0E0F1011121314151617" ) ) ); - QCA::AES192 cipherObj1(QCA::Cipher::ECB, QCA::Encode, key1, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key1( QCA::hexToArray( "000102030405060708090A0B0C0D0E0F1011121314151617" ) ); + QCA::AES192 cipherObj1( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key1 ); QSecureArray data1 = QCA::hexToArray( "00112233445566778899AABBCCDDEEFF" ); CHECK( QCA::arrayToHex( cipherObj1.update( data1 ) ), QString( "dda97ca4864cdfe06eaf70a0ec0d7191") ); CHECK( cipherObj1.ok(), true ); @@ -733,7 +733,7 @@ void CipherUnitTest::allTests() CHECK( cipherObj1.blockSize(), (unsigned)16 ); - QCA::AES192 cipherObj2(QCA::Cipher::ECB, QCA::Decode, key1, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::AES192 cipherObj2(QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key1); CHECK( QCA::arrayToHex( cipherObj2.update( QCA::hexToArray( "dda97ca4864cdfe06eaf70a0ec0d7191") ) ), QString( "00112233445566778899aabbccddeeff" ) ); @@ -742,15 +742,15 @@ void CipherUnitTest::allTests() CHECK( cipherObj2.ok(), true ); for (int n = 0; (0 != aes192ecbTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( aes192ecbTestValues[n].key ) ) ); - QCA::AES192 forwardCipher( QCA::Cipher::ECB, QCA::Encode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( aes192ecbTestValues[n].key ) ); + QCA::AES192 forwardCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( aes192ecbTestValues[n].plaintext ) ) ), QString( aes192ecbTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::AES192 reverseCipher( QCA::Cipher::ECB, QCA::Decode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::AES192 reverseCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( aes192ecbTestValues[n].ciphertext ) ) ), QString( aes192ecbTestValues[n].plaintext ) ); @@ -760,16 +760,16 @@ void CipherUnitTest::allTests() } for (int n = 0; (0 != aes192cbcTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( aes192cbcTestValues[n].key ) ) ); - QCA::InitializationVector iv( QSecureArray(QCA::hexToArray( aes192cbcTestValues[n].iv ) ) ); - QCA::AES192 forwardCipher( QCA::Cipher::CBC, QCA::Encode, key, iv, QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( aes192cbcTestValues[n].key ) ); + QCA::InitializationVector iv( QCA::hexToArray( aes192cbcTestValues[n].iv ) ); + QCA::AES192 forwardCipher( QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Encode, key, iv); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( aes192cbcTestValues[n].plaintext ) ) ), QString( aes192cbcTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::AES192 reverseCipher( QCA::Cipher::CBC, QCA::Decode, key, iv, QCA::Cipher::NoPadding ); + QCA::AES192 reverseCipher( QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Decode, key, iv); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( aes192cbcTestValues[n].ciphertext ) ) ), QString( aes192cbcTestValues[n].plaintext ) ); @@ -779,16 +779,16 @@ void CipherUnitTest::allTests() } for (int n = 0; (0 != aes192cfbTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( aes192cfbTestValues[n].key ) ) ); - QCA::InitializationVector iv( QSecureArray(QCA::hexToArray( aes192cfbTestValues[n].iv ) ) ); - QCA::AES192 forwardCipher( QCA::Cipher::CFB, QCA::Encode, key, iv, QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( aes192cfbTestValues[n].key ) ); + QCA::InitializationVector iv( QCA::hexToArray( aes192cfbTestValues[n].iv ) ); + QCA::AES192 forwardCipher( QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( aes192cfbTestValues[n].plaintext ) ) ), QString( aes192cfbTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::AES192 reverseCipher( QCA::Cipher::CFB, QCA::Decode, key, iv, QCA::Cipher::NoPadding ); + QCA::AES192 reverseCipher( QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( aes192cfbTestValues[n].ciphertext ) ) ), QString( aes192cfbTestValues[n].plaintext ) ); @@ -803,8 +803,8 @@ void CipherUnitTest::allTests() SKIP("AES256 not supported!"); else { // FIPS 197, Appendix C.3 - QCA::SymmetricKey key1(QSecureArray(QCA::hexToArray( "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" ) ) ); - QCA::AES256 cipherObj1(QCA::Cipher::ECB, QCA::Encode, key1, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key1(QCA::hexToArray( "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" ) ); + QCA::AES256 cipherObj1(QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key1); QSecureArray data1 = QCA::hexToArray( "00112233445566778899AABBCCDDEEFF" ); CHECK( QCA::arrayToHex( cipherObj1.update( data1 ) ), QString( "8ea2b7ca516745bfeafc49904b496089") ); CHECK( cipherObj1.ok(), true ); @@ -813,7 +813,7 @@ void CipherUnitTest::allTests() CHECK( cipherObj1.blockSize(), (unsigned)16 ); - QCA::AES256 cipherObj2(QCA::Cipher::ECB, QCA::Decode, key1, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::AES256 cipherObj2(QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key1); CHECK( QCA::arrayToHex( cipherObj2.update( QCA::hexToArray( "8EA2B7CA516745BFEAFC49904B496089") ) ), QString( "00112233445566778899aabbccddeeff" ) ); CHECK( cipherObj2.ok(), true ); @@ -821,15 +821,15 @@ void CipherUnitTest::allTests() CHECK( cipherObj2.ok(), true ); for (int n = 0; (0 != aes256ecbTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( aes256ecbTestValues[n].key ) ) ); - QCA::AES256 forwardCipher( QCA::Cipher::ECB, QCA::Encode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( aes256ecbTestValues[n].key ) ); + QCA::AES256 forwardCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( aes256ecbTestValues[n].plaintext ) ) ), QString( aes256ecbTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::AES256 reverseCipher( QCA::Cipher::ECB, QCA::Decode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::AES256 reverseCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( aes256ecbTestValues[n].ciphertext ) ) ), QString( aes256ecbTestValues[n].plaintext ) ); @@ -839,16 +839,16 @@ void CipherUnitTest::allTests() } for (int n = 0; (0 != aes256cbcTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray( QCA::hexToArray( aes256cbcTestValues[n].key ) ) ); - QCA::InitializationVector iv( QSecureArray(QCA::hexToArray( aes256cfbTestValues[n].iv ) ) ); - QCA::AES256 forwardCipher( QCA::Cipher::CBC, QCA::Encode, key, iv, QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( aes256cbcTestValues[n].key ) ); + QCA::InitializationVector iv( QCA::hexToArray( aes256cfbTestValues[n].iv ) ); + QCA::AES256 forwardCipher( QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Encode, key, iv); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( aes256cbcTestValues[n].plaintext ) ) ), QString( aes256cbcTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::AES256 reverseCipher( QCA::Cipher::CBC, QCA::Decode, key, iv, QCA::Cipher::NoPadding ); + QCA::AES256 reverseCipher( QCA::Cipher::CBC, QCA::Cipher::NoPadding, QCA::Decode, key, iv); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( aes256cbcTestValues[n].ciphertext ) ) ), QString( aes256cbcTestValues[n].plaintext ) ); @@ -858,16 +858,16 @@ void CipherUnitTest::allTests() } for (int n = 0; (0 != aes256cfbTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( aes256cfbTestValues[n].key ) ) ); - QCA::InitializationVector iv( QSecureArray(QCA::hexToArray( aes256cfbTestValues[n].iv ) ) ); - QCA::AES256 forwardCipher( QCA::Cipher::CFB, QCA::Encode, key, iv, QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( aes256cfbTestValues[n].key ) ); + QCA::InitializationVector iv( QCA::hexToArray( aes256cfbTestValues[n].iv ) ); + QCA::AES256 forwardCipher( QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Encode, key, iv); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( aes256cfbTestValues[n].plaintext ) ) ), QString( aes256cfbTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::AES256 reverseCipher( QCA::Cipher::CFB, QCA::Decode, key, iv, QCA::Cipher::NoPadding ); + QCA::AES256 reverseCipher( QCA::Cipher::CFB, QCA::Cipher::NoPadding, QCA::Decode, key, iv); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( aes256cfbTestValues[n].ciphertext ) ) ), QString( aes256cfbTestValues[n].plaintext ) ); @@ -880,21 +880,21 @@ void CipherUnitTest::allTests() if (!QCA::isSupported("tripledes") ) SKIP("Triple DES not supported!"); else { - QCA::TripleDES cipherObj1( QCA::Cipher::ECB, QCA::Encode, QCA::SymmetricKey( 24 ) ); + QCA::TripleDES cipherObj1( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, QCA::SymmetricKey( 24 ) ); CHECK( cipherObj1.keyLength().minimum(), 24 ); CHECK( cipherObj1.keyLength().maximum(), 24 ); CHECK( cipherObj1.blockSize(), (unsigned)8 ); for (int n = 0; (0 != tripledesTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( tripledesTestValues[n].key ) ) ); - QCA::TripleDES forwardCipher( QCA::Cipher::ECB, QCA::Encode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( tripledesTestValues[n].key ) ); + QCA::TripleDES forwardCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( tripledesTestValues[n].plaintext ) ) ), QString( tripledesTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::TripleDES reverseCipher( QCA::Cipher::ECB, QCA::Decode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::TripleDES reverseCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( tripledesTestValues[n].ciphertext ) ) ), QString( tripledesTestValues[n].plaintext ) ); @@ -907,21 +907,21 @@ void CipherUnitTest::allTests() if (!QCA::isSupported("des") ) SKIP("DES not supported!"); else { - QCA::DES cipherObj1( QCA::Cipher::ECB, QCA::Encode, QCA::SymmetricKey( 8 ) ); + QCA::DES cipherObj1( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, QCA::SymmetricKey( 8 ) ); CHECK( cipherObj1.keyLength().minimum(), 8 ); CHECK( cipherObj1.keyLength().maximum(), 8 ); CHECK( cipherObj1.blockSize(), (unsigned)8 ); for (int n = 0; (0 != desTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( desTestValues[n].key ) ) ); - QCA::DES forwardCipher( QCA::Cipher::ECB, QCA::Encode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( desTestValues[n].key ) ); + QCA::DES forwardCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( desTestValues[n].plaintext ) ) ), QString( desTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::DES reverseCipher( QCA::Cipher::ECB, QCA::Decode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::DES reverseCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( desTestValues[n].ciphertext ) ) ), QString( desTestValues[n].plaintext ) ); @@ -934,19 +934,19 @@ void CipherUnitTest::allTests() if (!QCA::isSupported("blowfish") ) SKIP("Blowfish not supported!"); else { - QCA::BlowFish cipherObj1( QCA::Cipher::ECB, QCA::Encode, QCA::SymmetricKey( 16 ) ); + QCA::BlowFish cipherObj1( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, QCA::SymmetricKey( 16 ) ); CHECK( cipherObj1.blockSize(), (unsigned)8 ); for (int n = 0; (0 != blowfishTestValues[n].plaintext); n++) { - QCA::SymmetricKey key( QSecureArray(QCA::hexToArray( blowfishTestValues[n].key ) ) ); - QCA::BlowFish forwardCipher( QCA::Cipher::ECB, QCA::Encode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::SymmetricKey key( QCA::hexToArray( blowfishTestValues[n].key ) ); + QCA::BlowFish forwardCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Encode, key); CHECK( QCA::arrayToHex( forwardCipher.update( QCA::hexToArray( blowfishTestValues[n].plaintext ) ) ), QString( blowfishTestValues[n].ciphertext ) ); CHECK( forwardCipher.ok(), true ); CHECK( QCA::arrayToHex( forwardCipher.final() ), QString( "" ) ); CHECK( forwardCipher.ok(), true ); - QCA::BlowFish reverseCipher( QCA::Cipher::ECB, QCA::Decode, key, QCA::InitializationVector(), QCA::Cipher::NoPadding ); + QCA::BlowFish reverseCipher( QCA::Cipher::ECB, QCA::Cipher::NoPadding, QCA::Decode, key); CHECK( QCA::arrayToHex( reverseCipher.update( QCA::hexToArray( blowfishTestValues[n].ciphertext ) ) ), QString( blowfishTestValues[n].plaintext ) ); diff --git a/unittest/kdfunittest.cpp b/unittest/kdfunittest.cpp index 07f3a274..282a2d66 100644 --- a/unittest/kdfunittest.cpp +++ b/unittest/kdfunittest.cpp @@ -81,7 +81,7 @@ void KDFUnitTest::pbkdf1Tests() else { for (int n = 0; (0 != pbkdf1TestValues[n].secret); n++) { QSecureArray password = QCA::hexToArray( pbkdf1TestValues[n].secret ); - QCA::InitializationVector salt( QSecureArray(QCA::hexToArray( pbkdf1TestValues[n].salt) ) ); + QCA::InitializationVector salt( QCA::hexToArray( pbkdf1TestValues[n].salt) ); QCA::SymmetricKey key = QCA::PBKDF1().makeKey( password, salt, pbkdf1TestValues[n].outputLength, diff --git a/unittest/macunittest.cpp b/unittest/macunittest.cpp index 6deac585..8355c391 100644 --- a/unittest/macunittest.cpp +++ b/unittest/macunittest.cpp @@ -57,7 +57,7 @@ void MACUnitTest::allTests() CHECK( QCA::arrayToHex( md5hmac1.final() ), QString( "750c783e6ab0b503eaa86e310a5db738" ) ); QCA::HMAC md5hmac2( "md5" ); - QCA::SymmetricKey key2( QSecureArray(QCA::hexToArray( "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" ) ) ); + QCA::SymmetricKey key2( QCA::hexToArray( "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" ) ); md5hmac2.setup( key2 ); QSecureArray data2 = QSecureArray( "Hi There" ); md5hmac2.update( data2 ); @@ -65,7 +65,7 @@ void MACUnitTest::allTests() // test reuse md5hmac2.clear(); - QCA::SymmetricKey key3( QSecureArray(QCA::hexToArray( "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ) ) ); + QCA::SymmetricKey key3( QCA::hexToArray( "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" ) ); md5hmac2.setup ( key3 ); QSecureArray data3( 50 ); for ( int i = 0; i < data3.size(); i++ ) @@ -73,7 +73,7 @@ void MACUnitTest::allTests() md5hmac2.update( data3 ); CHECK( QCA::arrayToHex( md5hmac2.final() ), QString( "56be34521d144c88dbb8c733f0e8b3f6" ) ); - QCA::SymmetricKey key4( QSecureArray(QCA::hexToArray( "0102030405060708090a0b0c0d0e0f10111213141516171819") ) ); + QCA::SymmetricKey key4( QCA::hexToArray( "0102030405060708090a0b0c0d0e0f10111213141516171819") ); QCA::HMAC md5hmac4( "md5", key4 ); QSecureArray data4( 50 ); for (int i = 0; i < data4.size(); i++ ) @@ -82,7 +82,7 @@ void MACUnitTest::allTests() CHECK( QCA::arrayToHex( md5hmac4.final() ), QString( "697eaf0aca3a3aea3a75164746ffaa79" ) ); QCA::HMAC md5hmac5( "md5" ); - QCA::SymmetricKey key5( QSecureArray(QCA::hexToArray( "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c" ) ) ); + QCA::SymmetricKey key5( QCA::hexToArray( "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c" ) ); md5hmac5.setup( key5 ); QSecureArray data5( "Test With Truncation" ); md5hmac5.update( data5 ); @@ -114,7 +114,7 @@ void MACUnitTest::allTests() // These tests are from RFC2202, Section 3. QCA::HMAC test1; // should be default - QCA::SymmetricKey key1( QSecureArray(QCA::hexToArray( "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" ) ) ); + QCA::SymmetricKey key1( QCA::hexToArray( "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" ) ); test1.setup( key1 ); QSecureArray data1( "Hi There" ); test1.update( data1 ); @@ -128,7 +128,7 @@ void MACUnitTest::allTests() CHECK( QCA::arrayToHex( test2.final() ), QString( "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79" ) ); QCA::HMAC test3; - QCA::SymmetricKey key3( QSecureArray(QCA::hexToArray( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) ) ); + QCA::SymmetricKey key3( QCA::hexToArray( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) ); test3.setup( key3 ); QSecureArray data3( 50 ); for ( int i = 0; i < data3.size(); i++ ) @@ -137,7 +137,7 @@ void MACUnitTest::allTests() CHECK( QCA::arrayToHex( test3.final() ), QString( "125d7342b9ac11cd91a39af48aa17b4f63f175d3" ) ); QCA::HMAC test4; - QCA::SymmetricKey key4( QSecureArray(QCA::hexToArray( "0102030405060708090a0b0c0d0e0f10111213141516171819" ) ) ); + QCA::SymmetricKey key4( QCA::hexToArray( "0102030405060708090a0b0c0d0e0f10111213141516171819" ) ); test4.setup( key4 ); QSecureArray data4( 50 ); for ( int i = 0; i < data4.size(); i++ ) @@ -146,7 +146,7 @@ void MACUnitTest::allTests() CHECK( QCA::arrayToHex( test4.final() ), QString( "4c9007f4026250c6bc8414f9bf50c86c2d7235da" ) ); QCA::HMAC test5; // should be default - QCA::SymmetricKey key5 ( QSecureArray(QCA::hexToArray( "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c" ) ) ); + QCA::SymmetricKey key5 ( QCA::hexToArray( "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c" ) ); test5.setup( key5 ); QSecureArray data5( "Test With Truncation" ); test5.update( data5 ); @@ -179,7 +179,7 @@ void MACUnitTest::allTests() // These tests are from RFC2286, Section 2. QCA::HMAC test1( "ripemd160" ); - QCA::SymmetricKey key1 ( QSecureArray(QCA::hexToArray( "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" ) ) ); + QCA::SymmetricKey key1 ( QCA::hexToArray( "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b" ) ); test1.setup( key1 ); QSecureArray data1( "Hi There" ); test1.update( data1 ); @@ -193,7 +193,7 @@ void MACUnitTest::allTests() CHECK( QCA::arrayToHex( test2.final() ), QString( "dda6c0213a485a9e24f4742064a7f033b43c4069" ) ); QCA::HMAC test3( "ripemd160" ); - QCA::SymmetricKey key3( QSecureArray( QCA::hexToArray( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) ) ); + QCA::SymmetricKey key3( QCA::hexToArray( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" ) ); test3.setup( key3 ); QSecureArray data3( 50 ); for ( int i = 0; i < data3.size(); i++ ) @@ -201,7 +201,7 @@ void MACUnitTest::allTests() test3.update( data3 ); CHECK( QCA::arrayToHex( test3.final() ), QString( "b0b105360de759960ab4f35298e116e295d8e7c1" ) ); - QCA::SymmetricKey key4( QSecureArray(QCA::hexToArray( "0102030405060708090a0b0c0d0e0f10111213141516171819" ) ) ); + QCA::SymmetricKey key4( QCA::hexToArray( "0102030405060708090a0b0c0d0e0f10111213141516171819" ) ); QCA::HMAC test4( "ripemd160", key4 ); QSecureArray data4( 50 ); for ( int i = 0; i < data4.size(); i++ ) @@ -210,7 +210,7 @@ void MACUnitTest::allTests() CHECK( QCA::arrayToHex( test4.final() ), QString( "d5ca862f4d21d5e610e18b4cf1beb97a4365ecf4" ) ); QCA::HMAC test5( "ripemd160" ); - QCA::SymmetricKey key5 ( QSecureArray(QCA::hexToArray( "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c" ) ) ); + QCA::SymmetricKey key5 ( QCA::hexToArray( "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c" ) ); test5.setup( key5 ); QSecureArray data5( "Test With Truncation" ); test5.update( data5 ); diff --git a/unittest/symmetrickeyunittest.cpp b/unittest/symmetrickeyunittest.cpp index 6df3d51f..37728173 100644 --- a/unittest/symmetrickeyunittest.cpp +++ b/unittest/symmetrickeyunittest.cpp @@ -85,7 +85,7 @@ void SymmetricKeyUnitTest::allTests() CHECK( anotherKey.size(), 0 ); for (int n = 0; (0 != DESTestValues[n].weak); n++) { - QCA::SymmetricKey key(QSecureArray(QCA::hexToArray(DESTestValues[n].key))); + QCA::SymmetricKey key(QCA::hexToArray(DESTestValues[n].key)); CHECK( key.isWeakDESKey(), DESTestValues[n].weak ); } }