Skip to content

Commit af2aff7

Browse files
ebiggersherbertx
authored andcommitted
crypto: x86/aegis128 - optimize length block preparation using SSE4.1
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 <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 595bca2 commit af2aff7

File tree

3 files changed

+7
-9
lines changed

3 files changed

+7
-9
lines changed

arch/x86/crypto/Kconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ config CRYPTO_CHACHA20_X86_64
363363
- AVX-512VL (Advanced Vector Extensions-512VL)
364364

365365
config CRYPTO_AEGIS128_AESNI_SSE2
366-
tristate "AEAD ciphers: AEGIS-128 (AES-NI/SSE2)"
366+
tristate "AEAD ciphers: AEGIS-128 (AES-NI/SSE4.1)"
367367
depends on X86 && 64BIT
368368
select CRYPTO_AEAD
369369
select CRYPTO_SIMD
@@ -372,7 +372,7 @@ config CRYPTO_AEGIS128_AESNI_SSE2
372372

373373
Architecture: x86_64 using:
374374
- AES-NI (AES New Instructions)
375-
- SSE2 (Streaming SIMD Extensions 2)
375+
- SSE4.1 (Streaming SIMD Extensions 4.1)
376376

377377
config CRYPTO_NHPOLY1305_SSE2
378378
tristate "Hash functions: NHPoly1305 (SSE2)"

arch/x86/crypto/aegis128-aesni-asm.S

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* SPDX-License-Identifier: GPL-2.0-only */
22
/*
3-
* AES-NI + SSE2 implementation of AEGIS-128
3+
* AES-NI + SSE4.1 implementation of AEGIS-128
44
*
55
* Copyright (c) 2017-2018 Ondrej Mosnacek <[email protected]>
66
* Copyright (C) 2017-2018 Red Hat, Inc. All rights reserved.
@@ -638,9 +638,7 @@ SYM_FUNC_START(crypto_aegis128_aesni_final)
638638

639639
/* prepare length block: */
640640
movd %edx, MSG
641-
movd %ecx, T0
642-
pslldq $8, T0
643-
pxor T0, MSG
641+
pinsrd $2, %ecx, MSG
644642
psllq $3, MSG /* multiply by 8 (to get bit count) */
645643

646644
pxor STATE3, MSG

arch/x86/crypto/aegis128-aesni-glue.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22
/*
33
* The AEGIS-128 Authenticated-Encryption Algorithm
4-
* Glue for AES-NI + SSE2 implementation
4+
* Glue for AES-NI + SSE4.1 implementation
55
*
66
* Copyright (c) 2017-2018 Ondrej Mosnacek <[email protected]>
77
* Copyright (C) 2017-2018 Red Hat, Inc. All rights reserved.
@@ -254,7 +254,7 @@ static struct simd_aead_alg *simd_alg;
254254

255255
static int __init crypto_aegis128_aesni_module_init(void)
256256
{
257-
if (!boot_cpu_has(X86_FEATURE_XMM2) ||
257+
if (!boot_cpu_has(X86_FEATURE_XMM4_1) ||
258258
!boot_cpu_has(X86_FEATURE_AES) ||
259259
!cpu_has_xfeatures(XFEATURE_MASK_SSE, NULL))
260260
return -ENODEV;
@@ -273,6 +273,6 @@ module_exit(crypto_aegis128_aesni_module_exit);
273273

274274
MODULE_LICENSE("GPL");
275275
MODULE_AUTHOR("Ondrej Mosnacek <[email protected]>");
276-
MODULE_DESCRIPTION("AEGIS-128 AEAD algorithm -- AESNI+SSE2 implementation");
276+
MODULE_DESCRIPTION("AEGIS-128 AEAD algorithm -- AESNI+SSE4.1 implementation");
277277
MODULE_ALIAS_CRYPTO("aegis128");
278278
MODULE_ALIAS_CRYPTO("aegis128-aesni");

0 commit comments

Comments
 (0)