From: Eric Biggers <ebiggers@kernel.org>
To: linux-crypto@vger.kernel.org
Cc: Ard Biesheuvel <ardb@kernel.org>,
"Jason A . Donenfeld" <Jason@zx2c4.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
x86@kernel.org, Antonio Quartulli <antonio@mandelbit.com>,
Eric Biggers <ebiggers@kernel.org>
Subject: [PATCH 00/11] Migrate x86_64 AES-GCM code into library
Date: Sun, 29 Nov 2026 12:02:34 -0800 [thread overview]
Message-ID: <20261129200245.146503-1-ebiggers@kernel.org> (raw)
This series is targeting libcrypto-next. It can also be retrieved from:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/ebiggers/linux.git aes-gcm-x86-v1
This series migrates the x86_64 optimized AES-GCM code into lib/crypto/,
fully optimizing the AES-GCM library functions on x86_64.
(As usual, it also fixes the longstanding issue where the
architecture-optimized code was disabled by default. The library always
enables optimizations, as long as the algorithm is enabled at all.)
It's divided into several parts:
- Patches 1-2 fix a couple existing bugs.
- Patches 3-4 add architecture hooks for one-shot AES-GCM and add a
linear fast path to AES-GCM. These are needed for parity with the
existing short message optimizations used in aesni-intel_glue.c.
- Patches 5-7 replace the existing, not very well optimized GHASH and
POLYVAL library code with new highly optimized code. It's roughly
based on the GHASH code in the three AES-GCM assembly files, and like
the AES-GCM code there are three versions for different CPU feature
sets: pclmul, vpclmul+avx2, and vpclmul+avx512.
This was a prerequisite for migrating the AES-GCM code (since the
AES-GCM library uses the GHASH library, including its key format).
But I've gone a bit further and unified the GHASH and POLYVAL code as
well, with the same assembly macros generating support for both.
GHASH and POLYVAL are nearly identical, so this makes a lot of sense.
- Patches 8-10 migrate the x86_64 optimized AES-GCM code into the
library, one patch per assembly file.
- Patch 11 deletes the aesni-intel module (which no longer has any
functionality left in it) and keeps CRYPTO_AES_NI_INTEL only as a
transitional symbol that causes AES-XTS support to be selected.
On long lengths, the KUnit benchmarks of the crypto library code on AMD
Ryzen 9 9950X (Zen 5) show the following performance improvements:
GHASH: 1928 MB/s => 39348 MB/s
POLYVAL: 10689 MB/s => 39020 MB/s
AES-GCM: 1747 MB/s => 26937 MB/s
Patches 5-10 contain more library benchmark results.
AES-GCM crypto_aead performance did not significantly change (except for
very long associated data lengths without VAES, which got much faster).
HCTR2 crypto_skcipher performance got faster due to the POLYVAL speedup.
AI disclosure: AI coding tools were used to help write, revise, and
review this patchset. But as usual it went through a lot of iterations,
with extensive manual review and editing (and prompting) to get things
the way I wanted.
Eric Biggers (11):
crypto: aes - Flush dcache in CBC-CTS and XTS linear fast paths
lib/crypto: gf128hash: Link libgf128hash before libaes
lib/crypto: aes-gcm: Add one-shot AES-GCM arch hooks
crypto: aes - Add linear fast path for AES-GCM
lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with PCLMULQDQ
and AVX
lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with VPCLMULQDQ
and AVX2
lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with VPCLMULQDQ
and AVX512
lib/crypto: x86/aes-gcm: Migrate AES-NI optimized code into library
lib/crypto: x86/aes-gcm: Migrate VAES+AVX2 optimized code into library
lib/crypto: x86/aes-gcm: Migrate VAES+AVX512 optimized code into
library
crypto: x86/aesni-intel - Remove empty module
Documentation/filesystems/fscrypt.rst | 2 -
arch/x86/crypto/Kconfig | 25 -
arch/x86/crypto/Makefile | 6 -
arch/x86/crypto/aesni-intel_glue.c | 888 ------------------
crypto/Kconfig | 9 +
crypto/aes.c | 213 ++++-
include/crypto/gf128hash.h | 48 +-
lib/crypto/Kconfig | 2 +-
lib/crypto/Makefile | 64 +-
lib/crypto/aes.c | 97 +-
.../crypto/x86}/aes-gcm-aesni-x86_64.S | 414 +++-----
.../crypto/x86}/aes-gcm-vaes-avx2.S | 419 ++-------
.../crypto/x86}/aes-gcm-vaes-avx512.S | 374 ++------
lib/crypto/x86/aes.h | 352 ++++++-
lib/crypto/x86/gf128hash-cpu.h | 54 ++
lib/crypto/x86/gf128hash-pclmul.S | 559 +++++++++++
lib/crypto/x86/gf128hash-vpclmul-avx2.S | 537 +++++++++++
lib/crypto/x86/gf128hash-vpclmul-avx512.S | 516 ++++++++++
lib/crypto/x86/gf128hash.h | 322 +++++--
lib/crypto/x86/ghash-pclmul.S | 127 ---
lib/crypto/x86/polyval-pclmul-avx.S | 319 -------
21 files changed, 2933 insertions(+), 2414 deletions(-)
delete mode 100644 arch/x86/crypto/aesni-intel_glue.c
rename {arch/x86/crypto => lib/crypto/x86}/aes-gcm-aesni-x86_64.S (75%)
rename {arch/x86/crypto => lib/crypto/x86}/aes-gcm-vaes-avx2.S (69%)
rename {arch/x86/crypto => lib/crypto/x86}/aes-gcm-vaes-avx512.S (74%)
create mode 100644 lib/crypto/x86/gf128hash-cpu.h
create mode 100644 lib/crypto/x86/gf128hash-pclmul.S
create mode 100644 lib/crypto/x86/gf128hash-vpclmul-avx2.S
create mode 100644 lib/crypto/x86/gf128hash-vpclmul-avx512.S
delete mode 100644 lib/crypto/x86/ghash-pclmul.S
delete mode 100644 lib/crypto/x86/polyval-pclmul-avx.S
base-commit: 7845a3cc6e006f849ff882737afbd46584168eac
--
2.56.1
next reply other threads:[~2026-11-29 20:04 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 20:02 Eric Biggers [this message]
2026-11-29 20:02 ` [PATCH 01/11] crypto: aes - Flush dcache in CBC-CTS and XTS linear fast paths Eric Biggers
2026-11-29 20:02 ` [PATCH 02/11] lib/crypto: gf128hash: Link libgf128hash before libaes Eric Biggers
2026-11-29 20:02 ` [PATCH 03/11] lib/crypto: aes-gcm: Add one-shot AES-GCM arch hooks Eric Biggers
2026-11-29 20:02 ` [PATCH 04/11] crypto: aes - Add linear fast path for AES-GCM Eric Biggers
2026-11-29 20:02 ` [PATCH 05/11] lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with PCLMULQDQ and AVX Eric Biggers
2026-11-29 20:02 ` [PATCH 06/11] lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with VPCLMULQDQ and AVX2 Eric Biggers
2026-11-29 20:02 ` [PATCH 07/11] lib/crypto: x86/gf128hash: Optimize GHASH and POLYVAL with VPCLMULQDQ and AVX512 Eric Biggers
2026-11-29 20:02 ` [PATCH 08/11] lib/crypto: x86/aes-gcm: Migrate AES-NI optimized code into library Eric Biggers
2026-11-29 20:02 ` [PATCH 09/11] lib/crypto: x86/aes-gcm: Migrate VAES+AVX2 " Eric Biggers
2026-11-29 20:02 ` [PATCH 10/11] lib/crypto: x86/aes-gcm: Migrate VAES+AVX512 " Eric Biggers
2026-11-29 20:02 ` [PATCH 11/11] crypto: x86/aesni-intel - Remove empty module Eric Biggers
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261129200245.146503-1-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=Jason@zx2c4.com \
--cc=antonio@mandelbit.com \
--cc=ardb@kernel.org \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox