diff options
author | subtly <subtly@users.noreply.github.com> | 2014-10-15 17:58:27 +0800 |
---|---|---|
committer | subtly <subtly@users.noreply.github.com> | 2014-10-15 17:58:27 +0800 |
commit | 0abb8e9b1d9d3549068c5c3432444292b713cbc6 (patch) | |
tree | b565c8c420bb6da21774a3393b0c3e08eb4151cf | |
parent | 15b524abc620f8328bd389ee7b96af1aa22c36fd (diff) | |
download | dexon-solidity-0abb8e9b1d9d3549068c5c3432444292b713cbc6.tar dexon-solidity-0abb8e9b1d9d3549068c5c3432444292b713cbc6.tar.gz dexon-solidity-0abb8e9b1d9d3549068c5c3432444292b713cbc6.tar.bz2 dexon-solidity-0abb8e9b1d9d3549068c5c3432444292b713cbc6.tar.lz dexon-solidity-0abb8e9b1d9d3549068c5c3432444292b713cbc6.tar.xz dexon-solidity-0abb8e9b1d9d3549068c5c3432444292b713cbc6.tar.zst dexon-solidity-0abb8e9b1d9d3549068c5c3432444292b713cbc6.zip |
cryptopp aes128-cbc
-rw-r--r-- | TestHelperCrypto.h | 10 | ||||
-rw-r--r-- | crypto.cpp | 43 |
2 files changed, 46 insertions, 7 deletions
diff --git a/TestHelperCrypto.h b/TestHelperCrypto.h index 6feeeb97..7e38c438 100644 --- a/TestHelperCrypto.h +++ b/TestHelperCrypto.h @@ -22,11 +22,13 @@ #pragma once //#include <ostream> -#include <eccrypto.h> -#include <ecp.h> -#include <files.h> #include <osrng.h> -#include <oids.h> +#include <eccrypto.h> // secp256r1 +#include <oids.h> // ec domain +#include <ecp.h> // ec prime field +#include <files.h> // also for buffer +#include <aes.h> +#include <modes.h> // aes modes using namespace std; using namespace CryptoPP; @@ -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<ECP>::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<Rijndael>::Encryption cbcEncryption(key, key.size(), iv); + cbcEncryption.ProcessData((byte*)&string128[0], (byte*)&string128[0], string128.size()); + assert(string128 != plainOriginal); + + CBC_Mode<Rijndael>::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) |