Skip to content

Commit c751059

Browse files
author
Eric Biggers
committed
lib/crypto: sparc/sha1: Migrate optimized code into library
Instead of exposing the sparc-optimized SHA-1 code via sparc-specific crypto_shash algorithms, instead just implement the sha1_blocks() library function. This is much simpler, it makes the SHA-1 library functions be sparc-optimized, and it fixes the longstanding issue where the sparc-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. Note: to see the diff from arch/sparc/crypto/sha1_glue.c to lib/crypto/sparc/sha1.h, view this commit with 'git show -M10'. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20250712232329.818226-13-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 377982d commit c751059

7 files changed

Lines changed: 45 additions & 106 deletions

File tree

arch/sparc/crypto/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@ config CRYPTO_MD5_SPARC64
2626

2727
Architecture: sparc64 using crypto instructions, when available
2828

29-
config CRYPTO_SHA1_SPARC64
30-
tristate "Hash functions: SHA-1"
31-
depends on SPARC64
32-
select CRYPTO_SHA1
33-
select CRYPTO_HASH
34-
help
35-
SHA-1 secure hash algorithm (FIPS 180)
36-
37-
Architecture: sparc64
38-
3929
config CRYPTO_AES_SPARC64
4030
tristate "Ciphers: AES, modes: ECB, CBC, CTR"
4131
depends on SPARC64

arch/sparc/crypto/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@
33
# Arch-specific CryptoAPI modules.
44
#
55

6-
obj-$(CONFIG_CRYPTO_SHA1_SPARC64) += sha1-sparc64.o
76
obj-$(CONFIG_CRYPTO_MD5_SPARC64) += md5-sparc64.o
87

98
obj-$(CONFIG_CRYPTO_AES_SPARC64) += aes-sparc64.o
109
obj-$(CONFIG_CRYPTO_DES_SPARC64) += des-sparc64.o
1110
obj-$(CONFIG_CRYPTO_CAMELLIA_SPARC64) += camellia-sparc64.o
1211

13-
sha1-sparc64-y := sha1_asm.o sha1_glue.o
1412
md5-sparc64-y := md5_asm.o md5_glue.o
1513

1614
aes-sparc64-y := aes_asm.o aes_glue.o

arch/sparc/crypto/sha1_glue.c

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

lib/crypto/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ config CRYPTO_LIB_SHA1_ARCH
151151
default y if MIPS && CPU_CAVIUM_OCTEON
152152
default y if PPC
153153
default y if S390
154+
default y if SPARC64
154155

155156
config CRYPTO_LIB_SHA256
156157
tristate

lib/crypto/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ ifeq ($(CONFIG_PPC),y)
8181
libsha1-y += powerpc/sha1-powerpc-asm.o
8282
libsha1-$(CONFIG_SPE) += powerpc/sha1-spe-asm.o
8383
endif
84+
libsha1-$(CONFIG_SPARC) += sparc/sha1_asm.o
8485
endif # CONFIG_CRYPTO_LIB_SHA1_ARCH
8586

8687
################################################################################

lib/crypto/sparc/sha1.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only */
2+
/*
3+
* SHA-1 accelerated using the sparc64 crypto opcodes
4+
*
5+
* Copyright (c) Alan Smithee.
6+
* Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
7+
* Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
8+
* Copyright (c) Mathias Krause <minipli@googlemail.com>
9+
*/
10+
11+
#include <asm/elf.h>
12+
#include <asm/opcodes.h>
13+
#include <asm/pstate.h>
14+
15+
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_sha1_opcodes);
16+
17+
asmlinkage void sha1_sparc64_transform(struct sha1_block_state *state,
18+
const u8 *data, size_t nblocks);
19+
20+
static void sha1_blocks(struct sha1_block_state *state,
21+
const u8 *data, size_t nblocks)
22+
{
23+
if (static_branch_likely(&have_sha1_opcodes))
24+
sha1_sparc64_transform(state, data, nblocks);
25+
else
26+
sha1_blocks_generic(state, data, nblocks);
27+
}
28+
29+
#define sha1_mod_init_arch sha1_mod_init_arch
30+
static inline void sha1_mod_init_arch(void)
31+
{
32+
unsigned long cfr;
33+
34+
if (!(sparc64_elf_hwcap & HWCAP_SPARC_CRYPTO))
35+
return;
36+
37+
__asm__ __volatile__("rd %%asr26, %0" : "=r" (cfr));
38+
if (!(cfr & CFR_SHA1))
39+
return;
40+
41+
static_branch_enable(&have_sha1_opcodes);
42+
pr_info("Using sparc64 sha1 opcode optimized SHA-1 implementation\n");
43+
}

0 commit comments

Comments
 (0)