Class: BLS::Fp12
- Inherits:
-
Object
show all
- Includes:
- FQP
- Defined in:
- lib/bls/field.rb
Overview
Finite extension field over irreducible polynomial. Fp6(w) / (w2 - γ) where γ = v
Constant Summary
collapse
- ZERO =
Fp12.new([Fp6::ZERO, Fp6::ZERO])
- ONE =
Fp12.new([Fp6::ONE, Fp6::ZERO])
- FROBENIUS_COEFFICIENTS =
[
Fp2.new([
0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001,
0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
]),
Fp2.new([
0x1904d3bf02bb0667c231beb4202c0d1f0fd603fd3cbd5f4f7b2443d784bab9c4f67ea53d63e7813d8d0775ed92235fb8,
0x00fc3e2b36c4e03288e9e902231f9fb854a14787b6c7b36fec0c8ec971f63c5f282d5ac14d6c7ec22cf78a126ddc4af3
]),
Fp2.new([
0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffeffff,
0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
]),
Fp2.new([
0x135203e60180a68ee2e9c448d77a2cd91c3dedd930b1cf60ef396489f61eb45e304466cf3e67fa0af1ee7b04121bdea2,
0x06af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09
]),
Fp2.new([
0x00000000000000005f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe,
0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
]),
Fp2.new([
0x144e4211384586c16bd3ad4afa99cc9170df3560e77982d0db45f3536814f0bd5871c1908bd478cd1ee605167ff82995,
0x05b2cfd9013a5fd8df47fa6b48b1e045f39816240c0b8fee8beadf4d8e9c0566c63a3e6e257f87329b18fae980078116
]),
Fp2.new([
0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaaa,
0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
]),
Fp2.new([
0x00fc3e2b36c4e03288e9e902231f9fb854a14787b6c7b36fec0c8ec971f63c5f282d5ac14d6c7ec22cf78a126ddc4af3,
0x1904d3bf02bb0667c231beb4202c0d1f0fd603fd3cbd5f4f7b2443d784bab9c4f67ea53d63e7813d8d0775ed92235fb8
]),
Fp2.new([
0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaac,
0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
]),
Fp2.new([
0x06af0e0437ff400b6831e36d6bd17ffe48395dabc2d3435e77f76e17009241c5ee67992f72ec05f4c81084fbede3cc09,
0x135203e60180a68ee2e9c448d77a2cd91c3dedd930b1cf60ef396489f61eb45e304466cf3e67fa0af1ee7b04121bdea2
]),
Fp2.new([
0x1a0111ea397fe699ec02408663d4de85aa0d857d89759ad4897d29650fb85f9b409427eb4f49fffd8bfd00000000aaad,
0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
]),
Fp2.new([
0x05b2cfd9013a5fd8df47fa6b48b1e045f39816240c0b8fee8beadf4d8e9c0566c63a3e6e257f87329b18fae980078116,
0x144e4211384586c16bd3ad4afa99cc9170df3560e77982d0db45f3536814f0bd5871c1908bd478cd1ee605167ff82995
])
].freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from FQP
#==, #add, #conjugate, #div, #negate, #pow, #subtract, #to_bytes, #to_hex, #zero?
Constructor Details
#initialize(coeffs) ⇒ Fp12
Returns a new instance of Fp12.
448
449
450
451
452
|
# File 'lib/bls/field.rb', line 448
def initialize(coeffs)
raise ArgumentError, 'Expected array with 2 elements' unless coeffs.size == 2
@coeffs = coeffs
end
|
Instance Attribute Details
#coeffs ⇒ Object
Returns the value of attribute coeffs.
446
447
448
|
# File 'lib/bls/field.rb', line 446
def coeffs
@coeffs
end
|
Instance Method Details
#cyclotomic_exp(n) ⇒ Object
583
584
585
586
587
588
589
590
591
592
|
# File 'lib/bls/field.rb', line 583
def cyclotomic_exp(n)
z = Fp12::ONE
i = BLS_X_LEN - 1
while i >= 0
z = z.cyclotomic_square
z *= self unless BLS.bit_get(n, i).zero?
i -= 1
end
z
end
|
#cyclotomic_square ⇒ Object
570
571
572
573
574
575
576
577
578
579
580
581
|
# File 'lib/bls/field.rb', line 570
def cyclotomic_square
c0, c1 = coeffs
c0c0, c0c1, c0c2 = c0.coeffs
c1c0, c1c1, c1c2 = c1.coeffs
t3, t4 = fp4_square(c0c0, c1c1)
t5, t6 = fp4_square(c1c0, c0c2)
t7, t8 = fp4_square(c0c1, c1c2)
t9 = t8.mul_by_non_residue
Fp12.new([
Fp6.new([(t3 - c0c0) * 2 + t3, (t5 - c0c1) * 2 + t5, (t7 - c0c2) * 2 + t7]),
Fp6.new([(t9 + c1c0) * 2 + t9, (t4 + c1c1) * 2 + t4, (t6 + c1c2) * 2 + t6])])
end
|
#final_exponentiate ⇒ Object
558
559
560
561
562
563
564
565
566
567
568
|
# File 'lib/bls/field.rb', line 558
def final_exponentiate
t0 = frobenius_map(6) / self
t1 = t0.frobenius_map(2) * t0
t2 = t1.cyclotomic_exp(Curve::X).conjugate
t3 = t1.cyclotomic_square.conjugate * t2
t4 = t3.cyclotomic_exp(Curve::X).conjugate
t5 = t4.cyclotomic_exp(Curve::X).conjugate
t6 = t5.cyclotomic_exp(Curve::X).conjugate * t2.cyclotomic_square
(t2 * t5).frobenius_map(2) * (t4 * t1).frobenius_map(3) *
(t6 * t1.conjugate).frobenius_map(1) * t6.cyclotomic_exp(Curve::X).conjugate * t3.conjugate * t1
end
|
#frobenius_map(power) ⇒ Object
#invert ⇒ Object
540
541
542
543
544
|
# File 'lib/bls/field.rb', line 540
def invert
c0, c1 = coeffs
t = (c0.square - c1.square.mul_by_non_residue).invert
Fp12.new([c0 * t, (c1 * t).negate])
end
|
#multiply(other) ⇒ Object
Also known as:
*
512
513
514
515
516
517
518
519
520
|
# File 'lib/bls/field.rb', line 512
def multiply(other)
return Fp12.new([coeffs[0] * other, coeffs[1] * other]) if other.is_a?(Integer)
c0, c1 = coeffs
r0, r1 = other.coeffs
t1 = c0 * r0
t2 = c1 * r1
Fp12.new([t1 + t2.mul_by_non_residue, (c0 + c1) * (r0 + r1) - (t1 + t2)])
end
|
#multiply_by_014(o0, o1, o4) ⇒ Object
523
524
525
526
527
528
|
# File 'lib/bls/field.rb', line 523
def multiply_by_014(o0, o1, o4)
c0, c1 = coeffs
t0 = c0.multiply_by_01(o0, o1)
t1 = c1.multiply_by_1(o4)
Fp12.new([t1.mul_by_non_residue + t0, (c1 + c0).multiply_by_01(o0, o1 + o4) - t0 - t1])
end
|
#multiply_by_fp2(other) ⇒ Object
530
531
532
|
# File 'lib/bls/field.rb', line 530
def multiply_by_fp2(other)
Fp12.new(coeffs.map{ |c| c.multiply_by_fp2(other) })
end
|
#square ⇒ Object
534
535
536
537
538
|
# File 'lib/bls/field.rb', line 534
def square
c0, c1 = coeffs
ab = c0 * c1
Fp12.new([(c1.mul_by_non_residue + c0) * (c0 + c1) - ab - ab.mul_by_non_residue, ab + ab])
end
|