add Ec::getStr(mcl::IoEcProj)

dev
MITSUNARI Shigeo 8 years ago
parent fdba821952
commit 9018dab21f
  1. 15
      include/mcl/ec.hpp
  2. 8
      test/ec_test.cpp

@ -652,6 +652,17 @@ public:
*/ */
void getStr(std::string& str, int ioMode = 0) const void getStr(std::string& str, int ioMode = 0) const
{ {
const char *sep = Fp::BaseFp::getIoSeparator();
if (ioMode & IoEcProj) {
str = '4';
str += sep;
str += x.getStr(ioMode);
str += sep;
str += y.getStr(ioMode);
str += sep;
str += z.getStr(ioMode);
return;
}
EcT P(*this); EcT P(*this);
P.normalize(); P.normalize();
if (ioMode & IoEcComp) { if (ioMode & IoEcComp) {
@ -672,7 +683,6 @@ public:
str = '0'; str = '0';
return; return;
} }
const char *sep = Fp::BaseFp::getIoSeparator();
if (ioMode & IoEcCompY) { if (ioMode & IoEcCompY) {
str = P.y.isOdd() ? '3' : '2'; str = P.y.isOdd() ? '3' : '2';
str += sep; str += sep;
@ -734,6 +744,9 @@ public:
} else if (c == '2' || c == '3') { } else if (c == '2' || c == '3') {
bool isYodd = c == '3'; bool isYodd = c == '3';
getYfromX(y, x, isYodd); getYfromX(y, x, isYodd);
} else if (c == '4') {
y.readStream(is, ioMode);
z.readStream(is, ioMode);
} else { } else {
throw cybozu::Exception("EcT:readStream:bad format") << c; throw cybozu::Exception("EcT:readStream:bad format") << c;
} }

@ -280,25 +280,25 @@ struct Test {
ss >> Q; ss >> Q;
CYBOZU_TEST_EQUAL(P, Q); CYBOZU_TEST_EQUAL(P, Q);
} }
// tight // IoEcComp
if (!Ec::isIoEcCompSupported()) return; if (!Ec::isIoEcCompSupported()) return;
P.set(x, y); P.set(x, y);
{ {
std::string s = P.getStr(mcl::IoTight); std::string s = P.getStr(mcl::IoEcComp);
CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize()); CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize());
Q.setStr(s, mcl::IoTight); Q.setStr(s, mcl::IoTight);
CYBOZU_TEST_EQUAL(P, Q); CYBOZU_TEST_EQUAL(P, Q);
} }
{ {
P = -P; P = -P;
std::string s = P.getStr(mcl::IoTight); std::string s = P.getStr(mcl::IoEcComp);
CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize()); CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize());
Q.setStr(s, mcl::IoTight); Q.setStr(s, mcl::IoTight);
CYBOZU_TEST_EQUAL(P, Q); CYBOZU_TEST_EQUAL(P, Q);
} }
P.clear(); P.clear();
{ {
std::string s = P.getStr(mcl::IoTight); std::string s = P.getStr(mcl::IoEcComp);
CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize()); CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize());
CYBOZU_TEST_ASSERT(mcl::fp::isZeroArray(s.c_str(), s.size())); CYBOZU_TEST_ASSERT(mcl::fp::isZeroArray(s.c_str(), s.size()));
Q.setStr(s, mcl::IoTight); Q.setStr(s, mcl::IoTight);

Loading…
Cancel
Save