arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bls12_377/src/fields/fq2.rs
bls12_377/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 = -5
13    const NONRESIDUE: Fq = MontFp!(Fq, "-5");
14
15    /// Coefficients for the Frobenius automorphism.
16    const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
17        // NONRESIDUE**(((q^0) - 1) / 2)
18        FQ_ONE,
19        // NONRESIDUE**(((q^1) - 1) / 2)
20        MontFp!(Fq, "-1"),
21    ];
22
23    #[inline(always)]
24    fn mul_fp_by_nonresidue(fe: &Self::Fp) -> Self::Fp {
25        let original = fe;
26        let mut fe = -fe.double();
27        fe.double_in_place();
28        fe - original
29    }
30}
31
32pub const FQ2_ZERO: Fq2 = QuadExt!(FQ_ZERO, FQ_ZERO);
33pub const FQ2_ONE: Fq2 = QuadExt!(FQ_ONE, FQ_ZERO);