diff --git a/include/mcl/fp.hpp b/include/mcl/fp.hpp index 4234fc5..88515d4 100644 --- a/include/mcl/fp.hpp +++ b/include/mcl/fp.hpp @@ -339,7 +339,6 @@ public: cybozu::write(pb, os, buf + sizeof(buf) - len, len); } /* - mode = Mod : set x mod p if sizeof(S) * n <= 64 else error set array x as little endian */ template @@ -351,15 +350,11 @@ public: template void setArray(bool *pb, const S *x, size_t n) { - setArray_(pb, x, n, fp::NoMask); - } - /* - mask x with (1 << bitLen) and subtract p if x >= p - */ - template - void setArrayMaskMod(const S *x, size_t n) - { - fp::copyAndMask(v_, x, sizeof(S) * n, op_, fp::MaskAndMod); + if (!fp::convertArrayAsLE(v_, op_.N, x, n) || fp::isGreaterOrEqualArray(v_, op_.p, op_.N)) { + *pb = false; + return; + } + *pb = true; toMont(); } /* diff --git a/src/fp.cpp b/src/fp.cpp index 7f2cfef..caad342 100644 --- a/src/fp.cpp +++ b/src/fp.cpp @@ -665,20 +665,6 @@ int detectIoMode(int ioMode, const std::ios_base& ios) bool copyAndMask(Unit *y, const void *x, size_t xByteSize, const Op& op, MaskMode maskMode) { const size_t fpByteSize = sizeof(Unit) * op.N; - if (maskMode == Mod) { - if (xByteSize > fpByteSize * 2) return false; - mpz_class mx; - bool b; - gmp::setArray(&b, mx, (const uint8_t*)x, xByteSize); - if (!b) return false; -#ifdef MCL_USE_VINT - op.modp.modp(mx, mx); -#else - mx %= op.mp; -#endif - mcl::fp::convertArrayAsLE(y, op.N, gmp::getUnit(mx), gmp::getUnitSize(mx)); - return true; - } if (xByteSize > fpByteSize) { if (maskMode == NoMask) return false; xByteSize = fpByteSize; diff --git a/test/fp_test.cpp b/test/fp_test.cpp index 9a8ee29..c863a66 100644 --- a/test/fp_test.cpp +++ b/test/fp_test.cpp @@ -512,11 +512,11 @@ void anotherFpTest(mcl::fp::Mode mode) void setArrayTest1() { - char b1[] = { 0x56, 0x34, 0x12 }; + uint8_t b1[] = { 0x56, 0x34, 0x12 }; Fp x; x.setArray(b1, 3); CYBOZU_TEST_EQUAL(x, 0x123456); - int b2[] = { 0x12, 0x34 }; + uint32_t b2[] = { 0x12, 0x34 }; x.setArray(b2, 2); CYBOZU_TEST_EQUAL(x, Fp("0x3400000012")); }