
When users initialize algorithm resources, the input alg_name needs to be checked. If algorithm is not supported, return error. Signed-off-by: Weili Qian <qianweili@huawei.com> --- wd_dh.c | 9 ++++++--- wd_ecc.c | 30 +++++++++++++++++------------- wd_rsa.c | 9 ++++++--- 3 files changed, 29 insertions(+), 19 deletions(-) diff --git a/wd_dh.c b/wd_dh.c index 203d3e0..5a79c6d 100644 --- a/wd_dh.c +++ b/wd_dh.c @@ -197,8 +197,8 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param { struct wd_ctx_nums dh_ctx_num[WD_DH_PHASE2] = {0}; struct wd_ctx_params dh_ctx_params = {0}; + int ret = -WD_EINVAL; bool flag; - int ret; pthread_atfork(NULL, NULL, wd_dh_clear_status); @@ -208,7 +208,11 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); - ret = -WD_EINVAL; + goto out_clear_init; + } + + if (strcmp(alg, "dh")) { + WD_ERR("invalid: the alg %s not support!\n", alg); goto out_clear_init; } @@ -220,7 +224,6 @@ int wd_dh_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_param wd_dh_setting.dlh_list = wd_dlopen_drv(NULL); if (!wd_dh_setting.dlh_list) { WD_ERR("failed to open driver lib files!\n"); - ret = -WD_EINVAL; goto out_clear_init; } diff --git a/wd_ecc.c b/wd_ecc.c index 695c61d..c539ce3 100644 --- a/wd_ecc.c +++ b/wd_ecc.c @@ -145,6 +145,16 @@ static int wd_ecc_open_driver(void) return 0; } +static bool is_alg_support(const char *alg) +{ + if (unlikely(strcmp(alg, "ecdh") && strcmp(alg, "ecdsa") && + strcmp(alg, "x25519") && strcmp(alg, "x448") && + strcmp(alg, "sm2"))) + return false; + + return true; +} + static void wd_ecc_clear_status(void) { wd_alg_clear_init(&wd_ecc_setting.status); @@ -253,8 +263,8 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para { struct wd_ctx_nums ecc_ctx_num[WD_EC_OP_MAX] = {0}; struct wd_ctx_params ecc_ctx_params = {0}; + int ret = -WD_EINVAL; bool flag; - int ret; pthread_atfork(NULL, NULL, wd_ecc_clear_status); @@ -264,7 +274,12 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); - ret = -WD_EINVAL; + goto out_clear_init; + } + + flag = is_alg_support(alg); + if (!flag) { + WD_ERR("invalid: alg %s not support!\n", alg); goto out_clear_init; } @@ -276,7 +291,6 @@ int wd_ecc_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para wd_ecc_setting.dlh_list = wd_dlopen_drv(NULL); if (!wd_ecc_setting.dlh_list) { WD_ERR("failed to open driver lib files!\n"); - ret = -WD_EINVAL; goto out_clear_init; } @@ -1079,16 +1093,6 @@ static bool is_key_width_support(__u32 key_bits) return true; } -static bool is_alg_support(const char *alg) -{ - if (unlikely(strcmp(alg, "ecdh") && strcmp(alg, "ecdsa") && - strcmp(alg, "x25519") && strcmp(alg, "x448") && - strcmp(alg, "sm2"))) - return false; - - return true; -} - static int setup_param_check(struct wd_ecc_sess_setup *setup) { if (unlikely(!setup || !setup->alg)) { diff --git a/wd_rsa.c b/wd_rsa.c index 58b1229..0b0be1c 100644 --- a/wd_rsa.c +++ b/wd_rsa.c @@ -238,8 +238,8 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para { struct wd_ctx_nums rsa_ctx_num[WD_RSA_GENKEY] = {0}; struct wd_ctx_params rsa_ctx_params = {0}; + int ret = -WD_EINVAL; bool flag; - int ret; pthread_atfork(NULL, NULL, wd_rsa_clear_status); @@ -249,7 +249,11 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para if (!alg || sched_type > SCHED_POLICY_BUTT || task_type < 0 || task_type > TASK_MAX_TYPE) { WD_ERR("invalid: input param is wrong!\n"); - ret = -WD_EINVAL; + goto out_clear_init; + } + + if (strcmp(alg, "rsa")) { + WD_ERR("invalid: the alg %s not support!\n", alg); goto out_clear_init; } @@ -261,7 +265,6 @@ int wd_rsa_init2_(char *alg, __u32 sched_type, int task_type, struct wd_ctx_para wd_rsa_setting.dlh_list = wd_dlopen_drv(NULL); if (!wd_rsa_setting.dlh_list) { WD_ERR("failed to open driver lib files!\n"); - ret = -WD_EINVAL; goto out_clear_init; } -- 2.30.0