libwd/0031-uadk-cipher-cleaup-judgement-sequence.patch
2023-09-28 09:15:32 +08:00

46 lines
1.5 KiB
Diff

From 03bd2bcd7980b4dad4b453dfdaa120dc93c0c6df Mon Sep 17 00:00:00 2001
From: Zhiqi Song <songzhiqi1@huawei.com>
Date: Sun, 24 Sep 2023 23:14:16 +0800
Subject: [PATCH 31/38] uadk/cipher: cleaup judgement sequence
Modify the jugement sequence in aes_sm4_len_check(),
prioritize the conditions that must be met.
Signed-off-by: Zhiqi Song <songzhiqi1@huawei.com>
---
drv/hisi_sec.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c
index 69529d2..2c71090 100644
--- a/drv/hisi_sec.c
+++ b/drv/hisi_sec.c
@@ -891,18 +891,18 @@ static void parse_cipher_bd2(struct hisi_qp *qp, struct hisi_sec_sqe *sqe,
static int aes_sm4_len_check(struct wd_cipher_msg *msg)
{
- if ((msg->mode == WD_CIPHER_CBC_CS1 ||
+ if (msg->alg == WD_CIPHER_AES &&
+ msg->in_bytes <= AES_BLOCK_SIZE &&
+ (msg->mode == WD_CIPHER_CBC_CS1 ||
msg->mode == WD_CIPHER_CBC_CS2 ||
- msg->mode == WD_CIPHER_CBC_CS3) &&
- msg->alg == WD_CIPHER_AES &&
- msg->in_bytes <= AES_BLOCK_SIZE) {
+ msg->mode == WD_CIPHER_CBC_CS3)) {
WD_ERR("failed to check input bytes of AES_CBC_CS_X, size = %u\n",
msg->in_bytes);
return -WD_EINVAL;
}
- if ((msg->mode == WD_CIPHER_CBC || msg->mode == WD_CIPHER_ECB) &&
- msg->in_bytes & (AES_BLOCK_SIZE - 1)) {
+ if ((msg->in_bytes & (AES_BLOCK_SIZE - 1)) &&
+ (msg->mode == WD_CIPHER_CBC || msg->mode == WD_CIPHER_ECB)) {
WD_ERR("failed to check input bytes of AES or SM4, size = %u\n",
msg->in_bytes);
return -WD_EINVAL;
--
2.25.1