title: Ridiculously poor performance with OpenSSL AES/GCM on Raspberry PI 2
body: <p>I developed a simple C++ program to benchmark the performance of OpenSSL AES/GCM calls to the EVP interface. 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. I am using incremental 4-bytes initialization vectors.</p>
  
  <p>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. That's 1 GB/s encryption speed. 8 GB/s (more or less) if we make use of all the cores simultaneously.</p>
  
  <p>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. That's more or less 6 MB/s, on a single core.</p>
  
  <p>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. So before assuming that Raspberry PI 2 is <em>really</em> that bad, I wanted to check if those parameters are reasonable.</p>
  
  <p>Has anybody done some kind of benchmark on that? Are 6 MB/s encryption speed reasonable on a Raspberry? Or am I doing something wrong?</p>
  
  <p>(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?)</p>
  
  <p><strong>UPDATE 1</strong>: I did <code>openssl -evp speed aes-256-cbc</code> on both my Macbook and the Raspberry. </p>
  
  <p>On the Macbook:</p>
  
  <pre><code>type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
  aes-256-cbc     534591.95k   564057.62k   566522.81k   570717.87k   574876.33k
  </code></pre>
  
  <p>On the Raspberry:</p>
  
  <pre><code>type             16 bytes     64 bytes    256 bytes   1024 bytes   8192 bytes
  aes-256-cbc      14288.53k    16653.74k    17165.31k    17298.43k    17337.00k
  </code></pre>
  
  <p>That's still a factor 33, but the Intel processor can make use of hardware accelerated AES calls. Still, as far as I know GCM mode should be quite faster than 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.</p>
  
  <p><strong>UPDATE 2</strong> Checked this page: <a href="http://elinux.org/RPi_Performance#OpenSSL">http://elinux.org/RPi_Performance#OpenSSL</a>. Looks like I am missing 10 MB/s more. Grand total: 27 MB/s with AES/CBC (as it should be) vs 6 MB/s with AES/GCM (as it actually is).</p>