wolfSSL v5.9.4: What AVX512 Buys You

On a CPU with AVX512, wolfSSL v5.9.4 runs most of its bulk ciphers about twice as fast as the AVX2 code it already had. ChaCha20-Poly1305 gets up to 3.1 times faster, and the post-quantum algorithms speed up by 1.2 to 2.7 times.

v5.9.4 adds 512-bit assembly for 12 algorithms: AES (ECB, CBC, CTR, GCM, GCM-SIV, XTS), ChaCha20, Poly1305, ChaCha20-Poly1305, X25519, Ed25519, ML-KEM, ML-DSA and FrodoKEM. You don’t have to do anything to use it. The library checks the CPU when it starts and picks the AVX512 code on its own if the CPU supports it.

We built v5.9.4 twice from the same source on an AMD Ryzen 9 9950X3D (Zen 5): once as normal, and once with the AVX512 code compiled out. Then we timed both builds with the wolfCrypt benchmark. All the numbers below come from those runs.

How we measured

Both builds use the same source, compiler and options. The only difference is whether the AVX512 code is compiled in. Without it, wolfSSL falls back to its AVX2/AES-NI assembly, so the comparison is AVX512 against wolfSSL’s own fast x86_64 code, not against plain C.

CPU AMD Ryzen 9 9950X3D, 16 cores, up to 5.76 GHz (Zen 5)
AVX512 extensions F, BW, DQ, VL, IFMA, VBMI, VBMI2, plus VAES and VPCLMULQDQ
Compiler GCC 15.2.0, -O2
wolfSSL v5.9.4, static library
Configure –enable-intelasm –enable-sp-asm –enable-all-crypto –enable-all-quantum-crypto –enable-aesxts –enable-aesgcm-siv –enable-experimental –enable-frodokem
Baseline build the same, plus CPPFLAGS=-DNO_AVX512_SUPPORT
Benchmark wolfcrypt/benchmark/benchmark, 1 MiB blocks, at least 1 s per test, pinned to one core with taskset -c 4

We ran each build twice and kept the better result for each test. Any test whose two runs differed by more than 2% was run five more times on each build, alternating between builds, and we report the median of those runs.

All numbers are for one core. Throughput is in MB/s and public-key results are in operations per second. Higher is better in both cases.

Results by algorithm

AES-ECB, AES-CBC and AES-CTR
AES-ECB, AES-CTR and AES-CBC decryption run 1.8 to 2.2 times faster. VAES with 512-bit registers works on four AES blocks per instruction where AVX2 handles two, and the AVX512 code keeps several of those registers busy at the same time.

AES-CBC encryption doesn’t get much faster with AVX512. In CBC, each block is XORed with the ciphertext of the block before it before it is encrypted. So a block can’t start until the previous block is done, and the speed depends on how long one AES block takes, not on how many blocks fit in a register. Wider registers have nothing to run in parallel. This holds for any AES implementation.

Mode AVX2 (MB/s) AVX512 (MB/s) Speedup
AES-128-ECB encrypt 31,631 58,596 1.85x
AES-256-ECB encrypt 21,556 42,021 1.95x
AES-128-CTR 23,976 52,144 2.17x
AES-256-CTR 16,905 36,330 2.15x
AES-128-CBC decrypt 30,084 55,985 1.86x
AES-256-CBC decrypt 20,803 40,769 1.96x

AES-GCM
AES-GCM, the default cipher for most TLS 1.3 connections, runs 2.1 to 2.35 times faster and reaches 29.7 GB/s on one core with AES-128. The AVX512 code encrypts with VAES and computes GHASH with 512-bit VPCLMULQDQ in the same loop. The streaming API (WOLFSSL_AESGCM_STREAM) gets the same speedup.

Operation AVX2 (MB/s) AVX512 (MB/s) Speedup
AES-128-GCM encrypt 13,122 28,395 2.16x
AES-128-GCM decrypt 13,740 29,733 2.16x
AES-256-GCM encrypt 10,838 25,445 2.35x
AES-256-GCM decrypt 11,941 25,770 2.16x
AES-256-GCM stream encrypt 10,866 25,407 2.34x

AES-GCM-SIV
AES-GCM-SIV (RFC 8452), the nonce-misuse-resistant AEAD, runs 1.84 to 1.91 times faster. v5.9.4 has AVX512 versions of both its CTR keystream and its POLYVAL hash.

Operation AVX2 (MB/s) AVX512 (MB/s) Speedup
AES-128-GCM-SIV encrypt 8,138 15,008 1.84x
AES-128-GCM-SIV decrypt 8,126 14,944 1.84x
AES-256-GCM-SIV encrypt 7,254 13,862 1.91x
AES-256-GCM-SIV decrypt 7,238 13,828 1.91x

AES-XTS
AES-XTS, the disk and storage encryption mode, runs 2.1 times faster in both directions. It goes from about 23 GB/s to 49 GB/s on one core, with the tweak computed in 512-bit registers. The streaming XTS API uses the same code.

Operation AVX2 (MB/s) AVX512 (MB/s) Speedup
AES-XTS encrypt 23,173 48,924 2.11x
AES-XTS decrypt 23,192 49,071 2.12x

ChaCha20
ChaCha20 runs 2.43 times faster, going from 3.99 GB/s to 9.69 GB/s. The AVX512 code generates 16 ChaCha blocks at a time across 512-bit registers. It uses the AVX512 rotate instruction (vprold), which does in one step what AVX2 needs a shuffle or a shift-and-or for. Data shorter than a full 512-bit batch goes through an AVX512VL path that uses 256-bit registers.

Operation AVX2 (MB/s) AVX512 (MB/s) Speedup
ChaCha20 3,993 9,686 2.43x

Poly1305
Poly1305 on its own runs 1.93 times faster, reaching 18.1 GB/s. On CPUs with AVX512 IFMA, the code uses vpmadd52luq/vpmadd52huq, which multiply 52-bit numbers and accumulate in one instruction, and works on 8 message blocks per step. CPUs with AVX512 but no IFMA use a 512-bit path built on 32-bit multiplies instead.

Operation AVX2 (MB/s) AVX512 (MB/s) Speedup
Poly1305 9,376 18,107 1.93x

ChaCha20-Poly1305
The ChaCha20-Poly1305 AEAD gets the biggest speedup of any algorithm here: 3.09 times faster, going from 2.79 GB/s to 8.64 GB/s. Instead of encrypting and then hashing in two passes, v5.9.4 does both in one pass. The 16-block ChaCha20 and an 8-way IFMA Poly1305 run interleaved over 1 KiB chunks, so the hash work fits into the gaps in the cipher work. Encryption, the _ex API and the streaming API all take this path.

The one-shot wc_ChaCha20Poly1305_Decrypt() is slower, at 2.25 times faster than AVX2. It checks the tag before decrypting anything, so no plaintext is released if the tag is wrong. That takes two passes over the data instead of one. Each pass is still AVX512.

API AVX2 (MB/s) AVX512 (MB/s) Speedup
Encrypt (one-shot) 2,792 8,637 3.09x
Encrypt_ex / Decrypt_ex 2,793 8,643 3.09x
Streaming 2,793 8,644 3.09x
Decrypt (one-shot, tag checked first) 2,794 6,291 2.25x

The single-pass kernel is used on every CPU with AVX512 IFMA. There’s also a 512-bit two-pass variant for Intel CPUs that slow their clock under heavy AVX512 load. You can force either path with WOLFSSL_CHACHA20_POLY1305_FUSED_ALWAYS / _NEVER and WOLFSSL_CHACHA20_POLY1305_FUSED_IFMA_ALWAYS / _NEVER.

X25519
X25519 key agreement, the most common key exchange in TLS 1.3, runs 1.36 times faster: 94,217 agreements per second against 69,285. The AVX512 IFMA code holds field elements in 52-bit limbs and multiplies them with vpmadd52*. On this CPU it takes the variant that also uses AVX512DQ.

Key generation stays the same speed. By default, wolfSSL generates X25519 keys with Ed25519’s precomputed fixed-base table, which is already fast. If you build with WOLFSSL_CURVE25519_NOT_USE_ED25519, key generation uses an AVX512 IFMA base-point routine instead.

Operation AVX2 (ops/s) AVX512 (ops/s) Speedup
X25519 agree 69,285 94,217 1.36x
X25519 key gen 187,508 185,674 0.99x

Ed25519
Ed25519 verification runs 1.48 times faster: 82,718 verifies per second against 55,724. A verify computes two scalar multiplications at once, and v5.9.4 does that step (ge_double_scalarmult_vartime) with AVX512 IFMA. Signing and key generation only use the fixed-base table, so their speed doesn’t change.

Operation AVX2 (ops/s) AVX512 (ops/s) Speedup
Ed25519 verify 55,724 82,718 1.48x
Ed25519 sign 169,344 167,841 0.99x
Ed25519 key gen 182,480 180,815 0.99x

ML-KEM (FIPS 203)
ML-KEM, the post-quantum key exchange now used in hybrid TLS 1.3 groups, runs 1.3 to 2.2 times faster. The bigger parameter sets gain the most. ML-KEM-1024 key generation goes from 158,545 to 348,894 operations per second.

In v5.9.4, ML-KEM key generation, encapsulation and decapsulation each run as a single AVX512 assembly routine. That covers the NTT and inverse NTT, basemul, CBD noise sampling, compression and decompression, and byte encoding and decoding. It also covers rejection sampling, which on CPUs with VBMI/VBMI2 uses byte permutes and compress-stores. The SHAKE-128/SHAKE-256 work that expands the matrix and noise seeds runs eight Keccak states side by side in 512-bit registers.

Parameter set Key gen (ops/s, AVX2 → AVX512) Encap (ops/s) Decap (ops/s)
ML-KEM-512 406,558 → 564,693 (1.39x) 362,674 → 541,488 (1.49x) 241,476 → 314,143 (1.30x)
ML-KEM-768 235,354 → 427,003 (1.81x) 227,970 → 414,103 (1.82x) 158,401 → 233,082 (1.47x)
ML-KEM-1024 158,545 → 348,894 (2.20x) 148,643 → 304,059 (2.05x) 108,943 → 176,786 (1.62x)

At about 2.3 to 5.7 µs per operation, ML-KEM-768, the parameter set used in the X25519MLKEM768 hybrid, now costs a TLS handshake roughly what X25519 costs.

ML-DSA (FIPS 204)
ML-DSA, the post-quantum signature scheme, runs 1.56 to 2.06 times faster across key generation, signing and verification. ML-DSA-87 doubles in both key generation and signing. The gain grows with the parameter set because the bigger sets spend more of their time on polynomial arithmetic.

The AVX512 code includes the NTT and inverse NTT, polynomial and vector multiplies, decompose, make-hint and use-hint, the norm check, rejection sampling, and every pack and unpack routine. As in ML-KEM, the matrix and mask are expanded with eight-way SHAKE.

Parameter set Key gen (ops/s, AVX2 → AVX512) Sign (ops/s) Verify (ops/s)
ML-DSA-44 80,188 → 148,476 (1.85x) 27,344 → 42,631 (1.56x) 73,743 → 121,714 (1.65x)
ML-DSA-65 46,440 → 90,343 (1.95x) 17,400 → 31,667 (1.82x) 45,754 → 83,194 (1.82x)
ML-DSA-87 30,133 → 62,134 (2.06x) 14,526 → 28,874 (1.99x) 29,503 → 56,309 (1.91x)

FrodoKEM
FrodoKEM, the conservative lattice KEM based on plain (unstructured) LWE, gets 2.4 to 2.7 times faster with SHAKE and about 1.2 times faster with AES. The AVX512 code covers its matrix multiplications, error sampling and matrix addition. The SHAKE variants also generate the large public matrix A with eight-way Keccak, which is where most of their gain comes from. In the AES variants, A is generated with AES, and the AVX2 code already used AES-NI there, so they gain less. FrodoKEM-976-AES key generation runs at one of two speeds on both builds, and which one a run gets changes from run to run. Its speedup therefore ranges from 1.06x to 1.24x; the table shows the median of 9 runs. The ephemeral (eFrodoKEM) variants perform the same as the standard ones, so we leave them out of the table.

Variant Key gen (ops/s, AVX2 → AVX512) Encap (ops/s) Decap (ops/s)
FrodoKEM-640-SHAKE 2,072 → 4,996 (2.41x) 1,958 → 4,629 (2.36x) 1,980 → 4,794 (2.42x)
FrodoKEM-976-SHAKE 939 → 2,379 (2.53x) 894 → 2,250 (2.52x) 904 → 2,345 (2.59x)
FrodoKEM-1344-SHAKE 505 → 1,338 (2.65x) 494 → 1,280 (2.59x) 499 → 1,321 (2.65x)
FrodoKEM-640-AES 10,525 → 12,410 (1.18x) 8,682 → 10,384 (1.20x) 9,340 → 11,302 (1.21x)
FrodoKEM-976-AES 5,634 → 6,305 (1.12x) 4,361 → 5,228 (1.20x) 4,722 → 5,773 (1.22x)
FrodoKEM-1344-AES 2,961 → 3,474 (1.17x) 2,583 → 3,108 (1.20x) 2,753 → 3,372 (1.22x)

At a glance

[embed: node/bd022647-6947]

Every algorithm with AVX512 code in v5.9.4 is at least 1.36 times faster than its AVX2 version. Ten of the 14 operations shown are at least 1.9 times faster. The two elliptic-curve results gain least, because each scalar multiplication has to run one step after another.

Also new: SHA-3 is 1.45x faster on AMD

On this AMD CPU, SHA-3 and SHAKE are 1.45 times faster in v5.9.4 than in v5.9.2, even though v5.9.4 has no AVX512 code for a single SHA-3 hash. The gain comes from choosing a better Keccak routine for the CPU.

v5.9.2 used its AVX2 Keccak on any CPU with AVX2. That is the faster choice on Intel, but on AMD Zen the AVX2 version is slower than the BMI2 one. v5.9.4 now uses AVX2 only on Intel and the BMI2 version everywhere else.

Algorithm v5.9.2 (MB/s) v5.9.4 (MB/s) Speedup
SHA3-224 589 854 1.45x
SHA3-256 559 809 1.45x
SHA3-384 427 622 1.46x
SHA3-512 295 431 1.46x
SHAKE128 690 997 1.45x
SHAKE256 559 808 1.45x

Both versions were built with –enable-intelasm –enable-sha3 –enable-shake128 –enable-shake256 and benchmarked the same way as above. To confirm the cause, we built v5.9.4 with WOLFSSL_SHA3_AVX2, which forces the AVX2 Keccak on any CPU. It ran at the same speed as v5.9.2. Turning AVX512 on or off made no difference to these numbers. Intel CPUs use AVX2 in both versions, so we expect little change there, but we couldn’t test that on this machine. WOLFSSL_SHA3_NO_AVX2 forces the BMI2 version on any CPU.

Anything that hashes with SHA-3 or SHAKE benefits, including HMAC-SHA3, KMAC, cSHAKE, and SLH-DSA with SHAKE parameters.

Getting the speedup

Build with Intel assembly turned on, and wolfSSL uses the AVX512 code on any CPU that supports it:

./configure --enable-intelasm        # or --enable-all-asm
make && sudo make install
  • Detected at run time. wolfSSL reads CPUID when it starts and checks that the operating system saves the 512-bit registers (XCR0). It then picks AVX512, AVX2 or the baseline code for each algorithm. One binary runs on every x86_64 machine and uses the fastest code that machine supports.
  • CPU extensions used. AES needs AVX512F plus VAES/VPCLMULQDQ. ML-KEM, ML-DSA and FrodoKEM need AVX512F+BW, and use VBMI/VBMI2 if present. Poly1305, X25519 and Ed25519 need AVX512 IFMA for their fastest paths. Recent AMD Zen 4/Zen 5 and Intel Ice Lake/Sapphire Rapids and newer server CPUs have all of these.
  • Turning it off. Define NO_AVX512_SUPPORT to compile the AVX512 code out. wolfSSL then uses its AVX2 code, which is the baseline in this post.
  • No change in v5.9.4. SHA-2 and standalone SHA-3/SHAKE have no AVX512 path in v5.9.4 (SHA-3 is still faster on AMD, as described above). GMAC through the 4-bit table and AES Key Wrap are also unchanged.

If your x86_64 servers or appliances have AVX512, upgrading to wolfSSL v5.9.4 is an easy speedup. TLS 1.3 record encryption with AES-GCM or ChaCha20-Poly1305 runs 2 to 3 times faster, and post-quantum handshakes with ML-KEM and ML-DSA take about half as long, without changing your application. For help or a commercial license, contact support@wolfssl.com.

If you have questions about any of the above, please contact us at facts@wolfssl.com or +1 425 245 8247.

Download wolfSSL Now