diff options
author | subtly <subtly@users.noreply.github.com> | 2014-10-22 21:57:52 +0800 |
---|---|---|
committer | subtly <subtly@users.noreply.github.com> | 2014-10-22 21:57:52 +0800 |
commit | 9a5a6db634eba31bc1e009ef54b71c82dbc33dfb (patch) | |
tree | a30434883199645ac3d2960f99412e1bbe943edf | |
parent | 7ca7fd97ab85cc01b99532b9108ea5218891e8d7 (diff) | |
download | dexon-solidity-9a5a6db634eba31bc1e009ef54b71c82dbc33dfb.tar dexon-solidity-9a5a6db634eba31bc1e009ef54b71c82dbc33dfb.tar.gz dexon-solidity-9a5a6db634eba31bc1e009ef54b71c82dbc33dfb.tar.bz2 dexon-solidity-9a5a6db634eba31bc1e009ef54b71c82dbc33dfb.tar.lz dexon-solidity-9a5a6db634eba31bc1e009ef54b71c82dbc33dfb.tar.xz dexon-solidity-9a5a6db634eba31bc1e009ef54b71c82dbc33dfb.tar.zst dexon-solidity-9a5a6db634eba31bc1e009ef54b71c82dbc33dfb.zip |
aes ctr mode test
-rw-r--r-- | crypto.cpp | 73 |
1 files changed, 73 insertions, 0 deletions
@@ -62,6 +62,11 @@ BOOST_AUTO_TEST_CASE(ecdhe_aes128_ctr_sha3mac) // Every new connection requires a new EC keypair // Every new trust requires a new EC keypair // All connections should share seed for PRF (or PRNG) for nonces + + + + + } BOOST_AUTO_TEST_CASE(cryptopp_ecies_message) @@ -149,6 +154,74 @@ BOOST_AUTO_TEST_CASE(cryptopp_ecdh_prime) assert(ssLocal == ssRemote); } +BOOST_AUTO_TEST_CASE(cryptopp_aes128_ctr) +{ + const int aesKeyLen = 16; + assert(sizeof(char) == sizeof(byte)); + + // generate test key + AutoSeededRandomPool rng; + SecByteBlock key(0x00, aesKeyLen); + rng.GenerateBlock(key, key.size()); + + // cryptopp uses IV as nonce/counter which is same as using nonce w/0 ctr + byte ctr[ AES::BLOCKSIZE ]; + rng.GenerateBlock( ctr, sizeof(ctr) ); + + string text = "Now is the time for all good men to come to the aide of humanity."; + // c++11 ftw + unsigned char const* in = (unsigned char*)&text[0]; + unsigned char* out = (unsigned char*)&text[0]; + string original = text; + + string cipherCopy; + try + { + CTR_Mode< AES >::Encryption e; + e.SetKeyWithIV( key, key.size(), ctr ); + e.ProcessData(out, in, text.size()); + assert(text!=original); + cipherCopy = text; + } + catch( CryptoPP::Exception& e ) + { + cerr << e.what() << endl; + } + + try + { + CTR_Mode< AES >::Decryption d; + d.SetKeyWithIV( key, key.size(), ctr ); + d.ProcessData(out, in, text.size()); + assert(text==original); + } + catch( CryptoPP::Exception& e ) + { + cerr << e.what() << endl; + } + + + // reencrypt ciphertext... + try + { + assert(cipherCopy!=text); + in = (unsigned char*)&cipherCopy[0]; + out = (unsigned char*)&cipherCopy[0]; + + CTR_Mode< AES >::Encryption e; + e.SetKeyWithIV( key, key.size(), ctr ); + e.ProcessData(out, in, text.size()); + + // yep, ctr mode. + assert(cipherCopy==original); + } + catch( CryptoPP::Exception& e ) + { + cerr << e.what() << endl; + } + +} + BOOST_AUTO_TEST_CASE(cryptopp_aes128_cbc) { const int aesKeyLen = 16; |