
From: Wenkai Lin <linwenkai6@hisilicon.com> The implementation of the SM3 algorithm requires 64B alignment of the first packet or middle packet, if the user use unaligned data, it should intercepted. Signed-off-by: Wenkai Lin <linwenkai6@hisilicon.com> Signed-off-by: Qi Tao <taoqi10@huawei.com> --- drv/isa_ce_sm3.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drv/isa_ce_sm3.c b/drv/isa_ce_sm3.c index 68be912a..84ae2854 100644 --- a/drv/isa_ce_sm3.c +++ b/drv/isa_ce_sm3.c @@ -19,6 +19,8 @@ #include "wd_digest.h" #include "wd_util.h" +#define SM3_ALIGN_MASK 63U + typedef void (sm3_ce_block_fn)(__u32 word_reg[SM3_STATE_WORDS], const unsigned char *src, size_t blocks); @@ -348,6 +350,13 @@ static int sm3_ce_drv_send(struct wd_alg_driver *drv, handle_t ctx, void *digest return -WD_EINVAL; } + if (msg->has_next) { + if (msg->in_bytes & SM3_ALIGN_MASK) { + WD_ERR("input data isn't aligned, size = %u\n", msg->in_bytes); + return -WD_EINVAL; + } + } + if (msg->mode == WD_DIGEST_NORMAL) { ret = do_sm3_ce(msg, digest); } else if (msg->mode == WD_DIGEST_HMAC) { -- 2.33.0