class BLS::Fq2
Finite extension field over irreducible polynomial. Fq(u) / (u^2 - β) where β = -1
Constants
Attributes
coeffs[R]
Public Class Methods
new(coeffs)
click to toggle source
# File lib/bls/field.rb, line 182 def initialize(coeffs) raise ArgumentError, 'Expected array with 2 elements' unless coeffs.size == 2 @coeffs = coeffs.map { |c| c.is_a?(Integer) ? Fq.new(c) : c } end
Public Instance Methods
frobenius_map(power)
click to toggle source
Raises to q**i -th power
# File lib/bls/field.rb, line 248 def frobenius_map(power) Fq2.new([coeffs[0], coeffs[1] * Fq2::FROBENIUS_COEFFICIENTS[power % 2]]) end
invert()
click to toggle source
# File lib/bls/field.rb, line 241 def invert a, b = values factor = Fq.new(a * a + b * b).invert Fq2.new([factor * a, factor * -b]) end
mul_by_non_residue()
click to toggle source
# File lib/bls/field.rb, line 252 def mul_by_non_residue c0, c1 = coeffs Fq2.new([c0 - c1, c0 + c1]) end
multiply(other)
click to toggle source
# File lib/bls/field.rb, line 230 def multiply(other) return Fq2.new(coeffs.map { |c| c * other }) if other.is_a?(Integer) c0, c1 = coeffs r0, r1 = other.coeffs t1 = c0 * r0 t2 = c1 * r1 Fq2.new([t1 - t2, ((c0 + c1) * (r0 + r1)) - (t1 + t2)]) end
Also aliased as: *
multiply_by_b()
click to toggle source
# File lib/bls/field.rb, line 257 def multiply_by_b c0, c1 = coeffs t0 = c0 * 4 t1 = c1 * 4 Fq2.new([t0 - t1, t0 + t1]) end
square()
click to toggle source
# File lib/bls/field.rb, line 221 def square c0 = coeffs[0] c1 = coeffs[1] a = c0 + c1 b = c0 - c1 c = c0 + c0 Fq2.new([a * b, c * c1]) end
values()
click to toggle source
# File lib/bls/field.rb, line 217 def values coeffs.map(&:value) end