Hardware v2 digest needs to check the zero byte packet in the frist and middle bd.
Signed-off-by: Kai Ye yekai13@huawei.com --- drv/hisi_sec.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index 5b676e9..9ceb9b4 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -1482,14 +1482,36 @@ static int aes_auth_len_check(struct wd_digest_msg *msg) return 0; }
+static int digest_bd2_zero_packet_check(struct wd_digest_msg *msg) +{ + /* Long hash first and middle bd */ + if (msg->has_next && !msg->in_bytes) { + WD_ERR("hardware v2 not supports 0 size in long hash!\n"); + return -WD_EINVAL; + } + + /* Block mode hash bd */ + if (!msg->has_next && !msg->iv_bytes && !msg->in_bytes) { + WD_ERR("hardware v2 not supports 0 size in block hash!\n"); + return -WD_EINVAL; + } + + return 0; +} + static int digest_len_check(struct wd_digest_msg *msg, enum sec_bd_type type) { int ret;
- /* End BD not need to check the input zero bytes */ - if (unlikely(type == BD_TYPE2 && !msg->has_next && !msg->in_bytes)) { - WD_ERR("kunpeng 920, digest mode not support 0 size!\n"); - return -WD_EINVAL; + /* + * 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. + */ + if (type == BD_TYPE2) { + ret = digest_bd2_zero_packet_check(msg); + if (ret) + return ret; }
if (type == BD_TYPE3) { @@ -1566,6 +1588,13 @@ int hisi_sec_digest_send(handle_t ctx, void *digest_msg) if (ret) goto put_sgl;
+ /* + * [has_next , iv_bytes] + * [ 1 , 0 ] = long hash(frist bd) + * [ 1 , 1 ] = long hash(middle bd) + * [ 0 , 1 ] = long hash(end bd) + * [ 0 , 0 ] = block hash(single bd) + */ ret = fill_digest_long_hash(h_qp, msg, &sqe); if (ret) goto put_sgl; @@ -1812,6 +1841,13 @@ int hisi_sec_digest_send_v3(handle_t ctx, void *digest_msg) if (ret) goto put_sgl;
+ /* + * [has_next , iv_bytes] + * [ 1 , 0 ] = long hash(frist bd) + * [ 1 , 1 ] = long hash(middle bd) + * [ 0 , 1 ] = long hash(end bd) + * [ 0 , 0 ] = block hash(single bd) + */ ret = fill_digest_long_hash3(h_qp, msg, &sqe); if (ret) goto put_sgl;