]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
lib/crypto: blake2s: Drop excessive const & rename block => data
authorEric Biggers <ebiggers@kernel.org>
Sat, 18 Oct 2025 04:30:59 +0000 (21:30 -0700)
committerEric Biggers <ebiggers@kernel.org>
Thu, 30 Oct 2025 05:04:24 +0000 (22:04 -0700)
A couple more small cleanups to the BLAKE2s code before these things get
propagated into the BLAKE2b code:

- Drop 'const' from some non-pointer function parameters.  It was a bit
  excessive and not conventional.

- Rename 'block' argument of blake2s_compress*() to 'data'.  This is for
  consistency with the SHA-* code, and also to avoid the implication
  that it points to a singular "block".

No functional changes.

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20251018043106.375964-4-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>
include/crypto/blake2s.h
lib/crypto/arm/blake2s-core.S
lib/crypto/arm/blake2s.h
lib/crypto/blake2s.c
lib/crypto/x86/blake2s.h

index 4c8d532ee97b3c010f04ba3f3fab49367f758e5d..33893057eb41434185a1f4f88c5eba4ac7551238 100644 (file)
@@ -67,14 +67,13 @@ static inline void __blake2s_init(struct blake2s_ctx *ctx, size_t outlen,
        }
 }
 
-static inline void blake2s_init(struct blake2s_ctx *ctx, const size_t outlen)
+static inline void blake2s_init(struct blake2s_ctx *ctx, size_t outlen)
 {
        __blake2s_init(ctx, outlen, NULL, 0);
 }
 
-static inline void blake2s_init_key(struct blake2s_ctx *ctx,
-                                   const size_t outlen, const void *key,
-                                   const size_t keylen)
+static inline void blake2s_init_key(struct blake2s_ctx *ctx, size_t outlen,
+                                   const void *key, size_t keylen)
 {
        WARN_ON(IS_ENABLED(DEBUG) && (!outlen || outlen > BLAKE2S_HASH_SIZE ||
                !key || !keylen || keylen > BLAKE2S_KEY_SIZE));
@@ -85,9 +84,9 @@ static inline void blake2s_init_key(struct blake2s_ctx *ctx,
 void blake2s_update(struct blake2s_ctx *ctx, const u8 *in, size_t inlen);
 void blake2s_final(struct blake2s_ctx *ctx, u8 *out);
 
-static inline void blake2s(const u8 *key, const size_t keylen,
-                          const u8 *in, const size_t inlen,
-                          u8 *out, const size_t outlen)
+static inline void blake2s(const u8 *key, size_t keylen,
+                          const u8 *in, size_t inlen,
+                          u8 *out, size_t outlen)
 {
        struct blake2s_ctx ctx;
 
index 78e758a7cb3e246d761274ab9d6faf1488204595..14eb7c18a8365a4c1e80747f7c8b92658f9cbee0 100644 (file)
 
 //
 // void blake2s_compress(struct blake2s_ctx *ctx,
-//                      const u8 *block, size_t nblocks, u32 inc);
+//                      const u8 *data, size_t nblocks, u32 inc);
 //
 // Only the first three fields of struct blake2s_ctx are used:
 //     u32 h[8];       (inout)
@@ -184,7 +184,7 @@ ENTRY(blake2s_compress)
 
 .Lnext_block:
        // r0 is 'ctx'
-       // r1 is 'block'
+       // r1 is 'data'
        // r3 is 'inc'
 
        // Load and increment the counter t[0..1].
@@ -275,7 +275,7 @@ ENTRY(blake2s_compress)
        // Advance to the next block, if there is one.  Note that if there are
        // multiple blocks, then 'inc' (the counter increment amount) must be
        // 64.  So we can simply set it to 64 without re-loading it.
-       ldm             sp, {r0, r1, r2}        // load (ctx, block, nblocks)
+       ldm             sp, {r0, r1, r2}        // load (ctx, data, nblocks)
        mov             r3, #64                 // set 'inc'
        subs            r2, r2, #1              // nblocks--
        str             r2, [sp, #8]
index ce009cd98de90ebe9ef2370d668c4a884306b8f8..42c04440c1913331dbadbb19777545a4f3f2b0ce 100644 (file)
@@ -2,4 +2,4 @@
 
 /* defined in blake2s-core.S */
 void blake2s_compress(struct blake2s_ctx *ctx,
-                     const u8 *block, size_t nblocks, u32 inc);
+                     const u8 *data, size_t nblocks, u32 inc);
index 1ad36cb29835fd7942298edcb13dcb1cd8481fe9..6182c21ed943d8d65dabb2ebf00af06f096c2a4d 100644 (file)
@@ -29,16 +29,15 @@ static const u8 blake2s_sigma[10][16] = {
        { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
 };
 
-static inline void blake2s_increment_counter(struct blake2s_ctx *ctx,
-                                            const u32 inc)
+static inline void blake2s_increment_counter(struct blake2s_ctx *ctx, u32 inc)
 {
        ctx->t[0] += inc;
        ctx->t[1] += (ctx->t[0] < inc);
 }
 
 static void __maybe_unused
-blake2s_compress_generic(struct blake2s_ctx *ctx, const u8 *block,
-                        size_t nblocks, const u32 inc)
+blake2s_compress_generic(struct blake2s_ctx *ctx,
+                        const u8 *data, size_t nblocks, u32 inc)
 {
        u32 m[16];
        u32 v[16];
@@ -49,7 +48,7 @@ blake2s_compress_generic(struct blake2s_ctx *ctx, const u8 *block,
 
        while (nblocks > 0) {
                blake2s_increment_counter(ctx, inc);
-               memcpy(m, block, BLAKE2S_BLOCK_SIZE);
+               memcpy(m, data, BLAKE2S_BLOCK_SIZE);
                le32_to_cpu_array(m, ARRAY_SIZE(m));
                memcpy(v, ctx->h, 32);
                v[ 8] = BLAKE2S_IV0;
@@ -99,7 +98,7 @@ blake2s_compress_generic(struct blake2s_ctx *ctx, const u8 *block,
                for (i = 0; i < 8; ++i)
                        ctx->h[i] ^= v[i] ^ v[i + 8];
 
-               block += BLAKE2S_BLOCK_SIZE;
+               data += BLAKE2S_BLOCK_SIZE;
                --nblocks;
        }
 }
@@ -130,6 +129,7 @@ void blake2s_update(struct blake2s_ctx *ctx, const u8 *in, size_t inlen)
        }
        if (inlen > BLAKE2S_BLOCK_SIZE) {
                const size_t nblocks = DIV_ROUND_UP(inlen, BLAKE2S_BLOCK_SIZE);
+
                blake2s_compress(ctx, in, nblocks - 1, BLAKE2S_BLOCK_SIZE);
                in += BLAKE2S_BLOCK_SIZE * (nblocks - 1);
                inlen -= BLAKE2S_BLOCK_SIZE * (nblocks - 1);
index de360935b8204dbf438088f1b0d70a929991838f..f8eed6cb042e4b541bd6b06277081c310a584bd3 100644 (file)
 #include <linux/sizes.h>
 
 asmlinkage void blake2s_compress_ssse3(struct blake2s_ctx *ctx,
-                                      const u8 *block, const size_t nblocks,
-                                      const u32 inc);
+                                      const u8 *data, size_t nblocks, u32 inc);
 asmlinkage void blake2s_compress_avx512(struct blake2s_ctx *ctx,
-                                       const u8 *block, const size_t nblocks,
-                                       const u32 inc);
+                                       const u8 *data, size_t nblocks, u32 inc);
 
 static __ro_after_init DEFINE_STATIC_KEY_FALSE(blake2s_use_ssse3);
 static __ro_after_init DEFINE_STATIC_KEY_FALSE(blake2s_use_avx512);
 
-static void blake2s_compress(struct blake2s_ctx *ctx, const u8 *block,
-                            size_t nblocks, const u32 inc)
+static void blake2s_compress(struct blake2s_ctx *ctx,
+                            const u8 *data, size_t nblocks, u32 inc)
 {
        /* SIMD disables preemption, so relax after processing each page. */
        BUILD_BUG_ON(SZ_4K / BLAKE2S_BLOCK_SIZE < 8);
 
        if (!static_branch_likely(&blake2s_use_ssse3) || !may_use_simd()) {
-               blake2s_compress_generic(ctx, block, nblocks, inc);
+               blake2s_compress_generic(ctx, data, nblocks, inc);
                return;
        }
 
@@ -38,13 +36,13 @@ static void blake2s_compress(struct blake2s_ctx *ctx, const u8 *block,
 
                kernel_fpu_begin();
                if (static_branch_likely(&blake2s_use_avx512))
-                       blake2s_compress_avx512(ctx, block, blocks, inc);
+                       blake2s_compress_avx512(ctx, data, blocks, inc);
                else
-                       blake2s_compress_ssse3(ctx, block, blocks, inc);
+                       blake2s_compress_ssse3(ctx, data, blocks, inc);
                kernel_fpu_end();
 
+               data += blocks * BLAKE2S_BLOCK_SIZE;
                nblocks -= blocks;
-               block += blocks * BLAKE2S_BLOCK_SIZE;
        } while (nblocks);
 }