From: Weili Qian <qianweili@huawei.com> Remove the soft field from PROV_RSA_SIG_CTX and PROV_RSA_ASYM_CTX to ensure structure size consistency with the default provider, which is required for proper context duplication via dupctx callback. UADK-specific initialization is performed before session allocation to compensate for the removed field. Signed-off-by: Weili Qian <qianweili@huawei.com> --- src/uadk_prov_rsa.c | 9 +++++++-- src/uadk_prov_rsa.h | 1 - src/uadk_prov_rsa_enc.c | 16 ++++++---------- src/uadk_prov_rsa_kmgmt.c | 6 ------ src/uadk_prov_rsa_sign.c | 23 +++++++++-------------- 5 files changed, 22 insertions(+), 33 deletions(-) diff --git a/src/uadk_prov_rsa.c b/src/uadk_prov_rsa.c index 386f7b5..208db37 100644 --- a/src/uadk_prov_rsa.c +++ b/src/uadk_prov_rsa.c @@ -208,7 +208,7 @@ static void uadk_rsa_mutex_infork(void) pthread_mutex_unlock(&rsa_mutex); } -int uadk_prov_rsa_init(void) +static int uadk_prov_rsa_init(void) { char alg_name[] = "rsa"; int ret; @@ -277,9 +277,14 @@ void rsa_free_eng_session(struct uadk_rsa_sess *rsa_sess) struct uadk_rsa_sess *rsa_get_eng_session(RSA *rsa, unsigned int bits, int is_crt) { - unsigned int key_size = bits >> BIT_BYTES_SHIFT; + unsigned int key_size = bits >> BIT_BYTES_SHIFT; struct sched_params params = {0}; struct uadk_rsa_sess *rsa_sess; + int ret; + + ret = uadk_prov_rsa_init(); + if (ret) + return NULL; rsa_sess = rsa_new_eng_session(rsa); if (!rsa_sess) diff --git a/src/uadk_prov_rsa.h b/src/uadk_prov_rsa.h index 4d2b00a..9af4cc4 100644 --- a/src/uadk_prov_rsa.h +++ b/src/uadk_prov_rsa.h @@ -155,7 +155,6 @@ int rsa_fill_prikey(RSA *rsa, struct uadk_rsa_sess *rsa_sess, int rsa_fill_pubkey(struct rsa_pubkey_param *pubkey_param, struct uadk_rsa_sess *rsa_sess, unsigned char *in_buf, unsigned char *to); -int uadk_prov_rsa_init(void); void rsa_free_eng_session(struct uadk_rsa_sess *rsa_sess); struct uadk_rsa_sess *rsa_get_eng_session(RSA *rsa, unsigned int bits, int is_crt); diff --git a/src/uadk_prov_rsa_enc.c b/src/uadk_prov_rsa_enc.c index 9c32bd7..3b7ce40 100644 --- a/src/uadk_prov_rsa_enc.c +++ b/src/uadk_prov_rsa_enc.c @@ -48,7 +48,6 @@ struct PROV_RSA_ASYM_CTX { /* PKCS#1 v1.5 decryption mode */ unsigned int implicit_rejection; # endif - unsigned int soft : 1; }; static UADK_PKEY_ASYM_CIPHER s_asym_cipher; @@ -366,9 +365,6 @@ static int uadk_rsa_asym_init(void *vprsactx, void *vrsa, return UADK_P_FAIL; } - if (uadk_prov_rsa_init()) - priv->soft = 1; - return uadk_asym_cipher_rsa_set_ctx_params(vprsactx, params); } @@ -478,9 +474,9 @@ static int uadk_asym_cipher_rsa_encrypt(void *vprsactx, unsigned char *out, size_t len; int ret; - if (!priv || priv->soft) { - ret = UADK_DO_SOFT; - goto exe_soft; + if (!priv) { + UADK_ERR("invalid: vprsactx is NULL for rsa encrypt\n"); + return UADK_P_FAIL; } len = uadk_rsa_size(priv->rsa); @@ -613,9 +609,9 @@ static int uadk_asym_cipher_rsa_decrypt(void *vprsactx, unsigned char *out, size_t len; int ret; - if (!priv || priv->soft) { - ret = UADK_DO_SOFT; - goto exe_soft; + if (!priv) { + UADK_ERR("invalid: vprsactx is NULL for rsa decrypt\n"); + return UADK_P_FAIL; } len = uadk_rsa_size(priv->rsa); diff --git a/src/uadk_prov_rsa_kmgmt.c b/src/uadk_prov_rsa_kmgmt.c index 3e5b0bf..7f2ea79 100644 --- a/src/uadk_prov_rsa_kmgmt.c +++ b/src/uadk_prov_rsa_kmgmt.c @@ -893,12 +893,6 @@ static void *uadk_keymgmt_rsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cba if (!gctx) return NULL; - ret = uadk_prov_rsa_init(); - if (ret) { - ret = UADK_DO_SOFT; - goto exe_soft; - } - rsa = ossl_rsa_new_with_ctx(gctx->libctx); if (!rsa) return NULL; diff --git a/src/uadk_prov_rsa_sign.c b/src/uadk_prov_rsa_sign.c index 2ecde8a..5f309f3 100644 --- a/src/uadk_prov_rsa_sign.c +++ b/src/uadk_prov_rsa_sign.c @@ -84,8 +84,6 @@ struct PROV_RSA_SIG_CTX { /* Temp buffer */ unsigned char *tbuf; - - unsigned int soft : 1; }; static int encode_pkcs1(unsigned char **out, size_t *out_len, int type, @@ -668,9 +666,6 @@ static int uadk_rsa_signverify_init(void *vprsactx, void *vrsa, return UADK_P_FAIL; } - if (uadk_prov_rsa_init()) - ctx->soft = 1; - if (!uadk_signature_rsa_set_ctx_params(ctx, params)) return UADK_P_FAIL; @@ -739,9 +734,9 @@ static int uadk_signature_rsa_verify_recover(void *vprsactx, unsigned char *rout struct PROV_RSA_SIG_CTX *priv = (struct PROV_RSA_SIG_CTX *)vprsactx; int ret; - if (!priv || priv->soft) { - ret = UADK_DO_SOFT; - goto exe_soft; + if (!priv) { + UADK_ERR("invalid: vprsactx is NULL for rsa verify_recover\n"); + return UADK_P_FAIL; } if (!rout) { @@ -927,9 +922,9 @@ static int uadk_signature_rsa_verify(void *vprsactx, const unsigned char *sig, size_t rslen = 0; int ret; - if (!priv || priv->soft) { - ret = UADK_DO_SOFT; - goto exe_soft; + if (!priv) { + UADK_ERR("invalid: vprsactx is NULL for rsa verify\n"); + return UADK_P_FAIL; } if (!priv->md) { @@ -1156,9 +1151,9 @@ static int uadk_signature_rsa_sign(void *vprsactx, unsigned char *sig, size_t mdsize; int ret; - if (!priv || priv->soft) { - ret = UADK_DO_SOFT; - goto exe_soft; + if (!priv) { + UADK_ERR("invalid: vprsactx is NULL for rsa sign\n"); + return UADK_P_FAIL; } rsasize = uadk_rsa_size(priv->rsa); -- 2.43.0