libwd/0028-uadk-digest-optimize-the-zero-byte-packet-checking-f.patch
2023-09-28 09:15:32 +08:00

142 lines
4.8 KiB
Diff

From 13c256f943f44a65c7d1e8b7b40ce20aa7bd4c51 Mon Sep 17 00:00:00 2001
From: Qi Tao <taoqi10@huawei.com>
Date: Wed, 20 Sep 2023 15:47:31 +0800
Subject: [PATCH 28/38] uadk/digest: optimize the zero byte packet checking for
hash
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 bc4c248..69529d2 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -1574,31 +1574,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;
}
@@ -1610,9 +1617,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);
@@ -1620,8 +1627,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 32bded4..1dd9f37 100644
--- a/v1/drv/hisi_sec_udrv.c
+++ b/v1/drv/hisi_sec_udrv.c
@@ -992,9 +992,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;
@@ -1383,6 +1390,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];
--
2.25.1