}
ret->meth = meth;
- ret->order = BN_new();
- if (ret->order == NULL)
- goto err;
- ret->cofactor = BN_new();
- if (ret->cofactor == NULL)
- goto err;
+ if ((ret->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0) {
+ ret->order = BN_new();
+ if (ret->order == NULL)
+ goto err;
+ ret->cofactor = BN_new();
+ if (ret->cofactor == NULL)
+ goto err;
+ }
ret->asn1_flag = OPENSSL_EC_NAMED_CURVE;
ret->asn1_form = POINT_CONVERSION_UNCOMPRESSED;
if (!meth->group_init(ret))
dest->generator = NULL;
}
- if (!BN_copy(dest->order, src->order))
- return 0;
- if (!BN_copy(dest->cofactor, src->cofactor))
- return 0;
+ if ((src->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0) {
+ if (!BN_copy(dest->order, src->order))
+ return 0;
+ if (!BN_copy(dest->cofactor, src->cofactor))
+ return 0;
+ }
dest->curve_name = src->curve_name;
dest->asn1_flag = src->asn1_flag;
} else
BN_zero(group->cofactor);
+
/*
- * We ignore the return value because some groups have an order with
+ * Some groups have an order with
* factors of two, which makes the Montgomery setup fail.
* |group->mont_data| will be NULL in this case.
*/
- ec_precompute_mont_data(group);
+ if (BN_is_odd(group->order)) {
+ return ec_precompute_mont_data(group);
+ }
+ BN_MONT_CTX_free(group->mont_data);
+ group->mont_data = NULL;
return 1;
}
int EC_GROUP_order_bits(const EC_GROUP *group)
{
- if (group->order)
- return BN_num_bits(group->order);
- return 0;
+ OPENSSL_assert(group->meth->group_order_bits != NULL);
+ return group->meth->group_order_bits(group);
}
int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor,
if (EC_GROUP_get_curve_name(a) && EC_GROUP_get_curve_name(b) &&
EC_GROUP_get_curve_name(a) != EC_GROUP_get_curve_name(b))
return 1;
+ if (a->meth->flags & EC_FLAGS_CUSTOM_CURVE)
+ return 0;
if (ctx == NULL)
ctx_new = ctx = BN_CTX_new();
return NULL;
}
- ret = OPENSSL_malloc(sizeof(*ret));
+ ret = OPENSSL_zalloc(sizeof(*ret));
if (ret == NULL) {
ECerr(EC_F_EC_POINT_NEW, ERR_R_MALLOC_FAILURE);
return NULL;
{
return CRYPTO_get_ex_data(&key->ex_data, idx);
}
+
+int ec_group_simple_order_bits(const EC_GROUP *group)
+{
+ if (group->order == NULL)
+ return 0;
+ return BN_num_bits(group->order);
+}