mirror of
https://github.com/torvalds/linux.git
synced 2026-05-12 16:18:45 +02:00
Instead of exposing the arm64-optimized SM3 code via arm64-specific crypto_shash algorithms, instead just implement the sm3_blocks() library function. This is much simpler, it makes the SM3 library functions be arm64-optimized, and it fixes the longstanding issue where the arm64-optimized SM3 code was disabled by default. SM3 still remains available through crypto_shash, but individual architectures no longer need to handle it. Tweak the SM3 assembly function prototypes to match what the library expects, including changing the block count from 'int' to 'size_t'. sm3_ce_transform() had to be updated to access 'x2' instead of 'w2', while sm3_neon_transform() already used 'x2'. Remove the CFI stubs which are no longer needed because the SM3 assembly functions are no longer ever indirectly called. Remove the dependency on KERNEL_MODE_NEON. It was unnecessary, because KERNEL_MODE_NEON is always enabled on arm64. Acked-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20260321040935.410034-8-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
42 lines
1.1 KiB
C
42 lines
1.1 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* SM3 optimized for ARM64
|
|
*
|
|
* Copyright 2026 Google LLC
|
|
*/
|
|
#include <asm/simd.h>
|
|
#include <linux/cpufeature.h>
|
|
|
|
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
|
|
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_ce);
|
|
|
|
asmlinkage void sm3_neon_transform(struct sm3_block_state *state,
|
|
const u8 *data, size_t nblocks);
|
|
asmlinkage void sm3_ce_transform(struct sm3_block_state *state,
|
|
const u8 *data, size_t nblocks);
|
|
|
|
static void sm3_blocks(struct sm3_block_state *state,
|
|
const u8 *data, size_t nblocks)
|
|
{
|
|
if (static_branch_likely(&have_neon) && likely(may_use_simd())) {
|
|
scoped_ksimd() {
|
|
if (static_branch_likely(&have_ce))
|
|
sm3_ce_transform(state, data, nblocks);
|
|
else
|
|
sm3_neon_transform(state, data, nblocks);
|
|
}
|
|
} else {
|
|
sm3_blocks_generic(state, data, nblocks);
|
|
}
|
|
}
|
|
|
|
#define sm3_mod_init_arch sm3_mod_init_arch
|
|
static void sm3_mod_init_arch(void)
|
|
{
|
|
if (cpu_have_named_feature(ASIMD)) {
|
|
static_branch_enable(&have_neon);
|
|
if (cpu_have_named_feature(SM3))
|
|
static_branch_enable(&have_ce);
|
|
}
|
|
}
|