ark-curves-cherry-picked/bls12_381/src/fields/fq2.rs
bls12_381/src/fields/fq2.rsRaw
1use crate::*;
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 = -1
12 #[rustfmt::skip]
13 const NONRESIDUE: Fq = field_new!(Fq, "-1");
14
15 /// QUADRATIC_NONRESIDUE = (U + 1)
16 #[rustfmt::skip]
17 const QUADRATIC_NONRESIDUE: (Fq, Fq) = (FQ_ONE, FQ_ONE);
18
19 /// Coefficients for the Frobenius automorphism.
20 #[rustfmt::skip]
21 const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
22 // Fq(-1)**(((q^0) - 1) / 2)
23 field_new!(Fq, "1"),
24 // Fq(-1)**(((q^1) - 1) / 2)
25 field_new!(Fq, "-1"),
26 ];
27
28 #[inline(always)]
29 fn mul_fp_by_nonresidue(fp: &Self::Fp) -> Self::Fp {
30 -(*fp)
31 }
32
33 // x + -1 * y, computed as x - y
34 #[inline(always)]
35 fn add_and_mul_fp_by_nonresidue(x: &Self::Fp, y: &Self::Fp) -> Self::Fp {
36 *x - y
37 }
38
39 // x - (-1 * y), computed as x + y
40 #[inline(always)]
41 fn sub_and_mul_fp_by_nonresidue(x: &Self::Fp, y: &Self::Fp) -> Self::Fp {
42 *x + y
43 }
44}
45
46pub const FQ2_ZERO: Fq2 = field_new!(Fq2, FQ_ZERO, FQ_ZERO);
47pub const FQ2_ONE: Fq2 = field_new!(Fq2, FQ_ONE, FQ_ZERO);