The performance test on the AES modes

Enterprise PostgreSQL Solutions

Leave a Comment

The performance test on the AES modes

After introducing the difference between the AES modes, in this document, I will put the results about the AES modes performance.
The following tests just use one core CPU.

AES-NI:The Advanced Encryption Standard Instruction Set (or Intel Advanced Encryption Standard New Instructions, AES-NI for short) is an extension of the x86 instruction set architecture for Intel and AMD microprocessors, presented by Intel in March 2008. [1] The purpose of this instruction set is to improve the speed at which applications use the Advanced Encryption Standard (AES) to perform encryption and decryption.

OpenSSL: OpenSSL is a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library. There is much Standard encryption algorithm in OpenSSL. We will use OpenSSL to test the AES modes performance.

How to get the performance resultsYou can refer to the official document:https://www.openssl.org/docs/manmaster/man1/speed.html.

Here we will use the following command to do the performance test.
With AES-NI enabled:
openssl speed -elapsed -evp aes-128-cbc
With disabled AES-NI
OPENSSL_ia32cap=”~0x200000200000000″ openssl speed -elapsed -evp aes-128-cbc

Performance test server configuration
  • CPU : i5 8400 (has the AES-NI)
  • Memory : 16G DDR4
  • Disk : Inter SSD 1T
  • OS : CentOS Linux release 7.6.1810 (Core)
  • OpenSSL :  OpenSSL 1.0.2k

The tests for each input data size was performed for 3 seconds, for the ciphers that we were interested in.

Five modes with 128-bits key, AES-NI enabled and disabled, encryption(the first row means OpenSSL will use ase-ecb with 128-bits key to encrypted 1371968.28k data in 3 seconds):

modeAES-NI enabled16 bytes64 bytes256 bytes1024 bytes8192 bytes
aes-128-ecbYes1371968.28k5423199.85k6373315.16k6185025.88k6337997.48k
aes-128-ecbNo393519.33k426293.50k433427.54k436615.85k437493.76k
aes-128-cbcYes1333548.38k1458045.21k1504091.39k1512224.43k1514831.87k
aes-128-cbcNo361409.25k402460.22k413829.03k417298.43k418106.03k
aes-128-cfbYes973355.89k972457.98k972651.01k973300.05k973474.47k
aes-128-cfbNo347312.88k354232.43k353715.29k355110.91k355467.26k
aes-128-ofbYes1154166.02k1327641.05k1319713.45k1317734.74k1317076.99k
aes-128-ofbNo354372.10k388733.06k396086.53k400353.62k401219.58k
aes-128-ctrYes1042913.12k2683962.99k5098530.65k6004447.23k6303976.11k
aes-128-ctrNo152004.41k166371.33k575773.78k636239.53k656258.39k

In the result, we can get the ECB is the fastest mode, but it is not be recommended, we suggest to use the CTR mode in the PostgreSQL to encrypt. After 1024 bytes, the speed is nearly the same, so we suggest to use the 8192 bytes as a unit to encrypt in the PostgreSQL.At the same time, we can know that AES-NI will have up to 10 times the performance gap between opening and closing.

After comparing the different modes in the horizontal direction, we will perform performance tests with different key lengths in the same mode. As the above test knows, we will use ctr mode encryption, so here we only test the performance comparison of different key lengths of ctr mode.CTR mode:

mode16 bytes64 bytes256 bytes1024 bytes8192 bytes
aes-128-ctr1042913.12k2683962.99k5098530.65k6004447.23k6303976.11k
aes-192-ctr901375.74k2573741.65k4438022.31k5061482.15k5259031.89k
aes-256-ctr827355.85k2355164.99k3671733.59k4291537.92k4505072.98k

In the results, we can know that as the key length increases, the encryption speed will also decrease. However, it is well known that as keys grow, security increases. How to balance the relationship between the two will be investigated later. But we can know that if you think speed is more important than security, you can use a 128-bit key, otherwise, you can use a 256-bit key.

Five modes with 128-bits key, AES-NI enabled, encryption and decryption

modeencryption16 bytes64 bytes256 bytes1024 bytes8192 bytes
aes-128-ecbencryption1371968.28k5423199.85k6373315.16k6185025.88k6337997.48k
aes-128-ecbdecryption1369603.95k5093928.19k6346512.98k6358113.96k6345064.45k
aes-128-cbcencryption1333548.38k1458045.21k1504091.39k1512224.43k1514831.87k
aes-128-cbcdecryption1310567.29k4620511.15k5941994.67k6256102.40k6325758.63k
aes-128-cfbencryption973355.89k972457.98k972651.01k973300.05k973474.47k
aes-128-cfbdecryption891813.84k955344.41k954807.47k956417.71k957098.67k
aes-128-ofbencryption1154166.02k1327641.05k1319713.45k1317734.74k1317076.99k
aes-128-ofbdecryption1040775.34k1316325.53k1316540.33k1316523.35k1316489.90k
aes-128-ctrencryption1042913.12k2683962.99k5098530.65k6004447.23k6288979.29k
aes-128-ctrdecryption999478.82k2498636.14k4890340.35k5921968.13k6288979.29k

Except for cbc mode, the encryption and decryption speed of all modes is almost the same.


In the end, comparing the encryption and decryption speeds of different modes, the encryption speed of different block sizes, the encryption speed of different key lengths, and the encryption speed of turning AES-NI on and off, I recommend using CTR mode for data encryption in PostgreSQL.

Leave a Reply