class BLS::Fq6

Finite extension field over irreducible polynomial. Fq2(v) / (v^3 - ξ) where ξ = u + 1

Constants

FROBENIUS_COEFFICIENTS_1
FROBENIUS_COEFFICIENTS_2
ONE
ZERO

Attributes

coeffs[R]

Public Class Methods

from_tuple(t) click to toggle source
# File lib/bls/field.rb, line 278
def self.from_tuple(t)
  Fq6.new([Fq2.new(t[0...2]), Fq2.new(t[2...4]), Fq2.new(t[4...6])])
end
new(coeffs) click to toggle source
# File lib/bls/field.rb, line 272
def initialize(coeffs)
  raise ArgumentError, 'Expected array with 3 elements' unless coeffs.size == 3

  @coeffs = coeffs
end

Public Instance Methods

*(other)
Alias for: multiply
frobenius_map(power) click to toggle source
# File lib/bls/field.rb, line 396
def frobenius_map(power)
  Fq6.new([
            coeffs[0].frobenius_map(power),
            coeffs[1].frobenius_map(power) * Fq6::FROBENIUS_COEFFICIENTS_1[power % 6],
            coeffs[2].frobenius_map(power) * Fq6::FROBENIUS_COEFFICIENTS_2[power % 6]
          ])
end
invert() click to toggle source
# File lib/bls/field.rb, line 387
def invert
  c0, c1, c2 = coeffs
  t0 = c0.square - (c2 * c1).mul_by_non_residue
  t1 = c2.square.mul_by_non_residue - (c0 * c1)
  t2 = c1.square - c0 * c2
  t4 = ((c2 * t1 + c1 * t2).mul_by_non_residue + c0 * t0).invert
  Fq6.new([t4 * t0, t4 * t1, t4 * t2])
end
mul_by_non_residue() click to toggle source

Multiply by quadratic non-residue v.

# File lib/bls/field.rb, line 340
def mul_by_non_residue
  Fq6.new([coeffs[2].mul_by_non_residue, coeffs[0], coeffs[1]])
end
multiply(other) click to toggle source
# File lib/bls/field.rb, line 344
def multiply(other)
  return Fq6.new([coeffs[0] * other, coeffs[1] * other, coeffs[2] * other]) if other.is_a?(Integer)

  c0, c1, c2 = coeffs
  r0, r1, r2 = other.coeffs
  t0 = c0 * r0
  t1 = c1 * r1
  t2 = c2 * r2

  Fq6.new([
            t0 + ((c1 + c2) * (r1 + r2) - (t1 + t2)).mul_by_non_residue,
            (c0 + c1) * (r0 + r1) - (t0 + t1) + t2.mul_by_non_residue,
            t1 + ((c0 + c2) * (r0 + r2) - (t0 + t2))
          ])
end
Also aliased as: *
multiply_by_01(b0, b1) click to toggle source

Sparse multiplication.

# File lib/bls/field.rb, line 367
def multiply_by_01(b0, b1)
  c0, c1, c2 = coeffs
  t0 = c0 * b0
  t1 = c1 * b1
  Fq6.new([((c1 + c2) * b1 - t1).mul_by_non_residue + t0, (b0 + b1) * (c0 + c1) - t0 - t1, (c0 + c2) * b0 - t0 + t1])
end
multiply_by_1(b1) click to toggle source

Sparse multiplication.

# File lib/bls/field.rb, line 362
def multiply_by_1(b1)
  Fq6.new([coeffs[2].multiply(b1).mul_by_non_residue, coeffs[0] * b1, coeffs[1] * b1])
end
multiply_by_fq2(other) click to toggle source
# File lib/bls/field.rb, line 374
def multiply_by_fq2(other)
  Fq6.new(coeffs.map { |c| c * other })
end
square() click to toggle source
# File lib/bls/field.rb, line 378
def square
  c0, c1, c2 = coeffs
  t0 = c0.square
  t1 = c0 * c1 * 2
  t3 = c1 * c2 * 2
  t4 = c2.square
  Fq6.new([t3.mul_by_non_residue + t0, t4.mul_by_non_residue + t1, t1 + (c0 - c1 + c2).square + t3 - t0 - t4])
end