arnaucube
arnaucube/ark-curves-cherry-pickedPublic Self-hosted repository
ark-curves-cherry-picked/bw6_761/src/fields/fq.rs
bw6_761/src/fields/fq.rsRaw
  1use ark_ff::{
  2    biginteger::BigInteger768 as BigInteger,
  3    field_new,
  4    fields::{FftParameters, Fp768, Fp768Parameters, FpParameters},
  5};
  6
  7pub type Fq = Fp768<FqParameters>;
  8
  9pub struct FqParameters;
 10
 11pub const FQ_ONE: Fq = field_new!(Fq, "1");
 12pub const FQ_ZERO: Fq = field_new!(Fq, "0");
 13
 14impl Fp768Parameters for FqParameters {}
 15impl FftParameters for FqParameters {
 16    type BigInt = BigInteger;
 17
 18    // The internal representation of this type is six 64-bit unsigned
 19    // integers in little-endian order. Values are always in
 20    // Montgomery form; i.e., Scalar(a) = aR mod p, with R=2^768.
 21
 22    // (MODULUS - 1) % 2^TWO_ADICITY == 0
 23    const TWO_ADICITY: u32 = 1;
 24
 25    // least_quadratic_nonresidue(MODULUS) in Sage.
 26    #[rustfmt::skip]
 27    const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInteger([
 28        17481284903592032950u64,
 29        10104133845767975835u64,
 30        8607375506753517913u64,
 31        13706168424391191299u64,
 32        9580010308493592354u64,
 33        14241333420363995524u64,
 34        6665632285037357566u64,
 35        5559902898979457045u64,
 36        15504799981718861253u64,
 37        8332096944629367896u64,
 38        18005297320867222879u64,
 39        58811391084848524u64,
 40    ]);
 41}
 42impl FpParameters for FqParameters {
 43    /// MODULUS = 6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299
 44    #[rustfmt::skip]
 45    const MODULUS: BigInteger = BigInteger([
 46       0xf49d00000000008b,
 47       0xe6913e6870000082,
 48       0x160cf8aeeaf0a437,
 49       0x98a116c25667a8f8,
 50       0x71dcd3dc73ebff2e,
 51       0x8689c8ed12f9fd90,
 52       0x03cebaff25b42304,
 53       0x707ba638e584e919,
 54       0x528275ef8087be41,
 55       0xb926186a81d14688,
 56       0xd187c94004faff3e,
 57       0x122e824fb83ce0a
 58    ]);
 59
 60    const MODULUS_BITS: u32 = 761;
 61
 62    const CAPACITY: u32 = Self::MODULUS_BITS - 1;
 63
 64    // gap to 64-bit machine word
 65    const REPR_SHAVE_BITS: u32 = 7;
 66
 67    // 2^768 % MODULUS
 68    #[rustfmt::skip]
 69    const R: BigInteger = BigInteger([
 70        144959613005956565u64,
 71        6509995272855063783u64,
 72        11428286765660613342u64,
 73        15738672438262922740u64,
 74        17071399330169272331u64,
 75        13899911246788437003u64,
 76        12055474021000362245u64,
 77        2545351818702954755u64,
 78        8887388221587179644u64,
 79        5009280847225881135u64,
 80        15539704305423854047u64,
 81        23071597697427581u64,
 82    ]);
 83
 84    // R^2
 85    #[rustfmt::skip]
 86    const R2: BigInteger = BigInteger([
 87        14305184132582319705u64,
 88        8868935336694416555u64,
 89        9196887162930508889u64,
 90        15486798265448570248u64,
 91        5402985275949444416u64,
 92        10893197322525159598u64,
 93        3204916688966998390u64,
 94        12417238192559061753u64,
 95        12426306557607898622u64,
 96        1305582522441154384u64,
 97        10311846026977660324u64,
 98        48736111365249031u64,
 99    ]);
100
101    // (-1/MODULUS) % 2^64
102    const INV: u64 = 744663313386281181u64;
103
104    /// GENERATOR = 2
105    // primitive_root(MODULUS)
106    #[rustfmt::skip]
107    const GENERATOR: BigInteger = BigInteger([
108        289919226011913130u64,
109        13019990545710127566u64,
110        4409829457611675068u64,
111        13030600802816293865u64,
112        15696054586628993047u64,
113        9353078419867322391u64,
114        5664203968291172875u64,
115        5090703637405909511u64,
116        17774776443174359288u64,
117        10018561694451762270u64,
118        12632664537138156478u64,
119        46143195394855163u64,
120    ]);
121
122    // (MODULUS - 1) / 2
123    #[rustfmt::skip]
124    const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
125        0x7a4e800000000045,
126        0xf3489f3438000041,
127        0x0b067c577578521b,
128        0x4c508b612b33d47c,
129        0x38ee69ee39f5ff97,
130        0x4344e476897cfec8,
131        0x81e75d7f92da1182,
132        0xb83dd31c72c2748c,
133        0x29413af7c043df20,
134        0x5c930c3540e8a344,
135        0x68c3e4a0027d7f9f,
136        0x9174127dc1e705,
137    ]);
138
139    // T =
140    // 3445725192157866269698394841137828771239834456268075054756895080104811711121745868043841591644705843820432283876893306725580879560277123879674755849562650799475802549689254425186271815711798397975949850214984556421382456559534149
141    // (MODULUS - 1) / 2 ^ TWO_ADICITY
142    #[rustfmt::skip]
143    const T: BigInteger = BigInteger([
144        0x7a4e800000000045,
145        0xf3489f3438000041,
146        0x0b067c577578521b,
147        0x4c508b612b33d47c,
148        0x38ee69ee39f5ff97,
149        0x4344e476897cfec8,
150        0x81e75d7f92da1182,
151        0xb83dd31c72c2748c,
152        0x29413af7c043df20,
153        0x5c930c3540e8a344,
154        0x68c3e4a0027d7f9f,
155        0x9174127dc1e705,
156    ]);
157
158    // (T - 1)/2 =
159    // 1722862596078933134849197420568914385619917228134037527378447540052405855560872934021920795822352921910216141938446653362790439780138561939837377924781325399737901274844627212593135907855899198987974925107492278210691228279767074
160    #[rustfmt::skip]
161    const T_MINUS_ONE_DIV_TWO: BigInteger = BigInteger([
162        0xbd27400000000022,
163        0xf9a44f9a1c000020,
164        0x05833e2bbabc290d,
165        0xa62845b09599ea3e,
166        0x1c7734f71cfaffcb,
167        0x21a2723b44be7f64,
168        0x40f3aebfc96d08c1,
169        0x5c1ee98e39613a46,
170        0x14a09d7be021ef90,
171        0xae49861aa07451a2,
172        0xb461f250013ebfcf,
173        0x48ba093ee0f382,
174    ]);
175}