ark-curves-cherry-picked/bn254/src/fields/fq2.rs
bn254/src/fields/fq2.rsRaw
1use ark_ff::{fields::*, MontFp, QuadExt};
2
3use crate::*;
4
5pub type Fq2 = Fp2<Fq2Config>;
6
7pub struct Fq2Config;
8
9impl Fp2Config for Fq2Config {
10 type Fp = Fq;
11
12 /// NONRESIDUE = -1
13 const NONRESIDUE: Fq = MontFp!(Fq, "-1");
14
15 /// QUADRATIC_NONRESIDUE = U+2
16 const QUADRATIC_NONRESIDUE: Fq2 = QuadExt!(MontFp!(Fq, "2"), MontFp!(Fq, "1"));
17
18 /// Coefficients for the Frobenius automorphism.
19 const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
20 // NONRESIDUE**(((q^0) - 1) / 2)
21 MontFp!(Fq, "1"),
22 // NONRESIDUE**(((q^1) - 1) / 2)
23 MontFp!(Fq, "-1"),
24 ];
25
26 #[inline(always)]
27 fn mul_fp_by_nonresidue(fe: &Self::Fp) -> Self::Fp {
28 -(*fe)
29 }
30}
31
32pub const FQ2_ZERO: Fq2 = QuadExt!(FQ_ZERO, FQ_ZERO);
33pub const FQ2_ONE: Fq2 = QuadExt!(FQ_ONE, FQ_ZERO);