ark-curves-cherry-picked/ed_on_mnt4_753/src/fields/fr.rs
ed_on_mnt4_753/src/fields/fr.rsRaw
1use ark_ff::{
2 biginteger::{BigInt, BigInteger768 as BigInteger},
3 fields::{FftParameters, Fp768, Fp768Parameters, FpParameters},
4};
5
6pub type Fr = Fp768<FrParameters>;
7
8pub struct FrParameters;
9
10impl Fp768Parameters for FrParameters {}
11impl FftParameters for FrParameters {
12 type BigInt = BigInteger;
13
14 const TWO_ADICITY: u32 = 7u32;
15
16 // ROOT_OF_UNITY = GENERATOR ^ t =
17 // 5051348772165646558710889803432238607797392809516000790038615454406641638798360636639094562941749878118669420392611632754442159525900729019616828636182878045303562497793780656635901271279409699078868658041674335385318499053954
18 // t is defined below
19 // This number needs to be in the Montgomery residue form.
20 // I.e., write
21 // 5051348772165646558710889803432238607797392809516000790038615454406641638798360636639094562941749878118669420392611632754442159525900729019616828636182878045303562497793780656635901271279409699078868658041674335385318499053954
22 // * R
23 // = 3163945077843586747114473523156080008349200300253316071422414259389979351386670787753361998953450578171951209600907861296956453653582402723399808696724060539858637307706671971132333536614595846054039300191656599533885935499352
24 #[rustfmt::skip]
25 const TWO_ADIC_ROOT_OF_UNITY: BigInteger = BigInt::new([
26 17630237153019476056u64,
27 13843632041501582123u64,
28 8277579215948731020u64,
29 16543319700733887487u64,
30 17904443422768964556u64,
31 4398189354108552378u64,
32 15178824470536352826u64,
33 5393472405610595666u64,
34 9815530206026813666u64,
35 9111703519527971535u64,
36 9880873531994141485u64,
37 37593433148184u64,
38 ]);
39}
40impl FpParameters for FrParameters {
41 // MODULUS = 5237311370989869175293026848905079641021338739994243633972937865128169101571388346632361720473792365177258871486054600656048925740061347509722287043067341250552640264308621296888446513816907173362124418513727200975392177480577
42 // Factors of MODULUS - 1:
43 // 2^7
44 // 3
45 // 67
46 // 193189
47 // 5324381
48 // 20502324317011
49 // 12991385268608969143
50 // 743005941432538001939136029613828619428586060274612824031793373798492678674419102414979927623550862639644071557313558044209469997283394306590808303316688123808776073253386140931
51 #[rustfmt::skip]
52 const MODULUS: BigInteger = BigInt::new([
53 1918157353135465345u64,
54 963476667289301255u64,
55 6719983938249379016u64,
56 3655897403342429413u64,
57 14998997414201165002u64,
58 13135040821375901270u64,
59 12914675130452106995u64,
60 6989506515121216945u64,
61 12382362535852178190u64,
62 13186314214759855613u64,
63 2451174275904461237u64,
64 62228802984066u64,
65 ]);
66
67 const MODULUS_BITS: u32 = 750;
68
69 const CAPACITY: u32 = Self::MODULUS_BITS - 1;
70
71 const REPR_SHAVE_BITS: u32 = 18;
72
73 // see ark_ff/src/fields/mod.rs for more information
74 // R = pow(2,768) % MODULUS
75 // R = 933352698056040166367534174176950366489065242993745918174914647273231163953185260894581718311971532174387033963715296372791285468903747270837716556902938133611910788060028435531754797383796835009316018259656953442114538695438
76 #[rustfmt::skip]
77 const R: BigInteger = BigInt::new([
78 13829252738394483470u64,
79 3696102008259415033u64,
80 13727024804350215797u64,
81 13923468026436718769u64,
82 5924604905079742862u64,
83 10708002647109138222u64,
84 14670460945619011269u64,
85 10920055614013427454u64,
86 16773322069409968132u64,
87 11648025004657998992u64,
88 5853759956175613481u64,
89 11089930891582u64,
90 ]);
91
92 // R2 = R * R % MODULUS
93 // R2 = 2468731867191023344597744941938926307216338526282824416880609839804154918771848044056240157551420210981962520047623686977567450338290776997282473798413876535168711321018336215486289519735826959884564283681071791441993286279295
94 #[rustfmt::skip]
95 const R2: BigInteger = BigInt::new([
96 10440129917231554687u64,
97 8797934528693354276u64,
98 14378434434829994158u64,
99 7755707164286885667u64,
100 16206546501540671680u64,
101 8674228973811871262u64,
102 12794601382709871071u64,
103 17194287857269754157u64,
104 2120600029739364160u64,
105 15454005187782655500u64,
106 18107041519543174727u64,
107 29333033326005u64,
108 ]);
109
110 // INV = -(MODULUS)^(-1) % 2^64
111 const INV: u64 = 3079018560679650175u64;
112
113 // GENERATOR = 5
114 // This number needs to be in the Montgomery residue form.
115 // I.e., write 5 * R =
116 // 4666763490280200831837670870884751832445326214968729590874573236366155819765926304472908591559857660871935169818576481863956427344518736354188582784514690668059553940300142177658773986918984175046580091298284767210572693477190
117 #[rustfmt::skip]
118 const GENERATOR: BigInteger = BigInt::new([
119 13806031470843762502u64,
120 33765967587523552u64,
121 13294891800622424138u64,
122 14277107911054939000u64,
123 11176280451689162697u64,
124 16646525088126587879u64,
125 18012072506966401499u64,
126 17706789922648034041u64,
127 10079634052211634198u64,
128 2899892802161340116u64,
129 10822055707168515792u64,
130 55449654457911u64,
131 ]);
132
133 // (n-1)/2 = 2618655685494934587646513424452539820510669369997121816986468932564084550785694173316180860236896182588629435743027300328024462870030673754861143521533670625276320132154310648444223256908453586681062209256863600487696088740288
134 #[rustfmt::skip]
135 const MODULUS_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
136 10182450713422508480u64,
137 481738333644650627u64,
138 12583364005979465316u64,
139 1827948701671214706u64,
140 7499498707100582501u64,
141 15790892447542726443u64,
142 15680709602080829305u64,
143 3494753257560608472u64,
144 15414553304780864903u64,
145 15816529144234703614u64,
146 1225587137952230618u64,
147 31114401492033u64,
148 ]);
149
150 // t = (n - 1) / 2^{TWO_ADICITY} =
151 // 40916495085858352931976772257070934695479208906205028390413577071313821106026471458065325941201502852947334933484801567625382232344229277419705367523963603519942502064911103881940988389194587291891597019638493757620251386567
152 const T: BigInteger = BigInt::new([
153 1023791920852361927u64,
154 10383820702924820450u64,
155 14608133870179016345u64,
156 10693085616076947257u64,
157 12511085841822051593u64,
158 16675864135140424508u64,
159 7162540115173594813u64,
160 2072218152711366715u64,
161 18111135716793329142u64,
162 7741123047823172587u64,
163 307380175182215347u64,
164 486162523313u64,
165 ]);
166
167 // (t-1)/2 = 20458247542929176465988386128535467347739604453102514195206788535656910553013235729032662970600751426473667466742400783812691116172114638709852683761981801759971251032455551940970494194597293645945798509819246878810125693283
168 const T_MINUS_ONE_DIV_TWO: BigInteger = BigInt::new([
169 511895960426180963u64,
170 14415282388317186033u64,
171 16527438971944283980u64,
172 14569914844893249436u64,
173 6255542920911025796u64,
174 17561304104424988062u64,
175 12804642094441573214u64,
176 1036109076355683357u64,
177 18278939895251440379u64,
178 13093933560766362101u64,
179 9377062124445883481u64,
180 243081261656u64,
181 ]);
182}