From b399592446caae925cb775456ac4952da7de3872 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Fri, 15 Nov 2019 11:56:02 +0900 Subject: [PATCH] refactor according to issues/69 --- src/fp.cpp | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/fp.cpp b/src/fp.cpp index 08e7388..7eb1e03 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -387,25 +387,24 @@ bool Op::init(const mpz_class& _p, size_t maxBitSize, int _xi_a, Mode mode, size #if defined(MCL_USE_LLVM) || defined(MCL_USE_XBYAK) 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; + const struct { + PrimeMode mode; + const char *str; + } tbl[] = { + { PM_NIST_P192, "0xfffffffffffffffffffffffffffffffeffffffffffffffff" }, + { PM_NIST_P521, "0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" }, + }; + // user fastMode for special primes + for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(tbl); i++) { + bool b; + mpz_class target; + gmp::setStr(&b, target, tbl[i].str); + if (b && mp == target) { + primeMode = tbl[i].mode; + isMont = false; + isFastMod = true; + break; + } } } #endif