Commit 39ee3970 authored by Eric Biggers's avatar Eric Biggers
Browse files

lib/crypto: blake2s: Consolidate into single C translation unit



As was done with the other algorithms, reorganize the BLAKE2s code so
that the generic implementation and the arch-specific "glue" code is
consolidated into a single translation unit, so that the compiler will
inline the functions and automatically decide whether to include the
generic code in the resulting binary or not.

Similarly, also consolidate the build rules into
lib/crypto/{Makefile,Kconfig}.  This removes the last uses of
lib/crypto/{arm,x86}/{Makefile,Kconfig}, so remove those too.

Don't keep the !KMSAN dependency.  It was needed only for other
algorithms such as ChaCha that initialize memory from assembly code.

Reviewed-by: default avatarArd Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20250827151131.27733-12-ebiggers@kernel.org


Signed-off-by: default avatarEric Biggers <ebiggers@kernel.org>
parent 5d313a76
Loading
Loading
Loading
Loading

include/crypto/internal/blake2s.h

deleted100644 → 0
+0 −19
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0 OR MIT */
/*
 * Helper functions for BLAKE2s implementations.
 * Keep this in sync with the corresponding BLAKE2b header.
 */

#ifndef _CRYPTO_INTERNAL_BLAKE2S_H
#define _CRYPTO_INTERNAL_BLAKE2S_H

#include <crypto/blake2s.h>
#include <linux/string.h>

void blake2s_compress_generic(struct blake2s_state *state, const u8 *block,
			      size_t nblocks, const u32 inc);

void blake2s_compress(struct blake2s_state *state, const u8 *block,
		      size_t nblocks, const u32 inc);

#endif /* _CRYPTO_INTERNAL_BLAKE2S_H */
+6 −23
Original line number Diff line number Diff line
@@ -28,21 +28,13 @@ config CRYPTO_LIB_ARC4
config CRYPTO_LIB_GF128MUL
	tristate

config CRYPTO_ARCH_HAVE_LIB_BLAKE2S
	bool
	help
	  Declares whether the architecture provides an arch-specific
	  accelerated implementation of the Blake2s library interface,
	  either builtin or as a module.
# BLAKE2s support is always built-in, so there's no CRYPTO_LIB_BLAKE2S option.

config CRYPTO_LIB_BLAKE2S_GENERIC
	def_bool !CRYPTO_ARCH_HAVE_LIB_BLAKE2S
	help
	  This symbol can be depended upon by arch implementations of the
	  Blake2s library interface that require the generic code as a
	  fallback, e.g., for SIMD implementations. If no arch specific
	  implementation is enabled, this implementation serves the users
	  of CRYPTO_LIB_BLAKE2S.
config CRYPTO_LIB_BLAKE2S_ARCH
	bool
	depends on !UML
	default y if ARM
	default y if X86_64

config CRYPTO_LIB_CHACHA
	tristate
@@ -208,13 +200,4 @@ config CRYPTO_LIB_SM3

source "lib/crypto/tests/Kconfig"

if !KMSAN # avoid false positives from assembly
if ARM
source "lib/crypto/arm/Kconfig"
endif
if X86
source "lib/crypto/x86/Kconfig"
endif
endif

endmenu
+8 −5
Original line number Diff line number Diff line
@@ -29,9 +29,15 @@ libarc4-y := arc4.o

obj-$(CONFIG_CRYPTO_LIB_GF128MUL)		+= gf128mul.o

################################################################################

# blake2s is used by the /dev/random driver which is always builtin
obj-y						+= libblake2s.o
libblake2s-y					:= blake2s.o
obj-y += blake2s.o
ifeq ($(CONFIG_CRYPTO_LIB_BLAKE2S_ARCH),y)
CFLAGS_blake2s.o += -I$(src)/$(SRCARCH)
obj-$(CONFIG_ARM) += arm/blake2s-core.o
obj-$(CONFIG_X86) += x86/blake2s-core.o
endif

################################################################################

@@ -256,9 +262,6 @@ obj-$(CONFIG_CRYPTO_SELFTESTS_FULL) += simd.o
obj-$(CONFIG_CRYPTO_LIB_SM3)			+= libsm3.o
libsm3-y					:= sm3.o

obj-$(CONFIG_ARM) += arm/
obj-$(CONFIG_X86) += x86/

# clean-files must be defined unconditionally
clean-files += arm/sha256-core.S arm/sha512-core.S
clean-files += arm64/sha256-core.S arm64/sha512-core.S

lib/crypto/arm/Kconfig

deleted100644 → 0
+0 −14
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only

config CRYPTO_BLAKE2S_ARM
	def_bool y
	select CRYPTO_ARCH_HAVE_LIB_BLAKE2S
	help
	  BLAKE2s cryptographic hash function (RFC 7693)

	  Architecture: arm

	  This is faster than the generic implementations of BLAKE2s and
	  BLAKE2b, but slower than the NEON implementation of BLAKE2b.
	  There is no NEON implementation of BLAKE2s, since NEON doesn't
	  really help with it.

lib/crypto/arm/Makefile

deleted100644 → 0
+0 −4
Original line number Diff line number Diff line
# SPDX-License-Identifier: GPL-2.0-only

obj-$(CONFIG_CRYPTO_BLAKE2S_ARM) += libblake2s-arm.o
libblake2s-arm-y := blake2s-core.o blake2s-glue.o
Loading