Skip to content

Commit f3d6cb3

Browse files
author
Eric Biggers
committed
lib/crypto: x86/sha1: Migrate optimized code into library
Instead of exposing the x86-optimized SHA-1 code via x86-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be x86-optimized, and it fixes the longstanding issue where the x86-optimized SHA-1 code was disabled by default. SHA-1 still remains available through crypto_shash, but individual architectures no longer need to handle it. To match sha1_blocks(), change the type of the nblocks parameter of the assembly functions from int to size_t. The assembly functions actually already treated it as size_t. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20250712232329.818226-14-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent c751059 commit f3d6cb3

9 files changed

Lines changed: 94 additions & 368 deletions

File tree

arch/x86/crypto/Kconfig

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -376,20 +376,6 @@ config CRYPTO_POLYVAL_CLMUL_NI
376376
Architecture: x86_64 using:
377377
- CLMUL-NI (carry-less multiplication new instructions)
378378

379-
config CRYPTO_SHA1_SSSE3
380-
tristate "Hash functions: SHA-1 (SSSE3/AVX/AVX2/SHA-NI)"
381-
depends on 64BIT
382-
select CRYPTO_SHA1
383-
select CRYPTO_HASH
384-
help
385-
SHA-1 secure hash algorithm (FIPS 180)
386-
387-
Architecture: x86_64 using:
388-
- SSSE3 (Supplemental SSE3)
389-
- AVX (Advanced Vector Extensions)
390-
- AVX2 (Advanced Vector Extensions 2)
391-
- SHA-NI (SHA Extensions New Instructions)
392-
393379
config CRYPTO_SM3_AVX_X86_64
394380
tristate "Hash functions: SM3 (AVX)"
395381
depends on 64BIT

arch/x86/crypto/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ ifeq ($(CONFIG_AS_VAES)$(CONFIG_AS_VPCLMULQDQ),yy)
5151
aesni-intel-$(CONFIG_64BIT) += aes-gcm-avx10-x86_64.o
5252
endif
5353

54-
obj-$(CONFIG_CRYPTO_SHA1_SSSE3) += sha1-ssse3.o
55-
sha1-ssse3-y := sha1_avx2_x86_64_asm.o sha1_ssse3_asm.o sha1_ni_asm.o sha1_ssse3_glue.o
56-
5754
obj-$(CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL) += ghash-clmulni-intel.o
5855
ghash-clmulni-intel-y := ghash-clmulni-intel_asm.o ghash-clmulni-intel_glue.o
5956

arch/x86/crypto/sha1_ssse3_glue.c

Lines changed: 0 additions & 324 deletions
This file was deleted.

lib/crypto/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ config CRYPTO_LIB_SHA1_ARCH
152152
default y if PPC
153153
default y if S390
154154
default y if SPARC64
155+
default y if X86_64
155156

156157
config CRYPTO_LIB_SHA256
157158
tristate

lib/crypto/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ libsha1-y += powerpc/sha1-powerpc-asm.o
8282
libsha1-$(CONFIG_SPE) += powerpc/sha1-spe-asm.o
8383
endif
8484
libsha1-$(CONFIG_SPARC) += sparc/sha1_asm.o
85+
libsha1-$(CONFIG_X86) += x86/sha1-ssse3-and-avx.o \
86+
x86/sha1-avx2-asm.o \
87+
x86/sha1-ni-asm.o
8588
endif # CONFIG_CRYPTO_LIB_SHA1_ARCH
8689

8790
################################################################################
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,8 @@
6262
*Visit http://software.intel.com/en-us/articles/
6363
*and refer to improving-the-performance-of-the-secure-hash-algorithm-1/
6464
*
65-
*Updates 20-byte SHA-1 record at start of 'state', from 'input', for
66-
*even number of 'blocks' consecutive 64-byte blocks.
67-
*
68-
*extern "C" void sha1_transform_avx2(
69-
* struct sha1_state *state, const u8* input, int blocks );
65+
* void sha1_transform_avx2(struct sha1_block_state *state,
66+
* const u8 *data, size_t nblocks);
7067
*/
7168

7269
#include <linux/linkage.h>

0 commit comments

Comments
 (0)