]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/crypto: arm64: Move remaining algorithms to scoped ksimd API
authorArd Biesheuvel <ardb@kernel.org>
Wed, 12 Nov 2025 08:54:34 +0000 (09:54 +0100)
committerEric Biggers <ebiggers@kernel.org>
Wed, 12 Nov 2025 18:14:11 +0000 (10:14 -0800)
Move the arm64 implementations of SHA-3 and POLYVAL to the newly
introduced scoped ksimd API, which replaces kernel_neon_begin() and
kernel_neon_end(). On arm64, this is needed because the latter API
will change in an incompatible manner.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
lib/crypto/arm64/polyval.h
lib/crypto/arm64/sha3.h

index 2486e80750d079a3eabedad754dbe00d2c557569..a39763395e9bf2542229089d85a4f73ce6aad0c2 100644 (file)
@@ -4,7 +4,6 @@
  *
  * Copyright 2025 Google LLC
  */
-#include <asm/neon.h>
 #include <asm/simd.h>
 #include <linux/cpufeature.h>
 
@@ -24,13 +23,14 @@ static void polyval_preparekey_arch(struct polyval_key *key,
        static_assert(ARRAY_SIZE(key->h_powers) == NUM_H_POWERS);
        memcpy(&key->h_powers[NUM_H_POWERS - 1], raw_key, POLYVAL_BLOCK_SIZE);
        if (static_branch_likely(&have_pmull) && may_use_simd()) {
-               kernel_neon_begin();
-               for (int i = NUM_H_POWERS - 2; i >= 0; i--) {
-                       key->h_powers[i] = key->h_powers[i + 1];
-                       polyval_mul_pmull(&key->h_powers[i],
-                                         &key->h_powers[NUM_H_POWERS - 1]);
+               scoped_ksimd() {
+                       for (int i = NUM_H_POWERS - 2; i >= 0; i--) {
+                               key->h_powers[i] = key->h_powers[i + 1];
+                               polyval_mul_pmull(
+                                       &key->h_powers[i],
+                                       &key->h_powers[NUM_H_POWERS - 1]);
+                       }
                }
-               kernel_neon_end();
        } else {
                for (int i = NUM_H_POWERS - 2; i >= 0; i--) {
                        key->h_powers[i] = key->h_powers[i + 1];
@@ -44,9 +44,8 @@ static void polyval_mul_arch(struct polyval_elem *acc,
                             const struct polyval_key *key)
 {
        if (static_branch_likely(&have_pmull) && may_use_simd()) {
-               kernel_neon_begin();
-               polyval_mul_pmull(acc, &key->h_powers[NUM_H_POWERS - 1]);
-               kernel_neon_end();
+               scoped_ksimd()
+                       polyval_mul_pmull(acc, &key->h_powers[NUM_H_POWERS - 1]);
        } else {
                polyval_mul_generic(acc, &key->h_powers[NUM_H_POWERS - 1]);
        }
@@ -62,9 +61,8 @@ static void polyval_blocks_arch(struct polyval_elem *acc,
                        size_t n = min_t(size_t, nblocks,
                                         4096 / POLYVAL_BLOCK_SIZE);
 
-                       kernel_neon_begin();
-                       polyval_blocks_pmull(acc, key, data, n);
-                       kernel_neon_end();
+                       scoped_ksimd()
+                               polyval_blocks_pmull(acc, key, data, n);
                        data += n * POLYVAL_BLOCK_SIZE;
                        nblocks -= n;
                } while (nblocks);
index 6dd5183056da40c5949e83c85a4f4e5a0d3a6127..b602f1b3b2822e510b1ffbed2af30f5639b1ac37 100644 (file)
@@ -7,7 +7,6 @@
  * published by the Free Software Foundation.
  */
 
-#include <asm/neon.h>
 #include <asm/simd.h>
 #include <linux/cpufeature.h>
 
@@ -23,10 +22,9 @@ static void sha3_absorb_blocks(struct sha3_state *state, const u8 *data,
                do {
                        size_t rem;
 
-                       kernel_neon_begin();
-                       rem = sha3_ce_transform(state, data, nblocks,
-                                               block_size);
-                       kernel_neon_end();
+                       scoped_ksimd()
+                               rem = sha3_ce_transform(state, data, nblocks,
+                                                       block_size);
                        data += (nblocks - rem) * block_size;
                        nblocks = rem;
                } while (nblocks);
@@ -46,9 +44,8 @@ static void sha3_keccakf(struct sha3_state *state)
                 */
                static const u8 zeroes[SHA3_512_BLOCK_SIZE];
 
-               kernel_neon_begin();
-               sha3_ce_transform(state, zeroes, 1, sizeof(zeroes));
-               kernel_neon_end();
+               scoped_ksimd()
+                       sha3_ce_transform(state, zeroes, 1, sizeof(zeroes));
        } else {
                sha3_keccakf_generic(state);
        }