mirror of
https://github.com/torvalds/linux.git
synced 2025-08-15 14:11:42 +02: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>
64 lines
1.8 KiB
C
64 lines
1.8 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/*
|
|
* SHA-256 optimized for ARM
|
|
*
|
|
* Copyright 2025 Google LLC
|
|
*/
|
|
#include <asm/neon.h>
|
|
#include <crypto/internal/sha2.h>
|
|
#include <crypto/internal/simd.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
|
|
asmlinkage void sha256_block_data_order(u32 state[SHA256_STATE_WORDS],
|
|
const u8 *data, size_t nblocks);
|
|
asmlinkage void sha256_block_data_order_neon(u32 state[SHA256_STATE_WORDS],
|
|
const u8 *data, size_t nblocks);
|
|
asmlinkage void sha256_ce_transform(u32 state[SHA256_STATE_WORDS],
|
|
const u8 *data, size_t nblocks);
|
|
|
|
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
|
|
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce);
|
|
|
|
void sha256_blocks_arch(u32 state[SHA256_STATE_WORDS],
|
|
const u8 *data, size_t nblocks)
|
|
{
|
|
if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) &&
|
|
static_branch_likely(&have_neon) && crypto_simd_usable()) {
|
|
kernel_neon_begin();
|
|
if (static_branch_likely(&have_ce))
|
|
sha256_ce_transform(state, data, nblocks);
|
|
else
|
|
sha256_block_data_order_neon(state, data, nblocks);
|
|
kernel_neon_end();
|
|
} else {
|
|
sha256_block_data_order(state, data, nblocks);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL(sha256_blocks_arch);
|
|
|
|
bool sha256_is_arch_optimized(void)
|
|
{
|
|
/* We always can use at least the ARM scalar implementation. */
|
|
return true;
|
|
}
|
|
EXPORT_SYMBOL(sha256_is_arch_optimized);
|
|
|
|
static int __init sha256_arm_mod_init(void)
|
|
{
|
|
if (IS_ENABLED(CONFIG_KERNEL_MODE_NEON) && (elf_hwcap & HWCAP_NEON)) {
|
|
static_branch_enable(&have_neon);
|
|
if (elf_hwcap2 & HWCAP2_SHA2)
|
|
static_branch_enable(&have_ce);
|
|
}
|
|
return 0;
|
|
}
|
|
subsys_initcall(sha256_arm_mod_init);
|
|
|
|
static void __exit sha256_arm_mod_exit(void)
|
|
{
|
|
}
|
|
module_exit(sha256_arm_mod_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_DESCRIPTION("SHA-256 optimized for ARM");
|