
From: Longfang Liu <liulongfang@huawei.com> When registering the SM4 algorithm in UADK, the algorithm name will be in the format xxx(sm4), such as cbc(sm4) or ctr(sm4). Therefore, when checking the process algorithm instruction, to determine if it's an SM4 algorithm, we need to match the trailing characters of the algorithm name. Signed-off-by: Longfang Liu <liulongfang@huawei.com> Signed-off-by: Qi Tao <taoqi10@huawei.com> --- wd_alg.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wd_alg.c b/wd_alg.c index a2999e36..b465e719 100644 --- a/wd_alg.c +++ b/wd_alg.c @@ -94,6 +94,9 @@ static bool wd_check_accel_dev(const char *dev_name) static bool wd_check_ce_support(const char *alg_name) { unsigned long hwcaps = 0; + const char *alg_tail; + size_t tail_len; + size_t alg_len; #if defined(__arm__) || defined(__arm) hwcaps = getauxval(AT_HWCAP2); @@ -103,7 +106,13 @@ static bool wd_check_ce_support(const char *alg_name) if (!strcmp("sm3", alg_name) && (hwcaps & HWCAP_CE_SM3)) return true; - if (!strcmp("sm4", alg_name) && (hwcaps & HWCAP_CE_SM4)) + alg_len = strlen(alg_name); + tail_len = strlen("(sm4)"); + if (alg_len <= tail_len) + return false; + + alg_tail = alg_name + (alg_len - tail_len); + if (!strcmp("(sm4)", alg_tail) && (hwcaps & HWCAP_CE_SM4)) return true; return false; -- 2.33.0