diff mbox series

[2/4] crypto: zynqmp-sha - Make descsize an algorithm attribute

Message ID 9df87c9d53d8bbed751d28c2091dd0fb1705717f.1744454589.git.herbert@gondor.apana.org.au
State New
Headers show
Series crypto: shash - Remove dynamic descsize | expand

Commit Message

Herbert Xu April 12, 2025, 10:47 a.m. UTC
Rather than setting descsize in init_tfm, set it statically and
double-check it in init_tfm.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
---
 drivers/crypto/xilinx/zynqmp-sha.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/drivers/crypto/xilinx/zynqmp-sha.c b/drivers/crypto/xilinx/zynqmp-sha.c
index 580649f9bff8..f66e0a4c1169 100644
--- a/drivers/crypto/xilinx/zynqmp-sha.c
+++ b/drivers/crypto/xilinx/zynqmp-sha.c
@@ -60,8 +60,14 @@  static int zynqmp_sha_init_tfm(struct crypto_shash *hash)
 	if (IS_ERR(fallback_tfm))
 		return PTR_ERR(fallback_tfm);
 
+	if (crypto_shash_descsize(hash) <
+	    sizeof(struct zynqmp_sha_desc_ctx) +
+	    crypto_shash_descsize(tfm_ctx->fbk_tfm)) {
+		crypto_free_shash(fallback_tfm);
+		return -EINVAL;
+	}
+
 	tfm_ctx->fbk_tfm = fallback_tfm;
-	hash->descsize += crypto_shash_descsize(tfm_ctx->fbk_tfm);
 
 	return 0;
 }
@@ -170,7 +176,8 @@  static struct zynqmp_sha_drv_ctx sha3_drv_ctx = {
 		.import = zynqmp_sha_import,
 		.init_tfm = zynqmp_sha_init_tfm,
 		.exit_tfm = zynqmp_sha_exit_tfm,
-		.descsize = sizeof(struct zynqmp_sha_desc_ctx),
+		.descsize = sizeof(struct zynqmp_sha_desc_ctx) +
+			    sizeof(struct sha3_state),
 		.statesize = sizeof(struct sha3_state),
 		.digestsize = SHA3_384_DIGEST_SIZE,
 		.base = {