]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add EC_GROUP_get0_field
authorDavid Asraf <dasraf9@gmail.com>
Thu, 7 Feb 2019 09:51:39 +0000 (11:51 +0200)
committerNicola Tuveri <nic.tuv@gmail.com>
Fri, 15 Feb 2019 14:43:18 +0000 (16:43 +0200)
New function to return internal pointer for field.

Reviewed-by: Nicola Tuveri <nic.tuv@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8195)

crypto/ec/ec_lib.c
doc/man3/EC_GROUP_copy.pod
include/openssl/ec.h
test/ectest.c
util/libcrypto.num

index c14d1a114e0e101f66110650d50c40b93666e071..2623b5377fa4fc595982c62e9055d73b56ae9801 100644 (file)
@@ -364,6 +364,11 @@ int EC_GROUP_get_curve_name(const EC_GROUP *group)
     return group->curve_name;
 }
 
+const BIGNUM *EC_GROUP_get0_field(const EC_GROUP *group)
+{
+    return group->field;
+}
+
 void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag)
 {
     group->asn1_flag = flag;
index 453825a760125976620046519c6be20b33a9cd2c..3f7108d0b89d0df4e8e19e4339740647b8dbd8a0 100644 (file)
@@ -11,7 +11,7 @@ EC_GROUP_get_point_conversion_form, EC_GROUP_get0_seed,
 EC_GROUP_get_seed_len, EC_GROUP_set_seed, EC_GROUP_get_degree,
 EC_GROUP_check, EC_GROUP_check_discriminant, EC_GROUP_cmp,
 EC_GROUP_get_basis_type, EC_GROUP_get_trinomial_basis,
-EC_GROUP_get_pentanomial_basis
+EC_GROUP_get_pentanomial_basis, EC_GROUP_get0_field
 - Functions for manipulating EC_GROUP objects
 
 =head1 SYNOPSIS
@@ -32,6 +32,7 @@ EC_GROUP_get_pentanomial_basis
  int EC_GROUP_order_bits(const EC_GROUP *group);
  int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx);
  const BIGNUM *EC_GROUP_get0_cofactor(const EC_GROUP *group);
+ const BIGNUM *EC_GROUP_get0_field(const EC_GROUP *group);
 
  void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
  int EC_GROUP_get_curve_name(const EC_GROUP *group);
@@ -177,6 +178,8 @@ specified curve respectively. If there is no curve name associated with a curve
 EC_GROUP_get0_order() returns an internal pointer to the group order.
 EC_GROUP_order_bits() returns the number of bits in the group order.
 EC_GROUP_get0_cofactor() returns an internal pointer to the group cofactor.
+EC_GROUP_get0_field() returns an internal pointer to the group field. For curves over GF(p), this is the modulus; for curves
+over GF(2^m), this is the irreducible polynomial defining the field.
 
 EC_GROUP_get0_seed returns a pointer to the seed that was used to generate the parameter b, or NULL if the seed is not
 specified. EC_GROUP_get_seed_len returns the length of the seed or 0 if the seed is not specified.
index 4afaad4516f5186663d5306089ef411051836c9d..7c153684f9bc34b8bc48e814de78193f17d8a5a1 100644 (file)
@@ -212,6 +212,12 @@ void EC_GROUP_set_curve_name(EC_GROUP *group, int nid);
  */
 int EC_GROUP_get_curve_name(const EC_GROUP *group);
 
+/** Gets the field of an EC_GROUP
+ *  \param  group  EC_GROUP object
+ *  \return the group field
+ */
+const BIGNUM *EC_GROUP_get0_field(const EC_GROUP *group);
+
 void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
 int EC_GROUP_get_asn1_flag(const EC_GROUP *group);
 
index cdfaeb69eb8eed431ba1aa84b1d946c4a495e1c0..0f4259796e6b3d00f8a7c23fc5c4de085b7ea517 100644 (file)
@@ -1159,6 +1159,43 @@ static int internal_curve_test_method(int n)
     return r;
 }
 
+static int group_field_test(void)
+{
+    int r = 1;
+    BIGNUM *secp521r1_field = NULL;
+    BIGNUM *sect163r2_field = NULL;
+    EC_GROUP *secp521r1_group = NULL;
+    EC_GROUP *sect163r2_group = NULL;
+
+    BN_hex2bn(&secp521r1_field,
+                "01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
+                "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
+                "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
+                "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
+                "FFFF");
+
+
+    BN_hex2bn(&sect163r2_field,
+                "08000000000000000000000000000000"
+                "00000000C9");
+
+    secp521r1_group = EC_GROUP_new_by_curve_name(NID_secp521r1);
+    if (BN_cmp(secp521r1_field, EC_GROUP_get0_field(secp521r1_group)))
+      r = 0;
+
+    # ifndef OPENSSL_NO_EC2M
+    sect163r2_group = EC_GROUP_new_by_curve_name(NID_sect163r2);
+    if (BN_cmp(sect163r2_field, EC_GROUP_get0_field(sect163r2_group)))
+      r = 0;
+    # endif
+
+    EC_GROUP_free(secp521r1_group);
+    EC_GROUP_free(sect163r2_group);
+    BN_free(secp521r1_field);
+    BN_free(sect163r2_field);
+    return r;
+}
+
 # ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
 /*
  * nistp_test_params contains magic numbers for testing our optimized
@@ -1513,6 +1550,7 @@ int setup_tests(void)
 # endif
     ADD_ALL_TESTS(internal_curve_test, crv_len);
     ADD_ALL_TESTS(internal_curve_test_method, crv_len);
+    ADD_TEST(group_field_test);
 #endif
     return 1;
 }
index 2b5365ecea69e42a511b2e67243292caecaa8a7b..b262bc770095ec68bc971af539dac1717604d390 100644 (file)
@@ -4639,3 +4639,4 @@ EVP_KDF_vctrl                           4594      3_0_0   EXIST::FUNCTION:
 EVP_KDF_ctrl_str                        4595   3_0_0   EXIST::FUNCTION:
 EVP_KDF_size                            4596   3_0_0   EXIST::FUNCTION:
 EVP_KDF_derive                          4597   3_0_0   EXIST::FUNCTION:
+EC_GROUP_get0_field                     4598   3_0_0   EXIST::FUNCTION:EC