mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net.git/
synced 2026-04-18 06:33:43 -04:00
Migrate the arm-optimized BLAKE2b code from arch/arm/crypto/ to lib/crypto/arm/. This makes the BLAKE2b library able to use it, and it also simplifies the code because it's easier to integrate with the library than crypto_shash. This temporarily makes the arm-optimized BLAKE2b code unavailable via crypto_shash. A later commit reimplements the blake2b-* crypto_shash algorithms on top of the BLAKE2b library API, making it available again. Note that as per the lib/crypto/ convention, the optimized code is now enabled by default. So, this also fixes the longstanding issue where the optimized BLAKE2b code was not enabled by default. To see the diff from arch/arm/crypto/blake2b-neon-glue.c to lib/crypto/arm/blake2b.h, view this commit with 'git show -M10'. Reviewed-by: Ard Biesheuvel <ardb@kernel.org> Link: https://lore.kernel.org/r/20251018043106.375964-8-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
42 lines
1017 B
C
42 lines
1017 B
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* BLAKE2b digest algorithm, NEON accelerated
|
|
*
|
|
* Copyright 2020 Google LLC
|
|
*/
|
|
|
|
#include <asm/neon.h>
|
|
#include <asm/simd.h>
|
|
|
|
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
|
|
|
|
asmlinkage void blake2b_compress_neon(struct blake2b_ctx *ctx,
|
|
const u8 *data, size_t nblocks, u32 inc);
|
|
|
|
static void blake2b_compress(struct blake2b_ctx *ctx,
|
|
const u8 *data, size_t nblocks, u32 inc)
|
|
{
|
|
if (!static_branch_likely(&have_neon) || !may_use_simd()) {
|
|
blake2b_compress_generic(ctx, data, nblocks, inc);
|
|
return;
|
|
}
|
|
do {
|
|
const size_t blocks = min_t(size_t, nblocks,
|
|
SZ_4K / BLAKE2B_BLOCK_SIZE);
|
|
|
|
kernel_neon_begin();
|
|
blake2b_compress_neon(ctx, data, blocks, inc);
|
|
kernel_neon_end();
|
|
|
|
data += blocks * BLAKE2B_BLOCK_SIZE;
|
|
nblocks -= blocks;
|
|
} while (nblocks);
|
|
}
|
|
|
|
#define blake2b_mod_init_arch blake2b_mod_init_arch
|
|
static void blake2b_mod_init_arch(void)
|
|
{
|
|
if (elf_hwcap & HWCAP_NEON)
|
|
static_branch_enable(&have_neon);
|
|
}
|