ark_bls12_377/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
14    const NONRESIDUE: Fq2 = Fq2::new(Fq::ZERO, Fq::ONE);
15
16    const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
17        // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
18        Fq2::new(Fq::ONE, Fq::ZERO),
19        // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
20        Fq2::new(
21            MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410946"),
22            Fq::ZERO,
23        ),
24        // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
25        Fq2::new(
26            MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
27            Fq::ZERO,
28        ),
29        // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
30        Fq2::new(MontFp!("-1"), Fq::ZERO),
31        // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
32        Fq2::new(
33            MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
34            Fq::ZERO,
35        ),
36        // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
37        Fq2::new(
38            MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047232"),
39            Fq::ZERO,
40        ),
41    ];
42
43    const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
44        // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3)
45        Fq2::new(Fq::ONE, Fq::ZERO),
46        // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3)
47        Fq2::new(
48            MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
49            Fq::ZERO
50        ),
51        // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3)
52        Fq2::new(
53            MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
54            Fq::ZERO,
55        ),
56        // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3)
57        Fq2::new(Fq::ONE, Fq::ZERO),
58        // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3)
59        Fq2::new(
60            MontFp!("80949648264912719408558363140637477264845294720710499478137287262712535938301461879813459410945"),
61            Fq::ZERO,
62        ),
63        // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3)
64        Fq2::new(
65            MontFp!("258664426012969093929703085429980814127835149614277183275038967946009968870203535512256352201271898244626862047231"),
66            Fq::ZERO,
67        ),
68    ];
69
70    #[inline(always)]
71    fn mul_fp2_by_nonresidue_in_place(fe: &mut Fq2) -> &mut Fq2 {
72        // Karatsuba multiplication with constant other = u.
73        let old_c0 = fe.c0;
74        fe.c0 = fe.c1;
75        Fq2Config::mul_fp_by_nonresidue_in_place(&mut fe.c0);
76        fe.c1 = old_c0;
77        fe
78    }
79}