diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index ab4d2bc..3fa361a 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -652,6 +652,17 @@ public: */ 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); P.normalize(); if (ioMode & IoEcComp) { @@ -672,7 +683,6 @@ public: str = '0'; return; } - const char *sep = Fp::BaseFp::getIoSeparator(); if (ioMode & IoEcCompY) { str = P.y.isOdd() ? '3' : '2'; str += sep; @@ -734,6 +744,9 @@ public: } else if (c == '2' || c == '3') { bool isYodd = c == '3'; getYfromX(y, x, isYodd); + } else if (c == '4') { + y.readStream(is, ioMode); + z.readStream(is, ioMode); } else { throw cybozu::Exception("EcT:readStream:bad format") << c; } diff --git a/test/ec_test.cpp b/test/ec_test.cpp index 6cc3255..421979b 100644 --- a/test/ec_test.cpp +++ b/test/ec_test.cpp @@ -280,25 +280,25 @@ struct Test { ss >> Q; CYBOZU_TEST_EQUAL(P, Q); } - // tight + // IoEcComp if (!Ec::isIoEcCompSupported()) return; 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()); Q.setStr(s, mcl::IoTight); CYBOZU_TEST_EQUAL(P, Q); } { P = -P; - std::string s = P.getStr(mcl::IoTight); + std::string s = P.getStr(mcl::IoEcComp); CYBOZU_TEST_EQUAL(s.size(), Fp::getByteSize()); Q.setStr(s, mcl::IoTight); CYBOZU_TEST_EQUAL(P, Q); } 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_ASSERT(mcl::fp::isZeroArray(s.c_str(), s.size())); Q.setStr(s, mcl::IoTight);