Skip to content

Commit b4a8528

Browse files
author
Eric Biggers
committed
lib/crypto: arm64/nh: Migrate optimized code into library
Migrate the arm64 NEON implementation of NH into lib/crypto/. This makes the nh() function be optimized on arm64 kernels. Note: this temporarily makes the adiantum template not utilize the arm64 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-5-ebiggers@kernel.org Signed-off-by: Eric Biggers <ebiggers@kernel.org>
1 parent 29e39a1 commit b4a8528

7 files changed

Lines changed: 37 additions & 94 deletions

File tree

arch/arm64/crypto/Kconfig

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,6 @@ config CRYPTO_GHASH_ARM64_CE
1515
Architecture: arm64 using:
1616
- ARMv8 Crypto Extensions
1717

18-
config CRYPTO_NHPOLY1305_NEON
19-
tristate "Hash functions: NHPoly1305 (NEON)"
20-
depends on KERNEL_MODE_NEON
21-
select CRYPTO_NHPOLY1305
22-
help
23-
NHPoly1305 hash function (Adiantum)
24-
25-
Architecture: arm64 using:
26-
- NEON (Advanced SIMD) extensions
27-
2818
config CRYPTO_SM3_NEON
2919
tristate "Hash functions: SM3 (NEON)"
3020
depends on KERNEL_MODE_NEON

arch/arm64/crypto/Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ aes-ce-blk-y := aes-glue-ce.o aes-ce.o
4141
obj-$(CONFIG_CRYPTO_AES_ARM64_NEON_BLK) += aes-neon-blk.o
4242
aes-neon-blk-y := aes-glue-neon.o aes-neon.o
4343

44-
obj-$(CONFIG_CRYPTO_NHPOLY1305_NEON) += nhpoly1305-neon.o
45-
nhpoly1305-neon-y := nh-neon-core.o nhpoly1305-neon-glue.o
46-
4744
obj-$(CONFIG_CRYPTO_AES_ARM64) += aes-arm64.o
4845
aes-arm64-y := aes-cipher-core.o aes-cipher-glue.o
4946

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

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

lib/crypto/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ config CRYPTO_LIB_NH_ARCH
118118
bool
119119
depends on CRYPTO_LIB_NH && !UML
120120
default y if ARM && KERNEL_MODE_NEON
121+
default y if ARM64 && KERNEL_MODE_NEON
121122

122123
config CRYPTO_LIB_POLY1305
123124
tristate

lib/crypto/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ libnh-y := nh.o
136136
ifeq ($(CONFIG_CRYPTO_LIB_NH_ARCH),y)
137137
CFLAGS_nh.o += -I$(src)/$(SRCARCH)
138138
libnh-$(CONFIG_ARM) += arm/nh-neon-core.o
139+
libnh-$(CONFIG_ARM64) += arm64/nh-neon-core.o
139140
endif
140141

141142
################################################################################
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
*/
99

1010
#include <linux/linkage.h>
11-
#include <linux/cfi_types.h>
1211

1312
KEY .req x0
1413
MESSAGE .req x1
@@ -63,7 +62,7 @@
6362
*
6463
* It's guaranteed that message_len % 16 == 0.
6564
*/
66-
SYM_TYPED_FUNC_START(nh_neon)
65+
SYM_FUNC_START(nh_neon)
6766

6867
ld1 {K0.4s,K1.4s}, [KEY], #32
6968
movi PASS0_SUMS.2d, #0

lib/crypto/arm64/nh.h

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

0 commit comments

Comments
 (0)