Skip to content

Commit 377982d

Browse files
author
Eric Biggers
committed
lib/crypto: s390/sha1: Migrate optimized code into library
Instead of exposing the s390-optimized SHA-1 code via s390-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be s390-optimized, and it fixes the longstanding issue where the s390-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. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20250712232329.818226-12-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 6b9ae8c commit 377982d

7 files changed

Lines changed: 29 additions & 116 deletions

File tree

arch/s390/configs/debug_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,6 @@ CONFIG_CRYPTO_USER_API_HASH=m
804804
CONFIG_CRYPTO_USER_API_SKCIPHER=m
805805
CONFIG_CRYPTO_USER_API_RNG=m
806806
CONFIG_CRYPTO_USER_API_AEAD=m
807-
CONFIG_CRYPTO_SHA1_S390=m
808807
CONFIG_CRYPTO_SHA3_256_S390=m
809808
CONFIG_CRYPTO_SHA3_512_S390=m
810809
CONFIG_CRYPTO_GHASH_S390=m

arch/s390/configs/defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -791,7 +791,6 @@ CONFIG_CRYPTO_USER_API_HASH=m
791791
CONFIG_CRYPTO_USER_API_SKCIPHER=m
792792
CONFIG_CRYPTO_USER_API_RNG=m
793793
CONFIG_CRYPTO_USER_API_AEAD=m
794-
CONFIG_CRYPTO_SHA1_S390=m
795794
CONFIG_CRYPTO_SHA3_256_S390=m
796795
CONFIG_CRYPTO_SHA3_512_S390=m
797796
CONFIG_CRYPTO_GHASH_S390=m

arch/s390/crypto/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,6 @@
22

33
menu "Accelerated Cryptographic Algorithms for CPU (s390)"
44

5-
config CRYPTO_SHA1_S390
6-
tristate "Hash functions: SHA-1"
7-
select CRYPTO_HASH
8-
help
9-
SHA-1 secure hash algorithm (FIPS 180)
10-
11-
Architecture: s390
12-
13-
It is available as of z990.
14-
155
config CRYPTO_SHA3_256_S390
166
tristate "Hash functions: SHA3-224 and SHA3-256"
177
select CRYPTO_HASH

arch/s390/crypto/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Cryptographic API
44
#
55

6-
obj-$(CONFIG_CRYPTO_SHA1_S390) += sha1_s390.o sha_common.o
76
obj-$(CONFIG_CRYPTO_SHA3_256_S390) += sha3_256_s390.o sha_common.o
87
obj-$(CONFIG_CRYPTO_SHA3_512_S390) += sha3_512_s390.o sha_common.o
98
obj-$(CONFIG_CRYPTO_DES_S390) += des_s390.o

arch/s390/crypto/sha1_s390.c

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

lib/crypto/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ config CRYPTO_LIB_SHA1_ARCH
150150
default y if ARM64 && KERNEL_MODE_NEON
151151
default y if MIPS && CPU_CAVIUM_OCTEON
152152
default y if PPC
153+
default y if S390
153154

154155
config CRYPTO_LIB_SHA256
155156
tristate

lib/crypto/s390/sha1.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* SHA-1 optimized using the CP Assist for Cryptographic Functions (CPACF)
4+
*
5+
* Copyright 2025 Google LLC
6+
*/
7+
#include <asm/cpacf.h>
8+
#include <linux/cpufeature.h>
9+
10+
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_cpacf_sha1);
11+
12+
static void sha1_blocks(struct sha1_block_state *state,
13+
const u8 *data, size_t nblocks)
14+
{
15+
if (static_branch_likely(&have_cpacf_sha1))
16+
cpacf_kimd(CPACF_KIMD_SHA_1, state, data,
17+
nblocks * SHA1_BLOCK_SIZE);
18+
else
19+
sha1_blocks_generic(state, data, nblocks);
20+
}
21+
22+
#define sha1_mod_init_arch sha1_mod_init_arch
23+
static inline void sha1_mod_init_arch(void)
24+
{
25+
if (cpu_have_feature(S390_CPU_FEATURE_MSA) &&
26+
cpacf_query_func(CPACF_KIMD, CPACF_KIMD_SHA_1))
27+
static_branch_enable(&have_cpacf_sha1);
28+
}

0 commit comments

Comments
 (0)