简体   繁体   English

Raspberry PI 2上使用OpenSSL AES / GCM的性能非常差

[英]Ridiculously poor performance with OpenSSL AES/GCM on Raspberry PI 2

I developed a simple C++ program to benchmark the performance of OpenSSL AES/GCM calls to the EVP interface. 我开发了一个简单的C ++程序来测试OpenSSL AES / GCM调用到EVP接口的性能。 What it does is to take a 1024 bytes string, encrypt it with a key, then encrypt the result with the same key, and again and again. 它的作用是取一个1024字节的字符串,用密钥加密它,然后用相同的密钥加密结果,并一次又一次地加密。 I am using incremental 4-bytes initialization vectors. 我正在使用增量4字节初始化向量。

When I tested it on my Macbook Pro (Intel i7) the result was quite impressive: it took exactly one second to run 1048576 iterations of the above procedure on a single core. 当我在我的Macbook Pro(Intel i7)上测试它时,结果非常令人印象深刻:在一个内核上运行上述过程的1048576次迭代需要一秒钟。 That's 1 GB/s encryption speed. 这是1 GB / s的加密速度。 8 GB/s (more or less) if we make use of all the cores simultaneously. 如果我们同时使用所有核心,则为8 GB / s(或多或少)。

Now, I ported the same benchmark on a Raspberry PI 2. When I ran it, however, it took 0.16 seconds to do 1024 iterations. 现在,我在Raspberry PI 2上移植了相同的基准测试。然而,当我运行它时,需要0.16秒来完成1024次迭代。 That's more or less 6 MB/s, on a single core. 在单核上,这或多或少为6 MB / s。

Now, I obviously understand that there's a huge, huge difference between a modern, costly i7 processor and the small ARM processor that runs on a Raspberry, but still that's 170 times faster. 现在,我很明白,现代昂贵的i7处理器和在Raspberry上运行的小型ARM处理器之间存在着巨大的巨大差异,但仍然快170倍。 So before assuming that Raspberry PI 2 is really that bad, I wanted to check if those parameters are reasonable. 因此,在假设Raspberry PI 2 真的那么糟糕之前,我想检查这些参数是否合理。

Has anybody done some kind of benchmark on that? 有没有人做过某种基准? Are 6 MB/s encryption speed reasonable on a Raspberry? Raspberry上6 MB / s的加密速度是否合理? Or am I doing something wrong? 或者我做错了什么?

(I am powering it via my Macbook USB: could that be so slow because it is not receiving enough power? That definitely doesn't sound reasonable. It wouldn't power on at all, right? Or could there be a downclocking mechanism to save power?) (我通过我的Macbook USB给它供电:可能这么慢,因为它没有获得足够的功率?这听起来听起来不合理。它根本不会启动,对吧?或者可能有一个超频机制来省电吗?)

UPDATE 1 : I did openssl -evp speed aes-256-cbc on both my Macbook and the Raspberry. 更新1 :我在我的Macbook和Raspberry上做了openssl -evp speed aes-256-cbc

On the Macbook: 在Macbook上:

type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
aes-256-cbc     534591.95k   564057.62k   566522.81k   570717.87k   574876.33k

On the Raspberry: 在覆盆子上:

type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
aes-256-cbc      14288.53k    16653.74k    17165.31k    17298.43k    17337.00k

That's still a factor 33, but the Intel processor can make use of hardware accelerated AES calls. 这仍然是因素33,但英特尔处理器可以使用硬件加速AES调用。 Still, as far as I know GCM mode should be quite faster than CBC. 不过,据我所知,GCM模式应该比CBC快得多。 I don't know why but looks like there isn't an openssl benchmark right for GCM, but even assuming they are performing identically I am missing a factor 3. 我不知道为什么但看起来没有一个用于GCM的openssl基准权利,但即使假设它们表现相同,我也错过了一个因素3。

UPDATE 2 Checked this page: http://elinux.org/RPi_Performance#OpenSSL . 更新2检查此页面: http//elinux.org/RPi_Performance#OpenSSL Looks like I am missing 10 MB/s more. 看起来我缺少10 MB / s以上。 Grand total: 27 MB/s with AES/CBC (as it should be) vs 6 MB/s with AES/GCM (as it actually is). 总计:使用AES / CBC(应该是)为27 MB / s,使用AES / GCM为6 MB / s(实际上是这样)。

Your Intel CPU has dedicated Hardware support using the AESNI extension. 您的Intel CPU使用AESNI扩展提供专用硬件支持。 If you compile without that, you will get about 250MB/s That difference in performance sounds reasonable. 如果你在没有它的情况下进行编译,你将获得大约250MB / s的性能差异听起来合理。 (And how much GHz any CPU has tells you nothing about the performance, except if it is exactly the same CPU type just with different clock) (并且任何CPU有多少GHz都没有告诉你性能,除非它只是使用不同的时钟完全相同的CPU类型)

If you haven't already accounted for it, why wouldn't the factor of 3 be explained by the factor of roughly 3 difference in processing power? 如果你还没有考虑到它,那为什么不能用3大小的处理能力差异来解释因子3?

Raspberry Pi 2 has a 900Mhz processor, and a typical i7 processor has 2.8Ghz, which results the in the Pi having roughly a third of the processing power. Raspberry Pi 2具有900Mhz处理器,典型的i7处理器具有2.8Ghz,这使得Pi具有大约三分之一的处理能力。

Also, I don't know where you're getting the conclusion that GCM should be faster than CBC under these circumstances. 此外,我不知道在这些情况下GCM应该比CBC更快的结论。 CBC doesn't provide authentication, so that alone should make GCM measurably slower (though perhaps not the factor of 4 you're seeing). CBC不提供身份验证,因此单独应该使GCM显着降低(尽管可能不是您所看到的4倍)。

Of course, that goes out the window when you bring in multiple cores, given that CBC cannot be parallelized and GCM can. 当然,如果CBC无法并行化并且GCM能够并行,那么当您引入多个内核时,这就会消失。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM