1 /** @file 2 ***************************************************************************** 3 * @author This file is part of libff, developed by SCIPR Lab 4 * and contributors (see AUTHORS). 5 * @copyright MIT license (see LICENSE file) 6 *****************************************************************************/ 7 8 #ifndef ALT_BN128_PAIRING_HPP_ 9 #define ALT_BN128_PAIRING_HPP_ 10 #include <vector> 11 12 #include <libff/algebra/curves/alt_bn128/alt_bn128_init.hpp> 13 14 namespace libff { 15 16 /* final exponentiation */ 17 18 alt_bn128_GT alt_bn128_final_exponentiation(const alt_bn128_Fq12 &elt); 19 20 /* ate pairing */ 21 22 struct alt_bn128_ate_G1_precomp { 23 alt_bn128_Fq PX; 24 alt_bn128_Fq PY; 25 26 bool operator==(const alt_bn128_ate_G1_precomp &other) const; 27 friend std::ostream& operator<<(std::ostream &out, const alt_bn128_ate_G1_precomp &prec_P); 28 friend std::istream& operator>>(std::istream &in, alt_bn128_ate_G1_precomp &prec_P); 29 }; 30 31 struct alt_bn128_ate_ell_coeffs { 32 alt_bn128_Fq2 ell_0; 33 alt_bn128_Fq2 ell_VW; 34 alt_bn128_Fq2 ell_VV; 35 36 bool operator==(const alt_bn128_ate_ell_coeffs &other) const; 37 friend std::ostream& operator<<(std::ostream &out, const alt_bn128_ate_ell_coeffs &dc); 38 friend std::istream& operator>>(std::istream &in, alt_bn128_ate_ell_coeffs &dc); 39 }; 40 41 struct alt_bn128_ate_G2_precomp { 42 alt_bn128_Fq2 QX; 43 alt_bn128_Fq2 QY; 44 std::vector<alt_bn128_ate_ell_coeffs> coeffs; 45 46 bool operator==(const alt_bn128_ate_G2_precomp &other) const; 47 friend std::ostream& operator<<(std::ostream &out, const alt_bn128_ate_G2_precomp &prec_Q); 48 friend std::istream& operator>>(std::istream &in, alt_bn128_ate_G2_precomp &prec_Q); 49 }; 50 51 alt_bn128_ate_G1_precomp alt_bn128_ate_precompute_G1(const alt_bn128_G1& P); 52 alt_bn128_ate_G2_precomp alt_bn128_ate_precompute_G2(const alt_bn128_G2& Q); 53 54 alt_bn128_Fq12 alt_bn128_ate_miller_loop(const alt_bn128_ate_G1_precomp &prec_P, 55 const alt_bn128_ate_G2_precomp &prec_Q); 56 alt_bn128_Fq12 alt_bn128_ate_double_miller_loop(const alt_bn128_ate_G1_precomp &prec_P1, 57 const alt_bn128_ate_G2_precomp &prec_Q1, 58 const alt_bn128_ate_G1_precomp &prec_P2, 59 const alt_bn128_ate_G2_precomp &prec_Q2); 60 61 alt_bn128_Fq12 alt_bn128_ate_pairing(const alt_bn128_G1& P, 62 const alt_bn128_G2 &Q); 63 alt_bn128_GT alt_bn128_ate_reduced_pairing(const alt_bn128_G1 &P, 64 const alt_bn128_G2 &Q); 65 66 /* choice of pairing */ 67 68 typedef alt_bn128_ate_G1_precomp alt_bn128_G1_precomp; 69 typedef alt_bn128_ate_G2_precomp alt_bn128_G2_precomp; 70 71 alt_bn128_G1_precomp alt_bn128_precompute_G1(const alt_bn128_G1& P); 72 73 alt_bn128_G2_precomp alt_bn128_precompute_G2(const alt_bn128_G2& Q); 74 75 alt_bn128_Fq12 alt_bn128_miller_loop(const alt_bn128_G1_precomp &prec_P, 76 const alt_bn128_G2_precomp &prec_Q); 77 78 alt_bn128_Fq12 alt_bn128_double_miller_loop(const alt_bn128_G1_precomp &prec_P1, 79 const alt_bn128_G2_precomp &prec_Q1, 80 const alt_bn128_G1_precomp &prec_P2, 81 const alt_bn128_G2_precomp &prec_Q2); 82 83 alt_bn128_Fq12 alt_bn128_pairing(const alt_bn128_G1& P, 84 const alt_bn128_G2 &Q); 85 86 alt_bn128_GT alt_bn128_reduced_pairing(const alt_bn128_G1 &P, 87 const alt_bn128_G2 &Q); 88 89 alt_bn128_GT alt_bn128_affine_reduced_pairing(const alt_bn128_G1 &P, 90 const alt_bn128_G2 &Q); 91 92 } // libff 93 #endif // ALT_BN128_PAIRING_HPP_ 94