Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
edwards_pairing.cpp
Go to the documentation of this file.
1
8#include <cassert>
9
15
16namespace libff {
17
19{
20 return (this->c_ZZ == other.c_ZZ &&
21 this->c_XY == other.c_XY &&
22 this->c_XZ == other.c_XZ);
23}
24
25std::ostream& operator<<(std::ostream &out, const edwards_Fq_conic_coefficients &cc)
26{
27 out << cc.c_ZZ << OUTPUT_SEPARATOR << cc.c_XY << OUTPUT_SEPARATOR << cc.c_XZ;
28 return out;
29}
30
31std::istream& operator>>(std::istream &in, edwards_Fq_conic_coefficients &cc)
32{
33 in >> cc.c_ZZ;
35 in >> cc.c_XY;
37 in >> cc.c_XZ;
38 return in;
39}
40
41std::ostream& operator<<(std::ostream& out, const edwards_tate_G1_precomp &prec_P)
42{
43 out << prec_P.size() << "\n";
44 for (const edwards_Fq_conic_coefficients &cc : prec_P)
45 {
46 out << cc << OUTPUT_NEWLINE;
47 }
48
49 return out;
50}
51
52std::istream& operator>>(std::istream& in, edwards_tate_G1_precomp &prec_P)
53{
54 prec_P.clear();
55
56 size_t s;
57 in >> s;
58
60 prec_P.reserve(s);
61
62 for (size_t i = 0; i < s; ++i)
63 {
65 in >> cc;
67 prec_P.emplace_back(cc);
68 }
69
70 return in;
71}
72
74{
75 return (this->y0 == other.y0 &&
76 this->eta == other.eta);
77}
78
79std::ostream& operator<<(std::ostream &out, const edwards_tate_G2_precomp &prec_Q)
80{
81 out << prec_Q.y0 << OUTPUT_SEPARATOR << prec_Q.eta;
82 return out;
83}
84
85std::istream& operator>>(std::istream &in, edwards_tate_G2_precomp &prec_Q)
86{
87 in >> prec_Q.y0;
89 in >> prec_Q.eta;
90 return in;
91}
92
94{
95 return (this->c_ZZ == other.c_ZZ &&
96 this->c_XY == other.c_XY &&
97 this->c_XZ == other.c_XZ);
98}
99
100std::ostream& operator<<(std::ostream &out, const edwards_Fq3_conic_coefficients &cc)
101{
102 out << cc.c_ZZ << OUTPUT_SEPARATOR << cc.c_XY << OUTPUT_SEPARATOR << cc.c_XZ;
103 return out;
104}
105
106std::istream& operator>>(std::istream &in, edwards_Fq3_conic_coefficients &cc)
107{
108 in >> cc.c_ZZ;
110 in >> cc.c_XY;
112 in >> cc.c_XZ;
113 return in;
114}
115
116std::ostream& operator<<(std::ostream& out, const edwards_ate_G2_precomp &prec_Q)
117{
118 out << prec_Q.size() << "\n";
119 for (const edwards_Fq3_conic_coefficients &cc : prec_Q)
120 {
121 out << cc << OUTPUT_NEWLINE;
122 }
123
124 return out;
125}
126
127std::istream& operator>>(std::istream& in, edwards_ate_G2_precomp &prec_Q)
128{
129 prec_Q.clear();
130
131 size_t s;
132 in >> s;
133
134 consume_newline(in);
135
136 prec_Q.reserve(s);
137
138 for (size_t i = 0; i < s; ++i)
139 {
141 in >> cc;
143 prec_Q.emplace_back(cc);
144 }
145
146 return in;
147}
148
150{
151 return (this->P_XY == other.P_XY &&
152 this->P_XZ == other.P_XZ &&
153 this->P_ZZplusYZ == other.P_ZZplusYZ);
154}
155
156std::ostream& operator<<(std::ostream &out, const edwards_ate_G1_precomp &prec_P)
157{
158 out << prec_P.P_XY << OUTPUT_SEPARATOR << prec_P.P_XZ << OUTPUT_SEPARATOR << prec_P.P_ZZplusYZ;
159
160 return out;
161}
162
163std::istream& operator>>(std::istream &in, edwards_ate_G1_precomp &prec_P)
164{
165 in >> prec_P.P_XY >> prec_P.P_XZ >> prec_P.P_ZZplusYZ;
166
167 return in;
168}
169
170/* final exponentiations */
172{
173 enter_block("Call to edwards_final_exponentiation_last_chunk");
174 const edwards_Fq6 elt_q = elt.Frobenius_map(1);
176 edwards_Fq6 w0_part;
178 {
180 } else {
182 }
183 edwards_Fq6 result = w1_part * w0_part;
184 leave_block("Call to edwards_final_exponentiation_last_chunk");
185
186 return result;
187}
188
190{
191 enter_block("Call to edwards_final_exponentiation_first_chunk");
192
193 /* (q^3-1)*(q+1) */
194
195 /* elt_q3 = elt^(q^3) */
196 const edwards_Fq6 elt_q3 = elt.Frobenius_map(3);
197 /* elt_q3_over_elt = elt^(q^3-1) */
198 const edwards_Fq6 elt_q3_over_elt = elt_q3 * elt_inv;
199 /* alpha = elt^((q^3-1) * q) */
200 const edwards_Fq6 alpha = elt_q3_over_elt.Frobenius_map(1);
201 /* beta = elt^((q^3-1)*(q+1) */
202 const edwards_Fq6 beta = alpha * elt_q3_over_elt;
203 leave_block("Call to edwards_final_exponentiation_first_chunk");
204 return beta;
205}
206
208{
209 enter_block("Call to edwards_final_exponentiation");
210 const edwards_Fq6 elt_inv = elt.inverse();
211 const edwards_Fq6 elt_to_first_chunk = edwards_final_exponentiation_first_chunk(elt, elt_inv);
212 const edwards_Fq6 elt_inv_to_first_chunk = edwards_final_exponentiation_first_chunk(elt_inv, elt);
213 edwards_GT result = edwards_final_exponentiation_last_chunk(elt_to_first_chunk, elt_inv_to_first_chunk);
214 leave_block("Call to edwards_final_exponentiation");
215
216 return result;
217}
218
220{
221 enter_block("Call to edwards_tate_precompute_G2");
222 edwards_G2 Qcopy = Q;
223 Qcopy.to_affine_coordinates();
225 result.y0 = Qcopy.Y * Qcopy.Z.inverse(); // Y/Z
226 result.eta = (Qcopy.Z+Qcopy.Y) * edwards_Fq6::mul_by_non_residue(Qcopy.X).inverse(); // (Z+Y)/(nqr*X)
227 leave_block("Call to edwards_tate_precompute_G2");
228
229 return result;
230}
231
237
238 void print() const
239 {
240 printf("extended edwards_G1 projective X/Y/Z/T:\n");
241 X.print();
242 Y.print();
243 Z.print();
244 T.print();
245 }
246
247 void test_invariant() const
248 {
249 assert(T*Z == X*Y);
250 }
251};
252
255{
256 const edwards_Fq &X = current.X, &Y = current.Y, &Z = current.Z, &T = current.T;
257 const edwards_Fq A = X.squared(); // A = X1^2
258 const edwards_Fq B = Y.squared(); // B = Y1^2
259 const edwards_Fq C = Z.squared(); // C = Z1^2
260 const edwards_Fq D = (X+Y).squared(); // D = (X1+Y1)^2
261 const edwards_Fq E = (Y+Z).squared(); // E = (Y1+Z1)^2
262 const edwards_Fq F = D-(A+B); // F = D-(A+B)
263 const edwards_Fq G = E-(B+C); // G = E-(B+C)
264 const edwards_Fq &H = A; // H = A (edwards_a=1)
265 const edwards_Fq I = H+B; // I = H+B
266 const edwards_Fq J = C-I; // J = C-I
267 const edwards_Fq K = J+C; // K = J+C
268
269 cc.c_ZZ = Y*(T-X); // c_ZZ = 2*Y1*(T1-X1)
270 cc.c_ZZ = cc.c_ZZ + cc.c_ZZ;
271
272 cc.c_XY = J+J+G; // c_XY = 2*J+G
273 cc.c_XZ = X*T-B; // c_XZ = 2*(X1*T1-B) (edwards_a=1)
274 cc.c_XZ = cc.c_XZ + cc.c_XZ;
275
276 current.X = F*K; // X3 = F*K
277 current.Y = I*(B-H); // Y3 = I*(B-H)
278 current.Z = I*K; // Z3 = I*K
279 current.T = F*(B-H); // T3 = F*(B-H)
280
281#ifdef DEBUG
282 current.test_invariant();
283#endif
284}
285
289{
290 const edwards_Fq &X1 = current.X, &Y1 = current.Y, &Z1 = current.Z, &T1 = current.T;
291 const edwards_Fq &X2 = base.X, &Y2 = base.Y, &Z2 = base.Z, &T2 = base.T;
292
293 const edwards_Fq A = X1*X2; // A = X1*X2
294 const edwards_Fq B = Y1*Y2; // B = Y1*Y2
295 const edwards_Fq C = Z1*T2; // C = Z1*T2
296 const edwards_Fq D = T1*Z2; // D = T1*Z2
297 const edwards_Fq E = D+C; // E = D+C
298 const edwards_Fq F = (X1-Y1)*(X2+Y2)+B-A; // F = (X1-Y1)*(X2+Y2)+B-A
299 const edwards_Fq G = B + A; // G = B + A (edwards_a=1)
300 const edwards_Fq H = D-C; // H = D-C
301 const edwards_Fq I = T1*T2; // I = T1*T2
302
303 cc.c_ZZ = (T1-X1)*(T2+X2)-I+A; // c_ZZ = (T1-X1)*(T2+X2)-I+A
304 cc.c_XY = X1*Z2-X2*Z1+F; // c_XY = X1*Z2-X2*Z1+F
305 cc.c_XZ = (Y1-T1)*(Y2+T2)-B+I-H; // c_XZ = (Y1-T1)*(Y2+T2)-B+I-H
306 current.X = E*F; // X3 = E*F
307 current.Y = G*H; // Y3 = G*H
308 current.Z = F*G; // Z3 = F*G
309 current.T = E*H; // T3 = E*H
310
311#ifdef DEBUG
312 current.test_invariant();
313#endif
314}
315
319{
320 const edwards_Fq &X1 = current.X, &Y1 = current.Y, &Z1 = current.Z, &T1 = current.T;
321 const edwards_Fq &X2 = base.X, &Y2 = base.Y, &T2 = base.T;
322
323 const edwards_Fq A = X1*X2; // A = X1*X2
324 const edwards_Fq B = Y1*Y2; // B = Y1*Y2
325 const edwards_Fq C = Z1*T2; // C = Z1*T2
326 const edwards_Fq D = T1; // D = T1*Z2
327 const edwards_Fq E = D+C; // E = D+C
328 const edwards_Fq F = (X1-Y1)*(X2+Y2)+B-A; // F = (X1-Y1)*(X2+Y2)+B-A
329 const edwards_Fq G = B + A; // G = B + A (edwards_a=1)
330 const edwards_Fq H = D-C; // H = D-C
331 const edwards_Fq I = T1*T2; // I = T1*T2
332
333 cc.c_ZZ = (T1-X1)*(T2+X2)-I+A; // c_ZZ = (T1-X1)*(T2+X2)-I+A
334 cc.c_XY = X1-X2*Z1+F; // c_XY = X1*Z2-X2*Z1+F
335 cc.c_XZ = (Y1-T1)*(Y2+T2)-B+I-H; // c_XZ = (Y1-T1)*(Y2+T2)-B+I-H
336 current.X = E*F; // X3 = E*F
337 current.Y = G*H; // Y3 = G*H
338 current.Z = F*G; // Z3 = F*G
339 current.T = E*H; // T3 = E*H
340
341#ifdef DEBUG
342 current.test_invariant();
343#endif
344}
345
347{
348 enter_block("Call to edwards_tate_precompute_G1");
350
351 edwards_G1 Pcopy = P;
352 Pcopy.to_affine_coordinates();
353
355 P_ext.X = Pcopy.X;
356 P_ext.Y = Pcopy.Y;
357 P_ext.Z = Pcopy.Z;
358 P_ext.T = Pcopy.X*Pcopy.Y;
359
361
362 bool found_one = false;
363 for (long i = edwards_modulus_r.max_bits(); i >= 0; --i)
364 {
365 const bool bit = edwards_modulus_r.test_bit(i);
366 if (!found_one)
367 {
368 /* this skips the MSB itself */
369 found_one |= bit;
370 continue;
371 }
372
373 /* code below gets executed for all bits (EXCEPT the MSB itself) of
374 edwards_modulus_r (skipping leading zeros) in MSB to LSB
375 order */
378 result.push_back(cc);
379
380 if (bit)
381 {
383 result.push_back(cc);
384 }
385 }
386
387 leave_block("Call to edwards_tate_precompute_G1");
388 return result;
389}
390
392 const edwards_tate_G2_precomp &prec_Q)
393{
394 enter_block("Call to edwards_tate_miller_loop");
395
397
398 bool found_one = false;
399 size_t idx = 0;
400 for (long i = edwards_modulus_r.max_bits()-1; i >= 0; --i)
401 {
402 const bool bit = edwards_modulus_r.test_bit(i);
403 if (!found_one)
404 {
405 /* this skips the MSB itself */
406 found_one |= bit;
407 continue;
408 }
409
410 /* code below gets executed for all bits (EXCEPT the MSB itself) of
411 edwards_modulus_r (skipping leading zeros) in MSB to LSB
412 order */
413 edwards_Fq_conic_coefficients cc = prec_P[idx++];
414 edwards_Fq6 g_RR_at_Q = edwards_Fq6(edwards_Fq3(cc.c_XZ, edwards_Fq(0l), edwards_Fq(0l)) + cc.c_XY * prec_Q.y0,
415 cc.c_ZZ * prec_Q.eta);
416 f = f.squared() * g_RR_at_Q;
417 if (bit)
418 {
419 cc = prec_P[idx++];
420
421 edwards_Fq6 g_RP_at_Q = edwards_Fq6(edwards_Fq3(cc.c_XZ, edwards_Fq(0l), edwards_Fq(0l)) + cc.c_XY * prec_Q.y0,
422 cc.c_ZZ * prec_Q.eta);
423 f = f * g_RP_at_Q;
424 }
425 }
426 leave_block("Call to edwards_tate_miller_loop");
427
428 return f;
429}
430
432{
433 enter_block("Call to edwards_tate_pairing");
436 edwards_Fq6 result = edwards_tate_miller_loop(prec_P, prec_Q);
437 leave_block("Call to edwards_tate_pairing");
438 return result;
439}
440
442{
443 enter_block("Call to edwards_tate_reduced_pairing");
446 leave_block("Call to edwards_tate_reduce_pairing");
447 return result;
448}
449
455
456 void print() const
457 {
458 printf("extended edwards_G2 projective X/Y/Z/T:\n");
459 X.print();
460 Y.print();
461 Z.print();
462 T.print();
463 }
464
465 void test_invariant() const
466 {
467 assert(T*Z == X*Y);
468 }
469};
470
473{
474 const edwards_Fq3 &X = current.X, &Y = current.Y, &Z = current.Z, &T = current.T;
475 const edwards_Fq3 A = X.squared(); // A = X1^2
476 const edwards_Fq3 B = Y.squared(); // B = Y1^2
477 const edwards_Fq3 C = Z.squared(); // C = Z1^2
478 const edwards_Fq3 D = (X+Y).squared(); // D = (X1+Y1)^2
479 const edwards_Fq3 E = (Y+Z).squared(); // E = (Y1+Z1)^2
480 const edwards_Fq3 F = D-(A+B); // F = D-(A+B)
481 const edwards_Fq3 G = E-(B+C); // G = E-(B+C)
482 const edwards_Fq3 H = edwards_G2::mul_by_a(A); // edwards_param_twist_coeff_a is 1 * X for us
483 // H = twisted_a * A
484 const edwards_Fq3 I = H+B; // I = H+B
485 const edwards_Fq3 J = C-I; // J = C-I
486 const edwards_Fq3 K = J+C; // K = J+C
487
488 cc.c_ZZ = Y*(T-X); // c_ZZ = 2*Y1*(T1-X1)
489 cc.c_ZZ = cc.c_ZZ + cc.c_ZZ;
490
491 // c_XY = 2*(C-edwards_a * A * delta_3-B)+G (edwards_a = 1 for us)
492 cc.c_XY = C - edwards_G2::mul_by_a(A) - B; // edwards_param_twist_coeff_a is 1 * X for us
493 cc.c_XY = cc.c_XY + cc.c_XY + G;
494
495 // c_XZ = 2*(edwards_a*X1*T1*delta_3-B) (edwards_a = 1 for us)
496 cc.c_XZ = edwards_G2::mul_by_a(X * T) - B; // edwards_param_twist_coeff_a is 1 * X for us
497 cc.c_XZ = cc.c_XZ + cc.c_XZ;
498
499 current.X = F*K; // X3 = F*K
500 current.Y = I*(B-H); // Y3 = I*(B-H)
501 current.Z = I*K; // Z3 = I*K
502 current.T = F*(B-H); // T3 = F*(B-H)
503#ifdef DEBUG
504 current.test_invariant();
505#endif
506}
507
511{
512 const edwards_Fq3 &X1 = current.X, &Y1 = current.Y, &Z1 = current.Z, &T1 = current.T;
513 const edwards_Fq3 &X2 = base.X, &Y2 = base.Y, &Z2 = base.Z, &T2 = base.T;
514
515 const edwards_Fq3 A = X1*X2; // A = X1*X2
516 const edwards_Fq3 B = Y1*Y2; // B = Y1*Y2
517 const edwards_Fq3 C = Z1*T2; // C = Z1*T2
518 const edwards_Fq3 D = T1*Z2; // D = T1*Z2
519 const edwards_Fq3 E = D+C; // E = D+C
520 const edwards_Fq3 F = (X1-Y1)*(X2+Y2)+B-A; // F = (X1-Y1)*(X2+Y2)+B-A
521 // G = B + twisted_edwards_a * A
522 const edwards_Fq3 G = B + edwards_G2::mul_by_a(A); // edwards_param_twist_coeff_a is 1*X for us
523 const edwards_Fq3 H = D-C; // H = D-C
524 const edwards_Fq3 I = T1*T2; // I = T1*T2
525
526 // c_ZZ = delta_3* ((T1-X1)*(T2+X2)-I+A)
527 cc.c_ZZ = edwards_G2::mul_by_a((T1-X1)*(T2+X2)-I+A); // edwards_param_twist_coeff_a is 1*X for us
528
529 cc.c_XY = X1*Z2-X2*Z1+F; // c_XY = X1*Z2-X2*Z1+F
530 cc.c_XZ = (Y1-T1)*(Y2+T2)-B+I-H; // c_XZ = (Y1-T1)*(Y2+T2)-B+I-H
531 current.X = E*F; // X3 = E*F
532 current.Y = G*H; // Y3 = G*H
533 current.Z = F*G; // Z3 = F*G
534 current.T = E*H; // T3 = E*H
535
536#ifdef DEBUG
537 current.test_invariant();
538#endif
539}
540
544{
545 const edwards_Fq3 &X1 = current.X, &Y1 = current.Y, &Z1 = current.Z, &T1 = current.T;
546 const edwards_Fq3 &X2 = base.X, &Y2 = base.Y, &T2 = base.T;
547
548 const edwards_Fq3 A = X1*X2; // A = X1*X2
549 const edwards_Fq3 B = Y1*Y2; // B = Y1*Y2
550 const edwards_Fq3 C = Z1*T2; // C = Z1*T2
551 const edwards_Fq3 E = T1+C; // E = T1+C
552 const edwards_Fq3 F = (X1-Y1)*(X2+Y2)+B-A; // F = (X1-Y1)*(X2+Y2)+B-A
553 // G = B + twisted_edwards_a * A
554 const edwards_Fq3 G = B + edwards_G2::mul_by_a(A); // edwards_param_twist_coeff_a is 1*X for us
555 const edwards_Fq3 H = T1-C; // H = T1-C
556 const edwards_Fq3 I = T1*T2; // I = T1*T2
557
558 // c_ZZ = delta_3* ((T1-X1)*(T2+X2)-I+A)
559 cc.c_ZZ = edwards_G2::mul_by_a((T1-X1)*(T2+X2)-I+A); // edwards_param_twist_coeff_a is 1*X for us
560
561 cc.c_XY = X1-X2*Z1+F; // c_XY = X1*Z2-X2*Z1+F
562 cc.c_XZ = (Y1-T1)*(Y2+T2)-B+I-H; // c_XZ = (Y1-T1)*(Y2+T2)-B+I-H
563 current.X = E*F; // X3 = E*F
564 current.Y = G*H; // Y3 = G*H
565 current.Z = F*G; // Z3 = F*G
566 current.T = E*H; // T3 = E*H
567
568#ifdef DEBUG
569 current.test_invariant();
570#endif
571}
572
574{
575 enter_block("Call to edwards_ate_precompute_G1");
576 edwards_G1 Pcopy = P;
577 Pcopy.to_affine_coordinates();
579 result.P_XY = Pcopy.X*Pcopy.Y;
580 result.P_XZ = Pcopy.X; // P.X * P.Z but P.Z = 1
581 result.P_ZZplusYZ = (edwards_Fq::one() + Pcopy.Y); // (P.Z + P.Y) * P.Z but P.Z = 1
582 leave_block("Call to edwards_ate_precompute_G1");
583 return result;
584}
585
587{
588 enter_block("Call to edwards_ate_precompute_G2");
591
592 edwards_G2 Qcopy(Q);
593 Qcopy.to_affine_coordinates();
594
596 Q_ext.X = Qcopy.X;
597 Q_ext.Y = Qcopy.Y;
598 Q_ext.Z = Qcopy.Z;
599 Q_ext.T = Qcopy.X*Qcopy.Y;
600
602
603 bool found_one = false;
604 for (long i = loop_count.max_bits()-1; i >= 0; --i)
605 {
606 const bool bit = loop_count.test_bit(i);
607 if (!found_one)
608 {
609 /* this skips the MSB itself */
610 found_one |= bit;
611 continue;
612 }
613
616 result.push_back(cc);
617 if (bit)
618 {
620 result.push_back(cc);
621 }
622 }
623
624 leave_block("Call to edwards_ate_precompute_G2");
625 return result;
626}
627
629 const edwards_ate_G2_precomp &prec_Q)
630{
631 enter_block("Call to edwards_ate_miller_loop");
633
635
636 bool found_one = false;
637 size_t idx = 0;
638 for (long i = loop_count.max_bits()-1; i >= 0; --i)
639 {
640 const bool bit = loop_count.test_bit(i);
641 if (!found_one)
642 {
643 /* this skips the MSB itself */
644 found_one |= bit;
645 continue;
646 }
647
648 /* code below gets executed for all bits (EXCEPT the MSB itself) of
649 edwards_param_p (skipping leading zeros) in MSB to LSB
650 order */
651 edwards_Fq3_conic_coefficients cc = prec_Q[idx++];
652
653 edwards_Fq6 g_RR_at_P = edwards_Fq6(prec_P.P_XY * cc.c_XY + prec_P.P_XZ * cc.c_XZ,
654 prec_P.P_ZZplusYZ * cc.c_ZZ);
655 f = f.squared() * g_RR_at_P;
656 if (bit)
657 {
658 cc = prec_Q[idx++];
659 edwards_Fq6 g_RQ_at_P = edwards_Fq6(prec_P.P_ZZplusYZ * cc.c_ZZ,
660 prec_P.P_XY * cc.c_XY + prec_P.P_XZ * cc.c_XZ);
661 f = f * g_RQ_at_P;
662 }
663 }
664 leave_block("Call to edwards_ate_miller_loop");
665
666 return f;
667}
668
670 const edwards_ate_G2_precomp &prec_Q1,
671 const edwards_ate_G1_precomp &prec_P2,
672 const edwards_ate_G2_precomp &prec_Q2)
673{
674 enter_block("Call to edwards_ate_double_miller_loop");
676
678
679 bool found_one = false;
680 size_t idx = 0;
681 for (long i = loop_count.max_bits()-1; i >= 0; --i)
682 {
683 const bool bit = loop_count.test_bit(i);
684 if (!found_one)
685 {
686 /* this skips the MSB itself */
687 found_one |= bit;
688 continue;
689 }
690
691 /* code below gets executed for all bits (EXCEPT the MSB itself) of
692 edwards_param_p (skipping leading zeros) in MSB to LSB
693 order */
694 edwards_Fq3_conic_coefficients cc1 = prec_Q1[idx];
695 edwards_Fq3_conic_coefficients cc2 = prec_Q2[idx];
696 ++idx;
697
698 edwards_Fq6 g_RR_at_P1 = edwards_Fq6(prec_P1.P_XY * cc1.c_XY + prec_P1.P_XZ * cc1.c_XZ,
699 prec_P1.P_ZZplusYZ * cc1.c_ZZ);
700
701 edwards_Fq6 g_RR_at_P2 = edwards_Fq6(prec_P2.P_XY * cc2.c_XY + prec_P2.P_XZ * cc2.c_XZ,
702 prec_P2.P_ZZplusYZ * cc2.c_ZZ);
703 f = f.squared() * g_RR_at_P1 * g_RR_at_P2;
704
705 if (bit)
706 {
707 cc1 = prec_Q1[idx];
708 cc2 = prec_Q2[idx];
709 ++idx;
710 edwards_Fq6 g_RQ_at_P1 = edwards_Fq6(prec_P1.P_ZZplusYZ * cc1.c_ZZ,
711 prec_P1.P_XY * cc1.c_XY + prec_P1.P_XZ * cc1.c_XZ);
712 edwards_Fq6 g_RQ_at_P2 = edwards_Fq6(prec_P2.P_ZZplusYZ * cc2.c_ZZ,
713 prec_P2.P_XY * cc2.c_XY + prec_P2.P_XZ * cc2.c_XZ);
714 f = f * g_RQ_at_P1 * g_RQ_at_P2;
715 }
716 }
717 leave_block("Call to edwards_ate_double_miller_loop");
718
719 return f;
720}
721
723{
724 enter_block("Call to edwards_ate_pairing");
727 edwards_Fq6 result = edwards_ate_miller_loop(prec_P, prec_Q);
728 leave_block("Call to edwards_ate_pairing");
729 return result;
730}
731
733{
734 enter_block("Call to edwards_ate_reduced_pairing");
737 leave_block("Call to edwards_ate_reduced_pairing");
738 return result;
739}
740
745
750
752 const edwards_G2_precomp &prec_Q)
753{
754 return edwards_ate_miller_loop(prec_P, prec_Q);
755}
756
758 const edwards_G2_precomp &prec_Q1,
759 const edwards_G1_precomp &prec_P2,
760 const edwards_G2_precomp &prec_Q2)
761{
762 return edwards_ate_double_miller_loop(prec_P1, prec_Q1, prec_P2, prec_Q2);
763}
764
766 const edwards_G2 &Q)
767{
768 return edwards_ate_pairing(P, Q);
769}
770
776} // libff
void clear()
Definition fp3.hpp:54
Fp3_model inverse() const
Fp3_model squared() const
void print() const
Definition fp3.hpp:55
Fp6_2over3_model inverse() const
Fp6_2over3_model cyclotomic_exp(const bigint< m > &exponent) const
static Fp6_2over3_model< n, modulus > one()
static my_Fp3 mul_by_non_residue(const my_Fp3 &elem)
Fp6_2over3_model Frobenius_map(unsigned long power) const
void print() const
Fp_model squared() const
bool test_bit(const std::size_t bitno) const
size_t max_bits() const
Definition bigint.hpp:48
void to_affine_coordinates()
static edwards_Fq3 mul_by_a(const edwards_Fq3 &elt)
void to_affine_coordinates()
#define D(var, file, col, who, lev,...)
Definition debug.h:44
#define P
Definition dtoa.c:437
#define OUTPUT_NEWLINE
#define OUTPUT_SEPARATOR
XT< 0 > X
Definition lib.h:50
const uint64 K
Definition make_512.cpp:78
void mixed_addition_step_for_miller_loop(const extended_edwards_G1_projective &base, extended_edwards_G1_projective &current, edwards_Fq_conic_coefficients &cc)
edwards_Fq6 edwards_ate_miller_loop(const edwards_ate_G1_precomp &prec_P, const edwards_ate_G2_precomp &prec_Q)
Fp3_model< edwards_q_limbs, edwards_modulus_q > edwards_Fq3
edwards_ate_G2_precomp edwards_ate_precompute_G2(const edwards_G2 &Q)
bigint< edwards_r_limbs > edwards_modulus_r
edwards_Fq6 edwards_final_exponentiation_first_chunk(const edwards_Fq6 &elt, const edwards_Fq6 &elt_inv)
std::vector< edwards_Fq_conic_coefficients > edwards_tate_G1_precomp
void consume_OUTPUT_NEWLINE(std::istream &in)
edwards_tate_G2_precomp edwards_tate_precompute_G2(const edwards_G2 &Q)
edwards_ate_G1_precomp edwards_ate_precompute_G1(const edwards_G1 &P)
void full_addition_step_for_miller_loop(const extended_edwards_G1_projective &base, extended_edwards_G1_projective &current, edwards_Fq_conic_coefficients &cc)
Fp_model< edwards_q_limbs, edwards_modulus_q > edwards_Fq
edwards_Fq6 edwards_ate_double_miller_loop(const edwards_ate_G1_precomp &prec_P1, const edwards_ate_G2_precomp &prec_Q1, const edwards_ate_G1_precomp &prec_P2, const edwards_ate_G2_precomp &prec_Q2)
std::istream & operator>>(std::istream &in, alt_bn128_G1 &g)
void consume_OUTPUT_SEPARATOR(std::istream &in)
edwards_tate_G1_precomp edwards_tate_precompute_G1(const edwards_G1 &P)
void doubling_step_for_miller_loop(extended_edwards_G1_projective &current, edwards_Fq_conic_coefficients &cc)
edwards_GT edwards_ate_reduced_pairing(const edwards_G1 &P, const edwards_G2 &Q)
edwards_Fq6 edwards_miller_loop(const edwards_G1_precomp &prec_P, const edwards_G2_precomp &prec_Q)
edwards_G1_precomp edwards_precompute_G1(const edwards_G1 &P)
edwards_GT edwards_tate_reduced_pairing(const edwards_G1 &P, const edwards_G2 &Q)
bigint< edwards_q_limbs > edwards_final_exponent_last_chunk_abs_of_w0
edwards_ate_G2_precomp edwards_G2_precomp
std::ostream & operator<<(std::ostream &out, const alt_bn128_G1 &g)
void enter_block(const std::string &msg, const bool indent)
void doubling_step_for_flipped_miller_loop(const alt_bn128_Fq two_inv, alt_bn128_G2 &current, alt_bn128_ate_ell_coeffs &c)
edwards_GT edwards_final_exponentiation(const edwards_Fq6 &elt)
edwards_Fq6 edwards_double_miller_loop(const edwards_G1_precomp &prec_P1, const edwards_G2_precomp &prec_Q1, const edwards_G1_precomp &prec_P2, const edwards_G2_precomp &prec_Q2)
edwards_Fq6 edwards_tate_pairing(const edwards_G1 &P, const edwards_G2 &Q)
edwards_Fq6 edwards_pairing(const edwards_G1 &P, const edwards_G2 &Q)
bigint< edwards_q_limbs > edwards_final_exponent_last_chunk_w1
void full_addition_step_for_flipped_miller_loop(const extended_edwards_G2_projective &base, extended_edwards_G2_projective &current, edwards_Fq3_conic_coefficients &cc)
Fp6_2over3_model< edwards_q_limbs, edwards_modulus_q > edwards_Fq6
bool edwards_final_exponent_last_chunk_is_w0_neg
edwards_Fq6 edwards_ate_pairing(const edwards_G1 &P, const edwards_G2 &Q)
edwards_Fq6 edwards_tate_miller_loop(const edwards_tate_G1_precomp &prec_P, const edwards_tate_G2_precomp &prec_Q)
edwards_GT edwards_reduced_pairing(const edwards_G1 &P, const edwards_G2 &Q)
std::vector< edwards_Fq3_conic_coefficients > edwards_ate_G2_precomp
void leave_block(const std::string &msg, const bool indent)
edwards_Fq6 edwards_final_exponentiation_last_chunk(const edwards_Fq6 &elt, const edwards_Fq6 &elt_inv)
void consume_newline(std::istream &in)
edwards_G2_precomp edwards_precompute_G2(const edwards_G2 &Q)
bigint< edwards_q_limbs > edwards_ate_loop_count
void mixed_addition_step_for_flipped_miller_loop(const alt_bn128_G2 base, alt_bn128_G2 &current, alt_bn128_ate_ell_coeffs &c)
#define T(meth, val, expected)
Definition lib.h:43
bool operator==(const edwards_Fq3_conic_coefficients &other) const
bool operator==(const edwards_Fq_conic_coefficients &other) const
bool operator==(const edwards_ate_G1_precomp &other) const
bool operator==(const edwards_tate_G2_precomp &other) const
#define R
#define A
int bit
Definition yubihsm.h:566
char * s
int l