我正在通过AES-128和AES-256进行性能测试。但我的结果大约是20%。我使用的是Intel Core 2 Duo 800 MHz。 2.60 GHz。 6 MB高速缓存T9500 CPU和Linux Mint 17.2 Rosa Xfce Os。我的测试有问题吗?任何帮助将不胜感激。
我的测试代码在这里: 标题;
// 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;
我的代码(针对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);
我的代码(针对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);
我使用crypto ++测试数据rijndael.dat作为plianText(1020字节)。就像;
std::string plain = "000102030405060708090A0B0C0D....
我的测试代码;
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();
我保持结果;
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;
}
最后我的结果在这里;
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)