Created
November 18, 2021 22:35
-
-
Save alinush/0570c0af59d20581e2629755ab1eb61a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GT MultiPairing(const std::vector<G1>& g1, const std::vector<G2>& g2) { | |
assertEqual(g1.size(), g2.size()); | |
using G1_precomp = libff::default_ec_pp::G1_precomp_type; | |
using G2_precomp = libff::default_ec_pp::G2_precomp_type; | |
using Fqk = libff::default_ec_pp::Fqk_type; | |
std::vector<G1_precomp> g1p; | |
std::vector<G2_precomp> g2p; | |
for(auto el : g1) { | |
g1p.push_back(libff::default_ec_pp::precompute_G1(el)); | |
} | |
for(auto el : g2) { | |
g2p.push_back(libff::default_ec_pp::precompute_G2(el)); | |
} | |
auto numDblMiller = g1.size() / 2; | |
bool singleMiller = (g1.size() % 2 == 1); | |
Fqk r = Fqk::one(); | |
for(size_t i = 0; i < numDblMiller; i++) { | |
r = r * libff::default_ec_pp::double_miller_loop( | |
g1p[2*i], | |
g2p[2*i], | |
g1p[2*i + 1], | |
g2p[2*i + 1] | |
); | |
} | |
if(singleMiller) { | |
r = r * libff::default_ec_pp::miller_loop( | |
g1p.back(), | |
g2p.back() | |
); | |
} | |
return libff::default_ec_pp::final_exponentiation(r); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment