add mclBnG{1,2,T}_mulVec

update-fork
MITSUNARI Shigeo 5 years ago
parent 3039bdb86f
commit e669a7a462
  1. 5
      include/mcl/bn.h
  2. 13
      include/mcl/impl/bn_c_impl.hpp
  3. 38
      test/bn_c_test.hpp

@ -430,6 +430,11 @@ MCLBN_DLL_API void mclBnGT_powGeneric(mclBnGT *z, const mclBnGT *x, const mclBnF
*/
MCLBN_DLL_API void mclBnGT_pow(mclBnGT *z, const mclBnGT *x, const mclBnFr *y);
// z = sum_{i=0}^{n-1} x[i] y[i]
MCLBN_DLL_API void mclBnG1_mulVec(mclBnG1 *z, const mclBnG1 *x, const mclBnFr *y, mclSize n);
MCLBN_DLL_API void mclBnG2_mulVec(mclBnG2 *z, const mclBnG2 *x, const mclBnFr *y, mclSize n);
MCLBN_DLL_API void mclBnGT_powVec(mclBnGT *z, const mclBnGT *x, const mclBnFr *y, mclSize n);
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);

@ -557,6 +557,19 @@ void mclBnGT_powGeneric(mclBnGT *z, const mclBnGT *x, const mclBnFr *y)
Fp12::powGeneric(*cast(z), *cast(x), *cast(y));
}
void mclBnG1_mulVec(mclBnG1 *z, const mclBnG1 *x, const mclBnFr *y, mclSize n)
{
G1::mulVec(*cast(z), cast(x), cast(y), n);
}
void mclBnG2_mulVec(mclBnG2 *z, const mclBnG2 *x, const mclBnFr *y, mclSize n)
{
G2::mulVec(*cast(z), cast(x), cast(y), n);
}
void mclBnGT_powVec(mclBnGT *z, const mclBnGT *x, const mclBnFr *y, mclSize n)
{
GT::powVec(*cast(z), cast(x), cast(y), n);
}
void mclBn_pairing(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y)
{
pairing(*cast(z), *cast(x), *cast(y));

@ -906,6 +906,44 @@ CYBOZU_TEST_AUTO(getLittleEndian)
}
}
CYBOZU_TEST_AUTO(mulVec)
{
const size_t N = 70;
mclBnG1 x1Vec[N], z1, w1;
mclBnG2 x2Vec[N], z2, w2;
mclBnGT xtVec[N], zt, wt;
mclBnFr yVec[N];
for (size_t i = 0; i < N; i++) {
char c = 'a' + i;
mclBnG1_hashAndMapTo(&x1Vec[i], &c, 1);
mclBnG2_hashAndMapTo(&x2Vec[i], &c, 1);
mclBn_pairing(&xtVec[i], &x1Vec[i], &x2Vec[i]);
mclBnFr_setByCSPRNG(&yVec[i]);
}
mclBnG1_mulVec(&z1, x1Vec, yVec, N);
mclBnG2_mulVec(&z2, x2Vec, yVec, N);
mclBnGT_powVec(&zt, xtVec, yVec, N);
mclBnG1_clear(&w1);
mclBnG2_clear(&w2);
mclBnGT_setInt(&wt, 1);
for (size_t i = 0; i < N; i++) {
mclBnG1 t1;
mclBnG2 t2;
mclBnGT tt;
mclBnG1_mul(&t1, &x1Vec[i], &yVec[i]);
mclBnG2_mul(&t2, &x2Vec[i], &yVec[i]);
mclBnGT_pow(&tt, &xtVec[i], &yVec[i]);
mclBnG1_add(&w1, &w1, &t1);
mclBnG2_add(&w2, &w2, &t2);
mclBnGT_mul(&wt, &wt, &tt);
}
CYBOZU_TEST_ASSERT(mclBnG1_isEqual(&z1, &w1));
CYBOZU_TEST_ASSERT(mclBnG2_isEqual(&z2, &w2));
CYBOZU_TEST_ASSERT(mclBnGT_isEqual(&zt, &wt));
}
void G1onlyTest(int curve)
{
printf("curve=%d\n", curve);

Loading…
Cancel
Save