Class: EllipticCurve::Curve::CurveFp
- Inherits:
-
Object
- Object
- EllipticCurve::Curve::CurveFp
- Defined in:
- lib/curve.rb
Instance Attribute Summary collapse
-
#_generatorPowersTable ⇒ Object
Returns the value of attribute _generatorPowersTable.
-
#a ⇒ Object
Returns the value of attribute a.
-
#b ⇒ Object
Returns the value of attribute b.
-
#g ⇒ Object
Returns the value of attribute g.
-
#glvParams ⇒ Object
Returns the value of attribute glvParams.
-
#n ⇒ Object
Returns the value of attribute n.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nBitLength ⇒ Object
Returns the value of attribute nBitLength.
-
#nistName ⇒ Object
Returns the value of attribute nistName.
-
#oid ⇒ Object
Returns the value of attribute oid.
-
#p ⇒ Object
Returns the value of attribute p.
Instance Method Summary collapse
- #contains(p) ⇒ Object
-
#initialize(a, b, p, n, gx, gy, name, oid, nistName = nil, glvParams = nil) ⇒ CurveFp
constructor
A new instance of CurveFp.
- #length ⇒ Object
- #y(x, isEven) ⇒ Object
Constructor Details
#initialize(a, b, p, n, gx, gy, name, oid, nistName = nil, glvParams = nil) ⇒ CurveFp
Returns a new instance of CurveFp.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/curve.rb', line 12 def initialize(a, b, p, n, gx, gy, name, oid, nistName=nil, glvParams=nil) @a = a @b = b @p = p @n = n @nBitLength = n.bit_length @g = Point.new(gx, gy) @name = name @oid = oid @nistName = nistName # GLV endomorphism parameters (only for curves that support one, # e.g. secp256k1). nil means no endomorphism; fall back to Shamir+JSF. @glvParams = glvParams @_generatorPowersTable = nil end |
Instance Attribute Details
#_generatorPowersTable ⇒ Object
Returns the value of attribute _generatorPowersTable.
10 11 12 |
# File 'lib/curve.rb', line 10 def _generatorPowersTable @_generatorPowersTable end |
#a ⇒ Object
Returns the value of attribute a.
9 10 11 |
# File 'lib/curve.rb', line 9 def a @a end |
#b ⇒ Object
Returns the value of attribute b.
9 10 11 |
# File 'lib/curve.rb', line 9 def b @b end |
#g ⇒ Object
Returns the value of attribute g.
9 10 11 |
# File 'lib/curve.rb', line 9 def g @g end |
#glvParams ⇒ Object
Returns the value of attribute glvParams.
9 10 11 |
# File 'lib/curve.rb', line 9 def glvParams @glvParams end |
#n ⇒ Object
Returns the value of attribute n.
9 10 11 |
# File 'lib/curve.rb', line 9 def n @n end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/curve.rb', line 9 def name @name end |
#nBitLength ⇒ Object
Returns the value of attribute nBitLength.
9 10 11 |
# File 'lib/curve.rb', line 9 def nBitLength @nBitLength end |
#nistName ⇒ Object
Returns the value of attribute nistName.
9 10 11 |
# File 'lib/curve.rb', line 9 def nistName @nistName end |
#oid ⇒ Object
Returns the value of attribute oid.
9 10 11 |
# File 'lib/curve.rb', line 9 def oid @oid end |
#p ⇒ Object
Returns the value of attribute p.
9 10 11 |
# File 'lib/curve.rb', line 9 def p @p end |
Instance Method Details
#contains(p) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/curve.rb', line 28 def contains(p) # Verify if the point `p` is on the curve # :param p: point p = Point(x, y) # :return: boolean if not (0 <= p.x and p.x <= @p - 1) return false end if not (0 <= p.y and p.y <= @p - 1) return false end if (p.y ** 2 - (p.x ** 3 + @a * p.x + @b)) % @p != 0 return false end return true end |
#length ⇒ Object
44 45 46 |
# File 'lib/curve.rb', line 44 def length return (1 + ("%x" % @n).length).div(2) end |
#y(x, isEven) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/curve.rb', line 48 def y(x, isEven) ySquared = (x.pow(3, @p) + @a * x + @b) % @p y = Math::modularSquareRoot(ySquared, @p) if isEven != (y % 2 == 0) y = @p - y end return y end |