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