Class: ECDSA::Ext::AbstractPoint
- Inherits:
-
Object
- Object
- ECDSA::Ext::AbstractPoint
- Defined in:
- lib/ecdsa/ext/abstract_point.rb
Overview
Abstract class of point
Direct Known Subclasses
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
-
#infinity ⇒ Object
readonly
Returns the value of attribute infinity.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
-
#z ⇒ Object
readonly
Returns the value of attribute z.
Class Method Summary collapse
-
.from_affine(point) ⇒ ECDSA::Ext::AbstractPoint
Convert coordinates from affine.
-
.infinity_point(group) ⇒ ECDSA::Ext::AbstractPoint
Create infinity point.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_to_point(other) ⇒ Object
-
#coords ⇒ Array
Return coordinates.
- #double ⇒ Object
-
#field ⇒ ECDSA::PrimeField
Get filed of this group.
-
#infinity? ⇒ Boolean
Check whether infinity point or not.
- #infinity_point ⇒ Object
-
#initialize(group, *args) ⇒ ECDSA::Ext::AbstractPoint
constructor
Create new instance.
-
#multiply_by_scalar(x) ⇒ ECDSA::Ext::ProjectivePoint
(also: #*)
Return the point multiplied by a non-negative integer.
-
#negate ⇒ ECDSA::Ext::AbstractPoint
Return additive inverse of the point.
- #to_affine ⇒ Object
Constructor Details
#initialize(group, *args) ⇒ ECDSA::Ext::AbstractPoint
Create new instance.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 13 def initialize(group, *args) @group = group if args == [:infinity] @infinity = true else @infinity = false @x, @y, @z = args raise ArgumentError, "Invalid x: #{x.inspect}" unless x.is_a?(Integer) raise ArgumentError, "Invalid y: #{y.inspect}" unless y.is_a?(Integer) raise ArgumentError, "Invalid z: #{z.inspect}" unless z.is_a?(Integer) end end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
7 8 9 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 7 def group @group end |
#infinity ⇒ Object (readonly)
Returns the value of attribute infinity.
7 8 9 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 7 def infinity @infinity end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
7 8 9 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 7 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
7 8 9 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 7 def y @y end |
#z ⇒ Object (readonly)
Returns the value of attribute z.
7 8 9 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 7 def z @z end |
Class Method Details
.from_affine(point) ⇒ ECDSA::Ext::AbstractPoint
Convert coordinates from affine.
35 36 37 38 39 40 41 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 35 def self.from_affine(point) if point.infinity? infinity_point(point.group) else new(point.group, point.x, point.y, 1) end end |
.infinity_point(group) ⇒ ECDSA::Ext::AbstractPoint
Create infinity point
45 46 47 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 45 def self.infinity_point(group) new(group, :infinity) end |
Instance Method Details
#==(other) ⇒ Object
106 107 108 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 106 def ==(other) raise NotImplementedError end |
#add_to_point(other) ⇒ Object
94 95 96 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 94 def add_to_point(other) raise NotImplementedError end |
#coords ⇒ Array
Return coordinates.
68 69 70 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 68 def coords [x, y, z] end |
#double ⇒ Object
98 99 100 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 98 def double raise NotImplementedError end |
#field ⇒ ECDSA::PrimeField
Get filed of this group.
28 29 30 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 28 def field group.field end |
#infinity? ⇒ Boolean
Check whether infinity point or not.
55 56 57 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 55 def infinity? @infinity end |
#infinity_point ⇒ Object
49 50 51 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 49 def infinity_point self.class.infinity_point(group) end |
#multiply_by_scalar(x) ⇒ ECDSA::Ext::ProjectivePoint Also known as: *
Return the point multiplied by a non-negative integer.
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 75 def multiply_by_scalar(x) raise ArgumentError, "Scalar is not an integer." unless x.is_a?(Integer) raise ArgumentError, "Scalar is negative." if x.negative? q = self.class.infinity_point(group) v = self p, n = to_naf(x) len = [p.bit_length, n.bit_length].max len.times do q += v if p.odd? q += v.negate if n.odd? v = v.double p >>= 1 n >>= 1 end q end |
#negate ⇒ ECDSA::Ext::AbstractPoint
Return additive inverse of the point.
61 62 63 64 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 61 def negate return self if infinity? self.class.new(group, x, field.mod(-y), z) end |
#to_affine ⇒ Object
102 103 104 |
# File 'lib/ecdsa/ext/abstract_point.rb', line 102 def to_affine raise NotImplementedError end |