Skip to content

Commit

Permalink
change args of invVec
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Sep 14, 2024
1 parent 54f09aa commit 78e918d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 26 deletions.
6 changes: 3 additions & 3 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,9 +466,9 @@ void mclBn_setRandFunc(
```c
void mclBnFr_neg(mclBnFr *y, const mclBnFr *x);
void mclBnFr_inv(mclBnFr *y, const mclBnFr *x);
// x[i] = 1/x[i] if x[i] != 0 else 0
// y[i] = 1/x[i] if x[i] != 0 else 0
// faster than normalizing each one individually
void mclBnFr_invVec(mclBnFr *x, mclSize n);
void mclBnFr_invVec(mclBnFr *y, const mclBnFr *x, mclSize n);
void mclBnFr_sqr(mclBnFr *y, const mclBnFr *x);
void mclBnFr_add(mclBnFr *z, const mclBnFr *x, const mclBnFr *y);
void mclBnFr_sub(mclBnFr *z, const mclBnFr *x, const mclBnFr *y);
Expand All @@ -477,7 +477,7 @@ void mclBnFr_div(mclBnFr *z, const mclBnFr *x, const mclBnFr *y);

void mclBnFp_neg(mclBnFp *y, const mclBnFp *x);
void mclBnFp_inv(mclBnFp *y, const mclBnFp *x);
void mclBnFp_invVec(mclBnFp *x, mclSize n);
void mclBnFp_invVec(mclBnFp *y, const mclBnFp *x, mclSize n);
void mclBnFp_sqr(mclBnFp *y, const mclBnFp *x);
void mclBnFp_add(mclBnFp *z, const mclBnFp *x, const mclBnFp *y);
void mclBnFp_sub(mclBnFp *z, const mclBnFp *x, const mclBnFp *y);
Expand Down
6 changes: 3 additions & 3 deletions include/mcl/bn.h
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,10 @@ MCLBN_DLL_API void mclBnGT_powVec(mclBnGT *z, const mclBnGT *x, const mclBnFr *y
// x[i] *= y[i]
MCLBN_DLL_API void mclBnG1_mulEach(mclBnG1 *x, const mclBnFr *y, mclSize n);

// x[i] = 1/x[i] for x[i] != 0 else 0
// y[i] = 1/x[i] for x[i] != 0 else 0
// 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);
MCLBN_DLL_API mclSize mclBnFr_invVec(mclBnFr *y, const mclBnFr *x, mclSize n);
MCLBN_DLL_API mclSize mclBnFp_invVec(mclBnFp *y, const mclBnFp *x, mclSize n);

// y[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 *y, const mclBnG1 *x, mclSize n);
Expand Down
8 changes: 4 additions & 4 deletions include/mcl/impl/bn_c_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,14 +927,14 @@ int mclBnFp_powArray(mclBnFp *z, const mclBnFp *x, const uint8_t *y, mclSize ySi
return F_powArray(*cast(z), *cast(x), y, ySize);
}

mclSize mclBnFr_invVec(mclBnFr *x, mclSize n)
mclSize mclBnFr_invVec(mclBnFr *y, const mclBnFr *x, mclSize n)
{
return mcl::invVec(cast(x), cast(x), n);
return mcl::invVec(cast(y), cast(x), n);
}

mclSize mclBnFp_invVec(mclBnFp *x, mclSize n)
mclSize mclBnFp_invVec(mclBnFp *y, const mclBnFp *x, mclSize n)
{
return mcl::invVec(cast(x), cast(x), n);
return mcl::invVec(cast(y), cast(x), n);
}

void mclBnG1_normalizeVec(mclBnG1 *y, const mclBnG1 *x, mclSize n)
Expand Down
26 changes: 10 additions & 16 deletions test/bn_c_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,14 @@ CYBOZU_TEST_AUTO(Fp_invVec)
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(oneTbl); i++) {
mclBnFr_setInt(&x[oneTbl[i]], 1);
}
for (size_t i = 0; i < n; i++) {
y[i] = x[i];
}
size_t doneN = mclBnFr_invVec(x, n);
size_t doneN = mclBnFr_invVec(y, x, n);
size_t c = 0;
for (size_t i = 0; i < n; i++) {
if (mclBnFr_isZero(&y[i])) {
CYBOZU_TEST_ASSERT(mclBnFr_isZero(&x[i]));
if (mclBnFr_isZero(&x[i])) {
CYBOZU_TEST_ASSERT(mclBnFr_isZero(&y[i]));
c++;
} else if (mclBnFr_isOne(&y[i])) {
CYBOZU_TEST_ASSERT(mclBnFr_isOne(&x[i]));
} else if (mclBnFr_isOne(&x[i])) {
CYBOZU_TEST_ASSERT(mclBnFr_isOne(&y[i]));
c++;
} else {
mclBnFr t;
Expand All @@ -490,17 +487,14 @@ CYBOZU_TEST_AUTO(Fr_invVec)
for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(oneTbl); i++) {
mclBnFr_setInt(&x[oneTbl[i]], 1);
}
for (size_t i = 0; i < n; i++) {
y[i] = x[i];
}
size_t doneN = mclBnFr_invVec(x, n);
size_t doneN = mclBnFr_invVec(y, x, n);
size_t c = 0;
for (size_t i = 0; i < n; i++) {
if (mclBnFr_isZero(&y[i])) {
CYBOZU_TEST_ASSERT(mclBnFr_isZero(&x[i]));
if (mclBnFr_isZero(&x[i])) {
CYBOZU_TEST_ASSERT(mclBnFr_isZero(&y[i]));
c++;
} else if (mclBnFr_isOne(&y[i])) {
CYBOZU_TEST_ASSERT(mclBnFr_isOne(&x[i]));
} else if (mclBnFr_isOne(&x[i])) {
CYBOZU_TEST_ASSERT(mclBnFr_isOne(&y[i]));
c++;
} else {
mclBnFr t;
Expand Down

0 comments on commit 78e918d

Please sign in to comment.