diff mbox series

[v2,1/6] crypto: shash - Cap state size to HASH_MAX_STATESIZE

Message ID 40527d5a34051a880c06fdcead0f566cc0e5a0ce.1746365585.git.herbert@gondor.apana.org.au
State New
Headers show
Series [v2,1/6] crypto: shash - Cap state size to HASH_MAX_STATESIZE | expand

Commit Message

Herbert Xu May 4, 2025, 1:33 p.m. UTC
Now that all shash algorithms have converted over to the generic
export format, limit the shash state size to HASH_MAX_STATESIZE.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 crypto/shash.c        | 2 ++
 include/crypto/hash.h | 5 ++++-
 2 files changed, 6 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/crypto/shash.c b/crypto/shash.c
index c4a724e55d7a..44a6df3132ad 100644
--- a/crypto/shash.c
+++ b/crypto/shash.c
@@ -479,6 +479,8 @@  static int shash_prepare_alg(struct shash_alg *alg)
 
 	if (alg->descsize > HASH_MAX_DESCSIZE)
 		return -EINVAL;
+	if (alg->statesize > HASH_MAX_STATESIZE)
+		return -EINVAL;
 
 	return 0;
 }
diff --git a/include/crypto/hash.h b/include/crypto/hash.h
index c2497c300a28..e0321b5ec363 100644
--- a/include/crypto/hash.h
+++ b/include/crypto/hash.h
@@ -167,8 +167,11 @@  struct shash_desc {
 
 #define HASH_MAX_DIGESTSIZE	 64
 
+/* Worst case is sha3-224. */
+#define HASH_MAX_STATESIZE	 200 + 144 + 1
+
 /*
- * Worst case is hmac(sha-224-s390).  Its context is a nested 'shash_desc'
+ * Worst case is hmac(sha3-224-s390).  Its context is a nested 'shash_desc'
  * containing a 'struct s390_sha_ctx'.
  */
 #define HASH_MAX_DESCSIZE	(sizeof(struct shash_desc) + 360)