Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
bn128_init.cpp
Go to the documentation of this file.
1
12
13namespace libff {
14
17
22
27
29{
30 bn::Param::init(); // init ate-pairing library
31
32 typedef bigint<bn128_r_limbs> bigint_r;
33 typedef bigint<bn128_q_limbs> bigint_q;
34
35 assert(sizeof(mp_limb_t) == 8 || sizeof(mp_limb_t) == 4); // Montgomery assumes this
36
37 /* parameters for scalar field Fr */
38 bn128_modulus_r = bigint_r("21888242871839275222246405745257275088548364400416034343698204186575808495617");
40 if (sizeof(mp_limb_t) == 8)
41 {
42 bn128_Fr::Rsquared = bigint_r("944936681149208446651664254269745548490766851729442924617792859073125903783");
43 bn128_Fr::Rcubed = bigint_r("5866548545943845227489894872040244720403868105578784105281690076696998248512");
44 bn128_Fr::inv = 0xc2e1f593efffffff;
45 }
46 if (sizeof(mp_limb_t) == 4)
47 {
48 bn128_Fr::Rsquared = bigint_r("944936681149208446651664254269745548490766851729442924617792859073125903783");
49 bn128_Fr::Rcubed = bigint_r("5866548545943845227489894872040244720403868105578784105281690076696998248512");
50 bn128_Fr::inv = 0xefffffff;
51 }
53 bn128_Fr::euler = bigint_r("10944121435919637611123202872628637544274182200208017171849102093287904247808");
54 bn128_Fr::s = 28;
55 bn128_Fr::t = bigint_r("81540058820840996586704275553141814055101440848469862132140264610111");
56 bn128_Fr::t_minus_1_over_2 = bigint_r("40770029410420498293352137776570907027550720424234931066070132305055");
58 bn128_Fr::root_of_unity = bn128_Fr("19103219067921713944291392827692070036145651957329286315305642004821462161904");
60 bn128_Fr::nqr_to_t = bn128_Fr("19103219067921713944291392827692070036145651957329286315305642004821462161904");
61
62 /* parameters for base field Fq */
63 bn128_modulus_q = bigint_q("21888242871839275222246405745257275088696311157297823662689037894645226208583");
65 if (sizeof(mp_limb_t) == 8)
66 {
67 bn128_Fq::Rsquared = bigint_q("3096616502983703923843567936837374451735540968419076528771170197431451843209");
68 bn128_Fq::Rcubed = bigint_q("14921786541159648185948152738563080959093619838510245177710943249661917737183");
69 bn128_Fq::inv = 0x87d20782e4866389;
70 }
71 if (sizeof(mp_limb_t) == 4)
72 {
73 bn128_Fq::Rsquared = bigint_q("3096616502983703923843567936837374451735540968419076528771170197431451843209");
74 bn128_Fq::Rcubed = bigint_q("14921786541159648185948152738563080959093619838510245177710943249661917737183");
75 bn128_Fq::inv = 0xe4866389;
76 }
78 bn128_Fq::euler = bigint_q("10944121435919637611123202872628637544348155578648911831344518947322613104291");
79 bn128_Fq::s = 1;
80 bn128_Fq::t = bigint_q("10944121435919637611123202872628637544348155578648911831344518947322613104291");
81 bn128_Fq::t_minus_1_over_2 = bigint_q("5472060717959818805561601436314318772174077789324455915672259473661306552145");
83 bn128_Fq::root_of_unity = bn128_Fq("21888242871839275222246405745257275088696311157297823662689037894645226208582");
85 bn128_Fq::nqr_to_t = bn128_Fq("21888242871839275222246405745257275088696311157297823662689037894645226208582");
86
87 /* additional parameters for square roots in Fq/Fq2 */
89 bn128_Fq_s = 1;
90 bn128_Fq_nqr_to_t = bn::Fp("21888242871839275222246405745257275088696311157297823662689037894645226208582");
91 bn128_Fq_t_minus_1_over_2 = mie::Vuint("5472060717959818805561601436314318772174077789324455915672259473661306552145");
92
93 bn128_twist_coeff_b = bn::Fp2(bn::Fp("19485874751759354771024239261021720505790618469301721065564631296452457478373"),
94 bn::Fp("266929791119991161246907387137283842545076965332900288569378510910307636690"));
95 bn128_Fq2_s = 4;
96 bn128_Fq2_nqr_to_t = bn::Fp2(bn::Fp("5033503716262624267312492558379982687175200734934877598599011485707452665730"),
97 bn::Fp("314498342015008975724433667930697407966947188435857772134235984660852259084"));
98 bn128_Fq2_t_minus_1_over_2 = mie::Vuint("14971724250519463826312126413021210649976634891596900701138993820439690427699319920245032869357433499099632259837909383182382988566862092145199781964621");
99
100 /* choice of group G1 */
104
108
110
112 bn128_G1::wnaf_window_table.push_back(10);
113 bn128_G1::wnaf_window_table.push_back(24);
114 bn128_G1::wnaf_window_table.push_back(40);
115 bn128_G1::wnaf_window_table.push_back(132);
116
118 // window 1 is unbeaten in [-inf, 4.24]
120 // window 2 is unbeaten in [4.24, 10.43]
122 // window 3 is unbeaten in [10.43, 24.88]
124 // window 4 is unbeaten in [24.88, 62.10]
126 // window 5 is unbeaten in [62.10, 157.80]
128 // window 6 is unbeaten in [157.80, 362.05]
130 // window 7 is unbeaten in [362.05, 806.67]
132 // window 8 is unbeaten in [806.67, 2090.34]
134 // window 9 is unbeaten in [2090.34, 4459.58]
136 // window 10 is unbeaten in [4459.58, 9280.12]
138 // window 11 is unbeaten in [9280.12, 43302.64]
140 // window 12 is unbeaten in [43302.64, 210998.73]
142 // window 13 is never the best
144 // window 14 is never the best
146 // window 15 is unbeaten in [210998.73, 506869.47]
148 // window 16 is unbeaten in [506869.47, 930023.36]
150 // window 17 is unbeaten in [930023.36, 8350812.20]
152 // window 18 is never the best
154 // window 19 is never the best
156 // window 20 is unbeaten in [8350812.20, 21708138.87]
157 bn128_G1::fixed_base_exp_window_table.push_back(8350812);
158 // window 21 is unbeaten in [21708138.87, 29482995.52]
159 bn128_G1::fixed_base_exp_window_table.push_back(21708139);
160 // window 22 is unbeaten in [29482995.52, inf]
161 bn128_G1::fixed_base_exp_window_table.push_back(29482996);
162
163 /* choice of group G2 */
167
168 bn128_G2::G2_one.X = bn::Fp2(bn::Fp("15267802884793550383558706039165621050290089775961208824303765753922461897946"),
169 bn::Fp("9034493566019742339402378670461897774509967669562610788113215988055021632533"));
170 bn128_G2::G2_one.Y = bn::Fp2(bn::Fp("644888581738283025171396578091639672120333224302184904896215738366765861164"),
171 bn::Fp("20532875081203448695448744255224543661959516361327385779878476709582931298750"));
173
175
177 bn128_G2::wnaf_window_table.push_back(7);
178 bn128_G2::wnaf_window_table.push_back(18);
179 bn128_G2::wnaf_window_table.push_back(35);
180 bn128_G2::wnaf_window_table.push_back(116);
181
183 // window 1 is unbeaten in [-inf, 4.13]
185 // window 2 is unbeaten in [4.13, 10.72]
187 // window 3 is unbeaten in [10.72, 25.60]
189 // window 4 is unbeaten in [25.60, 60.99]
191 // window 5 is unbeaten in [60.99, 153.66]
193 // window 6 is unbeaten in [153.66, 353.13]
195 // window 7 is unbeaten in [353.13, 771.87]
197 // window 8 is unbeaten in [771.87, 2025.85]
199 // window 9 is unbeaten in [2025.85, 4398.65]
201 // window 10 is unbeaten in [4398.65, 10493.42]
203 // window 11 is unbeaten in [10493.42, 37054.73]
205 // window 12 is unbeaten in [37054.73, 49928.78]
207 // window 13 is unbeaten in [49928.78, 114502.82]
209 // window 14 is unbeaten in [114502.82, 161445.26]
211 // window 15 is unbeaten in [161445.26, 470648.01]
213 // window 16 is unbeaten in [470648.01, 1059821.87]
215 // window 17 is unbeaten in [1059821.87, 5450848.25]
216 bn128_G2::fixed_base_exp_window_table.push_back(1059822);
217 // window 18 is never the best
219 // window 19 is unbeaten in [5450848.25, 5566795.57]
220 bn128_G2::fixed_base_exp_window_table.push_back(5450848);
221 // window 20 is unbeaten in [5566795.57, 33055217.52]
222 bn128_G2::fixed_base_exp_window_table.push_back(5566796);
223 // window 21 is never the best
225 // window 22 is unbeaten in [33055217.52, inf]
226 bn128_G2::fixed_base_exp_window_table.push_back(33055218);
227
229}
230} // libff
static bigint< n > euler
Definition fp.hpp:54
static Fp_model< n, modulus > multiplicative_generator
Definition fp.hpp:60
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
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 bn128_G1 G1_zero
Definition bn128_g1.hpp:33
static std::vector< size_t > wnaf_window_table
Definition bn128_g1.hpp:31
static std::vector< size_t > fixed_base_exp_window_table
Definition bn128_g1.hpp:32
static bool initialized
Definition bn128_g1.hpp:35
static bn128_G1 G1_one
Definition bn128_g1.hpp:34
static bn128_G2 G2_zero
Definition bn128_g2.hpp:34
static std::vector< size_t > fixed_base_exp_window_table
Definition bn128_g2.hpp:33
static bn128_G2 G2_one
Definition bn128_g2.hpp:35
static std::vector< size_t > wnaf_window_table
Definition bn128_g2.hpp:32
static bool initialized
Definition bn128_g2.hpp:36
static bn128_GT GT_one
Definition bn128_gt.hpp:25
bn::Fp12 elem
Definition bn128_gt.hpp:26
Definition zm2.h:18
mie::Fp Fp
Definition bn.h:2952
Fp12T< Fp6 > Fp12
Definition bn.h:2959
Fp2T< Fp > Fp2
Definition bn.h:2954
bn::Fp2 bn128_twist_coeff_b
mie::Vuint bn128_Fq_t_minus_1_over_2
size_t bn128_Fq2_s
bn::Fp bn128_coeff_b
bn::Fp2 bn128_Fq2_nqr_to_t
mie::Vuint bn128_Fq2_t_minus_1_over_2
Fp_model< bn128_r_limbs, bn128_modulus_r > bn128_Fr
bn::Fp bn128_Fq_nqr_to_t
Fp_model< bn128_q_limbs, bn128_modulus_q > bn128_Fq
bigint< bn128_q_limbs > bn128_modulus_q
void init_bn128_params()
size_t bn128_Fq_s
bigint< bn128_r_limbs > bn128_modulus_r
VuintT< local::FixedBuffer< mie::Unit, MIE_ZM_VUINT_BIT_LEN > > Vuint
Definition zm.h:1161
Definition bn.h:348
static void init(const CurveParam &cp, int mode=-1, bool useMulx=true)
Definition bn.h:206