Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

lib/crypto: blake2s: Drop excessive const & rename block => data

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>

+24 -27
+6 -7
include/crypto/blake2s.h
··· 67 67 } 68 68 } 69 69 70 - static inline void blake2s_init(struct blake2s_ctx *ctx, const size_t outlen) 70 + static inline void blake2s_init(struct blake2s_ctx *ctx, size_t outlen) 71 71 { 72 72 __blake2s_init(ctx, outlen, NULL, 0); 73 73 } 74 74 75 - static inline void blake2s_init_key(struct blake2s_ctx *ctx, 76 - const size_t outlen, const void *key, 77 - const size_t keylen) 75 + static inline void blake2s_init_key(struct blake2s_ctx *ctx, size_t outlen, 76 + const void *key, size_t keylen) 78 77 { 79 78 WARN_ON(IS_ENABLED(DEBUG) && (!outlen || outlen > BLAKE2S_HASH_SIZE || 80 79 !key || !keylen || keylen > BLAKE2S_KEY_SIZE)); ··· 84 85 void blake2s_update(struct blake2s_ctx *ctx, const u8 *in, size_t inlen); 85 86 void blake2s_final(struct blake2s_ctx *ctx, u8 *out); 86 87 87 - static inline void blake2s(const u8 *key, const size_t keylen, 88 - const u8 *in, const size_t inlen, 89 - u8 *out, const size_t outlen) 88 + static inline void blake2s(const u8 *key, size_t keylen, 89 + const u8 *in, size_t inlen, 90 + u8 *out, size_t outlen) 90 91 { 91 92 struct blake2s_ctx ctx; 92 93
+3 -3
lib/crypto/arm/blake2s-core.S
··· 171 171 172 172 // 173 173 // void blake2s_compress(struct blake2s_ctx *ctx, 174 - // const u8 *block, size_t nblocks, u32 inc); 174 + // const u8 *data, size_t nblocks, u32 inc); 175 175 // 176 176 // Only the first three fields of struct blake2s_ctx are used: 177 177 // u32 h[8]; (inout) ··· 184 184 185 185 .Lnext_block: 186 186 // r0 is 'ctx' 187 - // r1 is 'block' 187 + // r1 is 'data' 188 188 // r3 is 'inc' 189 189 190 190 // Load and increment the counter t[0..1]. ··· 275 275 // Advance to the next block, if there is one. Note that if there are 276 276 // multiple blocks, then 'inc' (the counter increment amount) must be 277 277 // 64. So we can simply set it to 64 without re-loading it. 278 - ldm sp, {r0, r1, r2} // load (ctx, block, nblocks) 278 + ldm sp, {r0, r1, r2} // load (ctx, data, nblocks) 279 279 mov r3, #64 // set 'inc' 280 280 subs r2, r2, #1 // nblocks-- 281 281 str r2, [sp, #8]
+1 -1
lib/crypto/arm/blake2s.h
··· 2 2 3 3 /* defined in blake2s-core.S */ 4 4 void blake2s_compress(struct blake2s_ctx *ctx, 5 - const u8 *block, size_t nblocks, u32 inc); 5 + const u8 *data, size_t nblocks, u32 inc);
+6 -6
lib/crypto/blake2s.c
··· 29 29 { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 }, 30 30 }; 31 31 32 - static inline void blake2s_increment_counter(struct blake2s_ctx *ctx, 33 - const u32 inc) 32 + static inline void blake2s_increment_counter(struct blake2s_ctx *ctx, u32 inc) 34 33 { 35 34 ctx->t[0] += inc; 36 35 ctx->t[1] += (ctx->t[0] < inc); 37 36 } 38 37 39 38 static void __maybe_unused 40 - blake2s_compress_generic(struct blake2s_ctx *ctx, const u8 *block, 41 - size_t nblocks, const u32 inc) 39 + blake2s_compress_generic(struct blake2s_ctx *ctx, 40 + const u8 *data, size_t nblocks, u32 inc) 42 41 { 43 42 u32 m[16]; 44 43 u32 v[16]; ··· 48 49 49 50 while (nblocks > 0) { 50 51 blake2s_increment_counter(ctx, inc); 51 - memcpy(m, block, BLAKE2S_BLOCK_SIZE); 52 + memcpy(m, data, BLAKE2S_BLOCK_SIZE); 52 53 le32_to_cpu_array(m, ARRAY_SIZE(m)); 53 54 memcpy(v, ctx->h, 32); 54 55 v[ 8] = BLAKE2S_IV0; ··· 98 99 for (i = 0; i < 8; ++i) 99 100 ctx->h[i] ^= v[i] ^ v[i + 8]; 100 101 101 - block += BLAKE2S_BLOCK_SIZE; 102 + data += BLAKE2S_BLOCK_SIZE; 102 103 --nblocks; 103 104 } 104 105 } ··· 129 130 } 130 131 if (inlen > BLAKE2S_BLOCK_SIZE) { 131 132 const size_t nblocks = DIV_ROUND_UP(inlen, BLAKE2S_BLOCK_SIZE); 133 + 132 134 blake2s_compress(ctx, in, nblocks - 1, BLAKE2S_BLOCK_SIZE); 133 135 in += BLAKE2S_BLOCK_SIZE * (nblocks - 1); 134 136 inlen -= BLAKE2S_BLOCK_SIZE * (nblocks - 1);
+8 -10
lib/crypto/x86/blake2s.h
··· 12 12 #include <linux/sizes.h> 13 13 14 14 asmlinkage void blake2s_compress_ssse3(struct blake2s_ctx *ctx, 15 - const u8 *block, const size_t nblocks, 16 - const u32 inc); 15 + const u8 *data, size_t nblocks, u32 inc); 17 16 asmlinkage void blake2s_compress_avx512(struct blake2s_ctx *ctx, 18 - const u8 *block, const size_t nblocks, 19 - const u32 inc); 17 + const u8 *data, size_t nblocks, u32 inc); 20 18 21 19 static __ro_after_init DEFINE_STATIC_KEY_FALSE(blake2s_use_ssse3); 22 20 static __ro_after_init DEFINE_STATIC_KEY_FALSE(blake2s_use_avx512); 23 21 24 - static void blake2s_compress(struct blake2s_ctx *ctx, const u8 *block, 25 - size_t nblocks, const u32 inc) 22 + static void blake2s_compress(struct blake2s_ctx *ctx, 23 + const u8 *data, size_t nblocks, u32 inc) 26 24 { 27 25 /* SIMD disables preemption, so relax after processing each page. */ 28 26 BUILD_BUG_ON(SZ_4K / BLAKE2S_BLOCK_SIZE < 8); 29 27 30 28 if (!static_branch_likely(&blake2s_use_ssse3) || !may_use_simd()) { 31 - blake2s_compress_generic(ctx, block, nblocks, inc); 29 + blake2s_compress_generic(ctx, data, nblocks, inc); 32 30 return; 33 31 } 34 32 ··· 36 38 37 39 kernel_fpu_begin(); 38 40 if (static_branch_likely(&blake2s_use_avx512)) 39 - blake2s_compress_avx512(ctx, block, blocks, inc); 41 + blake2s_compress_avx512(ctx, data, blocks, inc); 40 42 else 41 - blake2s_compress_ssse3(ctx, block, blocks, inc); 43 + blake2s_compress_ssse3(ctx, data, blocks, inc); 42 44 kernel_fpu_end(); 43 45 46 + data += blocks * BLAKE2S_BLOCK_SIZE; 44 47 nblocks -= blocks; 45 - block += blocks * BLAKE2S_BLOCK_SIZE; 46 48 } while (nblocks); 47 49 } 48 50