From: Weili Qian <qianweili@huawei.com> If the user has not set to retrieve the public and private keys, return ec key directly instead of a null pointer to avoid failure when using ec key. Signed-off-by: Weili Qian <qianweili@huawei.com> --- src/uadk_prov_sm2_kmgmt.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/uadk_prov_sm2_kmgmt.c b/src/uadk_prov_sm2_kmgmt.c index 7bd7c20..cf62677 100644 --- a/src/uadk_prov_sm2_kmgmt.c +++ b/src/uadk_prov_sm2_kmgmt.c @@ -501,6 +501,10 @@ static void *uadk_keymgmt_sm2_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cba goto free_ec_key; } + /* If there is no need to generate the private and public keys, return directly. */ + if (!gctx->selection & OSSL_KEYMGMT_SELECT_KEYPAIR) + return ec; + ret = uadk_prov_keymgmt_get_support_state(KEYMGMT_SM2); if (ret == UADK_P_FAIL) { UADK_ERR("failed to get hardware sm2 keygen support\n"); @@ -514,12 +518,6 @@ static void *uadk_keymgmt_sm2_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cba goto do_soft; } - /* Do sm2 keygen with hardware */ - if ((gctx->selection & OSSL_KEYMGMT_SELECT_KEYPAIR) == 0) { - UADK_ERR("invalid keymgmt keypair selection\n"); - goto free_ec_key; - } - ret = uadk_prov_sm2_keygen(ec); if (ret == UADK_P_FAIL) { UADK_ERR("failed to generate sm2 key\n"); -- 2.43.0