diff --git a/crypto/evp/p_ec_asn1.c b/crypto/evp/p_ec_asn1.c index c5828d93..0ad8f383 100644 --- a/crypto/evp/p_ec_asn1.c +++ b/crypto/evp/p_ec_asn1.c @@ -206,13 +206,7 @@ static int ec_missing_parameters(const EVP_PKEY *pkey) { } static int ec_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) { - EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec)); - if (group == NULL || - EC_KEY_set_group(to->pkey.ec, group) == 0) { - return 0; - } - EC_GROUP_free(group); - return 1; + return EC_KEY_set_group(to->pkey.ec, EC_KEY_get0_group(from->pkey.ec)); } static int ec_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) { diff --git a/crypto/fipsmodule/ec/ec.c b/crypto/fipsmodule/ec/ec.c index b559b541..7b5031f7 100644 --- a/crypto/fipsmodule/ec/ec.c +++ b/crypto/fipsmodule/ec/ec.c @@ -623,25 +623,18 @@ unsigned EC_GROUP_get_degree(const EC_GROUP *group) { } EC_POINT *EC_POINT_new(const EC_GROUP *group) { - EC_POINT *ret; - if (group == NULL) { OPENSSL_PUT_ERROR(EC, ERR_R_PASSED_NULL_PARAMETER); return NULL; } - ret = OPENSSL_malloc(sizeof *ret); + EC_POINT *ret = OPENSSL_malloc(sizeof *ret); if (ret == NULL) { OPENSSL_PUT_ERROR(EC, ERR_R_MALLOC_FAILURE); return NULL; } ret->group = EC_GROUP_dup(group); - if (ret->group == NULL) { - OPENSSL_free(ret); - return NULL; - } - ec_GFp_simple_point_init(ret); return ret; } diff --git a/include/openssl/ec.h b/include/openssl/ec.h index 53f22fd0..312a387c 100644 --- a/include/openssl/ec.h +++ b/include/openssl/ec.h @@ -114,11 +114,10 @@ typedef enum { // more modern primitives. OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_by_curve_name(int nid); -// EC_GROUP_free frees |group| and the data that it points to. +// EC_GROUP_free releases a reference to |group|. OPENSSL_EXPORT void EC_GROUP_free(EC_GROUP *group); -// EC_GROUP_dup returns a fresh |EC_GROUP| which is equal to |a| or NULL on -// error. +// EC_GROUP_dup takes a reference to |a| and returns it. OPENSSL_EXPORT EC_GROUP *EC_GROUP_dup(const EC_GROUP *a); // EC_GROUP_cmp returns zero if |a| and |b| are the same group and non-zero