From: Zhushuai Yin <yinzhushuai@huawei.com> 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 <yinzhushuai@huawei.com> --- 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 aaaaa1d..7d472b8 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; + } } } -- 2.28.0.windows.1
From: Zhushuai Yin <yinzhushuai@huawei.com> 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 <yinzhushuai@huawei.com> --- 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 f1be25f..cf4bcd9 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; + } + } } -- 2.28.0.windows.1
participants (1)
-
Chenghai Huang