You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.6 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. use ark_ff::{fields::*, MontFp};
  2. use crate::*;
  3. pub type Fq6 = Fp6<Fq6Config>;
  4. #[derive(Clone, Copy)]
  5. pub struct Fq6Config;
  6. impl Fp6Config for Fq6Config {
  7. type Fp2Config = Fq2Config;
  8. /// NONRESIDUE = U+9
  9. const NONRESIDUE: Fq2 = Fq2::new(MontFp!("9"), Fq::ONE);
  10. const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
  11. // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
  12. Fq2::new(Fq::ONE, Fq::ZERO),
  13. // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
  14. Fq2::new(
  15. MontFp!(
  16. "21575463638280843010398324269430826099269044274347216827212613867836435027261"
  17. ),
  18. MontFp!(
  19. "10307601595873709700152284273816112264069230130616436755625194854815875713954"
  20. ),
  21. ),
  22. // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
  23. Fq2::new(
  24. MontFp!(
  25. "21888242871839275220042445260109153167277707414472061641714758635765020556616"
  26. ),
  27. Fq::ZERO,
  28. ),
  29. // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
  30. Fq2::new(
  31. MontFp!("3772000881919853776433695186713858239009073593817195771773381919316419345261"),
  32. MontFp!("2236595495967245188281701248203181795121068902605861227855261137820944008926"),
  33. ),
  34. // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
  35. Fq2::new(
  36. MontFp!("2203960485148121921418603742825762020974279258880205651966"),
  37. Fq::ZERO,
  38. ),
  39. // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
  40. Fq2::new(
  41. MontFp!(
  42. "18429021223477853657660792034369865839114504446431234726392080002137598044644"
  43. ),
  44. MontFp!("9344045779998320333812420223237981029506012124075525679208581902008406485703"),
  45. ),
  46. ];
  47. const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
  48. // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3)
  49. Fq2::new(Fq::ONE, Fq::ZERO),
  50. // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3)
  51. Fq2::new(
  52. MontFp!("2581911344467009335267311115468803099551665605076196740867805258568234346338"),
  53. MontFp!(
  54. "19937756971775647987995932169929341994314640652964949448313374472400716661030"
  55. ),
  56. ),
  57. // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3)
  58. Fq2::new(
  59. MontFp!("2203960485148121921418603742825762020974279258880205651966"),
  60. Fq::ZERO,
  61. ),
  62. // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3)
  63. Fq2::new(
  64. MontFp!("5324479202449903542726783395506214481928257762400643279780343368557297135718"),
  65. MontFp!(
  66. "16208900380737693084919495127334387981393726419856888799917914180988844123039"
  67. ),
  68. ),
  69. // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3)
  70. Fq2::new(
  71. MontFp!(
  72. "21888242871839275220042445260109153167277707414472061641714758635765020556616"
  73. ),
  74. Fq::ZERO,
  75. ),
  76. // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3)
  77. Fq2::new(
  78. MontFp!(
  79. "13981852324922362344252311234282257507216387789820983642040889267519694726527"
  80. ),
  81. MontFp!("7629828391165209371577384193250820201684255241773809077146787135900891633097"),
  82. ),
  83. ];
  84. #[inline(always)]
  85. fn mul_fp2_by_nonresidue_in_place(fe: &mut Fq2) -> &mut Fq2 {
  86. // (c0+u*c1)*(9+u) = (9*c0-c1)+u*(9*c1+c0)
  87. let mut f = *fe;
  88. f.double_in_place().double_in_place().double_in_place();
  89. let mut c0 = fe.c1;
  90. Fq2Config::mul_fp_by_nonresidue_in_place(&mut c0);
  91. c0 += &f.c0;
  92. c0 += &fe.c0;
  93. let c1 = f.c1 + fe.c1 + fe.c0;
  94. *fe = Fq2::new(c0, c1);
  95. fe
  96. }
  97. }