From e116eefe123bf38158c87a40706d78ebf84d885e Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Wed, 1 May 2019 15:11:39 +0900 Subject: [PATCH] support nothrow version of gmp::setStr --- src/fp.cpp | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/fp.cpp b/src/fp.cpp index 2888f43..08e7388 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -386,17 +386,27 @@ bool Op::init(const mpz_class& _p, size_t maxBitSize, int _xi_a, Mode mode, size isFullBit = (bitSize % UnitBitSize) == 0; #if defined(MCL_USE_LLVM) || defined(MCL_USE_XBYAK) - if ((mode == FP_AUTO || mode == FP_LLVM || mode == FP_XBYAK) - && mp == mpz_class("0xfffffffffffffffffffffffffffffffeffffffffffffffff")) { - primeMode = PM_NIST_P192; - isMont = false; - isFastMod = true; - } - if ((mode == FP_AUTO || mode == FP_LLVM || mode == FP_XBYAK) - && mp == mpz_class("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")) { - primeMode = PM_NIST_P521; - isMont = false; - isFastMod = true; + if (mode == FP_AUTO || mode == FP_LLVM || mode == FP_XBYAK) { + const char *pStr = "0xfffffffffffffffffffffffffffffffeffffffffffffffff"; + bool b; + mpz_class p192; + gmp::setStr(&b, p192, pStr); + if (b && mp == p192) { + primeMode = PM_NIST_P192; + isMont = false; + isFastMod = true; + } + } + if (mode == FP_AUTO || mode == FP_LLVM || mode == FP_XBYAK) { + const char *pStr = "0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"; + bool b; + mpz_class p521; + gmp::setStr(&b, p521, pStr); + if (b && mp == p521) { + primeMode = PM_NIST_P521; + isMont = false; + isFastMod = true; + } } #endif #if defined(MCL_USE_VINT) && MCL_SIZEOF_UNIT == 8