非常教程

Ruby 2.4参考手册

OpenSSL

OpenSSL::PKey::EC::Point

父类:Object

属性

groupR

公共类方法

OpenSSL::PKey::EC::Point.new(point)显示源

OpenSSL::PKey::EC::Point.new(group)

OpenSSL::PKey::EC::Point.new(group, bn)

See the OpenSSL documentation for EC_POINT_*

static VALUE ossl_ec_point_initialize(int argc, VALUE *argv, VALUE self)
{
    EC_POINT *point;
    VALUE arg1, arg2;
    VALUE group_v = Qnil;
    const EC_GROUP *group = NULL;

    TypedData_Get_Struct(self, EC_POINT, &ossl_ec_point_type, point);
    if (point)
        ossl_raise(eEC_POINT, "EC_POINT already initialized");

    switch (rb_scan_args(argc, argv, "11", &arg1, &arg2)) {
    case 1:
        if (rb_obj_is_kind_of(arg1, cEC_POINT)) {
            const EC_POINT *arg_point;

            group_v = rb_attr_get(arg1, id_i_group);
            SafeGetECGroup(group_v, group);
            SafeGetECPoint(arg1, arg_point);

            point = EC_POINT_dup(arg_point, group);
        } else if (rb_obj_is_kind_of(arg1, cEC_GROUP)) {
            group_v = arg1;
            SafeGetECGroup(group_v, group);

            point = EC_POINT_new(group);
        } else {
            ossl_raise(eEC_POINT, "wrong argument type: must be OpenSSL::PKey::EC::Point or OpenSSL::Pkey::EC::Group");
        }

        break;
     case 2:
        if (!rb_obj_is_kind_of(arg1, cEC_GROUP))
            ossl_raise(rb_eArgError, "1st argument must be OpenSSL::PKey::EC::Group");
        group_v = arg1;
        SafeGetECGroup(group_v, group);

        if (rb_obj_is_kind_of(arg2, cBN)) {
            const BIGNUM *bn = GetBNPtr(arg2);

            point = EC_POINT_bn2point(group, bn, NULL, ossl_bn_ctx);
        } else {
            BIO *in = ossl_obj2bio(arg1);

/* BUG: finish me */

            BIO_free(in);

            if (point == NULL) {
                ossl_raise(eEC_POINT, "unknown type for 2nd arg");
            }
        }
        break;
    default:
        ossl_raise(rb_eArgError, "wrong number of arguments");
    }

    if (point == NULL)
        ossl_raise(eEC_POINT, NULL);

    if (NIL_P(group_v))
        ossl_raise(rb_eRuntimeError, "missing group (internal error)");

    RTYPEDDATA_DATA(self) = point;
    rb_ivar_set(self, id_i_group, group_v);

    return self;
}

公共实例方法

==(p1)

别名为:eql

eql?(point2) → true | false 显示源

point1 == point2 → true | false

static VALUE ossl_ec_point_eql(VALUE a, VALUE b)
{
    EC_POINT *point1, *point2;
    VALUE group_v1 = rb_attr_get(a, id_i_group);
    VALUE group_v2 = rb_attr_get(b, id_i_group);
    const EC_GROUP *group;

    if (ossl_ec_group_eql(group_v1, group_v2) == Qfalse)
        return Qfalse;

    GetECPoint(a, point1);
    SafeGetECPoint(b, point2);
    SafeGetECGroup(group_v1, group);

    if (EC_POINT_cmp(group, point1, point2, ossl_bn_ctx) == 1)
        return Qfalse;

    return Qtrue;
}

另外别名为:==

infinity? → true | false 显示源

static VALUE ossl_ec_point_is_at_infinity(VALUE self)
{
    EC_POINT *point;
    const EC_GROUP *group;

    GetECPoint(self, point);
    GetECPointGroup(self, group);

    switch (EC_POINT_is_at_infinity(group, point)) {
    case 1: return Qtrue;
    case 0: return Qfalse;
    default: ossl_raise(cEC_POINT, "EC_POINT_is_at_infinity");
    }

    UNREACHABLE;
}

invert! → self 显示源

static VALUE ossl_ec_point_invert(VALUE self)
{
    EC_POINT *point;
    const EC_GROUP *group;

    GetECPoint(self, point);
    GetECPointGroup(self, group);

    if (EC_POINT_invert(group, point, ossl_bn_ctx) != 1)
        ossl_raise(cEC_POINT, "EC_POINT_invert");

    return self;
}

make_affine! → self 显示源

static VALUE ossl_ec_point_make_affine(VALUE self)
{
    EC_POINT *point;
    const EC_GROUP *group;

    GetECPoint(self, point);
    GetECPointGroup(self, group);

    if (EC_POINT_make_affine(group, point, ossl_bn_ctx) != 1)
        ossl_raise(cEC_POINT, "EC_POINT_make_affine");

    return self;
}

mul(bn1 , bn2) → point 显示源

mul(bns, points , bn2) → point

执行椭圆曲线点乘法。

第一种形式计算bn1 * point + bn2 * GG组的生成器在哪里pointbn2可能会被省略,在这种情况下,结果就是这样bn1 * point

第二种形式计算bns[0] * point + bns[1] * points[0] + ... + bns[-1] * points[-1] + bn2 * Gbn2可能会被省略。bns必须是一个OpenSSL :: BN数组。points必须是OpenSSL :: PKey :: EC :: Point的数组。请注意,这points[0]不是乘以bns[0],而是bns[1]

static VALUE ossl_ec_point_mul(int argc, VALUE *argv, VALUE self)
{
    EC_POINT *point_self, *point_result;
    const EC_GROUP *group;
    VALUE group_v = rb_attr_get(self, id_i_group);
    VALUE arg1, arg2, arg3, result;
    const BIGNUM *bn_g = NULL;

    GetECPoint(self, point_self);
    SafeGetECGroup(group_v, group);

    result = rb_obj_alloc(cEC_POINT);
    ossl_ec_point_initialize(1, &group_v, result);
    GetECPoint(result, point_result);

    rb_scan_args(argc, argv, "12", &arg1, &arg2, &arg3);
    if (!RB_TYPE_P(arg1, T_ARRAY)) {
        BIGNUM *bn = GetBNPtr(arg1);

        if (!NIL_P(arg2))
            bn_g = GetBNPtr(arg2);
        if (EC_POINT_mul(group, point_result, bn_g, point_self, bn, ossl_bn_ctx) != 1)
            ossl_raise(eEC_POINT, NULL);
    } else {
        /*
         * bignums | arg1[0] | arg1[1] | arg1[2] | ...
         * points  | self    | arg2[0] | arg2[1] | ...
         */
        long i, num;
        VALUE bns_tmp, tmp_p, tmp_b;
        const EC_POINT **points;
        const BIGNUM **bignums;

        Check_Type(arg1, T_ARRAY);
        Check_Type(arg2, T_ARRAY);
        if (RARRAY_LEN(arg1) != RARRAY_LEN(arg2) + 1) /* arg2 must be 1 larger */
            ossl_raise(rb_eArgError, "bns must be 1 longer than points; see the documentation");

        num = RARRAY_LEN(arg1);
        bns_tmp = rb_ary_tmp_new(num);
        bignums = ALLOCV_N(const BIGNUM *, tmp_b, num);
        for (i = 0; i < num; i++) {
            VALUE item = RARRAY_AREF(arg1, i);
            bignums[i] = GetBNPtr(item);
            rb_ary_push(bns_tmp, item);
        }

        points = ALLOCV_N(const EC_POINT *, tmp_p, num);
        points[0] = point_self; /* self */
        for (i = 0; i < num - 1; i++)
            SafeGetECPoint(RARRAY_AREF(arg2, i), points[i + 1]);

        if (!NIL_P(arg3))
            bn_g = GetBNPtr(arg3);

        if (EC_POINTs_mul(group, point_result, bn_g, num, points, bignums, ossl_bn_ctx) != 1) {
            ALLOCV_END(tmp_b);
            ALLOCV_END(tmp_p);
            ossl_raise(eEC_POINT, NULL);
        }

        ALLOCV_END(tmp_b);
        ALLOCV_END(tmp_p);
    }

    return result;
}

on_curve? → true | false 显示源

static VALUE ossl_ec_point_is_on_curve(VALUE self)
{
    EC_POINT *point;
    const EC_GROUP *group;

    GetECPoint(self, point);
    GetECPointGroup(self, group);

    switch (EC_POINT_is_on_curve(group, point, ossl_bn_ctx)) {
    case 1: return Qtrue;
    case 0: return Qfalse;
    default: ossl_raise(cEC_POINT, "EC_POINT_is_on_curve");
    }

    UNREACHABLE;
}

set_to_infinity! → self 显示源

static VALUE ossl_ec_point_set_to_infinity(VALUE self)
{
    EC_POINT *point;
    const EC_GROUP *group;

    GetECPoint(self, point);
    GetECPointGroup(self, group);

    if (EC_POINT_set_to_infinity(group, point) != 1)
        ossl_raise(cEC_POINT, "EC_POINT_set_to_infinity");

    return self;
}

to_bn(conversion_form = nil) → OpenSSL::BN 显示源

将EC点转换为一个八位组串并存储在OpenSSL :: BN中。如果conversion_form给出,点数据将使用指定的表格进行转换。如果未提供,则使用在EC :: Group对象中设置的默认表单。

另见EC :: Point#point_conversion_form =。

static VALUE
ossl_ec_point_to_bn(int argc, VALUE *argv, VALUE self)
{
    EC_POINT *point;
    VALUE form_obj, bn_obj;
    const EC_GROUP *group;
    point_conversion_form_t form;
    BIGNUM *bn;

    GetECPoint(self, point);
    GetECPointGroup(self, group);
    rb_scan_args(argc, argv, "01", &form_obj);
    if (NIL_P(form_obj))
        form = EC_GROUP_get_point_conversion_form(group);
    else
        form = parse_point_conversion_form_symbol(form_obj);

    bn_obj = rb_obj_alloc(cBN);
    bn = GetBNPtr(bn_obj);

    if (EC_POINT_point2bn(group, point, form, bn, ossl_bn_ctx) == NULL)
        ossl_raise(eEC_POINT, "EC_POINT_point2bn");

    return bn_obj;
}

OpenSSL相关

1.OpenSSL::ASN1
2.OpenSSL::ASN1::ASN1Data
3.OpenSSL::ASN1::ASN1Error
4.OpenSSL::ASN1::Constructive
5.OpenSSL::ASN1::ObjectId
6.OpenSSL::ASN1::Primitive
7.OpenSSL::BN
8.OpenSSL::BNError
9.OpenSSL::Buffering
10.OpenSSL::Cipher
11.OpenSSL::Cipher::Cipher
12.OpenSSL::Config
13.OpenSSL::ConfigError
14.OpenSSL::Digest
15.OpenSSL::Digest::DigestError
16.OpenSSL::Engine
17.OpenSSL::Engine::EngineError
18.OpenSSL::ExtConfig
19.OpenSSL::HMAC
20.OpenSSL::HMACError
21.OpenSSL::Netscape
22.OpenSSL::Netscape::SPKI
23.OpenSSL::Netscape::SPKIError
24.OpenSSL::OCSP
25.OpenSSL::OCSP::BasicResponse
26.OpenSSL::OCSP::CertificateId
27.OpenSSL::OCSP::OCSPError
28.OpenSSL::OCSP::Request
29.OpenSSL::OCSP::Response
30.OpenSSL::OCSP::SingleResponse
31.OpenSSL::OpenSSLError
32.OpenSSL::PKCS12
33.OpenSSL::PKCS5
34.OpenSSL::PKCS5::PKCS5Error
35.OpenSSL::PKCS7
36.OpenSSL::PKCS7::RecipientInfo
37.OpenSSL::PKCS7::SignerInfo
38.OpenSSL::PKey
39.OpenSSL::PKey::DH
40.OpenSSL::PKey::DHError
41.OpenSSL::PKey::DSA
42.OpenSSL::PKey::DSAError
43.OpenSSL::PKey::EC
44.OpenSSL::PKey::EC::Group
45.OpenSSL::PKey::PKey
46.OpenSSL::PKey::PKeyError
47.OpenSSL::PKey::RSA
48.OpenSSL::PKey::RSAError
49.OpenSSL::Random
50.OpenSSL::SSL
51.OpenSSL::SSL::Session
52.OpenSSL::SSL::SocketForwarder
53.OpenSSL::SSL::SSLContext
54.OpenSSL::SSL::SSLError
55.OpenSSL::SSL::SSLServer
56.OpenSSL::SSL::SSLSocket
57.OpenSSL::X509::Attribute
58.OpenSSL::X509::Certificate
59.OpenSSL::X509::CRL
60.OpenSSL::X509::Extension
61.OpenSSL::X509::ExtensionFactory
62.OpenSSL::X509::Name
63.OpenSSL::X509::Name::RFC2253DN
64.OpenSSL::X509::Request
65.OpenSSL::X509::Revoked
66.OpenSSL::X509::Store
67.OpenSSL::X509::StoreContext
Ruby 2.4

Ruby 是一种面向对象、命令式、函数式、动态的通用编程语言,是世界上最优美而巧妙的语言。

主页 https://www.ruby-lang.org/
源码 https://github.com/ruby/ruby
版本 2.4
发布版本 2.4.1

Ruby 2.4目录

1.缩略 | Abbrev
2.ARGF
3.数组 | Array
4.Base64
5.基本对象 | BasicObject
6.基准测试 | Benchmark
7.BigDecimal
8.绑定 | Binding
9.CGI
10.类 | Class
11.比较 | Comparable
12.负责 | Complex
13.计算续体 | Continuation
14.覆盖 | Coverage
15.CSV
16.日期 | Date
17.日期时间 | DateTime
18.DBM
19.代理 | Delegator
20.摘要 | Digest
21.Dir
22.DRb
23.编码 | Encoding
24.枚举 | Enumerable
25.枚举 | Enumerator
26.ENV
27.ERB
28.错误 | Errors
29.Etc
30.期望值 | Exception
31.错误类 | FalseClass
32.Fiber
33.Fiddle
34.文件 | File
35.文件实用程序 | FileUtils
36.查找 | Find
37.浮点 | Float
38.Forwardable
39.GC
40.GDBM
41.GetoptLong
42.Hash
43.Integer
44.IO
45.IPAddr
46.JSON
47.Kernel
48.语言 | 3Language
49.记录 | Logger
50.编排 | Marshal
51.MatchData
52.数学 | Math
53.矩阵 | Matrix
54.方法 | Method
55.模型 | Module
56.监控 | Monitor
57. 互斥 | Mutex
58.Net
59.Net::FTP
60.Net::HTTP
61.Net::IMAP
62.Net::SMTP
63.NilClass
64.数字 | Numeric
65.对象 | Object
66.ObjectSpace
67.Observable
68.Open3
69.OpenSSL
70.OpenStruct
71.OpenURI
72.OptionParser
73.路径名 | Pathname
74.完整输出 | PrettyPrint
75.Prime
76.Proc
77.过程 | Process
78.PStore
79.PTY
80.队列 | Queue
81.随机 | Random
82.范围 | Range
83.合理的 | Rational
84.Readline
85.Regexp
86.Resolv
87.Ripper
88.RubyVM
89.Scanf
90.SDBM
91.SecureRandom
92.Set
93.Shell
94.信号 | Signal
95.Singleton
96.套接字 | Socket
97.字符串 | String
98.StringIO
99.StringScanner
100.结构 | Struct