mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
This reverts commit c4741b2305.
Crypto API self-tests no longer run at registration time and now
occur either at late_initcall or upon the first use.
Therefore the premise of the above commit no longer exists. Revert
it and subsequent additions of subsys_initcall and arch_initcall.
Note that lib/crypto calls will stay at subsys_initcall (or rather
downgraded from arch_initcall) because they may need to occur
before Crypto API registration.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
48 lines
1.2 KiB
C
48 lines
1.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* SHA-256 optimized using the CP Assist for Cryptographic Functions (CPACF)
|
|
*
|
|
* Copyright 2025 Google LLC
|
|
*/
|
|
#include <asm/cpacf.h>
|
|
#include <crypto/internal/sha2.h>
|
|
#include <linux/cpufeature.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
|
|
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_cpacf_sha256);
|
|
|
|
void sha256_blocks_arch(u32 state[SHA256_STATE_WORDS],
|
|
const u8 *data, size_t nblocks)
|
|
{
|
|
if (static_branch_likely(&have_cpacf_sha256))
|
|
cpacf_kimd(CPACF_KIMD_SHA_256, state, data,
|
|
nblocks * SHA256_BLOCK_SIZE);
|
|
else
|
|
sha256_blocks_generic(state, data, nblocks);
|
|
}
|
|
EXPORT_SYMBOL(sha256_blocks_arch);
|
|
|
|
bool sha256_is_arch_optimized(void)
|
|
{
|
|
return static_key_enabled(&have_cpacf_sha256);
|
|
}
|
|
EXPORT_SYMBOL(sha256_is_arch_optimized);
|
|
|
|
static int __init sha256_s390_mod_init(void)
|
|
{
|
|
if (cpu_have_feature(S390_CPU_FEATURE_MSA) &&
|
|
cpacf_query_func(CPACF_KIMD, CPACF_KIMD_SHA_256))
|
|
static_branch_enable(&have_cpacf_sha256);
|
|
return 0;
|
|
}
|
|
subsys_initcall(sha256_s390_mod_init);
|
|
|
|
static void __exit sha256_s390_mod_exit(void)
|
|
{
|
|
}
|
|
module_exit(sha256_s390_mod_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("SHA-256 using the CP Assist for Cryptographic Functions (CPACF)");
|