1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
// Platform-specific type aliases and precomputed constants.
// This module centralizes all backend differences in one place.
// Precomputed Montgomery form constants depend on the backend.
//
#[cfg(feature = "u32_backend")]
pub type LimbType = u32;
#[cfg(not(feature = "u32_backend"))]
pub type LimbType = u64;
/// Precomputed Montgomery form constants for Fp256 extension field operations.
pub mod fp256_constants {
#[cfg(feature = "u32_backend")]
mod values {
use gridiron::fp_256;
// 19500164908693981119838931622707971722847607432286901071563143508059255221534
pub const XI_INV_TIMES_9_ELEM1: fp_256::Monty = fp_256::Monty::new([
2050346385, 731299471, 959575992, 34915099, 1787054046, 707674376, 1189605443,
44293910, 138,
]);
// 6500054969564660373279643874235990574282535810762300357187714502686418407181
pub const XI_INV_TIMES_9_ELEM2: fp_256::Monty = fp_256::Monty::new([
729307778, 258461402, 1559141440, 1381403208, 157052610, 1802371594, 636365429,
127350700, 17,
]);
// 26098034838977895781559542626833399156321265654106457577426020397262786167059
pub const FROBENIUS_FACTOR_1_ELEM1: fp_256::Monty = fp_256::Monty::new([
12717650, 1979656862, 1972108829, 1559171847, 290869350, 694266310, 579853055,
1597302116, 4,
]);
// 15931493369629630809226283458085260090334794394361662678240713231519278691715
pub const FROBENIUS_FACTOR_1_ELEM2: fp_256::Monty = fp_256::Monty::new([
916222744, 723717387, 574787027, 1552331516, 1261698828, 887614939, 1510504974,
237248389, 8,
]);
// 19885131339612776214803633203834694332692106372356013117629940868870585019582
pub const FROBENIUS_FACTOR_2_ELEM1: fp_256::Monty = fp_256::Monty::new([
15189756, 1959629061, 767155255, 1427131279, 513871136, 1996531885, 1401068065,
1422686260, 66,
]);
// 21645619881471562101905880913352894726728173167203616652430647841922248593627
pub const FROBENIUS_FACTOR_2_ELEM2: fp_256::Monty = fp_256::Monty::new([
656635847, 1575335407, 606381995, 1750621660, 1486126693, 503904416, 1955368925,
270969940, 28,
]);
// 8669379979083712429711189836753509758585994370025260553045152614783263110636
pub const FROBENIUS_FACTOR_FP12_ELEM1: fp_256::Monty = fp_256::Monty::new([
454717458, 161507933, 804946138, 817080316, 1413496639, 904558052, 1356825578,
765259087, 11,
]);
// 19998038925833620163537568958541907098007303196759855091367510456613536016040
pub const FROBENIUS_FACTOR_FP12_ELEM2: fp_256::Monty = fp_256::Monty::new([
392395988, 386079276, 1435458002, 829532913, 1153717094, 1170750470, 311764801,
1868664732, 53,
]);
// 6500054969564660373279643874235990574282535810762300357187714502686418407178
pub const TWISTED_CURVE_CONST_COEFF_ELEM1: fp_256::Monty = fp_256::Monty::new([
1925150376, 516250914, 1051564560, 1369812449, 731601065, 672046428, 625168271,
1952553705, 93,
]);
// 45500384786952622612957507119651934019977750675336102500314001518804928850249
pub const TWISTED_CURVE_CONST_COEFF_ELEM2: fp_256::Monty = fp_256::Monty::new([
1674758358, 86153800, 1235541696, 1892123501, 768178752, 600790531, 1643777575,
1474105998, 5,
]);
}
#[cfg(not(feature = "u32_backend"))]
mod values {
use gridiron::fp_256;
// 19500164908693981119838931622707971722847607432286901071563143508059255221534
pub const XI_INV_TIMES_9_ELEM1: fp_256::Monty = fp_256::Monty::new([
2437092367148463419,
747601356261550748,
4360440282209411126,
1176028782564608324,
3,
]);
// 6500054969564660373279643874235990574282535810762300357187714502686418407181
pub const XI_INV_TIMES_9_ELEM2: fp_256::Monty = fp_256::Monty::new([
3667562471611102902,
1895479815975278242,
3563644202973503868,
4344338647121650331,
133,
]);
// 26098034838977895781559542626833399156321265654106457577426020397262786167059
pub const FROBENIUS_FACTOR_1_ELEM1: fp_256::Monty = fp_256::Monty::new([
580021601451177093,
2554094693196666125,
3880958341513721536,
1258103408516021080,
5,
]);
// 15931493369629630809226283458085260090334794394361662678240713231519278691715
pub const FROBENIUS_FACTOR_1_ELEM2: fp_256::Monty = fp_256::Monty::new([
2919641067713913960,
785195642811389734,
4388983840695877067,
2857182618617886998,
91,
]);
// 19885131339612776214803633203834694332692106372356013117629940868870585019582
pub const FROBENIUS_FACTOR_2_ELEM1: fp_256::Monty = fp_256::Monty::new([
1373079216138342057,
2136421292576945089,
2878262455954647621,
234710516073492855,
52,
]);
// 21645619881471562101905880913352894726728173167203616652430647841922248593627
pub const FROBENIUS_FACTOR_2_ELEM2: fp_256::Monty = fp_256::Monty::new([
3381370389007749833,
3937527858157889554,
2906734892403052175,
1567327638536670442,
29,
]);
// 8669379979083712429711189836753509758585994370025260553045152614783263110636
pub const FROBENIUS_FACTOR_FP12_ELEM1: fp_256::Monty = fp_256::Monty::new([
238732641083380945,
2132704291495236875,
39699523925983163,
151533609816880752,
77,
]);
// 19998038925833620163537568958541907098007303196759855091367510456613536016040
pub const FROBENIUS_FACTOR_FP12_ELEM2: fp_256::Monty = fp_256::Monty::new([
2117773316569516204,
4380150500464464703,
3189833601462288588,
3541641949267754530,
138,
]);
// 6500054969564660373279643874235990574282535810762300357187714502686418407178
pub const TWISTED_CURVE_CONST_COEFF_ELEM1: fp_256::Monty = fp_256::Monty::new([
1397519967783393590,
3165857086482956380,
852887086033865585,
4553379931935823845,
48,
]);
// 45500384786952622612957507119651934019977750675336102500314001518804928850249
pub const TWISTED_CURVE_CONST_COEFF_ELEM2: fp_256::Monty = fp_256::Monty::new([
3930061187480641836,
3390682528498379739,
3061152730537550312,
2084710193823479077,
140,
]);
}
pub use values::*;
}
/// Precomputed Montgomery form constants for Fp480 extension field operations.
pub mod fp480_constants {
#[cfg(feature = "u32_backend")]
mod values {
use gridiron::fp_480;
// 936473119752674041800925635616584383040922462852661215256585987396701358119923082460639686974874502662411220054705463943312731385327618652452806
pub const XI_INV_TIMES_9_ELEM1: fp_480::Monty = fp_480::Monty::new([
1671524251, 1452836661, 1514278714, 1089055752, 983710563, 1342902855, 1277558075,
1876974179, 947518822, 981090444, 247487949, 1283900828, 1334523677, 1392777601,
1513546415, 5235,
]);
// 312157706584224680600308545205528127680307487617553738418861995798900452706641027486879895658291500887470406684901821314437577128442539550817605
pub const XI_INV_TIMES_9_ELEM2: fp_480::Monty = fp_480::Monty::new([
335877574, 1323354927, 650625437, 272173725, 1832380438, 2065643415, 655409061,
1376608173, 1642768871, 464289801, 840813404, 665753910, 1051781983, 447188070,
183786362, 17059,
]);
// 2705020609406098470693743943193507017690525853579041639836321147125100162418094245778443957282985233325521741487078451689773015537700623376387510
pub const FROBENIUS_FACTOR_1_ELEM1: fp_480::Monty = fp_480::Monty::new([
1789717966, 1667803516, 415596737, 273473839, 86323342, 1847146047, 411641533,
883838890, 333532818, 2020025246, 1090726896, 1144837448, 1056047014, 650675300,
1518220857, 28583,
]);
// 1651643729828744562959031609260204931467006255025965356538853937438900508750440674159520451455470865884696804132950675577710427706655106873786415
pub const FROBENIUS_FACTOR_1_ELEM2: fp_480::Monty = fp_480::Monty::new([
1463808839, 1670428701, 447968177, 1822223094, 1576270537, 1038296259, 66655687,
578662642, 153246326, 1500216407, 53886423, 1315635309, 1456804263, 176996090,
1710325846, 31113,
]);
// 2306651261022207350847683647334036061609898996050387019709069937614457385067216464366007100887697910705559503143400341307341852524867445116042081
pub const FROBENIUS_FACTOR_2_ELEM1: fp_480::Monty = fp_480::Monty::new([
721025432, 530063334, 1045885399, 453726440, 2141696003, 1626330876, 1074975251,
1714081964, 1995410861, 609055642, 2058665923, 1876157870, 937690781, 1255299233,
741827240, 14111,
]);
// 2700715513864156317217817646762981219394581764002749630356081821581587105847754189716578562648186994801551242072586877237522675959303129100251619
pub const FROBENIUS_FACTOR_2_ELEM2: fp_480::Monty = fp_480::Monty::new([
147532118, 4451373, 893741577, 424324553, 481155820, 353715416, 620523272, 346497951,
1670022807, 1427377181, 732861676, 2088692375, 582789470, 669478976, 249410141, 28740,
]);
// 1656507924366244928424688705439191250492553228839737584554076474712325077234544758394965182643615114744030751122897661836350026981040666763359635
pub const FROBENIUS_FACTOR_FP12_ELEM1: fp_480::Monty = fp_480::Monty::new([
736041138, 285900164, 1852287620, 1099722104, 1782561133, 1457388007, 1874229037,
1965266811, 1231149838, 771491782, 467524787, 1737481601, 782773382, 79418783,
1572898018, 31139,
]);
// 411347727129503104504468123876138850111359831064167067331474757563790630947112631916366442374487601276802707186517326847256605909760387475785136
pub const FROBENIUS_FACTOR_FP12_ELEM2: fp_480::Monty = fp_480::Monty::new([
492638839, 304045155, 1057698408, 772372983, 1813080623, 1701111681, 801357526,
1606643950, 1537923020, 1695901916, 157173875, 1177883133, 354458948, 163418612,
376825454, 23056,
]);
// 312157706584224680600308545205528127680307487617553738418861995798900452706641027486879895658291500887470406684901821314437577128442539550817602
pub const TWISTED_CURVE_CONST_COEFF_ELEM1: fp_480::Monty = fp_480::Monty::new([
1976657987, 2124705180, 1103755761, 1290923474, 2085255841, 1647224075, 1270424569,
286550022, 1158572853, 451253923, 1853842034, 2007948773, 1667592921, 2116284018,
790821013, 23589,
]);
// 2185103946089572764202159816438696893762152413322876168932033970592303168946487192408159269608040506212292846794312749201063039899097776855723217
pub const TWISTED_CURVE_CONST_COEFF_ELEM2: fp_480::Monty = fp_480::Monty::new([
1531442428, 2081544602, 1531699218, 302801582, 1652317917, 456481830, 1063041565,
835589236, 1390322869, 278987042, 1335789303, 1086071918, 1573345690, 1085259625,
1063395545, 27530,
]);
}
#[cfg(not(feature = "u32_backend"))]
mod values {
use gridiron::fp_480;
// 936473119752674041800925635616584383040922462852661215256585987396701358119923082460639686974874502662411220054705463943312731385327618652452806
pub const XI_INV_TIMES_9_ELEM1: fp_480::Monty = fp_480::Monty::new([
3119942974383943579,
2338729420694622010,
2883861922948725603,
4030771358398283067,
2106875686646578534,
2757156034031148493,
2990967124782692125,
11243590443695,
]);
// 312157706584224680600308545205528127680307487617553738418861995798900452706641027486879895658291500887470406684901821314437577128442539550817605
pub const XI_INV_TIMES_9_ELEM2: fp_480::Monty = fp_480::Monty::new([
2841883066568611270,
584488624503374237,
4435935458143758358,
2956243541876064165,
997054757223442919,
1429695636157877084,
960329068957461343,
36634107337594,
]);
// 2705020609406098470693743943193507017690525853579041639836321147125100162418094245778443957282985233325521741487078451689773015537700623376387510
pub const FROBENIUS_FACTOR_1_ELEM1: fp_480::Monty = fp_480::Monty::new([
3581580780476624334,
587280597823881409,
3966715931486662798,
1898029564153112253,
4337971184665710226,
2458519700288777200,
1397314567963541414,
61383043331641,
]);
// 1651643729828744562959031609260204931467006255025965356538853937438900508750440674159520451455470865884696804132950675577710427706655106873786415
pub const FROBENIUS_FACTOR_1_ELEM2: fp_480::Monty = fp_480::Monty::new([
3587218322011190087,
3913194297820935089,
2229724239558343369,
1242668561470133703,
3221690202647059062,
2825305312862813655,
380096210491740583,
66816369066070,
]);
// 2306651261022207350847683647334036061609898996050387019709069937614457385067216464366007100887697910705559503143400341307341852524867445116042081
pub const FROBENIUS_FACTOR_2_ELEM1: fp_480::Monty = fp_480::Monty::new([
1138302342890387864,
974370111611138519,
3492518964589211651,
3680962990096699923,
1307937033912552877,
4029018348950175683,
2695734577152132765,
30303883584168,
]);
// 2700715513864156317217817646762981219394581764002749630356081821581587105847754189716578562648186994801551242072586877237522675959303129100251619
pub const FROBENIUS_FACTOR_2_ELEM2: fp_480::Monty = fp_480::Monty::new([
9559250876180822,
911230039906150921,
759598072386673388,
744098684458528520,
3065269157395859095,
4485432721747645676,
1437695154222573918,
61718929453661,
]);
// 1656507924366244928424688705439191250492553228839737584554076474712325077234544758394965182643615114744030751122897661836350026981040666763359635
pub const FROBENIUS_FACTOR_FP12_ELEM1: fp_480::Monty = fp_480::Monty::new([
613965927886559410,
2361635237536443012,
3129716915606370669,
4220378342453835565,
1656765987642530574,
3731213327315885235,
170550538619333766,
66872066213090,
]);
// 411347727129503104504468123876138850111359831064167067331474757563790630947112631916366442374487601276802707186517326847256605909760387475785136
pub const FROBENIUS_FACTOR_FP12_ELEM2: fp_480::Monty = fp_480::Monty::new([
652931999108764279,
1658658352207180392,
3653109520182372911,
3450241611584487126,
3641921634759792588,
2529484767529683059,
350938797403315524,
49512759813742,
]);
// 312157706584224680600308545205528127680307487617553738418861995798900452706641027486879895658291500887470406684901821314437577128442539550817602
pub const TWISTED_CURVE_CONST_COEFF_ELEM1: fp_480::Monty = fp_480::Monty::new([
4562769632847554627,
2772237052338108913,
3537386767739681441,
615361487849464825,
969060421896923957,
4312037157893005938,
4544685324846330585,
50657782593685,
]);
// 2185103946089572764202159816438696893762152413322876168932033970592303168946487192408159269608040506212292846794312749201063039899097776855723217
pub const TWISTED_CURVE_CONST_COEFF_ELEM2: fp_480::Monty = fp_480::Monty::new([
4470082996909110524,
650261447465230354,
980287267186433757,
1794414221817854493,
599120112089212085,
2332321685792786167,
2330577300095457690,
59121288224985,
]);
}
pub use values::*;
}
// Test constants for Fr256 Schnorr signature tests.
// These are functions rather than const because Fr256::new is not const fn.
#[cfg(test)]
pub mod fr256_test_constants {
use crate::internal::fp::fr_256::Fr256;
// 65000549695646603732796438742359905742570406053903786389881062969044166799967
#[cfg(feature = "u32_backend")]
pub fn schnorr_test_k() -> Fr256 {
Fr256::new([
1470919263, 878569654, 1621943440, 1953263767, 407749138, 1308464908, 685899370,
1518399909, 143,
])
}
#[cfg(not(feature = "u32_backend"))]
pub fn schnorr_test_k() -> Fr256 {
Fr256::new([
1886713967064937055,
4194602001485325456,
2809906994319573522,
3260738976388087402,
143,
])
}
// 4062534355977912733299777421397494108926584881726437723242321564179011504485
#[cfg(feature = "u32_backend")]
pub fn schnorr_expected_r() -> Fr256 {
Fr256::new([
1172343141, 1124832653, 1210936679, 1999488104, 1636097057, 1423956336, 713957350,
2108165914, 8,
])
}
#[cfg(not(feature = "u32_backend"))]
pub fn schnorr_expected_r() -> Fr256 {
Fr256::new([
2415559730226301285,
4293868008921460071,
3057922948662090785,
4527251828299931622,
8,
])
}
// 54576864563267907144762780592548274163132236814713061179326750530890377205812
#[cfg(feature = "u32_backend")]
pub fn schnorr_expected_s() -> Fr256 {
Fr256::new([
572266548, 1817264162, 947859163, 727064549, 1022507007, 908309245, 1790662289,
1421119645, 120,
])
}
#[cfg(not(feature = "u32_backend"))]
pub fn schnorr_expected_s() -> Fr256 {
Fr256::new([
3902545072563689524,
1561359230965853915,
1950579251987232767,
3051831201279727249,
120,
])
}
}