arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bn254/src/fields/fq6.rs
bn254/src/fields/fq6.rsRaw
 1use super::*;
 2use ark_ff::{field_new, fields::*};
 3
 4pub type Fq6 = Fp6<Fq6Parameters>;
 5
 6#[derive(Clone, Copy)]
 7pub struct Fq6Parameters;
 8
 9impl Fp6Parameters for Fq6Parameters {
10    type Fp2Params = Fq2Parameters;
11
12    /// NONRESIDUE = U+9
13    #[rustfmt::skip]
14    const NONRESIDUE: Fq2 = field_new!(Fq2, field_new!(Fq, "9"), field_new!(Fq, "1"));
15
16    #[rustfmt::skip]
17    const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
18        // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
19        field_new!(Fq2, 
20            field_new!(Fq, "1"),
21            field_new!(Fq, "0"),
22        ),
23        // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
24        field_new!(Fq2, 
25            field_new!(Fq, "21575463638280843010398324269430826099269044274347216827212613867836435027261"),
26            field_new!(Fq, "10307601595873709700152284273816112264069230130616436755625194854815875713954"),
27        ),
28        // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
29        field_new!(Fq2, 
30            field_new!(Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556616"),
31            field_new!(Fq, "0"),
32        ),
33        // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
34        field_new!(Fq2, 
35            field_new!(Fq, "3772000881919853776433695186713858239009073593817195771773381919316419345261"),
36            field_new!(Fq, "2236595495967245188281701248203181795121068902605861227855261137820944008926"),
37        ),
38        // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
39        field_new!(Fq2, 
40            field_new!(Fq, "2203960485148121921418603742825762020974279258880205651966"),
41            field_new!(Fq, "0"),
42        ),
43        // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
44        field_new!(Fq2, 
45            field_new!(Fq, "18429021223477853657660792034369865839114504446431234726392080002137598044644"),
46            field_new!(Fq, "9344045779998320333812420223237981029506012124075525679208581902008406485703"),
47        ),
48    ];
49    #[rustfmt::skip]
50    const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
51        // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3)
52        field_new!(Fq2, 
53            field_new!(Fq, "1"),
54            field_new!(Fq, "0"),
55        ),
56        // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3)
57        field_new!(Fq2, 
58            field_new!(Fq, "2581911344467009335267311115468803099551665605076196740867805258568234346338"),
59            field_new!(Fq, "19937756971775647987995932169929341994314640652964949448313374472400716661030"),
60        ),
61        // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3)
62        field_new!(Fq2, 
63            field_new!(Fq, "2203960485148121921418603742825762020974279258880205651966"),
64            field_new!(Fq, "0"),
65        ),
66        // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3)
67        field_new!(Fq2, 
68            field_new!(Fq, "5324479202449903542726783395506214481928257762400643279780343368557297135718"),
69            field_new!(Fq, "16208900380737693084919495127334387981393726419856888799917914180988844123039"),
70        ),
71        // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3)
72        field_new!(Fq2, 
73            field_new!(Fq, "21888242871839275220042445260109153167277707414472061641714758635765020556616"),
74            field_new!(Fq, "0"),
75        ),
76        // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3)
77        field_new!(Fq2, 
78            field_new!(Fq, "13981852324922362344252311234282257507216387789820983642040889267519694726527"),
79            field_new!(Fq, "7629828391165209371577384193250820201684255241773809077146787135900891633097"),
80        ),
81    ];
82
83    #[inline(always)]
84    fn mul_fp2_by_nonresidue(fe: &Fq2) -> Fq2 {
85        // (c0+u*c1)*(9+u) = (9*c0-c1)+u*(9*c1+c0)
86        let mut f = *fe;
87        f.double_in_place().double_in_place().double_in_place();
88        let c0 = f.c0 + fe.c0 + Fq2Parameters::mul_fp_by_nonresidue(&fe.c1);
89        let c1 = f.c1 + fe.c1 + fe.c0;
90        field_new!(Fq2, c0, c1)
91    }
92}