Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH 00/11] Migrate x86_64 AES-GCM code into library
@ 2026-11-29 20:02 Eric Biggers
  2026-11-29 20:02 ` [PATCH 01/11] crypto: aes - Flush dcache in CBC-CTS and XTS linear fast paths Eric Biggers
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Eric Biggers @ 2026-11-29 20:02 UTC (permalink / raw)
  To: linux-crypto
  Cc: Ard Biesheuvel, Jason A . Donenfeld, Herbert Xu, x86,
	Antonio Quartulli, Eric Biggers

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


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-29 20:04 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 20:02 [PATCH 00/11] Migrate x86_64 AES-GCM code into library Eric Biggers
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox