From 02dbe7743190f334609a86b61bc46ea6e91e82b4 Mon Sep 17 00:00:00 2001 From: Wenkai Lin Date: Wed, 16 Feb 2022 16:11:06 +0800 Subject: [PATCH 22/22] engine: fix engine can't work under hybrid mode If hpre works in no-sva mode, and sec works in sva mode, it will init hpre device first and return straightly, this casuse sec not initialized correctly. So uadk engine should init for both sva and no-sva device. Signed-off-by: Wenkai Lin --- src/e_uadk.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/e_uadk.c b/src/e_uadk.c index 4e87c86..2714d5b 100644 --- a/src/e_uadk.c +++ b/src/e_uadk.c @@ -319,10 +319,15 @@ static void bind_fn_uadk_alg(ENGINE *e) free(dev); } - if (!uadk_e_bind_ecc(e)) - fprintf(stderr, "uadk bind ecc failed\n"); - else - uadk_ecc = 1; + /* find an ecc device, no difference for sm2/ecdsa/ecdh/x25519/x448 */ + dev = wd_get_accel_dev("ecdsa"); + if (dev) { + if (!uadk_e_bind_ecc(e)) + fprintf(stderr, "uadk bind ecc failed\n"); + else + uadk_ecc = 1; + free(dev); + } } /* @@ -349,17 +354,15 @@ static int bind_fn(ENGINE *e, const char *id) uadk_dh_nosva) { async_module_init_v1(); pthread_atfork(NULL, NULL, engine_init_child_at_fork_handler_v1); - goto set_ctrl_cmd; } #endif - async_module_init(); - pthread_atfork(NULL, NULL, engine_init_child_at_fork_handler); - bind_fn_uadk_alg(e); -#ifdef KAE -set_ctrl_cmd: -#endif + if (uadk_cipher || uadk_digest || uadk_rsa || uadk_dh || uadk_ecc) { + async_module_init(); + pthread_atfork(NULL, NULL, engine_init_child_at_fork_handler); + } + ret = ENGINE_set_ctrl_function(e, uadk_engine_ctrl); if (ret != 1) { fprintf(stderr, "failed to set ctrl function\n"); -- 2.24.4