Class: OpenSSL::PKey::EC::Group
| Relationships & Source Files | |
| Namespace Children | |
| Exceptions: | |
| Inherits: | Object | 
| Defined in: | ext/openssl/ossl_pkey_ec.c | 
Class Method Summary
- 
    
      .new(ec_group)  
    
    constructor
    Creates a new Groupobject.
Instance Attribute Summary
- 
    
      #asn1_flag  ⇒ Integer 
    
    rw
    Returns the flags set on the group. 
- 
    
      #asn1_flag=(flags)  
    
    rw
    Sets flags on the group. 
- 
    
      #point_conversion_form  ⇒ Symbol 
    
    rw
    Returns the form how Pointdata is encoded asASN.1.
- 
    
      #point_conversion_form=(form)  
    
    rw
    Sets the form how Pointdata is encoded asASN.1as defined inX9.62.
- 
    
      #seed  ⇒ String? 
    
    rw
    See the ::OpenSSLdocumentation for EC_GROUP_get0_seed().
- 
    
      #seed=(seed)  ⇒ seed 
    
    rw
    See the ::OpenSSLdocumentation for EC_GROUP_set_seed().
Instance Method Summary
- 
    
      #==(group2)  ⇒ Boolean 
      (also: #eql?)
    
    Returns trueif the two groups use the same curve and have the same parameters,falseotherwise.
- 
    
      #get_cofactor  ⇒ cofactor_bn 
    
    Returns the cofactor of the group. 
- 
    
      #curve_name  ⇒ String 
    
    Returns the curve name (sn). 
- 
    
      #degree  ⇒ Integer 
    
    See the ::OpenSSLdocumentation for EC_GROUP_get_degree().
- 
    
      #eql?(group2)  ⇒ Boolean 
    
    Alias for #==. 
- 
    
      #generator  ⇒ ec_point 
    
    Returns the generator of the group. 
- 
    
      #get_order  ⇒ order_bn 
    
    Returns the order of the group. 
- 
    
      #set_generator(generator, order, cofactor)  ⇒ self 
    
    Sets the curve parameters. 
- 
    
      #to_text  ⇒ String 
    
    See the ::OpenSSLdocumentation for ECPKParameters_print().
Constructor Details
    
      .new(ec_group)  
      .new(pem_or_der_encoded)  
      .new(:GFp, bignum_p, bignum_a, bignum_b)  
      .new(:GF2m, bignum_p, bignum_a, bignum_b)  
    
  
Creates a new Group object.
If the first argument is :GFp or :GF2m, creates a new curve with given parameters.
# File 'ext/openssl/ossl_pkey_ec.c', line 625
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);
                group = EC_GROUP_new_by_curve_name(nid);
                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)) {
            ID id = SYM2ID(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 (id == s_GFp) {
                new_curve = EC_GROUP_new_curve_GFp;
#if !defined(OPENSSL_NO_EC2M)
            } else if (id == s_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;
}
  Instance Attribute Details
#asn1_flag ⇒ Integer (rw)
Returns the flags set on the group.
See also #asn1_flag=.
# File 'ext/openssl/ossl_pkey_ec.c', line 911
static VALUE ossl_ec_group_get_asn1_flag(VALUE self)
{
    EC_GROUP *group = NULL;
    int flag;
    GetECGroup(self, group);
    flag = EC_GROUP_get_asn1_flag(group);
    return INT2NUM(flag);
}
  #asn1_flag=(flags) (rw)
Sets flags on the group. The flag value is used to determine how to encode the group: encode explicit parameters or named curve using an OID.
The flag value can be either of:
See the ::OpenSSL documentation for EC_GROUP_set_asn1_flag().
# File 'ext/openssl/ossl_pkey_ec.c', line 936
static VALUE ossl_ec_group_set_asn1_flag(VALUE self, VALUE flag_v)
{
    EC_GROUP *group = NULL;
    GetECGroup(self, group);
    EC_GROUP_set_asn1_flag(group, NUM2INT(flag_v));
    return flag_v;
}
  
    #point_conversion_form  ⇒ Symbol  (rw)  
Returns the form how Point data is encoded as ASN.1.
See also #point_conversion_form=.
# File 'ext/openssl/ossl_pkey_ec.c', line 954
static VALUE ossl_ec_group_get_point_conversion_form(VALUE self)
{
    EC_GROUP *group = NULL;
    point_conversion_form_t form;
    VALUE ret;
    GetECGroup(self, group);
    form = EC_GROUP_get_point_conversion_form(group);
    switch (form) {
    case POINT_CONVERSION_UNCOMPRESSED:	ret = ID_uncompressed; break;
    case POINT_CONVERSION_COMPRESSED:	ret = ID_compressed; break;
    case POINT_CONVERSION_HYBRID:	ret = ID_hybrid; break;
    default:	ossl_raise(eEC_GROUP, "unsupported point conversion form: %d, this module should be updated", form);
    }
   return ID2SYM(ret);
}
  #point_conversion_form=(form) (rw)
Sets the form how Point data is encoded as ASN.1 as defined in X9.62.
format can be one of these:
- :compressed
- 
Encoded as z||x, where z is an octet indicating which solution of the equation y is. z will be 0x02 or 0x03. 
- :uncompressed
- 
Encoded as z||x||y, where z is an octet 0x04. 
- :hybrid
- 
Encodes as z||x||y, where z is an octet indicating which solution of the equation y is. z will be 0x06 or 0x07. 
See the ::OpenSSL documentation for EC_GROUP_set_point_conversion_form()
# File 'ext/openssl/ossl_pkey_ec.c', line 1008
static VALUE
ossl_ec_group_set_point_conversion_form(VALUE self, VALUE form_v)
{
    EC_GROUP *group;
    point_conversion_form_t form;
    GetECGroup(self, group);
    form = parse_point_conversion_form_symbol(form_v);
    EC_GROUP_set_point_conversion_form(group, form);
    return form_v;
}
  
    #seed  ⇒ String?  (rw)  
See the ::OpenSSL documentation for EC_GROUP_get0_seed()
# File 'ext/openssl/ossl_pkey_ec.c', line 1028
static VALUE ossl_ec_group_get_seed(VALUE self)
{
    EC_GROUP *group = NULL;
    size_t seed_len;
    GetECGroup(self, group);
    seed_len = EC_GROUP_get_seed_len(group);
    if (seed_len == 0)
        return Qnil;
    return rb_str_new((const char *)EC_GROUP_get0_seed(group), seed_len);
}
  #seed=(seed) ⇒ seed (rw)
See the ::OpenSSL documentation for EC_GROUP_set_seed()
# File 'ext/openssl/ossl_pkey_ec.c', line 1048
static VALUE ossl_ec_group_set_seed(VALUE self, VALUE seed)
{
    EC_GROUP *group = NULL;
    GetECGroup(self, group);
    StringValue(seed);
    if (EC_GROUP_set_seed(group, (unsigned char *)RSTRING_PTR(seed), RSTRING_LEN(seed)) != (size_t)RSTRING_LEN(seed))
        ossl_raise(eEC_GROUP, "EC_GROUP_set_seed");
    return seed;
}
  Instance Method Details
    
      #eql?(group2)  ⇒ Boolean 
      #==(group2)  ⇒ Boolean 
    
    Also known as: #eql?
  
Boolean 
      #==(group2)  ⇒ Boolean 
    Returns true if the two groups use the same curve and have the same parameters, false otherwise.
# File 'ext/openssl/ossl_pkey_ec.c', line 732
static VALUE ossl_ec_group_eql(VALUE a, VALUE b)
{
    EC_GROUP *group1 = NULL, *group2 = NULL;
    GetECGroup(a, group1);
    GetECGroup(b, group2);
    switch (EC_GROUP_cmp(group1, group2, ossl_bn_ctx)) {
    case 0: return Qtrue;
    case 1: return Qfalse;
    default: ossl_raise(eEC_GROUP, "EC_GROUP_cmp");
    }
}
  
    #get_cofactor  ⇒ cofactor_bn   
Returns the cofactor of the group.
See the ::OpenSSL documentation for EC_GROUP_get_cofactor()
# File 'ext/openssl/ossl_pkey_ec.c', line 826
static VALUE ossl_ec_group_get_cofactor(VALUE self)
{
    VALUE bn_obj;
    BIGNUM *bn;
    EC_GROUP *group = NULL;
    GetECGroup(self, group);
    bn_obj = ossl_bn_new(NULL);
    bn = GetBNPtr(bn_obj);
    if (EC_GROUP_get_cofactor(group, bn, ossl_bn_ctx) != 1)
        ossl_raise(eEC_GROUP, "EC_GROUP_get_cofactor");
    return bn_obj;
}
  
    #curve_name  ⇒ String   
Returns the curve name (sn).
See the ::OpenSSL documentation for EC_GROUP_get_curve_name()
# File 'ext/openssl/ossl_pkey_ec.c', line 851
static VALUE ossl_ec_group_get_curve_name(VALUE self)
{
    EC_GROUP *group = NULL;
    int nid;
    GetECGroup(self, group);
    if (group == NULL)
        return Qnil;
    nid = EC_GROUP_get_curve_name(group);
/* BUG: an nid or asn1 object should be returned, maybe. */
    return rb_str_new2(OBJ_nid2sn(nid));
}
  #degree ⇒ Integer
See the ::OpenSSL documentation for EC_GROUP_get_degree()
# File 'ext/openssl/ossl_pkey_ec.c', line 1069
static VALUE ossl_ec_group_get_degree(VALUE self)
{
    EC_GROUP *group = NULL;
    GetECGroup(self, group);
    return INT2NUM(EC_GROUP_get_degree(group));
}
  
    
      #eql?(group2)  ⇒ Boolean 
      #==(group2)  ⇒ Boolean 
    
  
Boolean 
      #==(group2)  ⇒ Boolean 
    Alias for #==.
    #generator  ⇒ ec_point   
Returns the generator of the group.
See the ::OpenSSL documentation for EC_GROUP_get0_generator()
# File 'ext/openssl/ossl_pkey_ec.c', line 754
static VALUE ossl_ec_group_get_generator(VALUE self)
{
    EC_GROUP *group;
    const EC_POINT *generator;
    GetECGroup(self, group);
    generator = EC_GROUP_get0_generator(group);
    if (!generator)
	return Qnil;
    return ec_point_new(generator, group);
}
  
    #get_order  ⇒ order_bn   
Returns the order of the group.
See the ::OpenSSL documentation for EC_GROUP_get_order()
# File 'ext/openssl/ossl_pkey_ec.c', line 801
static VALUE ossl_ec_group_get_order(VALUE self)
{
    VALUE bn_obj;
    BIGNUM *bn;
    EC_GROUP *group = NULL;
    GetECGroup(self, group);
    bn_obj = ossl_bn_new(NULL);
    bn = GetBNPtr(bn_obj);
    if (EC_GROUP_get_order(group, bn, ossl_bn_ctx) != 1)
        ossl_raise(eEC_GROUP, "EC_GROUP_get_order");
    return bn_obj;
}
  
    #set_generator(generator, order, cofactor)  ⇒ self   
# File 'ext/openssl/ossl_pkey_ec.c', line 776
static VALUE ossl_ec_group_set_generator(VALUE self, VALUE generator, VALUE order, VALUE cofactor)
{
    EC_GROUP *group = NULL;
    const EC_POINT *point;
    const BIGNUM *o, *co;
    GetECGroup(self, group);
    GetECPoint(generator, point);
    o = GetBNPtr(order);
    co = GetBNPtr(cofactor);
    if (EC_GROUP_set_generator(group, point, o, co) != 1)
        ossl_raise(eEC_GROUP, "EC_GROUP_set_generator");
    return self;
}
  
    #to_text  ⇒ String   
See the ::OpenSSL documentation for ECPKParameters_print()
# File 'ext/openssl/ossl_pkey_ec.c', line 1140
static VALUE ossl_ec_group_to_text(VALUE self)
{
    EC_GROUP *group;
    BIO *out;
    VALUE str;
    GetECGroup(self, group);
    if (!(out = BIO_new(BIO_s_mem()))) {
	ossl_raise(eEC_GROUP, "BIO_new(BIO_s_mem())");
    }
    if (!ECPKParameters_print(out, group, 0)) {
	BIO_free(out);
	ossl_raise(eEC_GROUP, NULL);
    }
    str = ossl_membio2str(out);
    return str;
}