diff --git a/test/TestHelperCrypto.h b/test/TestHelperCrypto.h index 6feeeb97f..7e38c438a 100644 --- a/test/TestHelperCrypto.h +++ b/test/TestHelperCrypto.h @@ -22,11 +22,13 @@ #pragma once //#include -#include -#include -#include #include -#include +#include // secp256r1 +#include // ec domain +#include // ec prime field +#include // also for buffer +#include +#include // aes modes using namespace std; using namespace CryptoPP; diff --git a/test/crypto.cpp b/test/crypto.cpp index 25106a77f..0f0a5f607 100644 --- a/test/crypto.cpp +++ b/test/crypto.cpp @@ -103,7 +103,7 @@ BOOST_AUTO_TEST_CASE(cryptopp_ecdh_prime) cnote << "Testing cryptopp_ecdh_prime..."; using namespace CryptoPP; - OID curve = ASN1::secp256r1(); + OID curve = ASN1::secp256k1(); ECDH::Domain dhLocal(curve); SecByteBlock privLocal(dhLocal.PrivateKeyLength()); @@ -136,14 +136,51 @@ BOOST_AUTO_TEST_CASE(cryptopp_ecdh_prime) assert(ssLocal == ssRemote); } +BOOST_AUTO_TEST_CASE(cryptopp_aes128_cbc) +{ + const int aesKeyLen = 16; + assert(sizeof(char) == sizeof(byte)); + + AutoSeededRandomPool rng; + SecByteBlock key(0x00, aesKeyLen); + rng.GenerateBlock(key, key.size()); + + // Generate random IV + byte iv[AES::BLOCKSIZE]; + rng.GenerateBlock(iv, AES::BLOCKSIZE); + + string string128("AAAAAAAAAAAAAAAA"); + string plainOriginal = string128; + + CryptoPP::CBC_Mode::Encryption cbcEncryption(key, key.size(), iv); + cbcEncryption.ProcessData((byte*)&string128[0], (byte*)&string128[0], string128.size()); + assert(string128 != plainOriginal); + + CBC_Mode::Decryption cbcDecryption(key, key.size(), iv); + cbcDecryption.ProcessData((byte*)&string128[0], (byte*)&string128[0], string128.size()); + assert(plainOriginal == string128); + + + // plaintext whose size isn't divisible by block size must use stream filter for padding + string string192("AAAAAAAAAAAAAAAABBBBBBBB"); + plainOriginal = string192; + + string cipher; + StreamTransformationFilter* aesStream = new StreamTransformationFilter(cbcEncryption, new StringSink(cipher)); + StringSource source(string192, true, aesStream); + assert(cipher.size() == 32); + + cbcDecryption.ProcessData((byte*)&cipher[0], (byte*)&string192[0], cipher.size()); + assert(string192 == plainOriginal); +} + BOOST_AUTO_TEST_CASE(cryptopp_ecdh_aes128_cbc_noauth) { // ECDH gives 256-bit shared while aes uses 128-bits // Use first 128-bits of shared secret as symmetric key // IV is 0 // New connections require new ECDH keypairs - - + } BOOST_AUTO_TEST_CASE(cryptopp_eth_fbba)