Optimize the zero byte packet checking in bd2 and add the zero byte packet checking in bd3.
Hardware v2: long hash mode does not support 0 byte packet in the frist and middle bd. Block hash mode does not support 0 byte packet.
Hardware v3: long hash mode does not support 0 byte packet in the frist and middle bd. But, block hash mode do support 0 byte packet.
Signed-off-by: Qi Tao taoqi10@huawei.com --- drv/hisi_sec.c | 39 +++++++++++++++++++++++---------------- v1/drv/hisi_sec_udrv.c | 21 ++++++++++++++++++--- 2 files changed, 41 insertions(+), 19 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index f8e5cfa..00e5f12 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -1578,31 +1578,38 @@ static int digest_long_bd_align_check(struct wd_digest_msg *msg) return 0; }
-static int aes_auth_len_check(struct wd_digest_msg *msg) +static int digest_bd2_zero_packet_check(struct wd_digest_msg *msg) { - if ((msg->alg == WD_DIGEST_AES_XCBC_MAC_96 || - msg->alg == WD_DIGEST_AES_XCBC_PRF_128 || - msg->alg == WD_DIGEST_AES_CMAC) && !msg->in_bytes) { - WD_ERR("digest mode: %u not supports 0 size!\n", msg->alg); + enum hash_bd_type type = get_hash_bd_type(msg); + + /* Long hash first and middle bd */ + if (type == HASH_FRIST_BD || type == HASH_MIDDLE_BD) { + WD_ERR("hardware v2 not supports 0 size in long hash!\n"); + return -WD_EINVAL; + } + + /* Block mode hash bd */ + if (type == HASH_SINGLE_BD) { + WD_ERR("hardware v2 not supports 0 size in block hash!\n"); return -WD_EINVAL; }
return 0; }
-static int digest_bd2_zero_packet_check(struct wd_digest_msg *msg) +static int digest_bd3_zero_packet_check(struct wd_digest_msg *msg) { enum hash_bd_type type = get_hash_bd_type(msg); - /* Long hash first and middle bd */ if (type == HASH_FRIST_BD || type == HASH_MIDDLE_BD) { - WD_ERR("hardware v2 not supports 0 size in long hash!\n"); + WD_ERR("invalid: hardware v3 not supports 0 size in long hash!\n"); return -WD_EINVAL; }
- /* Block mode hash bd */ - if (type == HASH_SINGLE_BD) { - WD_ERR("hardware v2 not supports 0 size in block hash!\n"); + if (msg->alg == WD_DIGEST_AES_XCBC_MAC_96 || + msg->alg == WD_DIGEST_AES_XCBC_PRF_128 || + msg->alg == WD_DIGEST_AES_CMAC) { + WD_ERR("invalid: digest mode %u not supports 0 size!\n", msg->alg); return -WD_EINVAL; }
@@ -1614,9 +1621,9 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type) int ret;
/* - * Hardware v2 needs to check the zero byte packet in the block - * and long hash mode. Frist and Middle bd not supports 0 size, - * final bd not need to check it. Hardware v3 has fixed it. + * Hardware needs to check the zero byte packet in the block + * and long hash mode. First and middle bd not support 0 size, + * final bd not need to check it. */ if (type == BD_TYPE2 && !msg->in_bytes) { ret = digest_bd2_zero_packet_check(msg); @@ -1624,8 +1631,8 @@ static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type) return ret; }
- if (type == BD_TYPE3) { - ret = aes_auth_len_check(msg); + if (type == BD_TYPE3 && !msg->in_bytes) { + ret = digest_bd3_zero_packet_check(msg); if (ret) return ret; } diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index 5d29054..e7cbf50 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -1146,9 +1146,16 @@ static int fill_digest_bd2_alg(struct wcrypto_digest_msg *msg, if (unlikely(ret)) return ret;
- if (unlikely(msg->in_bytes == 0)) { - WD_ERR("digest bd2 not supports 0 packet!\n"); - return -WD_EINVAL; + if(unlikely(msg->in_bytes == 0)) { + if ((msg->has_next && !msg->iv_bytes) || (msg->has_next && msg->iv_bytes)) { + /* Long hash first and middle BD */ + WD_ERR("invalid: digest bd2 not supports 0 packet in first bd and middle bd!\n"); + return -WD_EINVAL; + } else if (!msg->has_next && !msg->iv_bytes) { + /* Block hash BD */ + WD_ERR("invalid: digest bd2 not supports 0 packet in block mode!\n"); + return -WD_EINVAL; + } }
sqe->type2.mac_len = msg->out_bytes / WORD_BYTES; @@ -1537,6 +1544,14 @@ static int fill_digest_bd3_alg(struct wcrypto_digest_msg *msg, if (unlikely(ret)) return ret;
+ if (unlikely(msg->in_bytes == 0)) { + if ((msg->has_next && !msg->iv_bytes) || (msg->has_next && msg->iv_bytes)) { + /* Long hash first and middle BD */ + WD_ERR("invalid: digest bd3 not supports 0 packet in first bd and middle bd!\n"); + return -WD_EINVAL; + } + } + sqe->mac_len = msg->out_bytes / WORD_BYTES; if (msg->mode == WCRYPTO_DIGEST_NORMAL) sqe->a_alg = g_digest_a_alg[msg->alg];