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_digest.c | 13 +++++++------ wd_digest.c | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/v1/wd_digest.c b/v1/wd_digest.c index 3d05688d..e26909d3 100644 --- a/v1/wd_digest.c +++ b/v1/wd_digest.c @@ -274,6 +274,10 @@ static int digest_hmac_key_check(enum wcrypto_digest_alg alg, __u16 key_len) } break; case WCRYPTO_SHA384 ... WCRYPTO_SHA512_256: + if (key_len > MAX_HMAC_KEY_SIZE) { + WD_ERR("failed to check alg %u key bytes, key_len = %u\n", alg, key_len); + return -WD_EINVAL; + } break; case WCRYPTO_AES_XCBC_MAC_96: case WCRYPTO_AES_XCBC_PRF_128: @@ -304,21 +308,18 @@ int wcrypto_set_digest_key(void *ctx, __u8 *key, __u16 key_len) struct wcrypto_digest_ctx *ctxt = ctx; int ret;
- if (!ctx || !key) { + if (!ctx || (key_len && !key)) { WD_ERR("%s(): input param err!\n", __func__); return -WD_EINVAL; }
- if (key_len == 0 || key_len > MAX_HMAC_KEY_SIZE) { - WD_ERR("%s: input key length err, key_len = %u!\n", __func__, key_len); - return -WD_EINVAL; - } - ret = digest_hmac_key_check(ctxt->setup.alg, key_len); if (ret) return ret;
ctxt->key_bytes = key_len; + if (!key_len) + return WD_SUCCESS;
if (ctxt->setup.data_fmt == WD_SGL_BUF) wd_sgl_cp_from_pbuf(ctxt->key, 0, key, key_len); diff --git a/wd_digest.c b/wd_digest.c index 4709a1c9..1851203c 100644 --- a/wd_digest.c +++ b/wd_digest.c @@ -158,14 +158,13 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) struct wd_digest_sess *sess = (struct wd_digest_sess *)h_sess; int ret;
- if (!key || !sess) { - WD_ERR("invalid: failed to check input param, sess or key is NULL!\n"); + if (!sess || (key_len && !key)) { + WD_ERR("invalid: digest session or key is NULL!\n"); return -WD_EINVAL; }
- if ((sess->alg <= WD_DIGEST_SHA224 && key_len > - MAX_HMAC_KEY_SIZE >> 1) || key_len == 0 || - key_len > MAX_HMAC_KEY_SIZE) { + if ((sess->alg <= WD_DIGEST_SHA224 && key_len > MAX_HMAC_KEY_SIZE >> 1) || + key_len > MAX_HMAC_KEY_SIZE) { WD_ERR("failed to check digest key length, size = %u\n", key_len); return -WD_EINVAL; @@ -181,7 +180,8 @@ int wd_digest_set_key(handle_t h_sess, const __u8 *key, __u32 key_len) }
sess->key_bytes = key_len; - memcpy(sess->key, key, key_len); + if (key_len) + memcpy(sess->key, key, key_len);
return 0; }