理论上,我想知道在以下条件下,AES/CBC解密比AES/CBC加密要慢多少?
我之所以问这个问题,是因为我想知道我所拥有的实现的解密速度是否异常缓慢。我在不同大小的随机内存块上做了一些测试。结果如下:
64B:

64:

10 10MB 520:

所有数据都存储在我系统的内部内存中。应用程序生成要自己加密的数据。虚拟内存在测试PC上被禁用,这样就不会有任何I/O调用。
在分析表时,加密和解密之间的区别是否意味着我的实现异常缓慢?我做错什么了吗?
更新:
解密实现如下:
CryptoPP::AES::Decryption aesDecryption(aesKey, ENCRYPTION_KEY_SIZE_AES);
CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, aesIv);
CryptoPP::ArraySink * decSink = new CryptoPP::ArraySink(data, dataSizeMax);
CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, decSink);
stfDecryptor.Put(reinterpret_cast<const unsigned char*>(ciphertext), cipherSize);
stfDecryptor.MessageEnd();
*dataOutputSize = decSink->TotalPutLength(); 更新2:
发布于 2013-11-23 19:59:23
作为对称加密,加密和解密应该是相当接近的速度。不确定您的实现,但是如果您关心算法是如何使用的,有一些方法可以进行优化。在实验中,AES不是最快的,CBC将增加安全性,但减慢安全性。下面是一个比较,因为您询问的是键大小和块大小:

发布于 2017-12-25 08:26:55
在分析表时,加密和解密之间的区别是否意味着我的实现异常缓慢?我做错什么了吗?
有三四件事突然出现在我面前。我有点同意@JamesKPolk --数字看不见了。首先,密码库通常采用CTR模式,而不是CBC模式。还可以看到超基准。任何你必须使用循环每字节(cpb)来标准化测量单位跨机器.在没有上下文的情况下说“9MB/s”没有任何意义。
其次,我们需要知道机器和它的CPU频率。看起来您正在以9MB/s的速度加密数据,6.5MB/s的数据用于解密。现代的iCore机器,如以2.7 GHz运行的Core-i5,将以大约为980 MB/s或1GB/s的速度将CBC模式数据推至2.5或3.0CPB左右。就连我的旧Core2 Duo在2.0 GHz上运行也比你显示的更快地移动数据。Core 2以14.5 cpb或130 MB/s的速度移动数据。
第三,废除这段代码。有很大的改进空间,因此在这方面不值得批评;推荐的代码如下所示。值得一提的是,您正在创建许多对象,如ArraySource和StreamTransformationFilter。过滤器增加填充,扰乱AES加密和解密基准,并扭曲结果。您只需要一个加密对象,然后只需要调用ProcessBlock或ProcessString。
CryptoPP::AES::Decryption aesDecryption(aesKey, ENCRYPTION_KEY_SIZE_AES);
CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption(aesDecryption, aesIv);
...第四,Crypto++ wiki有一个具有以下代码的基准条款。这是一个新的部分,当你问你的问题时,它是不可用的。这是如何运行您的测试。
AutoSeededRandomPool prng;
SecByteBlock key(16);
prng.GenerateBlock(key, key.size());
CTR_Mode<AES>::Encryption cipher;
cipher.SetKeyWithIV(key, key.size(), key);
const int BUF_SIZE = RoundUpToMultipleOf(2048U,
dynamic_cast<StreamTransformation&>(cipher).OptimalBlockSize());
AlignedSecByteBlock buf(BUF_SIZE);
prng.GenerateBlock(buf, buf.size());
const double runTimeInSeconds = 3.0;
const double cpuFreq = 2.7 * 1000 * 1000 * 1000;
double elapsedTimeInSeconds;
unsigned long i=0, blocks=1;
ThreadUserTimer timer;
timer.StartTimer();
do
{
blocks *= 2;
for (; i<blocks; i++)
cipher.ProcessString(buf, BUF_SIZE);
elapsedTimeInSeconds = timer.ElapsedTimeAsDouble();
}
while (elapsedTimeInSeconds < runTimeInSeconds);
const double bytes = static_cast<double>(BUF_SIZE) * blocks;
const double ghz = cpuFreq / 1000 / 1000 / 1000;
const double mbs = bytes / 1024 / 1024 / elapsedTimeInSeconds;
const double cpb = elapsedTimeInSeconds * cpuFreq / bytes;
std::cout << cipher.AlgorithmName() << " benchmarks..." << std::endl;
std::cout << " " << ghz << " GHz cpu frequency" << std::endl;
std::cout << " " << cpb << " cycles per byte (cpb)" << std::endl;
std::cout << " " << mbs << " MiB per second (MiB)" << std::endl;在2.7 GHz的Core-i56400上运行代码将得到以下结果:
$ ./bench.exe
AES/CTR benchmarks...
2.7 GHz cpu frequency
0.58228 cycles per byte (cpb)
4422.13 MiB per second (MiB)第五,当我修改上面显示的基准程序以操作64字节块时:
const int BUF_SIZE = 64;
unsigned int blocks = 0;
...
do
{
blocks++;
cipher.ProcessString(buf, BUF_SIZE);
elapsedTimeInSeconds = timer.ElapsedTimeAsDouble();
}
while (elapsedTimeInSeconds < runTimeInSeconds);我看到3.4CPB或760 MB/s的Core-i56400在2.7 GHz的64字节块。这个库对于小型缓冲区来说很受欢迎,但大多数(全部?)图书馆有。
$ ./bench.exe
AES/CTR benchmarks...
2.7 GHz cpu frequency
3.39823 cycles per byte (cpb)
757.723 MiB per second (MiB)第六,您需要使处理器摆脱节能模式或低能量状态,以获得最佳/最一致的结果。库使用governor.sh在Linux上进行操作。它可以在TestScript/目录中获得。
第七,当我切换到CTR模式解密时:
CTR_Mode<AES>::Decryption cipher;
cipher.SetKeyWithIV(key, key.size(), key);然后,我看到了大批量解密的相同速率:
$ ./bench.exe
AES/CTR benchmarks...
2.7 GHz cpu frequency
0.579923 cycles per byte (cpb)
4440.11 MiB per second (MiB)这里是一组不同机器上的基准数据集合。在您调优测试时,它应该提供一个粗略的目标。
我的Beaglebone开发板运行在980 MHz上,移动数据的速度是你报告的两倍。Beaglebone实现了一个无聊的40 cpb和20 MB/s,因为它是正确的C/C++;而不是优化的A-32。
- [https://www.cryptopp.com/benchmarks.html](https://www.cryptopp.com/benchmarks.html)
- [https://www.cryptopp.com/benchmarks-core2.html](https://www.cryptopp.com/benchmarks-core2.html)
- [https://www.cryptopp.com/benchmarks-hikey.html](https://www.cryptopp.com/benchmarks-hikey.html)
- [https://www.cryptopp.com/benchmarks-opteron.html](https://www.cryptopp.com/benchmarks-opteron.html)
- [https://www.cryptopp.com/benchmarks-bananapi.html](https://www.cryptopp.com/benchmarks-bananapi.html)
- [https://www.cryptopp.com/benchmarks-power8.html](https://www.cryptopp.com/benchmarks-power8.html)
我的外卖是:
这是我希望看到的一切。
我认为下一步是使用样例程序在Crypto++ wiki上收集一些数据,然后评估结果。
发布于 2014-10-30 19:14:56
理论上,AES解密速度慢了30%。一般来说,这是Rijndael系统的一个属性。
来源:http://www4.ncsu.edu/~hartwig/Teaching/437/aes.pdf
https://stackoverflow.com/questions/20164502
复制相似问题