diff --git a/crypto/dh/dh_ameth.c b/crypto/dh/dh_ameth.c index 222cb20b4248b42f2837a5d817a529cb71c067d1..b7b37177c160174b06a390330e215ec4bc4383d0 100644 --- a/crypto/dh/dh_ameth.c +++ b/crypto/dh/dh_ameth.c @@ -437,7 +437,7 @@ static int dh_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) static int dh_missing_parameters(const EVP_PKEY *a) { - if (!a->pkey.dh->p || !a->pkey.dh->g) + if (a->pkey.dh == NULL || a->pkey.dh->p == NULL || a->pkey.dh->g == NULL) return 1; return 0; } diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c index 1bb11a9ed597761b134ffc170d3c18e6273f62fd..a53247c0748920164a4d1a4c9b99b68853d90d05 100644 --- a/crypto/dsa/dsa_ameth.c +++ b/crypto/dsa/dsa_ameth.c @@ -266,7 +266,7 @@ static int dsa_missing_parameters(const EVP_PKEY *pkey) { DSA *dsa; dsa = pkey->pkey.dsa; - if ((dsa->p == NULL) || (dsa->q == NULL) || (dsa->g == NULL)) + if (dsa == NULL || dsa->p == NULL || dsa->q == NULL || dsa->g == NULL) return 1; return 0; } diff --git a/crypto/ec/ec_ameth.c b/crypto/ec/ec_ameth.c index 684da95ab208f50119e279c451fa8ccaacad5225..6567a2f398cfcc219c2c250e0e5796653e31e081 100644 --- a/crypto/ec/ec_ameth.c +++ b/crypto/ec/ec_ameth.c @@ -292,7 +292,7 @@ static int ec_security_bits(const EVP_PKEY *pkey) static int ec_missing_parameters(const EVP_PKEY *pkey) { - if (EC_KEY_get0_group(pkey->pkey.ec) == NULL) + if (pkey->pkey.ec == NULL || EC_KEY_get0_group(pkey->pkey.ec) == NULL) return 1; return 0; } diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index 0b7884f9e569d11c37059cd48e28f2464e1aa4b5..0b50d3210e551dc7d35f4b4f9f0b4249547a1657 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -84,6 +84,14 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_MISSING_PARAMETERS); goto err; } + + if (!EVP_PKEY_missing_parameters(to)) { + if (EVP_PKEY_cmp_parameters(to, from) == 1) + return 1; + EVPerr(EVP_F_EVP_PKEY_COPY_PARAMETERS, EVP_R_DIFFERENT_PARAMETERS); + return 0; + } + if (from->ameth && from->ameth->param_copy) return from->ameth->param_copy(to, from); err: diff --git a/doc/crypto/EVP_PKEY_cmp.pod b/doc/crypto/EVP_PKEY_cmp.pod index 4e1f78bed16167e4388d5ff5b99805875f07014e..7c9e582a81a44616fe854b39c8adf5749609aea6 100644 --- a/doc/crypto/EVP_PKEY_cmp.pod +++ b/doc/crypto/EVP_PKEY_cmp.pod @@ -21,7 +21,9 @@ parameters of B are missing and 0 if they are present or the algorithm doesn't use parameters. The function EVP_PKEY_copy_parameters() copies the parameters from key -B to key B. +B to key B. An error is returned if the parameters are missing in +B or present in both B and B and mismatch. If the parameters +in B and B are both present and match this function has no effect. The function EVP_PKEY_cmp_parameters() compares the parameters of keys B and B.