0

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)
T. Rifle
  • 55
  • 1
  • 8
  • Why do you *expect* it to be 40% faster? – Jesper Juhl Mar 11 '17 at 11:49
  • In crypto++ benchmarks AES-128 is %40 faster than AES-256. And also AES-128 10 round and AES-256 14 round. – T. Rifle Mar 11 '17 at 11:52
  • have you tried using a different processor? like 64 bit vs 32 bit proc – AchmadJP Mar 11 '17 at 12:12
  • No I have not tried different processor. Only 32 bit proc. – T. Rifle Mar 11 '17 at 12:22
  • 1
    Input file is very small, try to use a much bigger one. There are also cache issues, try to generate random input for each run. – zett42 Mar 11 '17 at 12:54
  • @zett42 Random input is interesting proposition, but not really needed. A counter or something could be used instead. If random generation is used you must be certain that the time to generate the random isn't influencing the result (and, if you're really serious, you'd have to take the processors data cache into account as well. – Maarten Bodewes Mar 11 '17 at 12:58
  • Your code is in a `main`, while the loop is outside of it? I'm not sure if we can answer this with the code you've given us. So, just to be sure, you are comparing your own Crypto++ benchmarks against "official" benchmarks of Crypto++? – Maarten Bodewes Mar 11 '17 at 12:59
  • My loop is inside of main. Not comparing but isn't result must be %40 faster? – T. Rifle Mar 11 '17 at 13:29
  • @zett42 How can I clear proc's data cache? – T. Rifle Mar 11 '17 at 13:32
  • 2
    You might also try OpenSSL. From a Linux terminal, type `apt-get install libssl-dev` (or use `yum` on Red Hat systems), and then type `openssl speed aes`. The utility will provide benchmarking data for AES 128, 192 and 256. – jww Mar 11 '17 at 16:59
  • @jww AES-128 and AES-256 are testing in the same conditions but why AES-128 result is just %20 faster? – T. Rifle Mar 11 '17 at 21:07
  • Also see [Benchmarks](https://www.cryptopp.com/wiki/Benchmarks) on the Crypto++ wiki and [Calculate time encryption of AES/CCM in Visual Studio 2017](https://stackoverflow.com/q/47956337/608639) on Stack Overflow. – jww Dec 25 '17 at 07:42

0 Answers0