Skip to content

Commit

Permalink
add C interface of G1::mulEach
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Apr 23, 2024
1 parent e4b9178 commit 8eebb9e
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/mcl/bn.h
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ MCLBN_DLL_API void mclBnG1_mulVec(mclBnG1 *z, mclBnG1 *x, const mclBnFr *y, mclS
MCLBN_DLL_API void mclBnG2_mulVec(mclBnG2 *z, mclBnG2 *x, const mclBnFr *y, mclSize n);
MCLBN_DLL_API void mclBnGT_powVec(mclBnGT *z, const mclBnGT *x, const mclBnFr *y, mclSize n);

// x[i] *= y[i]
MCLBN_DLL_API void mclBnG1_mulEach(mclBnG1 *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);
Expand Down
4 changes: 4 additions & 0 deletions include/mcl/impl/bn_c_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,10 @@ void mclBnGT_powVec(mclBnGT *z, const mclBnGT *x, const mclBnFr *y, mclSize n)
{
GT::powVec(*cast(z), cast(x), cast(y), n);
}
void mclBnG1_mulEach(mclBnG1 *x, const mclBnFr *y, mclSize n)
{
G1::mulEach(cast(x), cast(y), n);
}

void mclBn_pairing(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y)
{
Expand Down
2 changes: 1 addition & 1 deletion src/msm_avx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ void mulVecAVX512(Unit *_P, Unit *_x, const Unit *_y, size_t n)
void mulEachAVX512(Unit *_x, const Unit *_y, size_t n)
{
assert(n % 8 == 0);
const bool isProj = false;
const bool isProj = true;
const bool mixed = true;
mcl::msm::G1A *x = (mcl::msm::G1A*)_x;
const mcl::msm::FrA *y = (const mcl::msm::FrA*)_y;
Expand Down
26 changes: 25 additions & 1 deletion test/bn_c_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,13 +1078,21 @@ CYBOZU_TEST_AUTO(mulVec)
for (size_t i = 0; i < N; i++) {
char c = char('a' + i);
mclBnG1_hashAndMapTo(&x1Vec[i], &c, 1);
if (i == 10) {
mclBnG1_clear(&x1Vec[i]); // x1Vec[i] contains zero
}
mclBnG2_hashAndMapTo(&x2Vec[i], &c, 1);
mclBn_pairing(&xtVec[i], &x1Vec[i], &x2Vec[i]);
mclBnFr_setByCSPRNG(&yVec[i]);
// mclBnFr_setByCSPRNG(&yVec[i]);
mclBnFr_setHashOf(&yVec[i], &c, 1);
}
mclBnG1 x1Vec2[N];
memcpy(x1Vec2, x1Vec, sizeof(x1Vec));

mclBnG1_mulVec(&z1, x1Vec, yVec, N);
mclBnG2_mulVec(&z2, x2Vec, yVec, N);
mclBnGT_powVec(&zt, xtVec, yVec, N);
mclBnG1_mulEach(x1Vec2, yVec, N);

mclBnG1_clear(&w1);
mclBnG2_clear(&w2);
Expand All @@ -1094,6 +1102,22 @@ CYBOZU_TEST_AUTO(mulVec)
mclBnG2 t2;
mclBnGT tt;
mclBnG1_mul(&t1, &x1Vec[i], &yVec[i]);
CYBOZU_TEST_ASSERT(mclBnG1_isEqual(&t1, &x1Vec2[i]));
#if 0
if (mclBnG1_isEqual(&t1, &x1Vec2[i]) == 0) {
char buf[1024];
printf("i=%zd\n", i);
mclBnG1_getStr(buf, sizeof(buf), &x1Vec[i], 10);
printf("x1=%s\n", buf);
mclBnFr_getStr(buf, sizeof(buf), &yVec[i], 10);
printf("y=%s\n", buf);
mclBnG1_getStr(buf, sizeof(buf), &t1, 10);
printf("xy=%s\n", buf);
mclBnG1_getStr(buf, sizeof(buf), &x1Vec2[i], 10);
printf("ng=%s\n", buf);
exit(1);
}
#endif
mclBnG2_mul(&t2, &x2Vec[i], &yVec[i]);
mclBnGT_pow(&tt, &xtVec[i], &yVec[i]);
mclBnG1_add(&w1, &w1, &t1);
Expand Down
4 changes: 2 additions & 2 deletions test/common_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void testMulVec(const G& P)
G::mulEach(xVec.data(), yVec.data(), n);
for (size_t j = 0; j < n; j++) {
G T;
G::mul(T, x0Vec[i], yVec[i]);
CYBOZU_TEST_EQUAL(xVec[i], T);
G::mul(T, x0Vec[j], yVec[j]);
CYBOZU_TEST_EQUAL(xVec[j], T);
}
}
}
Expand Down

0 comments on commit 8eebb9e

Please sign in to comment.