From c0cbd1b0239c725c4b97a9a8cbc81b553a967319 Mon Sep 17 00:00:00 2001 From: Zhushuai Yin Date: Thu, 13 Aug 2026 07:41:47 -0400 Subject: [PATCH 1/2] When the packet length of the CCM algorithm exceeds 16 bits, the software and hardware comparison fails because the driver does not adapt to the scenario where the packet length exceeds 16 bits. Therefore, the algorithm needs to be modified. Signed-off-by: Zhushuai Yin --- drv/hisi_sec.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drv/hisi_sec.c b/drv/hisi_sec.c index aaaaa1d7..7d472b8a 100644 --- a/drv/hisi_sec.c +++ b/drv/hisi_sec.c @@ -2751,7 +2751,7 @@ static void set_aead_auth_iv(struct wd_aead_msg *msg) __u32 data_size = msg->in_bytes; __u8 flags = 0x00; - __u8 cl, cm; + __u8 cl, cm, i; /* CCM need to cal a_iv, GCM same as c_iv */ memcpy(msg->aiv, msg->iv, msg->iv_bytes); @@ -2771,15 +2771,15 @@ static void set_aead_auth_iv(struct wd_aead_msg *msg) msg->aiv[0] = flags; /* - * the last 32bit is counter's initial number, - * but the nonce uses the first 16bit - * the tail 16bit fill with the cipher length - */ - msg->aiv[msg->iv_bytes - IV_LAST_BYTE1] = - data_size & IV_LAST_BYTE_MASK; - data_size >>= IV_BYTE_OFFSET; - msg->aiv[msg->iv_bytes - IV_LAST_BYTE2] = - data_size & IV_LAST_BYTE_MASK; + * the last 32bit is counter's initial number, + * but the nonce uses the first 16bit + * the tail 16bit fill with the cipher length + * When CL is 3, the tail 24bit fill with the cipher length. + */ + for (i = 1; i <= cl + 1; i++) { + msg->aiv[msg->iv_bytes - i] = data_size & IV_LAST_BYTE_MASK; + data_size >>= IV_BYTE_OFFSET; + } } } From 08acfd6c91bc80ba048e39cb8862126d4e43704c Mon Sep 17 00:00:00 2001 From: Zhushuai Yin Date: Thu, 13 Aug 2026 16:43:28 +0800 Subject: [PATCH 2/2] uadk/v1: fix CCM algorithm long packet failure When the packet length of the CCM algorithm exceeds 16 bits, the software and hardware comparison fails because the driver does not adapt to the scenario where the packet length exceeds 16 bits. Therefore, the algorithm needs to be modified. Signed-off-by: Zhushuai Yin --- v1/drv/hisi_sec_udrv.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/v1/drv/hisi_sec_udrv.c b/v1/drv/hisi_sec_udrv.c index f1be25fb..cf4bcd97 100644 --- a/v1/drv/hisi_sec_udrv.c +++ b/v1/drv/hisi_sec_udrv.c @@ -2221,7 +2221,7 @@ static void set_aead_auth_iv(struct wcrypto_aead_msg *msg) __u32 data_size = msg->in_bytes; __u8 flags = 0x00; __u8 *iv, *aiv; - __u8 cl, cm; + __u8 cl, cm, i; if (msg->data_fmt == WD_SGL_BUF) { /* CCM need to cal a_iv, GCM same as c_iv */ @@ -2252,12 +2252,13 @@ static void set_aead_auth_iv(struct wcrypto_aead_msg *msg) * the last 32bit is counter's initial number, * but the nonce uses the first 16bit * the tail 16bit fill with the cipher length + * When CL is 3, the tail 24bit fill with the cipher length. */ - aiv[msg->iv_bytes - IV_LAST_BYTE1] = - data_size & IV_LAST_BYTE_MASK; - data_size >>= IV_BYTE_OFFSET; - aiv[msg->iv_bytes - IV_LAST_BYTE2] = - data_size & IV_LAST_BYTE_MASK; + for (i = 1; i <= cl + 1; i++) { + aiv[msg->iv_bytes - i] = data_size & IV_LAST_BYTE_MASK; + data_size >>= IV_BYTE_OFFSET; + } + } }