* after choosing an appropriate EC_METHOD */
EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
-EC_GROUP *EC_GROUP_get_group_by_name(int name);
-/* Valid arguments to EC_GROUP_get_group_by_name(): */
+/* EC_GROUP_new_by_nid() and EC_GROUP_new_by_name() also set
+ * generator and order */
+EC_GROUP *EC_GROUP_new_by_nid(const int nid);
+EC_GROUP *EC_GROUP_new_by_name(int name);
+/* Currently valid arguments to EC_GROUP_new_by_name()
+ * (unfortunately some curves have no OIDs [and no NIDs]): */
#define EC_GROUP_NO_CURVE 0
#define EC_GROUP_NIST_PRIME_192 1
#define EC_GROUP_NIST_PRIME_224 2
#define EC_GROUP_X9_62_PRIME_239V3 NID_X9_62_prime239v3
#define EC_GROUP_X9_62_PRIME_256V1 NID_X9_62_prime256v1
-EC_GROUP *EC_GROUP_nid2group(const int nid);
-int EC_GROUP_group2nid(const EC_GROUP *group);
EC_POINT *EC_POINT_new(const EC_GROUP *);
#define EC_F_EC_GROUP_GET_COFACTOR 140
#define EC_F_EC_GROUP_GET_CURVE_GFP 130
#define EC_F_EC_GROUP_GET_EXTRA_DATA 107
-#define EC_F_EC_GROUP_GET_GROUP_BY_NAME 144
#define EC_F_EC_GROUP_GET_ORDER 141
-#define EC_F_EC_GROUP_GROUP2NID 145
+#define EC_F_EC_GROUP_GROUP2NID 147
#define EC_F_EC_GROUP_NEW 108
-#define EC_F_EC_GROUP_NID2GROUP 146
+#define EC_F_EC_GROUP_NEW_BY_NAME 144
+#define EC_F_EC_GROUP_NEW_BY_NID 146
+#define EC_F_EC_GROUP_NEW_GFP_FROM_HEX 148
#define EC_F_EC_GROUP_PRECOMPUTE_MULT 142
#define EC_F_EC_GROUP_SET_CURVE_GFP 109
#define EC_F_EC_GROUP_SET_EXTRA_DATA 110
#define EC_F_EC_GROUP_SET_GENERATOR 111
-#define EC_F_EC_GROUP_SET_PRIME_GROUP 147
#define EC_F_EC_POINTS_MAKE_AFFINE 136
#define EC_F_EC_POINTS_MUL 138
#define EC_F_EC_POINT_ADD 112
#include <openssl/asn1.h>
#include <openssl/asn1t.h>
-EC_GROUP *EC_GROUP_nid2group(const int nid)
- {
- switch(nid)
- {
- case NID_X9_62_prime192v1:
- return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_192V1);
- case NID_X9_62_prime192v2:
- return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_192V2);
- case NID_X9_62_prime192v3:
- return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_192V3);
- case NID_X9_62_prime239v1:
- return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_239V1);
- case NID_X9_62_prime239v2:
- return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_239V2);
- case NID_X9_62_prime239v3:
- return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_239V3);
- case NID_X9_62_prime256v1:
- return EC_GROUP_get_group_by_name(EC_GROUP_X9_62_PRIME_256V1);
- }
- ECerr(EC_F_EC_GROUP_NID2GROUP, EC_R_UNKNOWN_NID);
- return NULL;
- }
-
-int EC_GROUP_group2nid(const EC_GROUP *group)
- {
- return EC_GROUP_get_nid(group);
-
-#if 0
-/* TODO: a real compare function for EC_GROUPs */
-#define EC_GROUP_cmp(a,b) ((a) != (b))
-
- if (group == NULL)
- {
- ECerr(EC_F_EC_GROUP_GROUP2NID, EC_R_MISSING_PARAMETERS);
- return 0;
- }
- if (!EC_GROUP_cmp(group, EC_GROUP_GET_X9_62_192V1_GROUP()))
- return NID_X9_62_prime192v1;
- else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_192v2_group()))
- return NID_X9_62_prime192v2;
- else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_192v3_group()))
- return NID_X9_62_prime192v3;
- else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_239v1_group()))
- return NID_X9_62_prime239v1;
- else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_239v2_group()))
- return NID_X9_62_prime239v2;
- else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_239v3_group()))
- return NID_X9_62_prime239v3;
- else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_256v1_group()))
- return NID_X9_62_prime256v1;
- ECerr(EC_F_EC_GROUP_GROUP2NID, EC_R_UNKNOWN_GROUP);
- return 0;
-#endif
- }
-
-static EC_GROUP *ec_group_set_prime_group(const char *prime_in,
+static EC_GROUP *ec_group_new_GFp_from_hex(const char *prime_in,
const char *a_in, const char *b_in,
const char *x_in, const int y_bit, const char *order_in)
{
ok=1;
bn_err:
if (!ok)
- ECerr(EC_F_EC_GROUP_SET_PRIME_GROUP, ERR_R_BN_LIB);
+ ECerr(EC_F_EC_GROUP_NEW_GFP_FROM_HEX, ERR_R_BN_LIB);
err:
if (!ok)
{
if (order) BN_free(order);
if (x) BN_free(x);
return(group);
-}
+ }
-EC_GROUP *EC_GROUP_get_group_by_name(int name)
+EC_GROUP *EC_GROUP_new_by_name(int name)
{
EC_GROUP *ret = NULL;
switch (name)
return NULL;
case EC_GROUP_NIST_PRIME_224:
- return ec_group_set_prime_group(
+ return ec_group_new_GFp_from_hex(
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE",
"B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D");
case EC_GROUP_NIST_PRIME_384:
- return ec_group_set_prime_group(
+ return ec_group_new_GFp_from_hex(
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC",
"B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973");
case EC_GROUP_NIST_PRIME_521:
- return ec_group_set_prime_group(
+ return ec_group_new_GFp_from_hex(
"1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
"1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
case EC_GROUP_NIST_PRIME_192:
case EC_GROUP_X9_62_PRIME_192V1:
- ret = ec_group_set_prime_group(
+ ret = ec_group_new_GFp_from_hex(
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC",
"64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1",
return ret;
case EC_GROUP_X9_62_PRIME_192V2:
- ret = ec_group_set_prime_group(
+ ret = ec_group_new_GFp_from_hex(
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC",
"CC22D6DFB95C6B25E49C0D6364A4E5980C393AA21668D953",
return ret;
case EC_GROUP_X9_62_PRIME_192V3:
- ret = ec_group_set_prime_group(
+ ret = ec_group_new_GFp_from_hex(
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF",
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC",
"22123DC2395A05CAA7423DAECCC94760A7D462256BD56916",
return ret;
case EC_GROUP_X9_62_PRIME_239V1:
- ret = ec_group_set_prime_group(
+ ret = ec_group_new_GFp_from_hex(
"7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF",
"7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC",
"6B016C3BDCF18941D0D654921475CA71A9DB2FB27D1D37796185C2942C0A",
return ret;
case EC_GROUP_X9_62_PRIME_239V2:
- ret = ec_group_set_prime_group(
+ ret = ec_group_new_GFp_from_hex(
"7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF",
"7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC",
"617FAB6832576CBBFED50D99F0249C3FEE58B94BA0038C7AE84C8C832F2C",
return ret;
case EC_GROUP_X9_62_PRIME_239V3:
- ret = ec_group_set_prime_group(
+ ret = ec_group_new_GFp_from_hex(
"7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFF",
"7FFFFFFFFFFFFFFFFFFFFFFF7FFFFFFFFFFF8000000000007FFFFFFFFFFC",
"255705FA2A306654B1F4CB03D6A750A30C250102D4988717D9BA15AB6D3E",
case EC_GROUP_NIST_PRIME_256:
case EC_GROUP_X9_62_PRIME_256V1:
- ret = ec_group_set_prime_group(
+ ret = ec_group_new_GFp_from_hex(
"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF",
"FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC",
"5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B",
"FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551");
EC_GROUP_set_nid(ret, NID_X9_62_prime256v1);
return ret;
+ }
+
+ ECerr(EC_F_EC_GROUP_NEW_BY_NAME, EC_R_UNKNOWN_GROUP);
+ return NULL;
}
- ECerr(EC_F_EC_GROUP_GET_GROUP_BY_NAME, EC_R_UNKNOWN_GROUP);
+
+EC_GROUP *EC_GROUP_new_by_nid(const int nid)
+ {
+ switch(nid)
+ {
+ case NID_X9_62_prime192v1:
+ return EC_GROUP_new_by_name(EC_GROUP_X9_62_PRIME_192V1);
+ case NID_X9_62_prime192v2:
+ return EC_GROUP_new_by_name(EC_GROUP_X9_62_PRIME_192V2);
+ case NID_X9_62_prime192v3:
+ return EC_GROUP_new_by_name(EC_GROUP_X9_62_PRIME_192V3);
+ case NID_X9_62_prime239v1:
+ return EC_GROUP_new_by_name(EC_GROUP_X9_62_PRIME_239V1);
+ case NID_X9_62_prime239v2:
+ return EC_GROUP_new_by_name(EC_GROUP_X9_62_PRIME_239V2);
+ case NID_X9_62_prime239v3:
+ return EC_GROUP_new_by_name(EC_GROUP_X9_62_PRIME_239V3);
+ case NID_X9_62_prime256v1:
+ return EC_GROUP_new_by_name(EC_GROUP_X9_62_PRIME_256V1);
+ }
+ ECerr(EC_F_EC_GROUP_NEW_BY_NID, EC_R_UNKNOWN_NID);
return NULL;
-}
+ }
+
+
+#if 0
+int EC_GROUP_group2nid(const EC_GROUP *group)
+ {
+ return EC_GROUP_get_nid(group);
+
+#if 0
+/* TODO: a real compare function for EC_GROUPs */
+#define EC_GROUP_cmp(a,b) ((a) != (b))
+
+ if (group == NULL)
+ {
+ ECerr(EC_F_EC_GROUP_GROUP2NID, EC_R_MISSING_PARAMETERS);
+ return 0;
+ }
+ if (!EC_GROUP_cmp(group, EC_GROUP_GET_X9_62_192V1_GROUP()))
+ return NID_X9_62_prime192v1;
+ else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_192v2_group()))
+ return NID_X9_62_prime192v2;
+ else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_192v3_group()))
+ return NID_X9_62_prime192v3;
+ else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_239v1_group()))
+ return NID_X9_62_prime239v1;
+ else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_239v2_group()))
+ return NID_X9_62_prime239v2;
+ else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_239v3_group()))
+ return NID_X9_62_prime239v3;
+ else if (!EC_GROUP_cmp(group, EC_GROUP_get_x9_62_256v1_group()))
+ return NID_X9_62_prime256v1;
+ ECerr(EC_F_EC_GROUP_GROUP2NID, EC_R_UNKNOWN_GROUP);
+ return 0;
+#endif
+ }
+#endif
{ERR_PACK(0,EC_F_EC_GROUP_GET_COFACTOR,0), "EC_GROUP_get_cofactor"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_CURVE_GFP,0), "EC_GROUP_get_curve_GFp"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_EXTRA_DATA,0), "EC_GROUP_get_extra_data"},
-{ERR_PACK(0,EC_F_EC_GROUP_GET_GROUP_BY_NAME,0), "EC_GROUP_get_group_by_name"},
{ERR_PACK(0,EC_F_EC_GROUP_GET_ORDER,0), "EC_GROUP_get_order"},
-{ERR_PACK(0,EC_F_EC_GROUP_GROUP2NID,0), "EC_GROUP_group2nid"},
+{ERR_PACK(0,EC_F_EC_GROUP_GROUP2NID,0), "EC_GROUP_GROUP2NID"},
{ERR_PACK(0,EC_F_EC_GROUP_NEW,0), "EC_GROUP_new"},
-{ERR_PACK(0,EC_F_EC_GROUP_NID2GROUP,0), "EC_GROUP_nid2group"},
+{ERR_PACK(0,EC_F_EC_GROUP_NEW_BY_NAME,0), "EC_GROUP_new_by_name"},
+{ERR_PACK(0,EC_F_EC_GROUP_NEW_BY_NID,0), "EC_GROUP_new_by_nid"},
+{ERR_PACK(0,EC_F_EC_GROUP_NEW_GFP_FROM_HEX,0), "EC_GROUP_NEW_GFP_FROM_HEX"},
{ERR_PACK(0,EC_F_EC_GROUP_PRECOMPUTE_MULT,0), "EC_GROUP_precompute_mult"},
{ERR_PACK(0,EC_F_EC_GROUP_SET_CURVE_GFP,0), "EC_GROUP_set_curve_GFp"},
{ERR_PACK(0,EC_F_EC_GROUP_SET_EXTRA_DATA,0), "EC_GROUP_set_extra_data"},
{ERR_PACK(0,EC_F_EC_GROUP_SET_GENERATOR,0), "EC_GROUP_set_generator"},
-{ERR_PACK(0,EC_F_EC_GROUP_SET_PRIME_GROUP,0), "EC_GROUP_SET_PRIME_GROUP"},
{ERR_PACK(0,EC_F_EC_POINTS_MAKE_AFFINE,0), "EC_POINTs_make_affine"},
{ERR_PACK(0,EC_F_EC_POINTS_MUL,0), "EC_POINTs_mul"},
{ERR_PACK(0,EC_F_EC_POINT_ADD,0), "EC_POINT_add"},