fix check for MCL_MAX_BIT_SIZE > 521

dev
MITSUNARI Shigeo 8 years ago
parent 5eb95ba20f
commit 549b0fa11d
  1. 17
      src/fp.cpp
  2. 4
      test/fp_test.cpp

@ -272,13 +272,21 @@ void Op::init(const std::string& mstr, size_t maxBitSize, Mode mode)
{ {
assert(sizeof(mp_limb_t) == sizeof(Unit)); assert(sizeof(mp_limb_t) == sizeof(Unit));
clear(); clear();
if (maxBitSize > MCL_MAX_BIT_SIZE) {
throw cybozu::Exception("Op:init:too large maxBitSize") << maxBitSize << MCL_MAX_BIT_SIZE;
}
{
bool isMinus = fp::strToMpzArray(&bitSize, p, maxBitSize, mp, mstr, 0);
if (isMinus) throw cybozu::Exception("Op:init:mstr is minus") << mstr;
}
if (mp == 0) throw cybozu::Exception("Op:init:mstr is zero") << mstr;
/* /*
priority : MCL_USE_XBYAK > MCL_USE_LLVM > none priority : MCL_USE_XBYAK > MCL_USE_LLVM > none
Xbyak > llvm_mont > llvm > gmp_mont > gmp Xbyak > llvm_mont > llvm > gmp_mont > gmp
*/ */
#ifdef MCL_USE_XBYAK #ifdef MCL_USE_XBYAK
if (mode == fp::FP_AUTO) mode = fp::FP_XBYAK; if (mode == fp::FP_AUTO) mode = fp::FP_XBYAK;
if (mode == fp::FP_XBYAK && maxBitSize > 521) { if (mode == fp::FP_XBYAK && bitSize > 521) {
mode = fp::FP_AUTO; mode = fp::FP_AUTO;
} }
#else #else
@ -300,15 +308,8 @@ void Op::init(const std::string& mstr, size_t maxBitSize, Mode mode)
#endif #endif
"\n", ModeToStr(mode), isMont, (int)maxBitSize); "\n", ModeToStr(mode), isMont, (int)maxBitSize);
#endif #endif
if (maxBitSize > MCL_MAX_BIT_SIZE) {
throw cybozu::Exception("Op:init:too large maxBitSize") << maxBitSize << MCL_MAX_BIT_SIZE;
}
bool isMinus = fp::strToMpzArray(&bitSize, p, maxBitSize, mp, mstr, 0);
if (isMinus) throw cybozu::Exception("Op:init:mstr is minus") << mstr;
if (mp == 0) throw cybozu::Exception("Op:init:mstr is zero") << mstr;
isFullBit = (bitSize % UnitBitSize) == 0; isFullBit = (bitSize % UnitBitSize) == 0;
primeMode = PM_GENERIC;
#if defined(MCL_USE_LLVM) || defined(MCL_USE_XBYAK) #if defined(MCL_USE_LLVM) || defined(MCL_USE_XBYAK)
if ((mode == FP_AUTO || mode == FP_LLVM || mode == FP_XBYAK) if ((mode == FP_AUTO || mode == FP_LLVM || mode == FP_XBYAK)
&& mp == mpz_class("0xfffffffffffffffffffffffffffffffeffffffffffffffff")) { && mp == mpz_class("0xfffffffffffffffffffffffffffffffeffffffffffffffff")) {

@ -753,12 +753,12 @@ CYBOZU_TEST_AUTO(mod_NIST_P521)
mcl::gmp::getArray(ok, N + 1, my); mcl::gmp::getArray(ok, N + 1, my);
#ifdef MCL_USE_LLVM #ifdef MCL_USE_LLVM
mcl_fpDbl_mod_NIST_P521L(ex, in, Fp::getOp().p); mcl_fpDbl_mod_NIST_P521L(ex, in, Fp::getOp().p);
CYBOZU_TEST_ASSERT(memcmp(ex, ok, sizeof(ex)) == 0); CYBOZU_TEST_EQUAL_ARRAY(ex, ok, N + 1);
#endif #endif
#ifdef MCL_USE_XBYAK #ifdef MCL_USE_XBYAK
const mcl::fp::Op& op = Fp::getOp(); const mcl::fp::Op& op = Fp::getOp();
op.fpDbl_mod(ex, in, op.p); op.fpDbl_mod(ex, in, op.p);
CYBOZU_TEST_ASSERT(memcmp(ex, ok, sizeof(ex)) == 0); CYBOZU_TEST_EQUAL_ARRAY(ex, ok, N + 1);
#endif #endif
} }
} }

Loading…
Cancel
Save