From cbdeb04c90d2ab3e3b497f9cc7dce8c2ac828f4d Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 2 Mar 2021 19:04:55 +1000 Subject: [PATCH] prov: asym ciphers take an extra init() params argument Reviewed-by: Shane Lontis (Merged from https://github.com/openssl/openssl/pull/14383) --- .../implementations/asymciphers/rsa_enc.c | 21 ++++++++++++------- .../implementations/asymciphers/sm2_enc.c | 10 +++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/providers/implementations/asymciphers/rsa_enc.c b/providers/implementations/asymciphers/rsa_enc.c index 8bf93dc7a2..34ce13dd30 100644 --- a/providers/implementations/asymciphers/rsa_enc.c +++ b/providers/implementations/asymciphers/rsa_enc.c @@ -91,7 +91,8 @@ static void *rsa_newctx(void *provctx) return prsactx; } -static int rsa_init(void *vprsactx, void *vrsa, int operation) +static int rsa_init(void *vprsactx, void *vrsa, const OSSL_PARAM params[], + int operation) { PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx; @@ -116,17 +117,19 @@ static int rsa_init(void *vprsactx, void *vrsa, int operation) ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH); return 0; } - return 1; + return rsa_set_ctx_params(prsactx, params); } -static int rsa_encrypt_init(void *vprsactx, void *vrsa) +static int rsa_encrypt_init(void *vprsactx, void *vrsa, + const OSSL_PARAM params[]) { - return rsa_init(vprsactx, vrsa, EVP_PKEY_OP_ENCRYPT); + return rsa_init(vprsactx, vrsa, params, EVP_PKEY_OP_ENCRYPT); } -static int rsa_decrypt_init(void *vprsactx, void *vrsa) +static int rsa_decrypt_init(void *vprsactx, void *vrsa, + const OSSL_PARAM params[]) { - return rsa_init(vprsactx, vrsa, EVP_PKEY_OP_DECRYPT); + return rsa_init(vprsactx, vrsa, params, EVP_PKEY_OP_DECRYPT); } static int rsa_encrypt(void *vprsactx, unsigned char *out, size_t *outlen, @@ -329,7 +332,7 @@ static int rsa_get_ctx_params(void *vprsactx, OSSL_PARAM *params) PROV_RSA_CTX *prsactx = (PROV_RSA_CTX *)vprsactx; OSSL_PARAM *p; - if (prsactx == NULL || params == NULL) + if (prsactx == NULL) return 0; p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_PAD_MODE); @@ -422,8 +425,10 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[]) char mdprops[OSSL_MAX_PROPQUERY_SIZE] = { '\0' }; char *str = mdname; - if (prsactx == NULL || params == NULL) + if (prsactx == NULL) return 0; + if (params == NULL) + return 1; p = OSSL_PARAM_locate_const(params, OSSL_ASYM_CIPHER_PARAM_OAEP_DIGEST); if (p != NULL) { diff --git a/providers/implementations/asymciphers/sm2_enc.c b/providers/implementations/asymciphers/sm2_enc.c index efd87f9d6a..581ca632b2 100644 --- a/providers/implementations/asymciphers/sm2_enc.c +++ b/providers/implementations/asymciphers/sm2_enc.c @@ -56,7 +56,7 @@ static void *sm2_newctx(void *provctx) return psm2ctx; } -static int sm2_init(void *vpsm2ctx, void *vkey) +static int sm2_init(void *vpsm2ctx, void *vkey, const OSSL_PARAM params[]) { PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; @@ -65,7 +65,7 @@ static int sm2_init(void *vpsm2ctx, void *vkey) EC_KEY_free(psm2ctx->key); psm2ctx->key = vkey; - return 1; + return sm2_set_ctx_params(psm2ctx, params); } static const EVP_MD *sm2_get_md(PROV_SM2_CTX *psm2ctx) @@ -156,7 +156,7 @@ static int sm2_get_ctx_params(void *vpsm2ctx, OSSL_PARAM *params) PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; OSSL_PARAM *p; - if (vpsm2ctx == NULL || params == NULL) + if (vpsm2ctx == NULL) return 0; p = OSSL_PARAM_locate(params, OSSL_ASYM_CIPHER_PARAM_DIGEST); @@ -186,8 +186,10 @@ static int sm2_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[]) { PROV_SM2_CTX *psm2ctx = (PROV_SM2_CTX *)vpsm2ctx; - if (psm2ctx == NULL || params == NULL) + if (psm2ctx == NULL) return 0; + if (params == NULL) + return 1; if (!ossl_prov_digest_load_from_params(&psm2ctx->md, params, psm2ctx->libctx))