From: Wenkai Lin linwenkai6@hisilicon.com
According to the HMAC rfc, the auth key could be 0 bytes, so remove the wrong judgment.
Signed-off-by: Wenkai Lin linwenkai6@hisilicon.com --- v1/wd_aead.c | 12 ++++++------ wd_aead.c | 8 +++----- 2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/v1/wd_aead.c b/v1/wd_aead.c index 3ebe1899..f79c9d9c 100644 --- a/v1/wd_aead.c +++ b/v1/wd_aead.c @@ -387,14 +387,11 @@ int wcrypto_set_aead_akey(void *ctx, __u8 *key, __u16 key_len) { struct wcrypto_aead_ctx *ctxt = ctx;
- if (!ctx || !key) { - WD_ERR("input param is NULL!\n"); + if (!ctx || (key_len && !key)) { + WD_ERR("failed to check authenticate key param!\n"); return -WD_EINVAL; }
- if (key_len == 0) - goto err_key_len; - if (ctxt->setup.dalg > WCRYPTO_SHA256) { if (key_len > MAX_HMAC_KEY_SIZE) goto err_key_len; @@ -405,6 +402,9 @@ int wcrypto_set_aead_akey(void *ctx, __u8 *key, __u16 key_len)
ctxt->akey_bytes = key_len;
+ if (!key_len) + return WD_SUCCESS; + if (ctxt->setup.data_fmt == WD_SGL_BUF) wd_sgl_cp_from_pbuf(ctxt->akey, 0, key, key_len); else @@ -413,7 +413,7 @@ int wcrypto_set_aead_akey(void *ctx, __u8 *key, __u16 key_len) return WD_SUCCESS;
err_key_len: - WD_ERR("fail to check key length!\n"); + WD_ERR("failed to check authenticate key length, size = %u\n", key_len); return -WD_EINVAL; }
diff --git a/wd_aead.c b/wd_aead.c index c6c40374..9cf85d13 100644 --- a/wd_aead.c +++ b/wd_aead.c @@ -208,14 +208,11 @@ int wd_aead_set_akey(handle_t h_sess, const __u8 *key, __u16 key_len) { struct wd_aead_sess *sess = (struct wd_aead_sess *)h_sess;
- if (unlikely(!key || !sess)) { + if (!sess || (key_len && !key)) { WD_ERR("failed to check authenticate key param!\n"); return -WD_EINVAL; }
- if (key_len == 0) - goto err_key_len; - /* * Here dalg only supports sha1, sha256, sha512, * and should check key length with different max length. @@ -229,7 +226,8 @@ int wd_aead_set_akey(handle_t h_sess, const __u8 *key, __u16 key_len) }
sess->akey_bytes = key_len; - memcpy(sess->akey, key, key_len); + if (key_len) + memcpy(sess->akey, key, key_len);
return 0;