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::{biginteger::BigInteger384 as BigInteger, 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, BigInteger([
14        0xfc0b8000000002fa,
15        0x97d39cf6e000018b,
16        0x2072420fbfa05044,
17        0xcbbcbd50d97c3802,
18        0xbaf1ec35813f9eb,
19        0x9974a2c0945ad2,
20    ]));
21
22    /// QUADRATIC_NONRESIDUE = U
23    #[rustfmt::skip]
24    const QUADRATIC_NONRESIDUE: (Fq, Fq) = (
25        field_new!(Fq, BigInteger([0, 0, 0, 0, 0, 0])),
26        field_new!(Fq, BigInteger([
27            202099033278250856u64,
28            5854854902718660529u64,
29            11492539364873682930u64,
30            8885205928937022213u64,
31            5545221690922665192u64,
32            39800542322357402u64,
33        ])),
34    );
35
36    /// Coefficients for the Frobenius automorphism.
37    #[rustfmt::skip]
38    const FROBENIUS_COEFF_FP2_C1: &'static [Fq] = &[
39        // NONRESIDUE**(((q^0) - 1) / 2)
40        field_new!(Fq, BigInteger([
41            0x2cdffffffffff68,
42            0x51409f837fffffb1,
43            0x9f7db3a98a7d3ff2,
44            0x7b4e97b76e7c6305,
45            0x4cf495bf803c84e8,
46            0x8d6661e2fdf49a,
47        ])),
48        // NONRESIDUE**(((q^1) - 1) / 2)
49        field_new!(Fq, BigInteger([
50            0x823ac00000000099,
51            0xc5cabdc0b000004f,
52            0x7f75ae862f8c080d,
53            0x9ed4423b9278b089,
54            0x79467000ec64c452,
55            0x120d3e434c71c50,
56        ])),
57    ];
58
59    #[inline(always)]
60    fn mul_fp_by_nonresidue(fe: &Self::Fp) -> Self::Fp {
61        let original = fe;
62        let mut fe = -fe.double();
63        fe.double_in_place();
64        fe - original
65    }
66}
67
68pub const FQ2_ZERO: Fq2 = field_new!(Fq2, FQ_ZERO, FQ_ZERO);
69pub const FQ2_ONE: Fq2 = field_new!(Fq2, FQ_ONE, FQ_ZERO);