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 super::*;
 2use ark_ff::{field_new, fields::*};
 3
 4pub type Fq2 = Fp2<Fq2Parameters>;
 5
 6pub struct Fq2Parameters;
 7
 8impl Fp2Parameters for Fq2Parameters {
 9    type Fp = Fq;
10
11    /// NONRESIDUE = -5
12    #[rustfmt::skip]
13    const NONRESIDUE: Fq = field_new!(Fq, "-5");
14
15    /// QUADRATIC_NONRESIDUE = U
16    #[rustfmt::skip]
17    const QUADRATIC_NONRESIDUE: (Fq, Fq) = (FQ_ZERO, FQ_ONE);
18
19    /// Coefficients for the Frobenius automorphism.
20    #[rustfmt::skip]
21    const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
22        // NONRESIDUE**(((q^0) - 1) / 2)
23        FQ_ONE,
24        // NONRESIDUE**(((q^1) - 1) / 2)
25        field_new!(Fq, "-1"),
26    ];
27
28    #[inline(always)]
29    fn mul_fp_by_nonresidue(fe: &Self::Fp) -> Self::Fp {
30        let original = fe;
31        let mut fe = -fe.double();
32        fe.double_in_place();
33        fe - original
34    }
35}
36
37pub const FQ2_ZERO: Fq2 = field_new!(Fq2, FQ_ZERO, FQ_ZERO);
38pub const FQ2_ONE: Fq2 = field_new!(Fq2, FQ_ONE, FQ_ZERO);