class method
OpenSSL::PKey::EC::Group.new
(::OpenSSL::PKey::EC::Group group) -> ::OpenSSL::PKey::EC::Group
(::String pem_or_der_encoded) -> ::OpenSSL::PKey::EC::Group
(::OpenSSL::PKey::EC::ec_method ec_method) -> ::OpenSSL::PKey::EC::Group
(:GFp | :GF2m ec_method, ::Integer bignum_p, ::Integer bignum_a, ::Integer bignum_b) -> ::OpenSSL::PKey::EC::Group
OpenSSL::PKey::EC::Group.new(ec_group)
OpenSSL::PKey::EC::Group.new(pem_or_der_encoded)
OpenSSL::PKey::EC::Group.new(:GFp, bignum_p, bignum_a, bignum_b)
OpenSSL::PKey::EC::Group.new(:GF2m, bignum_p, bignum_a, bignum_b)
ext/openssl/ossl_pkey_ec.c
View on GitHub ↗
static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
{
VALUE arg1, arg2, arg3, arg4;
EC_GROUP *group;
TypedData_Get_Struct(self, EC_GROUP, &ossl_ec_group_type, group);
if (group)
ossl_raise(rb_eRuntimeError, "EC_GROUP is already initialized");
switch (rb_scan_args(argc, argv, "13", &arg1, &arg2, &arg3, &arg4)) {
case 1:
if (rb_obj_is_kind_of(arg1, cEC_GROUP)) {
const EC_GROUP *arg1_group;
GetECGroup(arg1, arg1_group);
if ((group = EC_GROUP_dup(arg1_group)) == NULL)
ossl_raise(eEC_GROUP, "EC_GROUP_dup");
} else {
BIO *in = ossl_obj2bio(&arg1);
group = PEM_read_bio_ECPKParameters(in, NULL, NULL, NULL);
if (!group) {
OSSL_BIO_reset(in);
group = d2i_ECPKParameters_bio(in, NULL);
}
BIO_free(in);
if (!group) {
const char *name = StringValueCStr(arg1);
int nid = OBJ_sn2nid(name);
ossl_clear_error(); /* ignore errors in d2i_ECPKParameters_bio() */
if (nid == NID_undef)
ossl_raise(eEC_GROUP, "unknown curve name (%"PRIsVALUE")", arg1);
#if !defined(OPENSSL_IS_AWSLC)
group = EC_GROUP_new_by_curve_name(nid);
#else /* EC_GROUPs are static and immutable by default in AWS-LC. */
group = EC_GROUP_new_by_curve_name_mutable(nid);
#endif
if (group == NULL)
ossl_raise(eEC_GROUP, "unable to create curve (%"PRIsVALUE")", arg1);
EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
EC_GROUP_set_point_conversion_form(group, POINT_CONVERSION_UNCOMPRESSED);
}
}
break;
case 4:
if (SYMBOL_P(arg1)) {
EC_GROUP *(*new_curve)(const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *) = NULL;
const BIGNUM *p = GetBNPtr(arg2);
const BIGNUM *a = GetBNPtr(arg3);
const BIGNUM *b = GetBNPtr(arg4);
if (arg1 == sym_GFp) {
new_curve = EC_GROUP_new_curve_GFp;
}
#if !defined(OPENSSL_NO_EC2M)
else if (arg1 == sym_GF2m) {
new_curve = EC_GROUP_new_curve_GF2m;
}
#endif
else {
ossl_raise(rb_eArgError, "unknown symbol, must be :GFp or :GF2m");
}
if ((group = new_curve(p, a, b, ossl_bn_ctx)) == NULL)
ossl_raise(eEC_GROUP, "EC_GROUP_new_by_GF*");
} else {
ossl_raise(rb_eArgError, "unknown argument, must be :GFp or :GF2m");
}
break;
default:
ossl_raise(rb_eArgError, "wrong number of arguments");
}
ASSUME(group);
RTYPEDDATA_DATA(self) = group;
return self;
}
Creates a new EC::Group object.
If the first argument is :GFp or :GF2m, creates a new curve with given parameters.