Will ChaCha20 be faster than in-built hardware support for AES?
Do we have any comparison document where it shows performance(cipher speed) over various resolutions starting from 576i to 4K over various bitrate from 2 Mbps to 20 Mbps?
OpenSSL has a speed command. If you consider that it is regularly patched against the founded insecurities, it is always a good base to compare ciphers.
The below is the performance comparison of the AES-256-GCM, AES(NI)-256-GCM, ChaCha20-Poly1305 (OpenSSL always use ChaCha with 256-bit key) on my Intel I7- 7. gen
type |
16 bytes |
64 bytes |
256 bytes |
1024 bytes |
8192 bytes |
16384 bytes |
chacha20 |
367799.29k |
702973.21k |
1416296.19k |
2988179.46k |
3125635.75k |
3059062.10k |
aes-256-ctr |
185286.74k |
188173.99k |
210752.17k |
211406.17k |
202839.38k |
206531.24k |
aes-256-ctr(NI) |
504215.69k |
1744835.29k |
2940341.50k |
3477252.44k |
3773789.53k |
3864182.78k |
chacha20-poly1305 |
259679.98k |
511848.38k |
1004036.78k |
1912721.38k |
2046227.80k |
1997160.45k |
aes-256-gcm |
101014.33k |
124328.36k |
129647.19k |
134264.83k |
133802.67k |
134146.73k |
aes-256-gcm (NI) |
410064.16k |
1119080.51k |
2036770.90k |
2994741.59k |
3582448.98k |
3772132.01k |
Run commands
$openssl speed -evp chacha20
$OPENSSL_ia32cap="~0x200000200000000" openssl speed -elapsed -evp aes-256-ctr
$openssl speed -evp aes-256-ctr
$openssl speed -evp chacha20-poly1305
$OPENSSL_ia32cap="~0x200000200000000" openssl speed -elapsed -evp aes-256-gcm
$openssl speed -evp aes-256-gc
Can ChaCha20 provide better security over AES over the years?
That depends on the key sizes. OpenSSL always uses ChaCha20 with 256-bit key sizes when compared to AES-256 we don't expect any problem on both ciphers even the quantum computers are built.
128-bit key size is problematic in two ways; multi-target attack and quantum attacks. That is why we prefer 256-bit key sizes. That mitigates all.
Also see, below;
Now, how feasible it is to move from AES to ChaCha20? What are the pros and cons of this?
Mode of Operation
We don't use AES as it is since it is primitive, however, ChaCha20 is designed in CTR mode. We need a mode of operation for AES, too. The most common ones AES-GCM and ChaCha20-Poly1305.
Poly1305 uses $\mathbb Z/(2^{130} - 5)\mathbb Z$ and is easy to implement in software without timing side channels.
GCM uses GHASH and that uses arithmetic in the binary field $\operatorname{GF}(2^{128})$. It has hardware support, if you don't use hardware, it will be slow in software without timing side channels.
There are technical differences, too.
PRF vs PRP
- AES is a pseudorandom permutation (PRP) family of 128-bit blocks.
- ChaCha is a pseudorandom function (PRF) family from 256-bit inputs to 512-bit outputs.
In most of the protocols, due to the AES is PRP, it is unsafe to encrypt more than $2^{64}$ blocks, however, ChaCha20 has no practical limit on this.
We can say ChaCha20 is better for the CTR mode than AES. Note that ChaCha20 is using the CTR mode by design.
Key schedule
AES key schedule has a cost to generate the subkeys while in ChaCha20 it has no cost. So if your protocol requires lots of new keys, ChaCha20 is better than AES.
Nonce
There is a variant of ChaCha20 that is XChaCha20 that uses 192-bit nonces. This is better than AES-GCM on generating random nonces. The $(key,IV)$ pair reuse problem is almost impractical on randomly generated nonces on XChaCha20, however, on should stop way earlier than $2^{48}$ random nonces on AES-GCM due to the birthday bound. If you stick to ChaCha20 then it has 128-bit nonces, too, the same problem.
One can use nonce-misresistant AES-GCM-SIV to eliminate the nonce reuse problem. This brings additional performance cost, though.
Side-channel
Since ChaCha20 uses ARX design that helps easy to implement against timing side-channel attacks. As one can see from the above table, the secure software implementation of AES is terribly slow. ChaCha20 is around %20 slower compared to AES-NI-256.
Number of round
AES-256 has 14 rounds and ChaCha20 has 20. The attack on the reduced rounds that is cheaper than brute-force seems around 7 for both ciphers. This means that ChaCha20 has a better security margin than AES.
In short, go for XChaCha20-Poly1305 where available. AES-GCM has many pitfalls.