add comment Fp::load

2merge^2
MITSUNARI Shigeo 4 years ago
parent 4cc28add06
commit 551c462467
  1. 3
      include/mcl/fp.hpp
  2. 9
      test/fp_test.cpp

@ -264,6 +264,7 @@ public:
{ {
if (isMont()) op_.fromMont(v_, v_); if (isMont()) op_.fromMont(v_, v_);
} }
// deny a string with large length even if the value is in Fp
template<class InputStream> template<class InputStream>
void load(bool *pb, InputStream& is, int ioMode) void load(bool *pb, InputStream& is, int ioMode)
{ {
@ -283,7 +284,7 @@ public:
} }
if (readSize != n) return; if (readSize != n) return;
} else { } else {
char buf[1024]; char buf[sizeof(*this) * 8 + 2]; // '0b' + max binary format length
size_t n = fp::local::loadWord(buf, sizeof(buf), is); size_t n = fp::local::loadWord(buf, sizeof(buf), is);
if (n == 0) return; if (n == 0) return;
n = fp::strToArray(&isMinus, v_, op_.N, buf, n, ioMode); n = fp::strToArray(&isMinus, v_, op_.N, buf, n, ioMode);

@ -105,6 +105,15 @@ void setStrTest()
CYBOZU_TEST_EXCEPTION(x.setStr("0b100", 10), cybozu::Exception); CYBOZU_TEST_EXCEPTION(x.setStr("0b100", 10), cybozu::Exception);
CYBOZU_TEST_EXCEPTION(x.setStr("0x100", 2), cybozu::Exception); CYBOZU_TEST_EXCEPTION(x.setStr("0x100", 2), cybozu::Exception);
CYBOZU_TEST_EXCEPTION(x.setStr("0x100", 10), cybozu::Exception); CYBOZU_TEST_EXCEPTION(x.setStr("0x100", 10), cybozu::Exception);
x = 1;
std::string s;
s.resize(Fp::getOp().N * mcl::fp::UnitBitSize, '0');
s = "0b" + s;
x.setStr(s, 2);
CYBOZU_TEST_ASSERT(x.isZero());
s += '0';
CYBOZU_TEST_EXCEPTION(x.setStr(s, 2), cybozu::Exception);
} }
} }

Loading…
Cancel
Save