I am making performance tests over AES-128 and AES-256. But my results are around %20. I am using Intel Core 2 Duo 800 MHz. 2.60 GHz. 6 MB Cache Memory T9500 CPU and Linux Mint 17.2 Rosa Xfce Os. Is there a problem with my testing? Any help would be appreciated.
My testing code is here: Headings;
// g++ -g3 -ggdb -O0 -DDEBUG -I/usr/include/cryptopp AESCBC128.cpp -o AESCBC128.exe -lcryptopp -lpthread
// g++ -g -O2 -DNDEBUG -I/usr/include/cryptopp AESCBC128.cpp -o AESCBC128.exe -lcryptopp -lpthread
#include "osrng.h"
using CryptoPP::AutoSeededRandomPool;
#include <iostream>
using std::cout;
using std::cerr;
using std::endl;
#include <string>
using std::string;
#include <cstdlib>
using std::exit;
#include "cryptlib.h"
using CryptoPP::Exception;
#include "hex.h"
using CryptoPP::HexEncoder;
using CryptoPP::HexDecoder;
#include "filters.h"
using CryptoPP::StringSink;
using CryptoPP::StringSource;
using CryptoPP::StreamTransformationFilter;
#include "aes.h"
using CryptoPP::AES;
#include "ccm.h"
using CryptoPP::CBC_Mode;
#include "assert.h"
#include<sstream>
const double CLOCK_TICKS_PER_SECOND = 1000000.0;
And my code (for AES-256);
int main(int argc, char* argv[]){
AutoSeededRandomPool prng;
byte key[AES::MAX_KEYLENGTH];
prng.GenerateBlock(key, sizeof(key));
byte iv[AES::BLOCKSIZE];
prng.GenerateBlock(iv, sizeof(iv));
CBC_Mode< AES >::Encryption e;
e.SetKeyWithIV(key, sizeof(key), iv);
And my code (for AES-128);
int main(int argc, char* argv[]){
AutoSeededRandomPool prng;
byte key[AES::DEFAULT_KEYLENGTH];
prng.GenerateBlock(key, sizeof(key));
byte iv[AES::BLOCKSIZE];
prng.GenerateBlock(iv, sizeof(iv));
CBC_Mode< AES >::Encryption e;
e.SetKeyWithIV(key, sizeof(key), iv);
I use crypto++ test data rijndael.dat as plianText (1020 bytes). It is like;
std::string plain = "000102030405060708090A0B0C0D....
My testing code;
clock_t startTime, finishTime;
std::string plain, cipher, encoded, recovered;
startTime = clock();
for ( int i = 0; i < 200000; i++ )
{
// clean up for next round
cipher = "";
try
{
// The StreamTransformationFilter removes
// padding as required.
StringSource s(plain, true,
new StreamTransformationFilter(e,
new StringSink(cipher)
) // StreamTransformationFilter
); // StringSource
}
catch(const CryptoPP::Exception& e)
{
cerr << e.what() << endl;
exit(1);
}
} // end-for
// save current time just after finishing the encryption loop
finishTime = clock();
And I am keeping results with;
double executionTimeInSec = double( finishTime - startTime ) / CLOCK_TICKS_PER_SECOND;
std::cout << "Encryption loop execution time: " << executionTimeInSec * 1000.0 << " microseconds." << std::endl;
std::cout << "Plain text size: " << plain.size() << " bytes." << std::endl;
double data_rate_MiBps = ((double)plain.size() / 1048576) / ((double)executionTimeInSec) ;
std::cout << "Encryption/decryption loop execution time MB/S: " << data_rate_MiBps << " MB/S." << std::endl;
return 0;
}
Finally my results are here;
AES-128/CBC ----------
2037.41 encryption loop execution time (microseconds)
0.083 microseconds for Key Setup and IV
95.48 Encrypiton loop execution time (MIB/Seconds)
AES-256/CBC ----------
2470.86 encryption loop execution time (microseconds)
0.092 microseconds for Key Setup and IV
78.72 Encrypiton loop execution time (MIB/Seconds)