Add EC_GROUP_order_bits, EC_GROUP_get0_order and EC_GROUP_get0_cofactor
[openssl.git] / crypto / ec / ec_ameth.c
index bc77391ef40f2568b1cf84c97268ccd4058c0819..1ba26853ab7799d6e0e9dd8c7c0f103ce57c6f12 100644 (file)
@@ -356,23 +356,7 @@ static int int_ec_size(const EVP_PKEY *pkey)
 
 static int ec_bits(const EVP_PKEY *pkey)
 {
 
 static int ec_bits(const EVP_PKEY *pkey)
 {
-    BIGNUM *order = BN_new();
-    const EC_GROUP *group;
-    int ret;
-
-    if (order == NULL) {
-        ERR_clear_error();
-        return 0;
-    }
-    group = EC_KEY_get0_group(pkey->pkey.ec);
-    if (!EC_GROUP_get_order(group, order, NULL)) {
-        ERR_clear_error();
-        return 0;
-    }
-
-    ret = BN_num_bits(order);
-    BN_free(order);
-    return ret;
+    return EC_GROUP_order_bits(EC_KEY_get0_group(pkey->pkey.ec));
 }
 
 static int ec_security_bits(const EVP_PKEY *pkey)
 }
 
 static int ec_security_bits(const EVP_PKEY *pkey)
@@ -435,7 +419,7 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
     const char *ecstr;
     size_t buf_len = 0, i;
     int ret = 0, reason = ERR_R_BIO_LIB;
     const char *ecstr;
     size_t buf_len = 0, i;
     int ret = 0, reason = ERR_R_BIO_LIB;
-    BIGNUM *pub_key = NULL, *order = NULL;
+    BIGNUM *pub_key = NULL;
     BN_CTX *ctx = NULL;
     const EC_GROUP *group;
     const EC_POINT *public_key;
     BN_CTX *ctx = NULL;
     const EC_GROUP *group;
     const EC_POINT *public_key;
@@ -488,11 +472,8 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
 
     if (!BIO_indent(bp, off, 128))
         goto err;
 
     if (!BIO_indent(bp, off, 128))
         goto err;
-    if ((order = BN_new()) == NULL)
-        goto err;
-    if (!EC_GROUP_get_order(group, order, NULL))
-        goto err;
-    if (BIO_printf(bp, "%s: (%d bit)\n", ecstr, BN_num_bits(order)) <= 0)
+    if (BIO_printf(bp, "%s: (%d bit)\n", ecstr,
+                   EC_GROUP_order_bits(group)) <= 0)
         goto err;
 
     if ((priv_key != NULL) && !ASN1_bn_print(bp, "priv:", priv_key,
         goto err;
 
     if ((priv_key != NULL) && !ASN1_bn_print(bp, "priv:", priv_key,
@@ -508,7 +489,6 @@ static int do_EC_KEY_print(BIO *bp, const EC_KEY *x, int off, int ktype)
     if (!ret)
         ECerr(EC_F_DO_EC_KEY_PRINT, reason);
     BN_free(pub_key);
     if (!ret)
         ECerr(EC_F_DO_EC_KEY_PRINT, reason);
     BN_free(pub_key);
-    BN_free(order);
     BN_CTX_free(ctx);
     OPENSSL_free(buffer);
     return (ret);
     BN_CTX_free(ctx);
     OPENSSL_free(buffer);
     return (ret);