Module: PolyPseudo::OpenSSLPointExtension
- Extended by:
- FFI::Library
- Defined in:
- lib/ext/openssl_ec.rb
Constant Summary collapse
- NID_brainpoolP320r1 =
929
- POINT_CONVERSION_COMPRESSED =
2
- POINT_CONVERSION_UNCOMPRESSED =
4
Class Method Summary collapse
Class Method Details
.add(point_0, point_1) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ext/openssl_ec.rb', line 22 def self.add(point_0, point_1) group = EC_GROUP_new_by_curve_name(NID_brainpoolP320r1) point_0_hex = point_0.to_bn.to_s(16) point_0_pt = EC_POINT_hex2point(group, point_0_hex, nil, nil) point_1_hex = point_1.to_bn.to_s(16) point_1_pt = EC_POINT_hex2point(group, point_1_hex, nil, nil) sum_point = EC_POINT_new(group) success = EC_POINT_add(group, sum_point, point_0_pt, point_1_pt, nil) if success hex = EC_POINT_point2hex(group, sum_point, POINT_CONVERSION_COMPRESSED, nil) OpenSSL::PKey::EC::Point.new(PolyPseudo.config.group, OpenSSL::BN.new(hex, 16)) end ensure EC_POINT_free(sum_point) end |
.point2hex(point, compressed) ⇒ Object
53 54 55 56 57 58 |
# File 'lib/ext/openssl_ec.rb', line 53 def self.point2hex(point, compressed) group = EC_GROUP_new_by_curve_name(NID_brainpoolP320r1) point_hex = point.to_bn.to_s(16) point_pt = EC_POINT_hex2point(group, point_hex, nil, nil) EC_POINT_point2hex(group, point_pt, compressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED, nil) end |
.x_y(point) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ext/openssl_ec.rb', line 38 def self.x_y(point) group = EC_GROUP_new_by_curve_name(NID_brainpoolP320r1) point_hex = point.to_bn.to_s(16) point_pt = EC_POINT_hex2point(group, point_hex, nil, nil) x_coord = BN_new() y_coord = BN_new() EC_POINT_get_affine_coordinates_GFp(group, point_pt, x_coord, y_coord, nil) [OpenSSL::BN.new(BN_bn2hex(x_coord), 16), OpenSSL::BN.new(BN_bn2hex(y_coord), 16)] ensure BN_free(x_coord) BN_free(y_coord) end |