From be2e334fce734e726a4085701bc3cbbaabf9d893 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Sun, 31 Jan 2016 16:34:07 +0000 Subject: Add EC_GROUP_order_bits, EC_GROUP_get0_order and EC_GROUP_get0_cofactor New functions to return internal pointer for order and cofactor. This avoids the need to allocate a new BIGNUM which to copy the value to. Simplify code to use new functions. Reviewed-by: Rich Salz --- crypto/ec/ec_asn1.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) (limited to 'crypto/ec/ec_asn1.c') diff --git a/crypto/ec/ec_asn1.c b/crypto/ec/ec_asn1.c index ab68e1ea5a..842f9c31df 100644 --- a/crypto/ec/ec_asn1.c +++ b/crypto/ec/ec_asn1.c @@ -536,16 +536,11 @@ static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group, { size_t len = 0; ECPARAMETERS *ret = NULL; - BIGNUM *tmp = NULL; + const BIGNUM *tmp; unsigned char *buffer = NULL; const EC_POINT *point = NULL; point_conversion_form_t form; - if ((tmp = BN_new()) == NULL) { - ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_MALLOC_FAILURE); - goto err; - } - if (param == NULL) { if ((ret = ECPARAMETERS_new()) == NULL) { ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_MALLOC_FAILURE); @@ -592,7 +587,8 @@ static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group, } /* set the order */ - if (!EC_GROUP_get_order(group, tmp, NULL)) { + tmp = EC_GROUP_get0_order(group); + if (tmp == NULL) { ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_EC_LIB); goto err; } @@ -603,7 +599,8 @@ static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group, } /* set the cofactor (optional) */ - if (EC_GROUP_get_cofactor(group, tmp, NULL)) { + tmp = EC_GROUP_get0_cofactor(group); + if (tmp != NULL) { ret->cofactor = BN_to_ASN1_INTEGER(tmp, ret->cofactor); if (ret->cofactor == NULL) { ECerr(EC_F_EC_ASN1_GROUP2PARAMETERS, ERR_R_ASN1_LIB); @@ -616,7 +613,6 @@ static ECPARAMETERS *ec_asn1_group2parameters(const EC_GROUP *group, err: if (!param) ECPARAMETERS_free(ret); - BN_free(tmp); OPENSSL_free(buffer); return NULL; } @@ -1315,7 +1311,6 @@ int ECDSA_size(const EC_KEY *r) { int ret, i; ASN1_INTEGER bs; - BIGNUM *order = NULL; unsigned char buf[4]; const EC_GROUP *group; @@ -1325,13 +1320,9 @@ int ECDSA_size(const EC_KEY *r) if (group == NULL) return 0; - if ((order = BN_new()) == NULL) + i = EC_GROUP_order_bits(group); + if (i == 0) return 0; - if (!EC_GROUP_get_order(group, order, NULL)) { - BN_clear_free(order); - return 0; - } - i = BN_num_bits(order); bs.length = (i + 7) / 8; bs.data = buf; bs.type = V_ASN1_INTEGER; @@ -1341,6 +1332,5 @@ int ECDSA_size(const EC_KEY *r) i = i2d_ASN1_INTEGER(&bs, NULL); i += i; /* r and s */ ret = ASN1_object_size(1, i, V_ASN1_SEQUENCE); - BN_clear_free(order); return (ret); } -- cgit v1.2.3