add mclBnG*_isValidOrder

dev
MITSUNARI Shigeo 6 years ago
parent bb3acae83f
commit 1b8bd7f712
  1. 9
      include/mcl/bn.h
  2. 40
      include/mcl/fp_tower.hpp
  3. 2
      include/mcl/op.hpp
  4. 8
      src/bn_c_impl.hpp
  5. 2
      test/bn_c_test.hpp

@ -230,6 +230,13 @@ MCLBN_DLL_API void mclBnG1_clear(mclBnG1 *x);
MCLBN_DLL_API int mclBnG1_isValid(const mclBnG1 *x);
MCLBN_DLL_API int mclBnG1_isEqual(const mclBnG1 *x, const mclBnG1 *y);
MCLBN_DLL_API int mclBnG1_isZero(const mclBnG1 *x);
/*
return 1 if x has a correct order
x is valid point of G1 if and only if
mclBnG1_isValid() is true, which contains mclBnG1_isValidOrder() if mclBn_verifyOrderG1(true)
mclBnG1_isValid() && mclBnG1_isValidOrder() is true if mclBn_verifyOrderG1(false)
*/
MCLBN_DLL_API int mclBnG1_isValidOrder(const mclBnG1 *x);
MCLBN_DLL_API int mclBnG1_hashAndMapTo(mclBnG1 *x, const void *buf, mclSize bufSize);
@ -254,6 +261,8 @@ MCLBN_DLL_API void mclBnG2_clear(mclBnG2 *x);
MCLBN_DLL_API int mclBnG2_isValid(const mclBnG2 *x);
MCLBN_DLL_API int mclBnG2_isEqual(const mclBnG2 *x, const mclBnG2 *y);
MCLBN_DLL_API int mclBnG2_isZero(const mclBnG2 *x);
// return 1 if x has a correct order
MCLBN_DLL_API int mclBnG2_isValidOrder(const mclBnG2 *x);
MCLBN_DLL_API int mclBnG2_hashAndMapTo(mclBnG2 *x, const void *buf, mclSize bufSize);

@ -674,21 +674,8 @@ struct Fp2DblT {
y.a = t;
}
}
static void sqrPre(Fp2DblT& y, const Fp2& x)
{
Fp t1, t2;
if (Fp::isFullBit()) {
Fp::add(t1, x.b, x.b); // 2b
Fp::add(t2, x.a, x.b); // a + b
} else {
Fp::addPre(t1, x.b, x.b); // 2b
Fp::addPre(t2, x.a, x.b); // a + b
}
FpDbl::mulPre(y.b, t1, x.a); // 2ab
Fp::sub(t1, x.a, x.b); // a - b
FpDbl::mulPre(y.a, t1, t2); // (a + b)(a - b)
}
static void (*mulPre)(Fp2DblT&, const Fp2&, const Fp2&);
static void (*sqrPre)(Fp2DblT&, const Fp2&);
static void mod(Fp2& y, const Fp2DblT& x)
{
FpDbl::mod(y.a, x.a);
@ -714,6 +701,15 @@ struct Fp2DblT {
mulPre = fp2Dbl_mulPreW<false>;
}
}
if (op.fp2Dbl_sqrPreA_) {
sqrPre = (void (*)(Fp2DblT&, const Fp2&))op.fp2Dbl_sqrPreA_;
} else {
if (op.isFullBit) {
sqrPre = fp2Dbl_sqrPreW<true>;
} else {
sqrPre = fp2Dbl_sqrPreW<false>;
}
}
}
/*
Fp2Dbl::mulPre by FpDblT
@ -749,9 +745,25 @@ struct Fp2DblT {
}
FpDbl::sub(d0, d0, d2); // ac - bd
}
template<bool isFullBit>
static void fp2Dbl_sqrPreW(Fp2DblT& y, const Fp2& x)
{
Fp t1, t2;
if (isFullBit) {
Fp::add(t1, x.b, x.b); // 2b
Fp::add(t2, x.a, x.b); // a + b
} else {
Fp::addPre(t1, x.b, x.b); // 2b
Fp::addPre(t2, x.a, x.b); // a + b
}
FpDbl::mulPre(y.b, t1, x.a); // 2ab
Fp::sub(t1, x.a, x.b); // a - b
FpDbl::mulPre(y.a, t1, t2); // (a + b)(a - b)
}
};
template<class Fp> void (*Fp2DblT<Fp>::mulPre)(Fp2DblT&, const Fp2T<Fp>&, const Fp2T<Fp>&);
template<class Fp> void (*Fp2DblT<Fp>::sqrPre)(Fp2DblT&, const Fp2T<Fp>&);
template<class Fp> uint32_t Fp2T<Fp>::xi_a_;
template<class Fp> Fp2T<Fp> Fp2T<Fp>::g[Fp2T<Fp>::gN];

@ -197,6 +197,7 @@ struct Op {
void2u fpDbl_sqrPreA_;
void2u fpDbl_modA_;
void3u fp2Dbl_mulPreA_;
void3u fp2Dbl_sqrPreA_;
size_t maxN;
size_t N;
size_t bitSize;
@ -285,6 +286,7 @@ struct Op {
fpDbl_sqrPreA_ = 0;
fpDbl_modA_ = 0;
fp2Dbl_mulPreA_ = 0;
fp2Dbl_sqrPreA_ = 0;
maxN = 0;
N = 0;
bitSize = 0;

@ -210,6 +210,10 @@ int mclBnG1_isZero(const mclBnG1 *x)
{
return cast(x)->isZero();
}
int mclBnG1_isValidOrder(const mclBnG1 *x)
{
return cast(x)->isValidOrder();
}
int mclBnG1_hashAndMapTo(mclBnG1 *x, const void *buf, mclSize bufSize)
{
@ -285,6 +289,10 @@ int mclBnG2_isZero(const mclBnG2 *x)
{
return cast(x)->isZero();
}
int mclBnG2_isValidOrder(const mclBnG2 *x)
{
return cast(x)->isValidOrder();
}
int mclBnG2_hashAndMapTo(mclBnG2 *x, const void *buf, mclSize bufSize)
{

@ -141,6 +141,7 @@ CYBOZU_TEST_AUTO(G1)
CYBOZU_TEST_ASSERT(mclBnG1_isZero(&x));
CYBOZU_TEST_ASSERT(!mclBnG1_hashAndMapTo(&y, "abc", 3));
CYBOZU_TEST_ASSERT(mclBnG1_isValidOrder(&y));
char buf[1024];
size_t size;
@ -184,6 +185,7 @@ CYBOZU_TEST_AUTO(G2)
CYBOZU_TEST_ASSERT(mclBnG2_isZero(&x));
CYBOZU_TEST_ASSERT(!mclBnG2_hashAndMapTo(&x, "abc", 3));
CYBOZU_TEST_ASSERT(mclBnG2_isValidOrder(&x));
char buf[1024];
size_t size;

Loading…
Cancel
Save