prov: asym ciphers take an extra init() params argument
authorPauli <ppzgs1@gmail.com>
Tue, 2 Mar 2021 09:04:55 +0000 (19:04 +1000)
committerPauli <ppzgs1@gmail.com>
Thu, 11 Mar 2021 22:27:11 +0000 (08:27 +1000)
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14383)

providers/implementations/asymciphers/rsa_enc.c
providers/implementations/asymciphers/sm2_enc.c

index 8bf93dc7a22197809db42f5b87468fceb15e39be..34ce13dd305908be489b37c187e98203254ed689 100644 (file)
@@ -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) {
index efd87f9d6aa779016707d5891e9a65e47d3accb2..581ca632b2a2306d4a09d0bed72061b2940a9859 100644 (file)
@@ -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))