Class: JOSE::JWA::Edwards448Point

Inherits:
EdwardsPoint show all
Defined in:
lib/jose/jwa/edwards_point.rb

Overview

A point on Edward448

Constant Summary collapse

BASE_FIELD =

Create a new point on curve.

JOSE::JWA::FieldElement.new(1, (2**448)-(2**224)-1).freeze
D =
BASE_FIELD.make(-39081).freeze
F0 =
BASE_FIELD.make(0).freeze
F1 =
BASE_FIELD.make(1).freeze
XB =
BASE_FIELD.make(224580040295924300187604334099896036246789641632564134246125461686950415467406032909029192869357953282578032075146446173674602635247710).freeze
YB =
BASE_FIELD.make(298819210078481492676017930443930673437544040154080242095928241372331506189835876003536878655418784733982303233503462500531545062832660).freeze
L =

Order of basepoint.

181709681073901722637330951972001133588410340171829515070372549795146003961539585716195755291692375963310293709091662304773755859649779
C =

The logarithm of cofactor.

2
N =

The highest set bit

447
B =

The coding length

456

Instance Attribute Summary

Attributes inherited from EdwardsPoint

#x, #y, #z

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from EdwardsPoint

#*, #<=>, #decode_base, #encode_base, #initpoint

Constructor Details

#initialize(x, y) ⇒ Edwards448Point

Returns a new instance of Edwards448Point.

Raises:

  • (ArgumentError)


191
192
193
194
195
# File 'lib/jose/jwa/edwards_point.rb', line 191

def initialize(x, y)
  # Check the point is actually on the curve.
  raise ArgumentError, "Invalid point" if y*y+x*x != F1+D*x*x*y*y
  initpoint(x, y)
end

Class Method Details

.stdbaseObject

The standard base point.



187
188
189
# File 'lib/jose/jwa/edwards_point.rb', line 187

def self.stdbase
  return new(XB, YB)
end

Instance Method Details

#+(y) ⇒ Object

Point addition.



227
228
229
230
231
232
233
234
235
236
237
# File 'lib/jose/jwa/edwards_point.rb', line 227

def +(y)
  # The formulas are from EFD.
  tmp = zero_elem
  xcp, ycp, zcp = @x * y.x, @y * y.y, @z * y.z
  b = zcp * zcp
  e = D * xcp * ycp
  f, g = b - e, b + e
  tmp.x = zcp * f * ((@x + @y) * (y.x + y.y) - xcp - ycp)
  tmp.y, tmp.z = zcp * g * (ycp - xcp), f * g
  return tmp
end

#decode(s) ⇒ Object

Decode a point representation.



198
199
200
201
202
# File 'lib/jose/jwa/edwards_point.rb', line 198

def decode(s)
  x, y = decode_base(s, B)
  return nil if x.nil?
  return JOSE::JWA::Edwards448Point.new(x, y)
end

#doubleObject

Point doubling.



240
241
242
243
244
245
246
247
248
249
# File 'lib/jose/jwa/edwards_point.rb', line 240

def double
  # The formulas are from EFD.
  tmp = zero_elem
  x1s, y1s, z1s = @x * @x, @y * @y, @z * @z
  xys = @x + @y
  f = x1s + y1s
  j = f - (z1s + z1s)
  tmp.x, tmp.y, tmp.z = (xys * xys - x1s - y1s) * j, f * (x1s - y1s), f * j
  return tmp
end

#encodeObject

Encode a point representation.



205
206
207
# File 'lib/jose/jwa/edwards_point.rb', line 205

def encode
  return encode_base(B)
end

#inspectObject



251
252
253
254
255
# File 'lib/jose/jwa/edwards_point.rb', line 251

def inspect
  "\n{#{@x.x},\n"\
  " #{@y.x},\n"\
  " #{@z.x}}"
end

#normalizeObject



209
210
211
212
213
214
# File 'lib/jose/jwa/edwards_point.rb', line 209

def normalize
  xp, yp, zp = @x / @z, @y / @z, @z / @z
  tmp = zero_elem
  tmp.x, tmp.y, tmp.z = xp, yp, zp
  return tmp
end

#solve_x2(y) ⇒ Object

Solve for x^2.



222
223
224
# File 'lib/jose/jwa/edwards_point.rb', line 222

def solve_x2(y)
  return ((y*y-F1)/(D*y*y-F1))
end

#zero_elemObject

Construct neutral point on this curve.



217
218
219
# File 'lib/jose/jwa/edwards_point.rb', line 217

def zero_elem
  return JOSE::JWA::Edwards448Point.new(F0, F1)
end