add mclBnF{r,p}_isNegative

update-fork
MITSUNARI Shigeo 5 years ago
parent 4bb5bb702d
commit 5259465695
  1. 5
      include/mcl/bn.h
  2. 8
      include/mcl/impl/bn_c_impl.hpp
  3. 25
      test/bn_c_test.hpp

@ -286,6 +286,11 @@ MCLBN_DLL_API int mclBnFp2_isEqual(const mclBnFp2 *x, const mclBnFp2 *y);
MCLBN_DLL_API int mclBnFp2_isZero(const mclBnFp2 *x); MCLBN_DLL_API int mclBnFp2_isZero(const mclBnFp2 *x);
MCLBN_DLL_API int mclBnFp2_isOne(const mclBnFp2 *x); MCLBN_DLL_API int mclBnFp2_isOne(const mclBnFp2 *x);
// return 1 if half <= x < r, where half = (r + 1) / 2 else 0
MCLBN_DLL_API int mclBnFr_isNegative(const mclBnFr *x);
// return 1 if half <= x < p, where half = (p + 1) / 2 else 0
MCLBN_DLL_API int mclBnFp_isNegative(const mclBnFp *x);
#ifndef MCL_DONT_USE_CSRPNG #ifndef MCL_DONT_USE_CSRPNG
// return 0 if success // return 0 if success
MCLBN_DLL_API int mclBnFr_setByCSPRNG(mclBnFr *x); MCLBN_DLL_API int mclBnFr_setByCSPRNG(mclBnFr *x);

@ -175,6 +175,10 @@ int mclBnFr_isOne(const mclBnFr *x)
{ {
return cast(x)->isOne(); return cast(x)->isOne();
} }
int mclBnFr_isNegative(const mclBnFr *x)
{
return cast(x)->isNegative();
}
#ifndef MCL_DONT_USE_CSRPNG #ifndef MCL_DONT_USE_CSRPNG
int mclBnFr_setByCSPRNG(mclBnFr *x) int mclBnFr_setByCSPRNG(mclBnFr *x)
@ -727,6 +731,10 @@ int mclBnFp_isOne(const mclBnFp *x)
{ {
return cast(x)->isOne(); return cast(x)->isOne();
} }
int mclBnFp_isNegative(const mclBnFp *x)
{
return cast(x)->isNegative();
}
int mclBnFp_setHashOf(mclBnFp *x, const void *buf, mclSize bufSize) int mclBnFp_setHashOf(mclBnFp *x, const void *buf, mclSize bufSize)
{ {

@ -327,6 +327,31 @@ CYBOZU_TEST_AUTO(GT_inv)
CYBOZU_TEST_ASSERT(mclBnGT_isOne(&e4)); CYBOZU_TEST_ASSERT(mclBnGT_isOne(&e4));
} }
CYBOZU_TEST_AUTO(Fr_isNegative)
{
mclBnFr a, half, one;
mclBnFr_setInt(&half, 2);
mclBnFr_inv(&half, &half); // half = (r + 1) / 2
mclBnFr_setInt(&one, 1);
mclBnFr_sub(&a, &half, &one);
CYBOZU_TEST_ASSERT(!mclBnFr_isNegative(&a));
mclBnFr_add(&a, &a, &one);
CYBOZU_TEST_ASSERT(mclBnFr_isNegative(&a));
}
CYBOZU_TEST_AUTO(Fp_isNegative)
{
mclBnFp a, half, one;
mclBnFp_setInt(&half, 2);
mclBnFp_inv(&half, &half); // half = (p + 1) / 2
mclBnFp_setInt(&one, 1);
mclBnFp_sub(&a, &half, &one);
CYBOZU_TEST_ASSERT(!mclBnFp_isNegative(&a));
mclBnFp_add(&a, &a, &one);
CYBOZU_TEST_ASSERT(mclBnFp_isNegative(&a));
}
CYBOZU_TEST_AUTO(pairing) CYBOZU_TEST_AUTO(pairing)
{ {
mclBnFr a, b, ab; mclBnFr a, b, ab;

Loading…
Cancel
Save