Skip to main content

airbender_crypto/bls12_381/fields/
fq6.rs

1use super::{Fq, Fq2, Fq2Config};
2#[cfg(any(
3    all(target_arch = "riscv32", feature = "bigint_ops"),
4    test,
5    feature = "proving"
6))]
7use crate::ark_ff_delegation::MontFp;
8#[cfg(not(any(
9    all(target_arch = "riscv32", feature = "bigint_ops"),
10    test,
11    feature = "proving"
12)))]
13use ark_ff::MontFp;
14use ark_ff::{AdditiveGroup, Field, Fp6, Fp6Config};
15
16pub type Fq6 = Fp6<Fq6Config>;
17
18#[derive(Clone, Copy)]
19pub struct Fq6Config;
20
21impl Fp6Config for Fq6Config {
22    type Fp2Config = Fq2Config;
23
24    /// NONRESIDUE = (U + 1)
25    const NONRESIDUE: Fq2 = Fq2::new(Fq::ONE, Fq::ONE);
26
27    const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
28        // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
29        Fq2::new(
30            Fq::ONE,
31            Fq::ZERO,
32        ),
33        // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
34        Fq2::new(
35            Fq::ZERO,
36            MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
37        ),
38        // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
39        Fq2::new(
40            MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
41            Fq::ZERO,
42        ),
43        // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
44        Fq2::new(
45            Fq::ZERO,
46            Fq::ONE,
47        ),
48        // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
49        Fq2::new(
50            MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
51            Fq::ZERO,
52        ),
53        // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
54        Fq2::new(
55            Fq::ZERO,
56            MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
57        ),
58];
59
60    #[rustfmt::skip]
61    const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
62        // Fq2(u + 1)**(((2q^0) - 2) / 3)
63        Fq2::new(
64            Fq::ONE,
65            Fq::ZERO,
66        ),
67        // Fq2(u + 1)**(((2q^1) - 2) / 3)
68        Fq2::new(
69            MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437"),
70            Fq::ZERO,
71        ),
72        // Fq2(u + 1)**(((2q^2) - 2) / 3)
73        Fq2::new(
74            MontFp!("4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939436"),
75            Fq::ZERO,
76        ),
77        // Fq2(u + 1)**(((2q^3) - 2) / 3)
78        Fq2::new(
79            MontFp!("-1"),
80            Fq::ZERO,
81        ),
82        // Fq2(u + 1)**(((2q^4) - 2) / 3)
83        Fq2::new(
84            MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350"),
85            Fq::ZERO,
86        ),
87        // Fq2(u + 1)**(((2q^5) - 2) / 3)
88        Fq2::new(
89            MontFp!("793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620351"),
90            Fq::ZERO,
91        ),
92    ];
93
94    /// Multiply this element by the quadratic nonresidue 1 + u.
95    /// Make this generic.
96    fn mul_fp2_by_nonresidue_in_place(fe: &mut Fq2) -> &mut Fq2 {
97        let t0 = fe.c0;
98        fe.c0 -= &fe.c1;
99        fe.c1 += &t0;
100        fe
101    }
102}