Class: BLS::Fp

Inherits:
Object
  • Object
show all
Includes:
Field
Defined in:
lib/bls/field.rb

Overview

Finite field over q.

Constant Summary collapse

ORDER =
BLS::Curve::P
MAX_BITS =
Curve::P.bit_length
BYTES_LEN =
(MAX_BITS / 8.0).ceil
ZERO =
Fp.new(0)
ONE =
Fp.new(1)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Field

#==, #add, #div, #invert, #multiply, #negate, #pow, #square, #subtract, #to_s, #zero?

Constructor Details

#initialize(value) ⇒ Fp

Returns a new instance of Fp.

Raises:

  • (ArgumentError)


83
84
85
86
87
# File 'lib/bls/field.rb', line 83

def initialize(value)
  raise ArgumentError, 'value must be Integer.' unless value.is_a?(Integer)

  @value = BLS.mod(value, ORDER)
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



81
82
83
# File 'lib/bls/field.rb', line 81

def value
  @value
end

Instance Method Details

#to_bytesObject



92
93
94
# File 'lib/bls/field.rb', line 92

def to_bytes
  [to_hex].pack('H*')
end

#to_hexObject



96
97
98
# File 'lib/bls/field.rb', line 96

def to_hex
  value.to_s(16).rjust(2 * BYTES_LEN, '0')
end