From: Chenghai Huang huangchenghai2@huawei.com
The digest update after optimization needs to distinguish whether the buffer is copied. If the buffer is filled, the data in the buffer after the copy will be processed. Otherwise, the remaining data will be processed directly.
Signed-off-by: Chenghai Huang huangchenghai2@huawei.com --- src/uadk_prov_digest.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-)
diff --git a/src/uadk_prov_digest.c b/src/uadk_prov_digest.c index 8af894e..91c091b 100644 --- a/src/uadk_prov_digest.c +++ b/src/uadk_prov_digest.c @@ -356,13 +356,19 @@ static int uadk_digest_update_inner(struct digest_priv_ctx *priv, const void *da uadk_fill_mac_buffer_len(priv);
do { - if (left_len == data_len) { + /* + * If there is data in the buffer, it will be filled and processed. Otherwise, it + * will be processed according to the UADK package len(16M-512Byte). Finally the + * remaining data less than the size of the buffer will be stored in the buffer. + */ + if (priv->last_update_bufflen != 0) { processing_len = DIGEST_BLOCK_SIZE - priv->last_update_bufflen; uadk_memcpy(priv->data + priv->last_update_bufflen, tmpdata, processing_len);
priv->req.in_bytes = DIGEST_BLOCK_SIZE; priv->req.in = priv->data; + priv->last_update_bufflen = 0; } else { if (left_len > BUF_LEN) processing_len = BUF_LEN; @@ -395,14 +401,15 @@ static int uadk_digest_update_inner(struct digest_priv_ctx *priv, const void *da return UADK_DIGEST_SUCCESS;
do_soft_digest: - if (priv->state == SEC_DIGEST_FIRST_UPDATING - && priv->data - && priv->last_update_bufflen != 0) { + if (priv->state == SEC_DIGEST_FIRST_UPDATING) { priv->switch_flag = UADK_DO_SOFT; uadk_digest_soft_init(priv); - ret = uadk_digest_soft_update(priv, priv->data, priv->last_update_bufflen); - if (ret != 1) - return ret; + /* filling buf has been executed */ + if (processing_len < DIGEST_BLOCK_SIZE) { + ret = uadk_digest_soft_update(priv, priv->data, DIGEST_BLOCK_SIZE); + if (ret != 1) + return ret; + }
return uadk_digest_soft_update(priv, tmpdata, left_len); }