From 1d7c99e8a7f6cef5484b6a53440d3e398d7b6771 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Wed, 28 Aug 2019 05:18:23 +0900 Subject: [PATCH] add millerLoopVec --- include/mcl/bn.h | 2 ++ include/mcl/impl/bn_c_impl.hpp | 4 ++++ test/bn_c_test.hpp | 20 ++++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/include/mcl/bn.h b/include/mcl/bn.h index e241f6d..20212da 100644 --- a/include/mcl/bn.h +++ b/include/mcl/bn.h @@ -407,6 +407,8 @@ MCLBN_DLL_API void mclBnGT_pow(mclBnGT *z, const mclBnGT *x, const mclBnFr *y); MCLBN_DLL_API void mclBn_pairing(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y); MCLBN_DLL_API void mclBn_finalExp(mclBnGT *y, const mclBnGT *x); MCLBN_DLL_API void mclBn_millerLoop(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y); +// z = prod_{i=0}^{n-1} millerLoop(x[i], y[i]) +MCLBN_DLL_API void mclBn_millerLoopVec(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y, mclSize n); // return precomputedQcoeffSize * sizeof(Fp6) / sizeof(uint64_t) MCLBN_DLL_API int mclBn_getUint64NumToPrecompute(void); diff --git a/include/mcl/impl/bn_c_impl.hpp b/include/mcl/impl/bn_c_impl.hpp index a081ba9..291ff71 100644 --- a/include/mcl/impl/bn_c_impl.hpp +++ b/include/mcl/impl/bn_c_impl.hpp @@ -527,6 +527,10 @@ void mclBn_millerLoop(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y) { millerLoop(*cast(z), *cast(x), *cast(y)); } +void mclBn_millerLoopVec(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y, mclSize n) +{ + millerLoopVec(*cast(z), cast(x), cast(y), n); +} int mclBn_getUint64NumToPrecompute(void) { return int(BN::param.precomputedQcoeffSize * sizeof(Fp6) / sizeof(uint64_t)); diff --git a/test/bn_c_test.hpp b/test/bn_c_test.hpp index 7aaf94a..654ab90 100644 --- a/test/bn_c_test.hpp +++ b/test/bn_c_test.hpp @@ -367,6 +367,26 @@ CYBOZU_TEST_AUTO(precomputed) CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&e1, &f3)); } +CYBOZU_TEST_AUTO(millerLoopVec) +{ + const size_t n = 7; + mclBnG1 Pvec[n]; + mclBnG2 Qvec[n]; + for (size_t i = 0; i < n; i++) { + char d = (char)(i + 1); + mclBnG1_hashAndMapTo(&Pvec[i], &d, 1); + mclBnG2_hashAndMapTo(&Qvec[i], &d, 1); + } + mclBnGT e1, e2; + mclBnGT_setInt(&e2, 1); + for (size_t i = 0; i < n; i++) { + mclBn_millerLoop(&e1, &Pvec[i], &Qvec[i]); + mclBnGT_mul(&e2, &e2, &e1); + } + mclBn_millerLoopVec(&e1, Pvec, Qvec, n); + CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&e1, &e2)); +} + CYBOZU_TEST_AUTO(serialize) { const size_t FrSize = mclBn_getFrByteSize();