ark_bls12_381/fields/
fq6.rs

1use ark_ff::{fields::*, MontFp};
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 + 1)
14    const NONRESIDUE: Fq2 = Fq2::new(Fq::ONE, Fq::ONE);
15
16    const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
17        // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
18        Fq2::new(
19            Fq::ONE,
20            Fq::ZERO,
21        ),
22        // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
23        Fq2::new(
24            Fq::ZERO,
25            MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
26        ),
27        // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
28        Fq2::new(
29            MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
30            Fq::ZERO,
31        ),
32        // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
33        Fq2::new(
34            Fq::ZERO,
35            Fq::ONE,
36        ),
37        // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
38        Fq2::new(
39            MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
40            Fq::ZERO,
41        ),
42        // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
43        Fq2::new(
44            Fq::ZERO,
45            MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
46        ),
47];
48
49    #[rustfmt::skip]
50    const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
51        // Fq2(u + 1)**(((2q^0) - 2) / 3)
52        Fq2::new(
53            Fq::ONE,
54            Fq::ZERO,
55        ),
56        // Fq2(u + 1)**(((2q^1) - 2) / 3)
57        Fq2::new(
58            MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),
59            Fq::ZERO,
60        ),
61        // Fq2(u + 1)**(((2q^2) - 2) / 3)
62        Fq2::new(
63            MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
64            Fq::ZERO,
65        ),
66        // Fq2(u + 1)**(((2q^3) - 2) / 3)
67        Fq2::new(
68            MontFp!("-1"),
69            Fq::ZERO,
70        ),
71        // Fq2(u + 1)**(((2q^4) - 2) / 3)
72        Fq2::new(
73            MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
74            Fq::ZERO,
75        ),
76        // Fq2(u + 1)**(((2q^5) - 2) / 3)
77        Fq2::new(
78            MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),
79            Fq::ZERO,
80        ),
81    ];
82
83    /// Multiply this element by the quadratic nonresidue 1 + u.
84    /// Make this generic.
85    fn mul_fp2_by_nonresidue_in_place(fe: &mut Fq2) -> &mut Fq2 {
86        let t0 = fe.c0;
87        fe.c0 -= &fe.c1;
88        fe.c1 += &t0;
89        fe
90    }
91}