From: Wenkai Lin linwenkai6@hisilicon.com
An uadk check error caused because digest mac full length check does not consider the new added request message type, so mac full length needs to be checked based on all message types.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- include/wd_digest.h | 1 + wd_digest.c | 33 ++++++++++++++++++++------------- 2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/include/wd_digest.h b/include/wd_digest.h index 7539866..ad4d579 100644 --- a/include/wd_digest.h +++ b/include/wd_digest.h @@ -90,6 +90,7 @@ enum wd_digest_msg_state { WD_DIGEST_DOING, WD_DIGEST_STREAM_END, WD_DIGEST_STREAM_DOING, + WD_DIGEST_MSG_STATE_MAX, };
/** diff --git a/wd_digest.c b/wd_digest.c index 69c4b28..2307bf1 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -463,19 +463,26 @@ static int wd_mac_length_check(struct wd_digest_sess *sess, return -WD_EINVAL; }
- if (unlikely(!req->has_next && - req->out_bytes > g_digest_mac_len[sess->alg])) { - WD_ERR("invalid: digest mac length, alg = %d, out_bytes = %u\n", - sess->alg, req->out_bytes); - return -WD_EINVAL; - } - - /* User need to input full mac buffer in first and middle hash */ - if (unlikely(req->has_next && - req->out_bytes != g_digest_mac_full_len[sess->alg])) { - WD_ERR("invalid: digest mac full length is error, alg = %d, out_bytes = %u\n", - sess->alg, req->out_bytes); - return -WD_EINVAL; + switch (req->has_next) { + case WD_DIGEST_END: + case WD_DIGEST_STREAM_END: + if (unlikely(req->out_bytes > g_digest_mac_len[sess->alg])) { + WD_ERR("invalid: digest mac length, alg = %d, out_bytes = %u\n", + sess->alg, req->out_bytes); + return -WD_EINVAL; + } + break; + case WD_DIGEST_DOING: + case WD_DIGEST_STREAM_DOING: + /* User need to input full mac buffer in first and middle hash */ + if (unlikely(req->out_bytes != g_digest_mac_full_len[sess->alg])) { + WD_ERR("invalid: digest mac full length, alg = %d, out_bytes = %u\n", + sess->alg, req->out_bytes); + return -WD_EINVAL; + } + break; + default: + break; }
return 0;