add millerLoopVec

update-fork
MITSUNARI Shigeo 5 years ago
parent c0efee00e1
commit 572fa8d816
  1. 19
      include/mcl/bn.hpp
  2. 23
      test/bn_test.cpp

@ -1900,6 +1900,25 @@ inline void precomputedMillerLoop2mixed(Fp12& f, const G1& P1, const G2& Q1, con
precomputedMillerLoop2mixed(f, P1, Q1, P2, Q2coeff.data()); precomputedMillerLoop2mixed(f, P1, Q1, P2, Q2coeff.data());
} }
#endif #endif
/*
f = prod_{i=0}^{n-1} millerLoop(Pvec[i], Qvec[i])
*/
inline void millerLoopVec(Fp12& f, const G1* Pvec, const G2* Qvec, size_t n)
{
if (n == 0) {
f = 1;
return;
}
millerLoop(f, Pvec[0], Qvec[0]);
for (size_t i = 1; i < n; i++) {
Fp12 g;
millerLoop(g, Pvec[i], Qvec[i]);
f *= g;
}
}
inline void mapToG1(bool *pb, G1& P, const Fp& x) { *pb = BN::param.mapTo.calcG1(P, x); } inline void mapToG1(bool *pb, G1& P, const Fp& x) { *pb = BN::param.mapTo.calcG1(P, x); }
inline void mapToG2(bool *pb, G2& P, const Fp2& x) { *pb = BN::param.mapTo.calcG2(P, x); } inline void mapToG2(bool *pb, G2& P, const Fp2& x) { *pb = BN::param.mapTo.calcG2(P, x); }
#ifndef CYBOZU_DONT_USE_EXCEPTION #ifndef CYBOZU_DONT_USE_EXCEPTION

@ -249,6 +249,28 @@ void testMillerLoop2(const G1& P1, const G2& Q1)
CYBOZU_TEST_EQUAL(e2, e3); CYBOZU_TEST_EQUAL(e2, e3);
} }
void testMillerLoopVec()
{
const size_t n = 8;
G1 Pvec[n];
G2 Qvec[n];
char c = 'a';
for (size_t i = 0; i < n; i++) {
hashAndMapToG1(Pvec[i], &c, 1);
hashAndMapToG2(Qvec[i], &c, 1);
c++;
}
Fp12 f1, f2;
f1 = 1;
for (size_t i = 0; i < n; i++) {
Fp12 e;
millerLoop(e, Pvec[i], Qvec[i]);
f1 *= e;
}
millerLoopVec(f2, Pvec, Qvec, n);
CYBOZU_TEST_EQUAL(f1, f2);
}
void testPairing(const G1& P, const G2& Q, const char *eStr) void testPairing(const G1& P, const G2& Q, const char *eStr)
{ {
Fp12 e1; Fp12 e1;
@ -378,6 +400,7 @@ CYBOZU_TEST_AUTO(naive)
testPairing(P, Q, ts.e); testPairing(P, Q, ts.e);
testPrecomputed(P, Q); testPrecomputed(P, Q);
testMillerLoop2(P, Q); testMillerLoop2(P, Q);
testMillerLoopVec();
testBench(P, Q); testBench(P, Q);
benchAddDblG1(); benchAddDblG1();
benchAddDblG2(); benchAddDblG2();

Loading…
Cancel
Save