arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/cp6_782/src/fields/fq3.rs
cp6_782/src/fields/fq3.rsRaw
 1use ark_ff::{
 2    fields::fp3::{Fp3, Fp3Config},
 3    CubicExt, Field, MontFp,
 4};
 5
 6use crate::{fields::FQ_ZERO, Fq};
 7
 8pub type Fq3 = Fp3<Fq3Config>;
 9
10pub struct Fq3Config;
11
12impl Fp3Config for Fq3Config {
13    type Fp = Fq;
14
15    /// NONRESIDUE = 13
16    const NONRESIDUE: Fq = MontFp!(Fq, "13");
17
18    const TWO_ADICITY: u32 = 3;
19
20    #[rustfmt::skip]
21    const TRACE_MINUS_ONE_DIV_TWO: &'static [u64] = &[
22        0x62730e2cd2029617,
23        0x660647f735cb88cf,
24        0x274359d60784f69d,
25        0x83067194eb102629,
26        0x54ea4a12a9381160,
27        0xade0b24e398dac25,
28        0xb476ae9f927e81cb,
29        0x220fd4a9178adc3b,
30        0x57e0cb9b0569745b,
31        0xba15024addc8f52e,
32        0x145b9bc116144ab6,
33        0x6bc2260726e88b15,
34        0x51da6bf151066474,
35        0x9fd1b3190f6320cf,
36        0x2097bfb7bf4167b0,
37        0x27c35b1e7e628e09,
38        0x94f80c9d623dd9bb,
39        0x20bfa6d5bf31e7d3,
40        0x19fb862c049d3a8,
41        0xdf4c5efe04c0cec1,
42        0x32c9a8abe9b50297,
43        0x268d5c2076b44f0a,
44        0x76027ec67b23ca21,
45        0x248d61e0c45d270,
46        0x419cd0d1d6be027e,
47        0xbcd8dc3b1986ef18,
48        0x73093d8719c862c2,
49        0x651d60f8f9f6fcd9,
50        0x8dabebe38a09b261,
51        0xfa85b5a9e180cd3f,
52        0x6a97fc618f319fb7,
53        0xce08b93a5652a8e1,
54        0x37525cbc4ba24cf9,
55        0xb104c580df9d2150,
56        0x1407c1bfe240a89d,
57        0x34c96a73372daf9a,
58        0x2b87fda171,
59    ];
60
61    const QUADRATIC_NONRESIDUE_TO_T: Fq3 = CubicExt!(
62        MontFp!(Fq, "5759691735434357221228070840130186543101559976323700017469395641639510585333061695996665166662748527158637897523704071820491869715512532675375604262649010727161924084052120196921150869218319839231115277876207074651754402338718419191428"),
63        FQ_ZERO,
64        FQ_ZERO,
65    );
66
67    const FROBENIUS_COEFF_FP3_C1: &'static [Fq] = &[
68        MontFp!(Fq, "1"),
69        MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
70        MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
71    ];
72
73    const FROBENIUS_COEFF_FP3_C2: &'static [Fq] = &[
74        MontFp!(Fq, "1"),
75        MontFp!(Fq, "19953705140271686593528343007184948545186721150606416593204794941773275185711211206130361134875604609812811649452874332003866805473427708373329547516091672819022569300184729084448897691707139947053705234905346679611277243843727293068715"),
76        MontFp!(Fq, "2416169158604010336818399199316106389588878314690767988978701685873498866746813334102117883272276610365242925950967572554030909749205624998805208910209389668659757274773858916683688639755413288353778854399286396639505385648830027756861"),
77    ];
78
79    #[inline(always)]
80    fn mul_fp_by_nonresidue(fe: &Self::Fp) -> Self::Fp {
81        let original = *fe;
82        let mut four_fe = fe.double();
83        four_fe.double_in_place();
84        let eight_fe = four_fe.double();
85        eight_fe + &four_fe + &original
86    }
87}