From 6136bd700e5f5b23843a3e8aae9e3a925c37ca50 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Tue, 14 Dec 2021 19:24:49 +0800
Subject: [PATCH 05/28] digest/v1: check the length of the key need to be
 changed.

The maximum length of the key is fixed by digest spec.

Signed-off-by: Kai Ye <yekai13@huawei.com>
---
 v1/wd_digest.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/v1/wd_digest.c b/v1/wd_digest.c
index d684512..aae4823 100644
--- a/v1/wd_digest.c
+++ b/v1/wd_digest.c
@@ -243,7 +243,9 @@ int wcrypto_set_digest_key(void *ctx, __u8 *key, __u16 key_len)
 		return -WD_EINVAL;
 	}
 
-	if (key_len == 0 || key_len > MAX_HMAC_KEY_SIZE) {
+	if ((ctxt->setup.alg <= WCRYPTO_SHA224 && key_len >
+		MAX_HMAC_KEY_SIZE >> 1) || key_len == 0 ||
+		key_len > MAX_HMAC_KEY_SIZE) {
 		WD_ERR("%s: input key length err!\n", __func__);
 		return -WD_EINVAL;
 	}
-- 
2.31.1

