public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/crypto: sha1: Explicitly specify alignment of sha1_ctx::buf
@ 2026-03-20 23:14 Eric Biggers
  2026-03-21  5:59 ` Eric Biggers
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Biggers @ 2026-03-20 23:14 UTC (permalink / raw)
  To: linux-crypto
  Cc: linux-kernel, Ard Biesheuvel, Jason A . Donenfeld, Herbert Xu,
	Eric Biggers

__sha1_final() writes a __be64 to &ctx->buf[56] using a plain write.
That assumes that the alignment of buf is at least that of __be64.  It
is, since it immediately follows a u64 field.  However, to make this
assumption explicit it's best to specify the field alignment explicitly
too, like what is done in the corresponding SHA-2 and MD5 structs.

Signed-off-by: Eric Biggers <ebiggers@kernel.org>
---
 include/crypto/sha1.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/crypto/sha1.h b/include/crypto/sha1.h
index 4d973e016cd6..560ed4fd1703 100644
--- a/include/crypto/sha1.h
+++ b/include/crypto/sha1.h
@@ -38,11 +38,11 @@ struct sha1_block_state {
  * @buf: partial block buffer; bytecount % SHA1_BLOCK_SIZE bytes are valid
  */
 struct sha1_ctx {
 	struct sha1_block_state state;
 	u64 bytecount;
-	u8 buf[SHA1_BLOCK_SIZE];
+	u8 buf[SHA1_BLOCK_SIZE] __aligned(__alignof__(__be64));
 };
 
 /**
  * sha1_init() - Initialize a SHA-1 context for a new message
  * @ctx: the context to initialize

base-commit: 6bc9effb4cbf9b6eba0f51aba1c8893dfd4c8100
-- 
2.53.0


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

end of thread, other threads:[~2026-03-21  6:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-20 23:14 [PATCH] lib/crypto: sha1: Explicitly specify alignment of sha1_ctx::buf Eric Biggers
2026-03-21  5:59 ` Eric Biggers

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