uadk_engine/0058-uadk_digest-fix-the-full-mac-buffer-length-as-doing-.patch
2023-08-04 16:24:25 +08:00

75 lines
2.3 KiB
Diff

From 36ea42a1d9556e937be5ebf47f41f66b51a29cb6 Mon Sep 17 00:00:00 2001
From: Kai Ye <yekai13@huawei.com>
Date: Tue, 16 Aug 2022 09:57:18 +0800
Subject: uadk_digest: fix the full mac buffer length as doing long hash
Sha224 and Sha384 need full length mac buffer as doing long hash.
Depends-on:uadk 802878d71999("digest: fix mac buffer len as long hash")
Signed-off-by: Kai Ye <yekai13@huawei.com>
---
src/uadk_digest.c | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/src/uadk_digest.c b/src/uadk_digest.c
index b2646cb..63887e7 100644
--- a/src/uadk_digest.c
+++ b/src/uadk_digest.c
@@ -484,7 +484,7 @@ static void digest_priv_ctx_setup(struct digest_priv_ctx *priv,
{
priv->setup.alg = alg;
priv->setup.mode = mode;
- priv->req.out_buf_bytes = out_len;
+ priv->req.out_buf_bytes = MAX_DIGEST_LENGTH;
priv->req.out_bytes = out_len;
}
@@ -543,15 +543,30 @@ soft_init:
return digest_soft_init(priv->soft_ctx, priv->e_nid);
}
+static void digest_update_out_length(EVP_MD_CTX *ctx)
+{
+ struct digest_priv_ctx *priv =
+ (struct digest_priv_ctx *)EVP_MD_CTX_md_data(ctx);
+
+ /* Sha224 and Sha384 need full length mac buffer as doing long hash */
+ if (priv->e_nid == NID_sha224)
+ priv->req.out_bytes = WD_DIGEST_SHA224_FULL_LEN;
+
+ if (priv->e_nid == NID_sha384)
+ priv->req.out_bytes = WD_DIGEST_SHA384_FULL_LEN;
+}
+
static int digest_update_inner(EVP_MD_CTX *ctx, const void *data, size_t data_len)
{
struct digest_priv_ctx *priv =
- (struct digest_priv_ctx *) EVP_MD_CTX_md_data(ctx);
+ (struct digest_priv_ctx *)EVP_MD_CTX_md_data(ctx);
const unsigned char *tmpdata = (const unsigned char *)data;
size_t left_len = data_len;
int copy_to_bufflen;
int ret;
+ digest_update_out_length(ctx);
+
priv->req.has_next = DIGEST_DOING;
while (priv->last_update_bufflen + left_len > DIGEST_BLOCK_SIZE) {
@@ -708,6 +723,12 @@ static int uadk_e_digest_final(EVP_MD_CTX *ctx, unsigned char *digest)
priv->req.in_bytes = priv->last_update_bufflen;
priv->e_nid = EVP_MD_nid(EVP_MD_CTX_md(ctx));
+ if (priv->e_nid == NID_sha224)
+ priv->req.out_bytes = WD_DIGEST_SHA224_LEN;
+
+ if (priv->e_nid == NID_sha384)
+ priv->req.out_bytes = WD_DIGEST_SHA384_LEN;
+
ret = async_setup_async_event_notification(&op);
if (unlikely(!ret)) {
fprintf(stderr, "failed to setup async event notification.\n");
--
1.8.3.1