Skip to content

Commit

Permalink
add mclBn{G1,G2}_normalizeVec
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Sep 13, 2024
1 parent 3d2a9a4 commit 6c523eb
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/mcl/bn.h
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,10 @@ MCLBN_DLL_API void mclBnG1_mulEach(mclBnG1 *x, const mclBnFr *y, mclSize n);
// return # of x[i] not in {0, 1}
MCLBN_DLL_API mclSize mclBnFr_invVec(mclBnFr *x, mclSize n);
MCLBN_DLL_API mclSize mclBnFp_invVec(mclBnFp *x, mclSize n);
// x[i] = normalize(x[i])
// normalized x[i].z = 1 or 0

// x[i] = normalize(x[i]) : [X:Y:Z] -> [x:y:1] or 0 where (x, y) is Affine coordinate
MCLBN_DLL_API void mclBnG1_normalizeVec(mclBnG1 *x, mclSize n);
MCLBN_DLL_API void mclBnG2_normalizeVec(mclBnG1 *x, mclSize n);
MCLBN_DLL_API void mclBnG2_normalizeVec(mclBnG2 *x, 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);
Expand Down
10 changes: 10 additions & 0 deletions include/mcl/impl/bn_c_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -936,3 +936,13 @@ mclSize mclBnFp_invVec(mclBnFp *x, mclSize n)
{
return mcl::invVec(cast(x), cast(x), n);
}

void mclBnG1_normalizeVec(mclBnG1 *x, mclSize n)
{
mcl::ec::normalizeVec(cast(x), cast(x), n);
}

void mclBnG2_normalizeVec(mclBnG2 *x, mclSize n)
{
mcl::ec::normalizeVec(cast(x), cast(x), n);
}
30 changes: 30 additions & 0 deletions test/bn_c_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,21 @@ void G1test()
CYBOZU_TEST_ASSERT(mclBnG1_isEqual(&x, &z));
mclBnG1_normalize(&y, &z);
CYBOZU_TEST_ASSERT(mclBnG1_isEqual(&y, &z));
const size_t N = 10;
mclBnG1 v1[N], v2[N];
mclBnG1_dbl(&v1[0], &z);
for (size_t i = 1; i < N; i++) {
mclBnG1_add(&v1[i], &v1[i-1], &y);
}
mclBnG1_clear(&v1[N/2]);
for (size_t i = 0; i < N; i++) {
v2[i] = v1[i];
}
mclBnG1_normalizeVec(v1, N);
for (size_t i = 0; i < N; i++) {
CYBOZU_TEST_ASSERT(mclBnG1_isEqual(&v1[i], &v2[i]));
CYBOZU_TEST_ASSERT(mclBnFp_isOne(&v1[i].z) || mclBnFp_isZero(&v1[i].z));
}
}

CYBOZU_TEST_AUTO(G1)
Expand Down Expand Up @@ -311,6 +326,21 @@ CYBOZU_TEST_AUTO(G2)
CYBOZU_TEST_ASSERT(mclBnG2_isEqual(&x, &z));
mclBnG2_normalize(&y, &z);
CYBOZU_TEST_ASSERT(mclBnG2_isEqual(&y, &z));
const size_t N = 10;
mclBnG2 v1[N], v2[N];
mclBnG2_dbl(&v1[0], &z);
for (size_t i = 1; i < N; i++) {
mclBnG2_add(&v1[i], &v1[i-1], &y);
}
mclBnG2_clear(&v1[N/2]);
for (size_t i = 0; i < N; i++) {
v2[i] = v1[i];
}
mclBnG2_normalizeVec(v1, N);
for (size_t i = 0; i < N; i++) {
CYBOZU_TEST_ASSERT(mclBnG2_isEqual(&v1[i], &v2[i]));
CYBOZU_TEST_ASSERT(mclBnFp2_isOne(&v1[i].z) || mclBnFp2_isZero(&v1[i].z));
}
}

CYBOZU_TEST_AUTO(GT)
Expand Down

0 comments on commit 6c523eb

Please sign in to comment.