Browse Source

cryptopp aes128-cbc

cl-refactor
subtly 10 years ago
parent
commit
5253be9938
  1. 10
      test/TestHelperCrypto.h
  2. 41
      test/crypto.cpp

10
test/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;

41
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<ECP>::Domain dhLocal(curve);
SecByteBlock privLocal(dhLocal.PrivateKeyLength());
@ -136,6 +136,44 @@ 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
@ -143,7 +181,6 @@ BOOST_AUTO_TEST_CASE(cryptopp_ecdh_aes128_cbc_noauth)
// IV is 0
// New connections require new ECDH keypairs
}
BOOST_AUTO_TEST_CASE(cryptopp_eth_fbba)

Loading…
Cancel
Save