Skip to main content

airbender_crypto/bls12_381/fields/
fq2.rs

1use super::Fq;
2#[cfg(any(
3    all(target_arch = "riscv32", feature = "bigint_ops"),
4    test,
5    feature = "proving"
6))]
7use crate::ark_ff_delegation::MontFp;
8#[cfg(not(any(
9    all(target_arch = "riscv32", feature = "bigint_ops"),
10    test,
11    feature = "proving"
12)))]
13use ark_ff::MontFp;
14use ark_ff::{AdditiveGroup, Field, Fp2, Fp2Config};
15
16pub type Fq2 = Fp2<Fq2Config>;
17
18pub struct Fq2Config;
19
20impl Fp2Config for Fq2Config {
21    type Fp = Fq;
22
23    /// NONRESIDUE = -1
24    const NONRESIDUE: Fq = MontFp!("-1");
25
26    /// Coefficients for the Frobenius automorphism.
27    const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
28        // Fq(-1)**(((q^0) - 1) / 2)
29        Fq::ONE,
30        // Fq(-1)**(((q^1) - 1) / 2)
31        MontFp!("-1"),
32    ];
33
34    #[inline(always)]
35    fn mul_fp_by_nonresidue_in_place(fp: &mut Self::Fp) -> &mut Self::Fp {
36        fp.neg_in_place()
37    }
38
39    #[inline(always)]
40    fn sub_and_mul_fp_by_nonresidue(y: &mut Self::Fp, x: &Self::Fp) {
41        *y += x;
42    }
43
44    #[inline(always)]
45    fn mul_fp_by_nonresidue_plus_one_and_add(y: &mut Self::Fp, x: &Self::Fp) {
46        *y = *x;
47    }
48
49    fn mul_fp_by_nonresidue_and_add(y: &mut Self::Fp, x: &Self::Fp) {
50        y.neg_in_place();
51        *y += x;
52    }
53}