ark-curves-cherry-picked/bn254/src/fields/fq6.rs
bn254/src/fields/fq6.rsRaw
1use ark_ff::{fields::*, MontFp, QuadExt};
2
3use crate::*;
4
5pub type Fq6 = Fp6<Fq6Config>;
6
7#[derive(Clone, Copy)]
8pub struct Fq6Config;
9
10impl Fp6Config for Fq6Config {
11 type Fp2Config = Fq2Config;
12
13 /// NONRESIDUE = U+9
14 const NONRESIDUE: Fq2 = QuadExt!(MontFp!(Fq, "9"), MontFp!(Fq, "1"));
15
16 const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
17 // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
18 QuadExt!(MontFp!(Fq, "1"), MontFp!(Fq, "0"),),
19 // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
20 QuadExt!(
21 MontFp!(
22 Fq,
23 "21575463638280843010398324269430826099269044274347216827212613867836435027261"
24 ),
25 MontFp!(
26 Fq,
27 "10307601595873709700152284273816112264069230130616436755625194854815875713954"
28 ),
29 ),
30 // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
31 QuadExt!(
32 MontFp!(
33 Fq,
34 "21888242871839275220042445260109153167277707414472061641714758635765020556616"
35 ),
36 MontFp!(Fq, "0"),
37 ),
38 // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
39 QuadExt!(
40 MontFp!(
41 Fq,
42 "3772000881919853776433695186713858239009073593817195771773381919316419345261"
43 ),
44 MontFp!(
45 Fq,
46 "2236595495967245188281701248203181795121068902605861227855261137820944008926"
47 ),
48 ),
49 // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
50 QuadExt!(
51 MontFp!(
52 Fq,
53 "2203960485148121921418603742825762020974279258880205651966"
54 ),
55 MontFp!(Fq, "0"),
56 ),
57 // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
58 QuadExt!(
59 MontFp!(
60 Fq,
61 "18429021223477853657660792034369865839114504446431234726392080002137598044644"
62 ),
63 MontFp!(
64 Fq,
65 "9344045779998320333812420223237981029506012124075525679208581902008406485703"
66 ),
67 ),
68 ];
69
70 const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
71 // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3)
72 QuadExt!(MontFp!(Fq, "1"), MontFp!(Fq, "0"),),
73 // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3)
74 QuadExt!(
75 MontFp!(
76 Fq,
77 "2581911344467009335267311115468803099551665605076196740867805258568234346338"
78 ),
79 MontFp!(
80 Fq,
81 "19937756971775647987995932169929341994314640652964949448313374472400716661030"
82 ),
83 ),
84 // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3)
85 QuadExt!(
86 MontFp!(
87 Fq,
88 "2203960485148121921418603742825762020974279258880205651966"
89 ),
90 MontFp!(Fq, "0"),
91 ),
92 // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3)
93 QuadExt!(
94 MontFp!(
95 Fq,
96 "5324479202449903542726783395506214481928257762400643279780343368557297135718"
97 ),
98 MontFp!(
99 Fq,
100 "16208900380737693084919495127334387981393726419856888799917914180988844123039"
101 ),
102 ),
103 // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3)
104 QuadExt!(
105 MontFp!(
106 Fq,
107 "21888242871839275220042445260109153167277707414472061641714758635765020556616"
108 ),
109 MontFp!(Fq, "0"),
110 ),
111 // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3)
112 QuadExt!(
113 MontFp!(
114 Fq,
115 "13981852324922362344252311234282257507216387789820983642040889267519694726527"
116 ),
117 MontFp!(
118 Fq,
119 "7629828391165209371577384193250820201684255241773809077146787135900891633097"
120 ),
121 ),
122 ];
123
124 #[inline(always)]
125 fn mul_fp2_by_nonresidue(fe: &Fq2) -> Fq2 {
126 // (c0+u*c1)*(9+u) = (9*c0-c1)+u*(9*c1+c0)
127 let mut f = *fe;
128 f.double_in_place().double_in_place().double_in_place();
129 let c0 = f.c0 + fe.c0 + Fq2Config::mul_fp_by_nonresidue(&fe.c1);
130 let c1 = f.c1 + fe.c1 + fe.c0;
131 QuadExt!(c0, c1)
132 }
133}