public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] crypto: blake2b - use memcpy_and_pad in __blake2b_init
@ 2026-04-14 15:49 Thorsten Blum
  2026-04-14 15:49 ` [PATCH 2/2] crypto: blake2s - use memcpy_and_pad in __blake2s_init Thorsten Blum
  0 siblings, 1 reply; 3+ messages in thread
From: Thorsten Blum @ 2026-04-14 15:49 UTC (permalink / raw)
  To: Herbert Xu, David S. Miller; +Cc: Thorsten Blum, linux-crypto, linux-kernel

Use memcpy_and_pad() instead of memcpy() followed by memset() to
simplify __blake2b_init(). Use sizeof(ctx->buf) instead of the macro
BLAKE2B_BLOCK_SIZE.

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
 include/crypto/blake2b.h | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/include/crypto/blake2b.h b/include/crypto/blake2b.h
index 3bc37fd103a7..a7a6440bd784 100644
--- a/include/crypto/blake2b.h
+++ b/include/crypto/blake2b.h
@@ -66,9 +66,8 @@ static inline void __blake2b_init(struct blake2b_ctx *ctx, size_t outlen,
 	ctx->buflen = 0;
 	ctx->outlen = outlen;
 	if (keylen) {
-		memcpy(ctx->buf, key, keylen);
-		memset(&ctx->buf[keylen], 0, BLAKE2B_BLOCK_SIZE - keylen);
-		ctx->buflen = BLAKE2B_BLOCK_SIZE;
+		memcpy_and_pad(ctx->buf, sizeof(ctx->buf), key, keylen, 0);
+		ctx->buflen = sizeof(ctx->buf);
 	}
 }
 

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-14 17:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-14 15:49 [PATCH 1/2] crypto: blake2b - use memcpy_and_pad in __blake2b_init Thorsten Blum
2026-04-14 15:49 ` [PATCH 2/2] crypto: blake2s - use memcpy_and_pad in __blake2s_init Thorsten Blum
2026-04-14 17:39   ` Eric Biggers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox