aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-03-08 14:22:03 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-03-08 14:22:03 +0800
commit2d538d8c593bbbef87a946243389807a7befe80b (patch)
treedf28e1af80033cd7643f8c5d4838e40b99632708
parentfa9bab8666586efe21522c5cbd5b794e20aea502 (diff)
downloaddexon-mcl-2d538d8c593bbbef87a946243389807a7befe80b.tar.gz
dexon-mcl-2d538d8c593bbbef87a946243389807a7befe80b.tar.zst
dexon-mcl-2d538d8c593bbbef87a946243389807a7befe80b.zip
add precomputed functions for C
-rw-r--r--include/mcl/bn.hpp43
1 files changed, 25 insertions, 18 deletions
diff --git a/include/mcl/bn.hpp b/include/mcl/bn.hpp
index c862d7b..c2ce74a 100644
--- a/include/mcl/bn.hpp
+++ b/include/mcl/bn.hpp
@@ -1091,32 +1091,32 @@ struct BNT {
*/
static void precomputeG2(std::vector<Fp6>& Qcoeff, const G2& Q)
{
- Qcoeff.clear();
- Qcoeff.reserve(param.siTbl.size() * 2);
+ Qcoeff.resize(param.precomputedQcoeffSize);
+ precomputeG2(Qcoeff.data(), Q);
+ }
+ /*
+ allocate param.precomputedQcoeffSize elements of Fp6 for Qcoeff
+ */
+ static void precomputeG2(Fp6 *Qcoeff, const G2& Q)
+ {
+ size_t idx = 0;
Q.normalize();
G2 T = Q;
G2 negQ;
if (param.useNAF) {
G2::neg(negQ, Q);
}
- Fp6 d;
- dblLineWithoutP(d, T);
- Qcoeff.push_back(d);
- Fp6 e;
assert(param.siTbl[1] == 1);
- addLineWithoutP(e, T, Q);
- Qcoeff.push_back(e);
- Fp6 l;
+ dblLineWithoutP(Qcoeff[idx++], T);
+ addLineWithoutP(Qcoeff[idx++], T, Q);
for (size_t i = 2; i < param.siTbl.size(); i++) {
- dblLineWithoutP(l, T);
- Qcoeff.push_back(l);
+ dblLineWithoutP(Qcoeff[idx++], T);
if (param.siTbl[i]) {
if (param.siTbl[i] > 0) {
- addLineWithoutP(l, T, Q);
+ addLineWithoutP(Qcoeff[idx++], T, Q);
} else {
- addLineWithoutP(l, T, negQ);
+ addLineWithoutP(Qcoeff[idx++], T, negQ);
}
- Qcoeff.push_back(l);
}
}
G2 Q1, Q2;
@@ -1126,13 +1126,16 @@ struct BNT {
if (param.z < 0) {
G2::neg(T, T);
}
- addLineWithoutP(d, T, Q1);
- Qcoeff.push_back(d);
- addLineWithoutP(e, T, Q2);
- Qcoeff.push_back(e);
+ addLineWithoutP(Qcoeff[idx++], T, Q1);
+ addLineWithoutP(Qcoeff[idx++], T, Q2);
+ assert(idx == param.precomputedQcoeffSize);
}
static void precomputedMillerLoop(Fp12& f, const G1& P, const std::vector<Fp6>& Qcoeff)
{
+ precomputedMillerLoop(f, P, Qcoeff.data());
+ }
+ static void precomputedMillerLoop(Fp12& f, const G1& P, const Fp6* Qcoeff)
+ {
P.normalize();
size_t idx = 0;
Fp6 d, e;
@@ -1170,6 +1173,10 @@ struct BNT {
*/
static void precomputedMillerLoop2(Fp12& f, const G1& P1, const std::vector<Fp6>& Q1coeff, const G1& P2, const std::vector<Fp6>& Q2coeff)
{
+ precomputedMillerLoop2(f, P1, Q1coeff.data(), P2, Q2coeff.data());
+ }
+ static void precomputedMillerLoop2(Fp12& f, const G1& P1, const Fp6* Q1coeff, const G1& P2, const Fp6* Q2coeff)
+ {
P1.normalize();
P2.normalize();
size_t idx = 0;