start to develop Ec::mulVec

update-fork
MITSUNARI Shigeo 5 years ago
parent 43a1e4983d
commit 2c2db22773
  1. 14
      include/mcl/ec.hpp
  2. 2
      test/bls12_test.cpp
  3. 2
      test/bn384_test.cpp
  4. 2
      test/bn512_test.cpp
  5. 2
      test/bn_test.cpp
  6. 25
      test/common_test.hpp

@ -1009,6 +1009,20 @@ public:
{
mulArrayBase(z, x, gmp::getUnit(y), gmp::getUnitSize(y), y < 0, constTime);
}
/*
z = sum_{i=0}^{n-1} xVec[i] * yVec[i]
*/
template<class tag, size_t maxBitSize, template<class _tag, size_t _maxBitSize>class FpT>
static inline void mulVec(EcT& z, const EcT *xVec, const FpT<tag, maxBitSize> *yVec, size_t n)
{
EcT r, t;
r.clear();
for (size_t i = 0; i < n; i++) {
mul(t, xVec[i], yVec[i]);
r += t;
}
z = r;
}
#ifndef CYBOZU_DONT_USE_EXCEPTION
static inline void init(const std::string& astr, const std::string& bstr, int mode = ec::Jacobi)
{

@ -6,6 +6,7 @@ cybozu::CpuClock clk;
#include <mcl/bls12_381.hpp>
#include <cybozu/option.hpp>
#include <cybozu/xorshift.hpp>
#include "common_test.hpp"
#if defined(__EMSCRIPTEN__) && !defined(MCL_AVOID_EXCEPTION_TEST)
#define MCL_AVOID_EXCEPTION_TEST
@ -383,6 +384,7 @@ CYBOZU_TEST_AUTO(naive)
testPairing(P, Q, ts.e);
testPrecomputed(P, Q);
testMillerLoop2(P, Q);
testCommon();
testBench(P, Q);
}
int count = (int)clk.getCount();

@ -5,6 +5,7 @@
#include <cybozu/xorshift.hpp>
#include <mcl/bn384.hpp>
#include <mcl/bn.hpp>
#include "common_test.hpp"
using namespace mcl::bn384;
@ -39,6 +40,7 @@ void testCurve(const mcl::CurveParam& cp)
pairing(e2, aP, bQ);
GT::pow(e1, e1, a * b);
CYBOZU_TEST_EQUAL(e1, e2);
testCommon();
testBench(P, Q);
testSquareRoot();
testLagrange();

@ -5,6 +5,7 @@
#include <cybozu/xorshift.hpp>
#include <mcl/bn512.hpp>
#include <mcl/bn.hpp>
#include "common_test.hpp"
using namespace mcl::bn512;
@ -33,6 +34,7 @@ void testCurve(const mcl::CurveParam& cp)
pairing(e2, aP, bQ);
GT::pow(e1, e1, a * b);
CYBOZU_TEST_EQUAL(e1, e2);
testCommon();
testBench(P, Q);
testSquareRoot();
testLagrange();

@ -6,6 +6,7 @@ cybozu::CpuClock clk;
#include <mcl/bn256.hpp>
#include <cybozu/option.hpp>
#include <cybozu/xorshift.hpp>
#include "common_test.hpp"
#if defined(__EMSCRIPTEN__) && !defined(MCL_AVOID_EXCEPTION_TEST)
#define MCL_AVOID_EXCEPTION_TEST
@ -401,6 +402,7 @@ CYBOZU_TEST_AUTO(naive)
testPrecomputed(P, Q);
testMillerLoop2(P, Q);
testMillerLoopVec();
testCommon();
testBench(P, Q);
benchAddDblG1();
benchAddDblG2();

@ -0,0 +1,25 @@
void testMulVec()
{
using namespace mcl::bn;
const size_t n = 5;
G1 xVec[n];
Fr yVec[n];
G1 ok;
ok.clear();
char c = 'a';
for (size_t i = 0; i < n; i++) {
hashAndMapToG1(xVec[i], &c, 1);
yVec[i].setByCSPRNG();
G1 t;
G1::mul(t, xVec[i], yVec[i]);
ok += t;
}
G1 z;
G1::mulVec(z, xVec, yVec, n);
CYBOZU_TEST_EQUAL(z, ok);
}
void testCommon()
{
testMulVec();
}
Loading…
Cancel
Save