Skip to content

Commit 29e39a1

Browse files
author
Eric Biggers
committed
lib/crypto: arm/nh: Migrate optimized code into library
Migrate the arm32 NEON implementation of NH into lib/crypto/. This makes the nh() function be optimized on arm32 kernels. Note: this temporarily makes the adiantum template not utilize the arm32 optimized NH code. This is resolved in a later commit that converts the adiantum template to use nh() instead of "nhpoly1305". Link: https://lore.kernel.org/r/20251211011846.8179-4-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 7246fe6 commit 29e39a1

7 files changed

Lines changed: 35 additions & 92 deletions

File tree

arch/arm/crypto/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,6 @@ config CRYPTO_GHASH_ARM_CE
2323
that is part of the ARMv8 Crypto Extensions, or a slower variant that
2424
uses the vmull.p8 instruction that is part of the basic NEON ISA.
2525

26-
config CRYPTO_NHPOLY1305_NEON
27-
tristate "Hash functions: NHPoly1305 (NEON)"
28-
depends on KERNEL_MODE_NEON
29-
select CRYPTO_NHPOLY1305
30-
help
31-
NHPoly1305 hash function (Adiantum)
32-
33-
Architecture: arm using:
34-
- NEON (Advanced SIMD) extensions
35-
3626
config CRYPTO_AES_ARM
3727
tristate "Ciphers: AES"
3828
select CRYPTO_ALGAPI

arch/arm/crypto/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
obj-$(CONFIG_CRYPTO_AES_ARM) += aes-arm.o
77
obj-$(CONFIG_CRYPTO_AES_ARM_BS) += aes-arm-bs.o
8-
obj-$(CONFIG_CRYPTO_NHPOLY1305_NEON) += nhpoly1305-neon.o
98

109
obj-$(CONFIG_CRYPTO_AES_ARM_CE) += aes-arm-ce.o
1110
obj-$(CONFIG_CRYPTO_GHASH_ARM_CE) += ghash-arm-ce.o
@@ -14,4 +13,3 @@ aes-arm-y := aes-cipher-core.o aes-cipher-glue.o
1413
aes-arm-bs-y := aes-neonbs-core.o aes-neonbs-glue.o
1514
aes-arm-ce-y := aes-ce-core.o aes-ce-glue.o
1615
ghash-arm-ce-y := ghash-ce-core.o ghash-ce-glue.o
17-
nhpoly1305-neon-y := nh-neon-core.o nhpoly1305-neon-glue.o

arch/arm/crypto/nhpoly1305-neon-glue.c

Lines changed: 0 additions & 80 deletions
This file was deleted.

lib/crypto/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ config CRYPTO_LIB_NH
117117
config CRYPTO_LIB_NH_ARCH
118118
bool
119119
depends on CRYPTO_LIB_NH && !UML
120+
default y if ARM && KERNEL_MODE_NEON
120121

121122
config CRYPTO_LIB_POLY1305
122123
tristate

lib/crypto/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ obj-$(CONFIG_CRYPTO_LIB_NH) += libnh.o
135135
libnh-y := nh.o
136136
ifeq ($(CONFIG_CRYPTO_LIB_NH_ARCH),y)
137137
CFLAGS_nh.o += -I$(src)/$(SRCARCH)
138+
libnh-$(CONFIG_ARM) += arm/nh-neon-core.o
138139
endif
139140

140141
################################################################################

lib/crypto/arm/nh.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* ARM32 accelerated implementation of NH
4+
*
5+
* Copyright 2018 Google LLC
6+
*/
7+
8+
#include <asm/neon.h>
9+
#include <asm/simd.h>
10+
11+
static __ro_after_init DEFINE_STATIC_KEY_FALSE(have_neon);
12+
13+
asmlinkage void nh_neon(const u32 *key, const u8 *message, size_t message_len,
14+
__le64 hash[NH_NUM_PASSES]);
15+
16+
static bool nh_arch(const u32 *key, const u8 *message, size_t message_len,
17+
__le64 hash[NH_NUM_PASSES])
18+
{
19+
if (static_branch_likely(&have_neon) && message_len >= 64 &&
20+
may_use_simd()) {
21+
scoped_ksimd()
22+
nh_neon(key, message, message_len, hash);
23+
return true;
24+
}
25+
return false;
26+
}
27+
28+
#define nh_mod_init_arch nh_mod_init_arch
29+
static void nh_mod_init_arch(void)
30+
{
31+
if (elf_hwcap & HWCAP_NEON)
32+
static_branch_enable(&have_neon);
33+
}

0 commit comments

Comments
 (0)