add Fp2::readStream

dev
MITSUNARI Shigeo 8 years ago
parent d369883770
commit 0a61ca2d05
  1. 56
      include/mcl/ec.hpp
  2. 9
      include/mcl/fp_tower.hpp
  3. 5
      src/fp.cpp

@ -706,6 +706,11 @@ public:
}
void readStream(std::istream& is, int ioMode)
{
#ifdef MCL_EC_USE_AFFINE
inf_ = false;
#else
z = 1;
#endif
if (ioMode & IoTight) {
if (!isIoEcCompSupported()) throw cybozu::Exception("EcT:readStream:not supported ioMode") << ioMode;
std::string str;
@ -716,49 +721,32 @@ public:
clear();
return;
}
#ifdef MCL_EC_USE_AFFINE
inf_ = false;
#else
z = 1;
#endif
bool isYodd = (str[n - 1] >> 7) != 0;
str[n - 1] &= 0x7f;
x.setArray(&str[0], n);
getYfromX(y, x, isYodd);
if (verifyOrder_ && !isValidOrder()) {
throw cybozu::Exception("EcT:setStr:bad order") << *this;
}
return;
}
char c = 0;
if (ioMode & (IoArray | IoArrayRaw)) {
is.read(&c, 1);
} else {
char c = 0;
is >> c;
}
if (c == '0') {
clear();
return;
}
#ifdef MCL_EC_USE_AFFINE
inf_ = false;
#else
z = 1;
#endif
is >> x;
if (c == '1') {
is >> y;
if (!isValid(x, y)) {
throw cybozu::Exception("EcT:operator>>:bad value") << x << y;
if (c == '0') {
clear();
return;
}
x.readStream(is, ioMode);
if (c == '1') {
y.readStream(is, ioMode);
if (!isValid(x, y)) {
throw cybozu::Exception("EcT:readStream:bad value") << x << y;
}
} else if (c == '2' || c == '3') {
bool isYodd = c == '3';
getYfromX(y, x, isYodd);
} else {
throw cybozu::Exception("EcT:readStream:bad format") << c;
}
} else if (c == '2' || c == '3') {
bool isYodd = c == '3';
getYfromX(y, x, isYodd);
} else {
throw cybozu::Exception("EcT:operator>>:bad format") << c;
}
if (verifyOrder_ && !isValidOrder()) {
throw cybozu::Exception("EcT:operator>>:bad order") << *this;
throw cybozu::Exception("EcT:readStream:bad order") << *this;
}
}
friend inline std::istream& operator>>(std::istream& is, EcT& self)

@ -155,6 +155,11 @@ public:
a.setArray(buf, n);
b.setArray(buf + n, n);
}
void readStream(std::istream& is, int ioMode)
{
a.readStream(is, ioMode);
b.readStream(is, ioMode);
}
/*
Fp2T = <a> + ' ' + <b>
*/
@ -164,7 +169,9 @@ public:
}
friend std::istream& operator>>(std::istream& is, Fp2T& self)
{
return is >> self.a >> self.b;
int ioMode = fp::detectIoMode(Fp::BaseFp::getIoMode(), is);
self.readStream(is, ioMode);
return is;
}
void getStr(std::string& str, int ioMode = 10) const
{

@ -536,8 +536,9 @@ void streamToArray(bool *pIsMinus, Unit *x, size_t byteSize, std::istream& is, i
is >> str;
const char *p = verifyStr(pIsMinus, &ioMode, str);
mpz_class mx;
if (!gmp::setStr(mx, p, ioMode & ~IoPrefix)) {
throw cybozu::Exception("fp:streamToArray:bad format") << str;
// check low 5-bit of ioMode
if (!gmp::setStr(mx, p, ioMode & (31 & ~IoPrefix))) {
throw cybozu::Exception("fp:streamToArray:bad format") << ioMode << str;
}
const size_t n = (byteSize + sizeof(Unit) - 1) / sizeof(Unit);
gmp::getArray(x, n, mx);

Loading…
Cancel
Save