arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bw6_761/src/fields/fq3.rs
bw6_761/src/fields/fq3.rsRaw
 1use ark_ff::{
 2    fields::fp3::{Fp3, Fp3Config},
 3    CubicExt, MontFp,
 4};
 5
 6use crate::{
 7    fields::{FQ_ONE, FQ_ZERO},
 8    Fq,
 9};
10
11pub type Fq3 = Fp3<Fq3Config>;
12
13pub struct Fq3Config;
14
15impl Fp3Config for Fq3Config {
16    type Fp = Fq;
17
18    /// NONRESIDUE = -4
19    // Fq3 = Fq\[u\]/u^3+4
20    const NONRESIDUE: Fq = MontFp!(Fq, "-4");
21
22    // (MODULUS^3 - 1) % 2^TWO_ADICITY == 0
23    const TWO_ADICITY: u32 = 1;
24
25    // (T-1)/2 with T = (MODULUS^3-1) / 2^TWO_ADICITY
26    #[rustfmt::skip]
27    const TRACE_MINUS_ONE_DIV_TWO: &'static [u64] = &[
28        0xb5e7c000000a3eac,
29        0xf79b99dbf41cf4ab,
30        0xe9372b1919e55ee5,
31        0xbb7bbc4936c1980b,
32        0x7c0cb9d4399b36e1,
33        0x73304a5507bb1ae0,
34        0x92f639be8963936f,
35        0x4f574ac2439ba816,
36        0x670d9bd389dd29ef,
37        0x606ddf900d2124f1,
38        0x928fb14985ec3270,
39        0x6b2f2428c5f420f3,
40        0xac9ade29d5ab5fbe,
41        0xec0d0434c4005822,
42        0x973f10d7f3c5c108,
43        0x6d5e83fc81095979,
44        0xdac3e6e4e1647752,
45        0x227febf93994603e,
46        0x4ab8755d894167d1,
47        0x4fd2d3f67d8b537a,
48        0x33e196a4d5f4030a,
49        0x88b51fb72092df1a,
50        0xa67e5b1e8fc48316,
51        0xb0855eb2a00d7dab,
52        0xe875dd2da6751442,
53        0x777594a243e25676,
54        0x294e0f70376a85a8,
55        0x83f431c7988e4f18,
56        0x8e8fb6af3ca2f5f1,
57        0x7297896b4b9e90f1,
58        0xff38f54664d66123,
59        0xb5ecf80bfff41e13,
60        0x1662a3666bb8392a,
61        0x07a0968e8742d3e1,
62        0xf12927e564bcdfdc,
63        0x5de9825a0e,
64    ];
65
66    // NONRESIDUE^T % q
67    const QUADRATIC_NONRESIDUE_TO_T: Fq3 = CubicExt!(
68        MontFp!(Fq, "6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068298"),
69        FQ_ZERO,
70        FQ_ZERO,
71    );
72
73    // NQR ^ (MODULUS^i - 1)/3, i=0,1,2 with NQR = u = (0,1,0)
74    const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[
75        FQ_ONE,
76        MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
77        MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
78    ];
79
80    // NQR ^ (2*MODULUS^i - 2)/3, i=0,1,2 with NQR = u = (0,1,0)
81    const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[
82        FQ_ONE,
83        MontFp!(Fq, "1968985824090209297278610739700577151397666382303825728450741611566800370218827257750865013421937292370006175842381275743914023380727582819905021229583192207421122272650305267822868639090213645505120388400344940985710520836292650"),
84        MontFp!(Fq, "4922464560225523242118178942575080391082002530232324381063048548642823052024664478336818169867474395270858391911405337707247735739826664939444490469542109391530482826728203582549674992333383150446779312029624171857054392282775648"),
85    ];
86
87    #[inline(always)]
88    fn mul_fp_by_nonresidue(fe: &Self::Fp) -> Self::Fp {
89        let original = -(*fe);
90        let double = original + &original;
91        double + &double
92    }
93}