Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
mnt4_init.cpp
Go to the documentation of this file.
1
17
18namespace libff {
19
20// bigint<mnt4_r_limbs> mnt4_modulus_r = mnt46_modulus_A;
21// bigint<mnt4_q_limbs> mnt4_modulus_q = mnt46_modulus_B;
22
32
39
41{
42 typedef bigint<mnt4_r_limbs> bigint_r;
43 typedef bigint<mnt4_q_limbs> bigint_q;
44
45 assert(sizeof(mp_limb_t) == 8 || sizeof(mp_limb_t) == 4); // Montgomery assumes this
46
47 /* parameters for scalar field Fr */
48 mnt4_modulus_r = bigint_r("475922286169261325753349249653048451545124878552823515553267735739164647307408490559963137");
50 if (sizeof(mp_limb_t) == 8)
51 {
52 mnt4_Fr::Rsquared = bigint_r("163983144722506446826715124368972380525894397127205577781234305496325861831001705438796139");
53 mnt4_Fr::Rcubed = bigint_r("207236281459091063710247635236340312578688659363066707916716212805695955118593239854980171");
54 mnt4_Fr::inv = 0xbb4334a3ffffffff;
55 }
56 if (sizeof(mp_limb_t) == 4)
57 {
58 mnt4_Fr::Rsquared = bigint_r("163983144722506446826715124368972380525894397127205577781234305496325861831001705438796139");
59 mnt4_Fr::Rcubed = bigint_r("207236281459091063710247635236340312578688659363066707916716212805695955118593239854980171");
60 mnt4_Fr::inv = 0xffffffff;
61 }
63 mnt4_Fr::euler = bigint_r("237961143084630662876674624826524225772562439276411757776633867869582323653704245279981568");
64 mnt4_Fr::s = 34;
65 mnt4_Fr::t = bigint_r("27702323054502562488973446286577291993024111641153199339359284829066871159442729");
66 mnt4_Fr::t_minus_1_over_2 = bigint_r("13851161527251281244486723143288645996512055820576599669679642414533435579721364");
68 mnt4_Fr::root_of_unity = mnt4_Fr("120638817826913173458768829485690099845377008030891618010109772937363554409782252579816313");
69 mnt4_Fr::nqr = mnt4_Fr("5");
70 mnt4_Fr::nqr_to_t = mnt4_Fr("406220604243090401056429458730298145937262552508985450684842547562990900634752279902740880");
71
72 /* parameters for base field Fq */
73 mnt4_modulus_q = bigint_q("475922286169261325753349249653048451545124879242694725395555128576210262817955800483758081");
75 if (sizeof(mp_limb_t) == 8)
76 {
77 mnt4_Fq::Rsquared = bigint_q("273000478523237720910981655601160860640083126627235719712980612296263966512828033847775776");
78 mnt4_Fq::Rcubed = bigint_q("427298980065529822574935274648041073124704261331681436071990730954930769758106792920349077");
79 mnt4_Fq::inv = 0xb071a1b67165ffff;
80 }
81 if (sizeof(mp_limb_t) == 4)
82 {
83 mnt4_Fq::Rsquared = bigint_q("273000478523237720910981655601160860640083126627235719712980612296263966512828033847775776");
84 mnt4_Fq::Rcubed = bigint_q("427298980065529822574935274648041073124704261331681436071990730954930769758106792920349077");
85 mnt4_Fq::inv = 0x7165ffff;
86 }
88 mnt4_Fq::euler = bigint_q("237961143084630662876674624826524225772562439621347362697777564288105131408977900241879040");
89 mnt4_Fq::s = 17;
90 mnt4_Fq::t = bigint_q("3630998887399759870554727551674258816109656366292531779446068791017229177993437198515");
91 mnt4_Fq::t_minus_1_over_2 = bigint_q("1815499443699879935277363775837129408054828183146265889723034395508614588996718599257");
93 mnt4_Fq::root_of_unity = mnt4_Fq("264706250571800080758069302369654305530125675521263976034054878017580902343339784464690243");
94 mnt4_Fq::nqr = mnt4_Fq("17");
95 mnt4_Fq::nqr_to_t = mnt4_Fq("264706250571800080758069302369654305530125675521263976034054878017580902343339784464690243");
96
97 /* parameters for twist field Fq2 */
98 mnt4_Fq2::euler = bigint<2*mnt4_q_limbs>("113251011236288135098249345249154230895914381858788918106847214243419142422924133497460817468249854833067260038985710370091920860837014281886963086681184370139950267830740466401280");
99 mnt4_Fq2::s = 18;
100 mnt4_Fq2::t = bigint<2*mnt4_q_limbs>("864036645784668999467844736092790457885088972921668381552484239528039111503022258739172496553419912972009735404859240494475714575477709059806542104196047745818712370534824115");
101 mnt4_Fq2::t_minus_1_over_2 = bigint<2*mnt4_q_limbs>("432018322892334499733922368046395228942544486460834190776242119764019555751511129369586248276709956486004867702429620247237857287738854529903271052098023872909356185267412057");
104 mnt4_Fq2::nqr_to_t = mnt4_Fq2(mnt4_Fq("0"),mnt4_Fq("29402818985595053196743631544512156561638230562612542604956687802791427330205135130967658"));
106 mnt4_Fq2::Frobenius_coeffs_c1[1] = mnt4_Fq("475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080");
107
108 /* parameters for Fq4 */
111 mnt4_Fq4::Frobenius_coeffs_c1[1] = mnt4_Fq("7684163245453501615621351552473337069301082060976805004625011694147890954040864167002308");
112 mnt4_Fq4::Frobenius_coeffs_c1[2] = mnt4_Fq("475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080");
113 mnt4_Fq4::Frobenius_coeffs_c1[3] = mnt4_Fq("468238122923807824137727898100575114475823797181717920390930116882062371863914936316755773");
114
115 /* choice of short Weierstrass curve and its twist */
117 mnt4_G1::coeff_b = mnt4_Fq("423894536526684178289416011533888240029318103673896002803341544124054745019340795360841685");
128 mnt4_twist_mul_by_q_X = mnt4_Fq("475922286169261325753349249653048451545124879242694725395555128576210262817955800483758080");
129 mnt4_twist_mul_by_q_Y = mnt4_Fq("7684163245453501615621351552473337069301082060976805004625011694147890954040864167002308");
130
131 /* choice of group G1 */
133 mnt4_Fq::one(),
134 mnt4_Fq::zero());
135
136
137 mnt4_G1::G1_one = mnt4_G1(mnt4_Fq("60760244141852568949126569781626075788424196370144486719385562369396875346601926534016838"),
138 mnt4_Fq("363732850702582978263902770815145784459747722357071843971107674179038674942891694705904306"),
139 mnt4_Fq::one());
141
143 mnt4_G1::wnaf_window_table.push_back(11);
144 mnt4_G1::wnaf_window_table.push_back(24);
145 mnt4_G1::wnaf_window_table.push_back(60);
146 mnt4_G1::wnaf_window_table.push_back(127);
147
149 // window 1 is unbeaten in [-inf, 5.09]
151 // window 2 is unbeaten in [5.09, 9.64]
153 // window 3 is unbeaten in [9.64, 24.79]
155 // window 4 is unbeaten in [24.79, 60.29]
157 // window 5 is unbeaten in [60.29, 144.37]
159 // window 6 is unbeaten in [144.37, 344.90]
161 // window 7 is unbeaten in [344.90, 855.00]
163 // window 8 is unbeaten in [855.00, 1804.62]
165 // window 9 is unbeaten in [1804.62, 3912.30]
167 // window 10 is unbeaten in [3912.30, 11264.50]
169 // window 11 is unbeaten in [11264.50, 27897.51]
171 // window 12 is unbeaten in [27897.51, 57596.79]
173 // window 13 is unbeaten in [57596.79, 145298.71]
175 // window 14 is unbeaten in [145298.71, 157204.59]
176 mnt4_G1::fixed_base_exp_window_table.push_back(145299);
177 // window 15 is unbeaten in [157204.59, 601600.62]
178 mnt4_G1::fixed_base_exp_window_table.push_back(157205);
179 // window 16 is unbeaten in [601600.62, 1107377.25]
180 mnt4_G1::fixed_base_exp_window_table.push_back(601601);
181 // window 17 is unbeaten in [1107377.25, 1789646.95]
182 mnt4_G1::fixed_base_exp_window_table.push_back(1107377);
183 // window 18 is unbeaten in [1789646.95, 4392626.92]
184 mnt4_G1::fixed_base_exp_window_table.push_back(1789647);
185 // window 19 is unbeaten in [4392626.92, 8221210.60]
186 mnt4_G1::fixed_base_exp_window_table.push_back(4392627);
187 // window 20 is unbeaten in [8221210.60, 42363731.19]
188 mnt4_G1::fixed_base_exp_window_table.push_back(8221211);
189 // window 21 is never the best
191 // window 22 is unbeaten in [42363731.19, inf]
192 mnt4_G1::fixed_base_exp_window_table.push_back(42363731);
193
194 /* choice of group G2 */
198
199 mnt4_G2::G2_one = mnt4_G2(mnt4_Fq2(mnt4_Fq("438374926219350099854919100077809681842783509163790991847867546339851681564223481322252708"),
200 mnt4_Fq("37620953615500480110935514360923278605464476459712393277679280819942849043649216370485641")),
201 mnt4_Fq2(mnt4_Fq("37437409008528968268352521034936931842973546441370663118543015118291998305624025037512482"),
202 mnt4_Fq("424621479598893882672393190337420680597584695892317197646113820787463109735345923009077489")),
203 mnt4_Fq2::one());
205
207 mnt4_G2::wnaf_window_table.push_back(5);
208 mnt4_G2::wnaf_window_table.push_back(15);
209 mnt4_G2::wnaf_window_table.push_back(39);
210 mnt4_G2::wnaf_window_table.push_back(109);
211
213 // window 1 is unbeaten in [-inf, 4.17]
215 // window 2 is unbeaten in [4.17, 10.12]
217 // window 3 is unbeaten in [10.12, 24.65]
219 // window 4 is unbeaten in [24.65, 60.03]
221 // window 5 is unbeaten in [60.03, 143.16]
223 // window 6 is unbeaten in [143.16, 344.73]
225 // window 7 is unbeaten in [344.73, 821.24]
227 // window 8 is unbeaten in [821.24, 1793.92]
229 // window 9 is unbeaten in [1793.92, 3919.59]
231 // window 10 is unbeaten in [3919.59, 11301.46]
233 // window 11 is unbeaten in [11301.46, 18960.09]
235 // window 12 is unbeaten in [18960.09, 44198.62]
237 // window 13 is unbeaten in [44198.62, 150799.57]
239 // window 14 is never the best
241 // window 15 is unbeaten in [150799.57, 548694.81]
242 mnt4_G2::fixed_base_exp_window_table.push_back(150800);
243 // window 16 is unbeaten in [548694.81, 1051769.08]
244 mnt4_G2::fixed_base_exp_window_table.push_back(548695);
245 // window 17 is unbeaten in [1051769.08, 2023925.59]
246 mnt4_G2::fixed_base_exp_window_table.push_back(1051769);
247 // window 18 is unbeaten in [2023925.59, 3787108.68]
248 mnt4_G2::fixed_base_exp_window_table.push_back(2023926);
249 // window 19 is unbeaten in [3787108.68, 7107480.30]
250 mnt4_G2::fixed_base_exp_window_table.push_back(3787109);
251 // window 20 is unbeaten in [7107480.30, 38760027.14]
252 mnt4_G2::fixed_base_exp_window_table.push_back(7107480);
253 // window 21 is never the best
255 // window 22 is unbeaten in [38760027.14, inf]
256 mnt4_G2::fixed_base_exp_window_table.push_back(38760027);
257
258 /* pairing parameters */
259 mnt4_ate_loop_count = bigint_q("689871209842287392837045615510547309923794944");
261 mnt4_final_exponent = bigint<4*mnt4_q_limbs>("107797360357109903430794490309592072278927783803031854357910908121903439838772861497177116410825586743089760869945394610511917274977971559062689561855016270594656570874331111995170645233717143416875749097203441437192367065467706065411650403684877366879441766585988546560");
262 mnt4_final_exponent_last_chunk_abs_of_w0 = bigint_q("689871209842287392837045615510547309923794945");
264 mnt4_final_exponent_last_chunk_w1 = bigint_q("1");
265}
266
267} // libff
static Fp2_model< n, modulus > zero()
static Fp2_model< n, modulus > nqr_to_t
Definition fp2.hpp:46
static Fp2_model< n, modulus > one()
static Fp2_model< n, modulus > nqr
Definition fp2.hpp:45
static my_Fp Frobenius_coeffs_c1[4]
Definition fp4.hpp:41
static my_Fp non_residue
Definition fp4.hpp:40
static bigint< n > euler
Definition fp.hpp:54
static Fp_model< n, modulus > multiplicative_generator
Definition fp.hpp:60
static Fp_model< n, modulus > zero()
static Fp_model< n, modulus > one()
static size_t s
Definition fp.hpp:55
static bigint< n > t
Definition fp.hpp:56
static bigint< n > t_minus_1_over_2
Definition fp.hpp:57
static Fp_model< n, modulus > root_of_unity
Definition fp.hpp:61
Fp_model squared() const
static bigint< n > Rcubed
Definition fp.hpp:64
static bool modulus_is_valid()
Definition fp.hpp:66
static mp_limb_t inv
Definition fp.hpp:62
static Fp_model< n, modulus > nqr_to_t
Definition fp.hpp:59
static Fp_model< n, modulus > nqr
Definition fp.hpp:58
static bigint< n > Rsquared
Definition fp.hpp:63
static size_t num_bits
Definition fp.hpp:53
static std::vector< size_t > wnaf_window_table
Definition mnt4_g1.hpp:32
static bool initialized
Definition mnt4_g1.hpp:36
static mnt4_G1 G1_one
Definition mnt4_g1.hpp:35
static mnt4_G1 G1_zero
Definition mnt4_g1.hpp:34
static std::vector< size_t > fixed_base_exp_window_table
Definition mnt4_g1.hpp:33
static mnt4_Fq coeff_a
Definition mnt4_g1.hpp:37
static mnt4_Fq coeff_b
Definition mnt4_g1.hpp:38
static bool initialized
Definition mnt4_g2.hpp:36
static std::vector< size_t > fixed_base_exp_window_table
Definition mnt4_g2.hpp:33
static std::vector< size_t > wnaf_window_table
Definition mnt4_g2.hpp:32
static mnt4_Fq2 coeff_b
Definition mnt4_g2.hpp:39
static mnt4_G2 G2_zero
Definition mnt4_g2.hpp:34
static mnt4_G2 G2_one
Definition mnt4_g2.hpp:35
static mnt4_Fq2 coeff_a
Definition mnt4_g2.hpp:38
static mnt4_Fq2 twist
Definition mnt4_g2.hpp:37
bool mnt4_final_exponent_last_chunk_is_w0_neg
Definition mnt4_init.cpp:37
Fp_model< mnt4_q_limbs, mnt4_modulus_q > mnt4_Fq
Definition mnt4_init.hpp:36
bigint< mnt4_q_limbs > mnt4_modulus_q
bigint< 4 *mnt4_q_limbs > mnt4_final_exponent
Definition mnt4_init.cpp:35
void init_mnt4_params()
Definition mnt4_init.cpp:40
mnt4_Fq mnt4_twist_mul_by_b_c1
Definition mnt4_init.cpp:29
bool mnt4_ate_is_loop_count_neg
Definition mnt4_init.cpp:34
bigint< mnt4_q_limbs > mnt4_final_exponent_last_chunk_abs_of_w0
Definition mnt4_init.cpp:36
mnt4_Fq2 mnt4_twist
Definition mnt4_init.cpp:23
bigint< mnt4_r_limbs > mnt4_modulus_r
bigint< mnt4_q_limbs > mnt4_final_exponent_last_chunk_w1
Definition mnt4_init.cpp:38
bigint< mnt4_q_limbs > mnt4_ate_loop_count
Definition mnt4_init.cpp:33
mnt4_Fq mnt4_twist_mul_by_a_c0
Definition mnt4_init.cpp:26
mnt4_Fq2 mnt4_twist_coeff_b
Definition mnt4_init.cpp:25
mnt4_Fq mnt4_twist_mul_by_q_X
Definition mnt4_init.cpp:30
Fp_model< mnt4_r_limbs, mnt4_modulus_r > mnt4_Fr
Definition mnt4_init.hpp:35
mnt4_Fq mnt4_twist_mul_by_a_c1
Definition mnt4_init.cpp:27
mnt4_Fq2 mnt4_twist_coeff_a
Definition mnt4_init.cpp:24
Fp2_model< mnt4_q_limbs, mnt4_modulus_q > mnt4_Fq2
Definition mnt4_init.hpp:37
mnt4_Fq mnt4_twist_mul_by_b_c0
Definition mnt4_init.cpp:28
mnt4_Fq mnt4_twist_mul_by_q_Y
Definition mnt4_init.cpp:31