summaryrefslogtreecommitdiffstats
path: root/crypto/dh
diff options
context:
space:
mode:
authorTomas Mraz <tomas@openssl.org>2021-04-08 18:25:26 +0200
committerTomas Mraz <tomas@openssl.org>2021-04-15 09:19:39 +0200
commitb4f447c038c05260491eb880e4a9c420b476c119 (patch)
tree1f77cb414be14032b47264c1c98356c9398b4516 /crypto/dh
parent4a9fe33c8e12f4fefae0471c0834f8e674dc7e4e (diff)
Add selection support to the provider keymgmt_dup function
Reviewed-by: Shane Lontis <shane.lontis@oracle.com> (Merged from https://github.com/openssl/openssl/pull/14793)
Diffstat (limited to 'crypto/dh')
-rw-r--r--crypto/dh/dh_ameth.c2
-rw-r--r--crypto/dh/dh_backend.c15
2 files changed, 12 insertions, 5 deletions
diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c
index 1e72561d25..d96b54285b 100644
--- a/crypto/dh/dh_ameth.c
+++ b/crypto/dh/dh_ameth.c
@@ -543,7 +543,7 @@ static int dh_pkey_copy(EVP_PKEY *to, EVP_PKEY *from)
int ret;
if (dh != NULL) {
- dupkey = ossl_dh_dup(dh);
+ dupkey = ossl_dh_dup(dh, OSSL_KEYMGMT_SELECT_ALL);
if (dupkey == NULL)
return 0;
}
diff --git a/crypto/dh/dh_backend.c b/crypto/dh/dh_backend.c
index aebb38d1c9..18cf3f5992 100644
--- a/crypto/dh/dh_backend.c
+++ b/crypto/dh/dh_backend.c
@@ -125,7 +125,7 @@ static ossl_inline int dh_bn_dup_check(BIGNUM **out, const BIGNUM *f)
return 1;
}
-DH *ossl_dh_dup(const DH *dh)
+DH *ossl_dh_dup(const DH *dh, int selection)
{
DH *dupkey = NULL;
@@ -139,14 +139,20 @@ DH *ossl_dh_dup(const DH *dh)
return NULL;
dupkey->length = DH_get_length(dh);
- if (!ossl_ffc_params_copy(&dupkey->params, &dh->params))
+ if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0
+ && !ossl_ffc_params_copy(&dupkey->params, &dh->params))
goto err;
dupkey->flags = dh->flags;
- if (!dh_bn_dup_check(&dupkey->pub_key, dh->pub_key))
+ if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0
+ && ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) == 0
+ || !dh_bn_dup_check(&dupkey->pub_key, dh->pub_key)))
goto err;
- if (!dh_bn_dup_check(&dupkey->priv_key, dh->priv_key))
+
+ if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0
+ && ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) == 0
+ || !dh_bn_dup_check(&dupkey->priv_key, dh->priv_key)))
goto err;
#ifndef FIPS_MODULE
@@ -161,6 +167,7 @@ DH *ossl_dh_dup(const DH *dh)
DH_free(dupkey);
return NULL;
}
+
#ifndef FIPS_MODULE
DH *ossl_dh_key_from_pkcs8(const PKCS8_PRIV_KEY_INFO *p8inf,
OSSL_LIB_CTX *libctx, const char *propq)