mirror of
git://git.yoctoproject.org/linux-yocto.git
synced 2026-01-27 12:47:24 +01:00
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>
This commit is contained in:
parent
6b9ae8cfaa
commit
377982d561
|
|
@ -804,7 +804,6 @@ CONFIG_CRYPTO_USER_API_HASH=m
|
|||
CONFIG_CRYPTO_USER_API_SKCIPHER=m
|
||||
CONFIG_CRYPTO_USER_API_RNG=m
|
||||
CONFIG_CRYPTO_USER_API_AEAD=m
|
||||
CONFIG_CRYPTO_SHA1_S390=m
|
||||
CONFIG_CRYPTO_SHA3_256_S390=m
|
||||
CONFIG_CRYPTO_SHA3_512_S390=m
|
||||
CONFIG_CRYPTO_GHASH_S390=m
|
||||
|
|
|
|||
|
|
@ -791,7 +791,6 @@ CONFIG_CRYPTO_USER_API_HASH=m
|
|||
CONFIG_CRYPTO_USER_API_SKCIPHER=m
|
||||
CONFIG_CRYPTO_USER_API_RNG=m
|
||||
CONFIG_CRYPTO_USER_API_AEAD=m
|
||||
CONFIG_CRYPTO_SHA1_S390=m
|
||||
CONFIG_CRYPTO_SHA3_256_S390=m
|
||||
CONFIG_CRYPTO_SHA3_512_S390=m
|
||||
CONFIG_CRYPTO_GHASH_S390=m
|
||||
|
|
|
|||
|
|
@ -2,16 +2,6 @@
|
|||
|
||||
menu "Accelerated Cryptographic Algorithms for CPU (s390)"
|
||||
|
||||
config CRYPTO_SHA1_S390
|
||||
tristate "Hash functions: SHA-1"
|
||||
select CRYPTO_HASH
|
||||
help
|
||||
SHA-1 secure hash algorithm (FIPS 180)
|
||||
|
||||
Architecture: s390
|
||||
|
||||
It is available as of z990.
|
||||
|
||||
config CRYPTO_SHA3_256_S390
|
||||
tristate "Hash functions: SHA3-224 and SHA3-256"
|
||||
select CRYPTO_HASH
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
# Cryptographic API
|
||||
#
|
||||
|
||||
obj-$(CONFIG_CRYPTO_SHA1_S390) += sha1_s390.o sha_common.o
|
||||
obj-$(CONFIG_CRYPTO_SHA3_256_S390) += sha3_256_s390.o sha_common.o
|
||||
obj-$(CONFIG_CRYPTO_SHA3_512_S390) += sha3_512_s390.o sha_common.o
|
||||
obj-$(CONFIG_CRYPTO_DES_S390) += des_s390.o
|
||||
|
|
|
|||
|
|
@ -1,103 +0,0 @@
|
|||
// SPDX-License-Identifier: GPL-2.0+
|
||||
/*
|
||||
* Cryptographic API.
|
||||
*
|
||||
* s390 implementation of the SHA1 Secure Hash Algorithm.
|
||||
*
|
||||
* Derived from cryptoapi implementation, adapted for in-place
|
||||
* scatterlist interface. Originally based on the public domain
|
||||
* implementation written by Steve Reid.
|
||||
*
|
||||
* s390 Version:
|
||||
* Copyright IBM Corp. 2003, 2007
|
||||
* Author(s): Thomas Spatzier
|
||||
* Jan Glauber (jan.glauber@de.ibm.com)
|
||||
*
|
||||
* Derived from "crypto/sha1_generic.c"
|
||||
* Copyright (c) Alan Smithee.
|
||||
* Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
|
||||
* Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
|
||||
*/
|
||||
#include <asm/cpacf.h>
|
||||
#include <crypto/internal/hash.h>
|
||||
#include <crypto/sha1.h>
|
||||
#include <linux/cpufeature.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
|
||||
#include "sha.h"
|
||||
|
||||
static int s390_sha1_init(struct shash_desc *desc)
|
||||
{
|
||||
struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
|
||||
|
||||
sctx->state[0] = SHA1_H0;
|
||||
sctx->state[1] = SHA1_H1;
|
||||
sctx->state[2] = SHA1_H2;
|
||||
sctx->state[3] = SHA1_H3;
|
||||
sctx->state[4] = SHA1_H4;
|
||||
sctx->count = 0;
|
||||
sctx->func = CPACF_KIMD_SHA_1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s390_sha1_export(struct shash_desc *desc, void *out)
|
||||
{
|
||||
struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
|
||||
struct sha1_state *octx = out;
|
||||
|
||||
octx->count = sctx->count;
|
||||
memcpy(octx->state, sctx->state, sizeof(octx->state));
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int s390_sha1_import(struct shash_desc *desc, const void *in)
|
||||
{
|
||||
struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
|
||||
const struct sha1_state *ictx = in;
|
||||
|
||||
sctx->count = ictx->count;
|
||||
memcpy(sctx->state, ictx->state, sizeof(ictx->state));
|
||||
sctx->func = CPACF_KIMD_SHA_1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct shash_alg alg = {
|
||||
.digestsize = SHA1_DIGEST_SIZE,
|
||||
.init = s390_sha1_init,
|
||||
.update = s390_sha_update_blocks,
|
||||
.finup = s390_sha_finup,
|
||||
.export = s390_sha1_export,
|
||||
.import = s390_sha1_import,
|
||||
.descsize = S390_SHA_CTX_SIZE,
|
||||
.statesize = SHA1_STATE_SIZE,
|
||||
.base = {
|
||||
.cra_name = "sha1",
|
||||
.cra_driver_name= "sha1-s390",
|
||||
.cra_priority = 300,
|
||||
.cra_flags = CRYPTO_AHASH_ALG_BLOCK_ONLY |
|
||||
CRYPTO_AHASH_ALG_FINUP_MAX,
|
||||
.cra_blocksize = SHA1_BLOCK_SIZE,
|
||||
.cra_module = THIS_MODULE,
|
||||
}
|
||||
};
|
||||
|
||||
static int __init sha1_s390_init(void)
|
||||
{
|
||||
if (!cpacf_query_func(CPACF_KIMD, CPACF_KIMD_SHA_1))
|
||||
return -ENODEV;
|
||||
return crypto_register_shash(&alg);
|
||||
}
|
||||
|
||||
static void __exit sha1_s390_fini(void)
|
||||
{
|
||||
crypto_unregister_shash(&alg);
|
||||
}
|
||||
|
||||
module_cpu_feature_match(S390_CPU_FEATURE_MSA, sha1_s390_init);
|
||||
module_exit(sha1_s390_fini);
|
||||
|
||||
MODULE_ALIAS_CRYPTO("sha1");
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
|
||||
|
|
@ -150,6 +150,7 @@ config CRYPTO_LIB_SHA1_ARCH
|
|||
default y if ARM64 && KERNEL_MODE_NEON
|
||||
default y if MIPS && CPU_CAVIUM_OCTEON
|
||||
default y if PPC
|
||||
default y if S390
|
||||
|
||||
config CRYPTO_LIB_SHA256
|
||||
tristate
|
||||
|
|
|
|||
28
lib/crypto/s390/sha1.h
Normal file
28
lib/crypto/s390/sha1.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
/*
|
||||
* SHA-1 optimized using the CP Assist for Cryptographic Functions (CPACF)
|
||||
*
|
||||
* Copyright 2025 Google LLC
|
||||
*/
|
||||
#include <asm/cpacf.h>
|
||||
#include <linux/cpufeature.h>
|
||||
|
||||
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_cpacf_sha1);
|
||||
|
||||
static void sha1_blocks(struct sha1_block_state *state,
|
||||
const u8 *data, size_t nblocks)
|
||||
{
|
||||
if (static_branch_likely(&have_cpacf_sha1))
|
||||
cpacf_kimd(CPACF_KIMD_SHA_1, state, data,
|
||||
nblocks * SHA1_BLOCK_SIZE);
|
||||
else
|
||||
sha1_blocks_generic(state, data, nblocks);
|
||||
}
|
||||
|
||||
#define sha1_mod_init_arch sha1_mod_init_arch
|
||||
static inline void sha1_mod_init_arch(void)
|
||||
{
|
||||
if (cpu_have_feature(S390_CPU_FEATURE_MSA) &&
|
||||
cpacf_query_func(CPACF_KIMD, CPACF_KIMD_SHA_1))
|
||||
static_branch_enable(&have_cpacf_sha1);
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user