From 06dc69840ae1cd73ae4c9a6b34e97e79ccfb5397 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Mon, 25 Sep 2017 11:24:14 +0900 Subject: [PATCH] [she] use precompute miller loop for Q --- include/mcl/she.hpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/mcl/she.hpp b/include/mcl/she.hpp index 7c7fd90..b8d14f5 100644 --- a/include/mcl/she.hpp +++ b/include/mcl/she.hpp @@ -337,6 +337,7 @@ struct SHET { static G2 Q; static GT ePQ; // e(P, Q) static GT mPQ; // millerLoop(P, Q) + static std::vector Qcoeff_; static local::HashTable g1HashTbl; static mcl::fp::WindowMethod g2wm; typedef local::InterfaceForHashTable GTasEC; @@ -458,6 +459,7 @@ public: BN::hashAndMapToG2(Q, "0"); BN::millerLoop(mPQ, P, Q); BN::finalExp(ePQ, mPQ); + BN::precomputeG2(Qcoeff_, Q); const size_t bitSize = Fr::getBitSize(); g2wm.init(Q, bitSize, local::winSize); gtwm.init(static_cast(mPQ), bitSize, local::winSize); @@ -666,7 +668,7 @@ public: rb.setRand(rg); rc.setRand(rg); GT e; -#if 1 // 6.5Mclk -> 5.9Mclk +#if 1 G1 P1, P2; G1::mul(P1, xP, ra); if (m) { @@ -674,7 +676,8 @@ public: g1HashTbl.mulByWindowMethod(P2, m); P1 += P2; } - BN::millerLoop(c.g[0], P1, Q); +// BN::millerLoop(c.g[0], P1, Q); + BN::precomputedMillerLoop(c.g[0], P1, Qcoeff_); // G1::mul(P1, P, rb); g1HashTbl.mulByWindowMethod(P1, rb); G1::mul(P2, xP, rc); @@ -724,7 +727,9 @@ public: Enc(1) = (S, T) = (Q + r yQ, rQ) = (Q, 0) if r = 0 cm = c1 * (Q, 0) = (S, T) * (Q, 0) = (e(S, Q), 1, e(T, Q), 1) */ - doubleMillerLoop(cm.g[0], cm.g[2], c1.S, c1.T, Q); +// doubleMillerLoop(cm.g[0], cm.g[2], c1.S, c1.T, Q); + BN::precomputedMillerLoop(cm.g[0], c1.S, Qcoeff_); + BN::precomputedMillerLoop(cm.g[2], c1.T, Qcoeff_); cm.g[1] = 1; cm.g[3] = 1; } @@ -1146,6 +1151,7 @@ template typename BN::G1 SHET::P; template typename BN::G2 SHET::Q; template typename BN::Fp12 SHET::ePQ; template typename BN::Fp12 SHET::mPQ; +template std::vector SHET::Qcoeff_; template local::HashTable SHET::g1HashTbl; template mcl::fp::WindowMethod SHET::g2wm; template mcl::fp::WindowMethod > SHET::gtwm;