arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bn254/src/fields/fq6.rs
bn254/src/fields/fq6.rsRaw
  1use super::*;
  2use ark_ff::{biginteger::BigInteger256, field_new, fields::*};
  3
  4pub type Fq6 = Fp6<Fq6Parameters>;
  5
  6#[derive(Clone, Copy)]
  7pub struct Fq6Parameters;
  8
  9impl Fp6Parameters for Fq6Parameters {
 10    type Fp2Params = Fq2Parameters;
 11
 12    /// NONRESIDUE = U+9
 13    #[rustfmt::skip]
 14    const NONRESIDUE: Fq2 = field_new!(Fq2,
 15       field_new!(Fq, BigInteger256([
 16            0xf60647ce410d7ff7,
 17            0x2f3d6f4dd31bd011,
 18            0x2943337e3940c6d1,
 19            0x1d9598e8a7e39857,
 20        ])),
 21        field_new!(Fq, BigInteger256([
 22            202099033278250856u64,
 23            8885205928937022213u64,
 24            5545221690922665192u64,
 25            39800542322357402u64,
 26        ])),
 27    );
 28
 29    #[rustfmt::skip]
 30    const FROBENIUS_COEFF_FP6_C1: &'static [Fq2] = &[
 31        // Fp2::NONRESIDUE^(((q^0) - 1) / 3)
 32        field_new!(Fq2,
 33            field_new!(Fq, BigInteger256([
 34                0xd35d438dc58f0d9d,
 35                0x0a78eb28f5c70b3d,
 36                0x666ea36f7879462c,
 37                0xe0a77c19a07df2f,
 38            ])),
 39            field_new!(Fq, BigInteger256([0x0, 0x0, 0x0, 0x0])),
 40        ),
 41        // Fp2::NONRESIDUE^(((q^1) - 1) / 3)
 42        field_new!(Fq2,
 43            field_new!(Fq, BigInteger256([
 44                0xb5773b104563ab30,
 45                0x347f91c8a9aa6454,
 46                0x7a007127242e0991,
 47                0x1956bcd8118214ec,
 48            ])),
 49            field_new!(Fq, BigInteger256([
 50                0x6e849f1ea0aa4757,
 51                0xaa1c7b6d89f89141,
 52                0xb6e713cdfae0ca3a,
 53                0x26694fbb4e82ebc3,
 54            ])),
 55        ),
 56        // Fp2::NONRESIDUE^(((q^2) - 1) / 3)
 57        field_new!(Fq2,
 58            field_new!(Fq, BigInteger256([
 59                0x3350c88e13e80b9c,
 60                0x7dce557cdb5e56b9,
 61                0x6001b4b8b615564a,
 62                0x2682e617020217e0,
 63            ])),
 64            field_new!(Fq, BigInteger256([0x0, 0x0, 0x0, 0x0])),
 65        ),
 66        // Fp2::NONRESIDUE^(((q^3) - 1) / 3)
 67        field_new!(Fq2,
 68            field_new!(Fq, BigInteger256([
 69                0xc9af22f716ad6bad,
 70                0xb311782a4aa662b2,
 71                0x19eeaf64e248c7f4,
 72                0x20273e77e3439f82,
 73            ])),
 74            field_new!(Fq, BigInteger256([
 75                0xacc02860f7ce93ac,
 76                0x3933d5817ba76b4c,
 77                0x69e6188b446c8467,
 78                0xa46036d4417cc55,
 79            ])),
 80        ),
 81        // Fp2::NONRESIDUE^(((q^4) - 1) / 3)
 82        field_new!(Fq2,
 83            field_new!(Fq, BigInteger256([
 84                0x71930c11d782e155,
 85                0xa6bb947cffbe3323,
 86                0xaa303344d4741444,
 87                0x2c3b3f0d26594943,
 88            ])),
 89            field_new!(Fq, BigInteger256([0x0, 0x0, 0x0, 0x0])),
 90        ),
 91        // Fp2::NONRESIDUE^(((q^5) - 1) / 3)
 92        field_new!(Fq2,
 93            field_new!(Fq, BigInteger256([
 94                0xf91aba2654e8e3b1,
 95                0x4771cb2fdc92ce12,
 96                0xdcb16ae0fc8bdf35,
 97                0x274aa195cd9d8be4,
 98            ])),
 99            field_new!(Fq, BigInteger256([
100                0x5cfc50ae18811f8b,
101                0x4bb28433cb43988c,
102                0x4fd35f13c3b56219,
103                0x301949bd2fc8883a,
104            ])),
105        ),
106    ];
107    #[rustfmt::skip]
108    const FROBENIUS_COEFF_FP6_C2: &'static [Fq2] = &[
109        // Fp2::NONRESIDUE^((2*(q^0) - 2) / 3)
110        field_new!(Fq2,
111            field_new!(Fq, BigInteger256([
112                0xd35d438dc58f0d9d,
113                0x0a78eb28f5c70b3d,
114                0x666ea36f7879462c,
115                0xe0a77c19a07df2f,
116            ])),
117            field_new!(Fq, BigInteger256([0x0, 0x0, 0x0, 0x0])),
118        ),
119        // Fp2::NONRESIDUE^((2*(q^1) - 2) / 3)
120        field_new!(Fq2,
121            field_new!(Fq, BigInteger256([
122                0x7361d77f843abe92,
123                0xa5bb2bd3273411fb,
124                0x9c941f314b3e2399,
125                0x15df9cddbb9fd3ec,
126            ])),
127            field_new!(Fq, BigInteger256([
128                0x5dddfd154bd8c949,
129                0x62cb29a5a4445b60,
130                0x37bc870a0c7dd2b9,
131                0x24830a9d3171f0fd,
132            ])),
133        ),
134        // Fp2::NONRESIDUE^((2*(q^2) - 2) / 3)
135        field_new!(Fq2,
136            field_new!(Fq, BigInteger256([
137                0x71930c11d782e155,
138                0xa6bb947cffbe3323,
139                0xaa303344d4741444,
140                0x2c3b3f0d26594943,
141            ])),
142            field_new!(Fq, BigInteger256([0x0, 0x0, 0x0, 0x0])),
143        ),
144        // Fp2::NONRESIDUE^((2*(q^3) - 2) / 3)
145        field_new!(Fq2,
146            field_new!(Fq, BigInteger256([
147                0x448a93a57b6762df,
148                0xbfd62df528fdeadf,
149                0xd858f5d00e9bd47a,
150                0x6b03d4d3476ec58,
151            ])),
152            field_new!(Fq, BigInteger256([
153                0x2b19daf4bcc936d1,
154                0xa1a54e7a56f4299f,
155                0xb533eee05adeaef1,
156                0x170c812b84dda0b2,
157            ])),
158        ),
159        // Fp2::NONRESIDUE^((2*(q^4) - 2) / 3)
160        field_new!(Fq2,
161            field_new!(Fq, BigInteger256([
162                0x3350c88e13e80b9c,
163                0x7dce557cdb5e56b9,
164                0x6001b4b8b615564a,
165                0x2682e617020217e0,
166            ])),
167            field_new!(Fq, BigInteger256([0x0, 0x0, 0x0, 0x0])),
168        ),
169        // Fp2::NONRESIDUE^((2*(q^5) - 2) / 3)
170        field_new!(Fq2,
171            field_new!(Fq, BigInteger256([
172                0x843420f1d8dadbd6,
173                0x31f010c9183fcdb2,
174                0x436330b527a76049,
175                0x13d47447f11adfe4,
176            ])),
177            field_new!(Fq, BigInteger256([
178                0xef494023a857fa74,
179                0x2a925d02d5ab101a,
180                0x83b015829ba62f10,
181                0x2539111d0c13aea3,
182            ])),
183        ),
184    ];
185
186    #[inline(always)]
187    fn mul_fp2_by_nonresidue(fe: &Fq2) -> Fq2 {
188        // (c0+u*c1)*(9+u) = (9*c0-c1)+u*(9*c1+c0)
189        let mut f = *fe;
190        f.double_in_place().double_in_place().double_in_place();
191        let c0 = f.c0 + fe.c0 + Fq2Parameters::mul_fp_by_nonresidue(&fe.c1);
192        let c1 = f.c1 + fe.c1 + fe.c0;
193        field_new!(Fq2, c0, c1)
194    }
195}