Class: BLS::Fp6
Overview
Finite extension field over irreducible polynomial. Fp2(v) / (v^3 - ξ) where ξ = u + 1
Constant Summary collapse
- ZERO =
Fp6.new([Fp2::ZERO, Fp2::ZERO, Fp2::ZERO])
- ONE =
Fp6.new([Fp2::ONE, Fp2::ZERO, Fp2::ZERO])
- FROBENIUS_COEFFICIENTS_1 =
[ Fp2.new([ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ]), Fp2.new([ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac ]), Fp2.new([ 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, ]), Fp2.new([ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 ]), Fp2.new([ 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ]), Fp2.new([ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe ]) ].freeze
- FROBENIUS_COEFFICIENTS_2 =
[ Fp2.new([ 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ]), Fp2.new([ 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaad, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ]), Fp2.new([ 0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ]), Fp2.new([ 0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ]), Fp2.new([ 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ]), Fp2.new([ 0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffeffff, 0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ]) ].freeze
Instance Attribute Summary collapse
-
#coeffs ⇒ Object
readonly
Returns the value of attribute coeffs.
Class Method Summary collapse
Instance Method Summary collapse
- #frobenius_map(power) ⇒ Object
-
#initialize(coeffs) ⇒ Fp6
constructor
A new instance of Fp6.
- #invert ⇒ Object
-
#mul_by_non_residue ⇒ Object
Multiply by quadratic non-residue v.
- #multiply(other) ⇒ Object (also: #*)
-
#multiply_by_01(b0, b1) ⇒ Object
Sparse multiplication.
-
#multiply_by_1(b1) ⇒ Object
Sparse multiplication.
- #multiply_by_fp2(other) ⇒ Object
- #square ⇒ Object
Methods included from FQP
#==, #add, #conjugate, #div, #negate, #pow, #subtract, #to_bytes, #to_hex, #zero?
Constructor Details
#initialize(coeffs) ⇒ Fp6
Returns a new instance of Fp6.
308 309 310 311 312 |
# File 'lib/bls/field.rb', line 308 def initialize(coeffs) raise ArgumentError, 'Expected array with 3 elements' unless coeffs.size == 3 @coeffs = coeffs end |
Instance Attribute Details
#coeffs ⇒ Object (readonly)
Returns the value of attribute coeffs.
306 307 308 |
# File 'lib/bls/field.rb', line 306 def coeffs @coeffs end |
Class Method Details
Instance Method Details
#frobenius_map(power) ⇒ Object
432 433 434 435 436 437 438 |
# File 'lib/bls/field.rb', line 432 def frobenius_map(power) Fp6.new([ coeffs[0].frobenius_map(power), coeffs[1].frobenius_map(power) * Fp6::FROBENIUS_COEFFICIENTS_1[power % 6], coeffs[2].frobenius_map(power) * Fp6::FROBENIUS_COEFFICIENTS_2[power % 6] ]) end |
#invert ⇒ Object
423 424 425 426 427 428 429 430 |
# File 'lib/bls/field.rb', line 423 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 Fp6.new([t4 * t0, t4 * t1, t4 * t2]) end |
#mul_by_non_residue ⇒ Object
Multiply by quadratic non-residue v.
376 377 378 |
# File 'lib/bls/field.rb', line 376 def mul_by_non_residue Fp6.new([coeffs[2].mul_by_non_residue, coeffs[0], coeffs[1]]) end |
#multiply(other) ⇒ Object Also known as: *
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 |
# File 'lib/bls/field.rb', line 380 def multiply(other) return Fp6.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 Fp6.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 |
#multiply_by_01(b0, b1) ⇒ Object
Sparse multiplication.
403 404 405 406 407 408 |
# File 'lib/bls/field.rb', line 403 def multiply_by_01(b0, b1) c0, c1, c2 = coeffs t0 = c0 * b0 t1 = c1 * b1 Fp6.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) ⇒ Object
Sparse multiplication.
398 399 400 |
# File 'lib/bls/field.rb', line 398 def multiply_by_1(b1) Fp6.new([coeffs[2].multiply(b1).mul_by_non_residue, coeffs[0] * b1, coeffs[1] * b1]) end |