ark-curves-cherry-picked/bls12_381/src/fields/fq2.rs
bls12_381/src/fields/fq2.rsRaw
1use ark_ff::{fields::*, MontFp};
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!("-1");
14
15 /// Coefficients for the Frobenius automorphism.
16 const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
17 // Fq(-1)**(((q^0) - 1) / 2)
18 Fq::ONE,
19 // Fq(-1)**(((q^1) - 1) / 2)
20 MontFp!("-1"),
21 ];
22
23 #[inline(always)]
24 fn mul_fp_by_nonresidue_in_place(fp: &mut Self::Fp) -> &mut Self::Fp {
25 fp.neg_in_place()
26 }
27
28 #[inline(always)]
29 fn sub_and_mul_fp_by_nonresidue(y: &mut Self::Fp, x: &Self::Fp) {
30 *y += x;
31 }
32
33 #[inline(always)]
34 fn mul_fp_by_nonresidue_plus_one_and_add(y: &mut Self::Fp, x: &Self::Fp) {
35 *y = *x;
36 }
37
38 fn mul_fp_by_nonresidue_in_place_and_add(y: &mut Self::Fp, x: &Self::Fp) {
39 y.neg_in_place();
40 *y += x;
41 }
42}