]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: x86/aegis128 - optimize length block preparation using SSE4.1
authorEric Biggers <ebiggers@google.com>
Thu, 17 Oct 2024 00:00:46 +0000 (17:00 -0700)
committerHerbert Xu <herbert@gondor.apana.org.au>
Mon, 28 Oct 2024 10:33:10 +0000 (18:33 +0800)
Start using SSE4.1 instructions in the AES-NI AEGIS code, with the first
use case being preparing the length block in fewer instructions.

In practice this does not reduce the set of CPUs on which the code can
run, because all Intel and AMD CPUs with AES-NI also have SSE4.1.

Upgrade the existing SSE2 feature check to SSE4.1, though it seems this
check is not strictly necessary; the aesni-intel module has been getting
away with using SSE4.1 despite checking for AES-NI only.

Reviewed-by: Ondrej Mosnacek <omosnace@redhat.com>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
arch/x86/crypto/Kconfig
arch/x86/crypto/aegis128-aesni-asm.S
arch/x86/crypto/aegis128-aesni-glue.c

index 7b1bebed879df32ccaf5ae56f90a3da21d335798..3d2e38ba524033940ff1124bd644827bc4fba21d 100644 (file)
@@ -363,7 +363,7 @@ config CRYPTO_CHACHA20_X86_64
          - AVX-512VL (Advanced Vector Extensions-512VL)
 
 config CRYPTO_AEGIS128_AESNI_SSE2
-       tristate "AEAD ciphers: AEGIS-128 (AES-NI/SSE2)"
+       tristate "AEAD ciphers: AEGIS-128 (AES-NI/SSE4.1)"
        depends on X86 && 64BIT
        select CRYPTO_AEAD
        select CRYPTO_SIMD
@@ -372,7 +372,7 @@ config CRYPTO_AEGIS128_AESNI_SSE2
 
          Architecture: x86_64 using:
          - AES-NI (AES New Instructions)
-         - SSE2 (Streaming SIMD Extensions 2)
+         - SSE4.1 (Streaming SIMD Extensions 4.1)
 
 config CRYPTO_NHPOLY1305_SSE2
        tristate "Hash functions: NHPoly1305 (SSE2)"
index 5541aca2fd0dd18842a765aa9b9411e49ab7b924..6ed4bc452c292c4766eb942127580ad19320651a 100644 (file)
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * AES-NI + SSE2 implementation of AEGIS-128
+ * AES-NI + SSE4.1 implementation of AEGIS-128
  *
  * Copyright (c) 2017-2018 Ondrej Mosnacek <omosnacek@gmail.com>
  * Copyright (C) 2017-2018 Red Hat, Inc. All rights reserved.
@@ -638,9 +638,7 @@ SYM_FUNC_START(crypto_aegis128_aesni_final)
 
        /* prepare length block: */
        movd %edx, MSG
-       movd %ecx, T0
-       pslldq $8, T0
-       pxor T0, MSG
+       pinsrd $2, %ecx, MSG
        psllq $3, MSG /* multiply by 8 (to get bit count) */
 
        pxor STATE3, MSG
index deb39cef0be1aadf3801cad02aaacd3d9c53435a..4dd2d981a514f132ae7da1e0e135b96be5a4213b 100644 (file)
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * The AEGIS-128 Authenticated-Encryption Algorithm
- *   Glue for AES-NI + SSE2 implementation
+ *   Glue for AES-NI + SSE4.1 implementation
  *
  * Copyright (c) 2017-2018 Ondrej Mosnacek <omosnacek@gmail.com>
  * Copyright (C) 2017-2018 Red Hat, Inc. All rights reserved.
@@ -254,7 +254,7 @@ static struct simd_aead_alg *simd_alg;
 
 static int __init crypto_aegis128_aesni_module_init(void)
 {
-       if (!boot_cpu_has(X86_FEATURE_XMM2) ||
+       if (!boot_cpu_has(X86_FEATURE_XMM4_1) ||
            !boot_cpu_has(X86_FEATURE_AES) ||
            !cpu_has_xfeatures(XFEATURE_MASK_SSE, NULL))
                return -ENODEV;
@@ -273,6 +273,6 @@ module_exit(crypto_aegis128_aesni_module_exit);
 
 MODULE_LICENSE("GPL");
 MODULE_AUTHOR("Ondrej Mosnacek <omosnacek@gmail.com>");
-MODULE_DESCRIPTION("AEGIS-128 AEAD algorithm -- AESNI+SSE2 implementation");
+MODULE_DESCRIPTION("AEGIS-128 AEAD algorithm -- AESNI+SSE4.1 implementation");
 MODULE_ALIAS_CRYPTO("aegis128");
 MODULE_ALIAS_CRYPTO("aegis128-aesni");