diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-08-23 15:14:57 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-08-23 15:14:57 +0800 |
commit | d1c59fd632b5250662e897527049bd4314043b9e (patch) | |
tree | 00c18f78352a02cee1bbc6e3c4eaa3b5b8430f48 | |
parent | 07d2febc321ff0bb287147a93c1c52b8a0d4b1ca (diff) | |
download | tangerine-mcl-d1c59fd632b5250662e897527049bd4314043b9e.tar.gz tangerine-mcl-d1c59fd632b5250662e897527049bd4314043b9e.tar.zst tangerine-mcl-d1c59fd632b5250662e897527049bd4314043b9e.zip |
change ioMode for Ec
-rw-r--r-- | include/mcl/ec.hpp | 2 | ||||
-rw-r--r-- | include/mcl/elgamal.hpp | 22 | ||||
-rw-r--r-- | test/elgamal_test.cpp | 10 |
3 files changed, 18 insertions, 16 deletions
diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index 702db29..9b8c6c5 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -741,7 +741,7 @@ public: if (c == '1') { y.readStream(is, ioMode); if (!isValid(x, y)) { - throw cybozu::Exception("EcT:readStream:bad value") << x << y; + throw cybozu::Exception("EcT:readStream:bad value") << ioMode << x << y; } } else if (c == '2' || c == '3') { bool isYodd = c == '3'; diff --git a/include/mcl/elgamal.hpp b/include/mcl/elgamal.hpp index 4e94452..c3dc371 100644 --- a/include/mcl/elgamal.hpp +++ b/include/mcl/elgamal.hpp @@ -96,12 +96,12 @@ struct ElgamalT { } friend inline std::ostream& operator<<(std::ostream& os, const CipherText& self) { - int ioMode = fp::detectIoMode(Ec::Fp::BaseFp::getIoMode(), os); + int ioMode = fp::detectIoMode(Ec::getIoMode(), os); return os << self.getStr(ioMode); } friend inline std::istream& operator>>(std::istream& is, CipherText& self) { - int ioMode = fp::detectIoMode(Ec::Fp::BaseFp::getIoMode(), is); + int ioMode = fp::detectIoMode(Ec::getIoMode(), is); return self.readStream(is, ioMode); } // obsolete @@ -148,12 +148,12 @@ struct ElgamalT { } friend inline std::ostream& operator<<(std::ostream& os, const Zkp& self) { - int ioMode = fp::detectIoMode(Ec::Fp::BaseFp::getIoMode(), os); + int ioMode = fp::detectIoMode(Zn::getIoMode(), os); return os << self.getStr(ioMode); } friend inline std::istream& operator>>(std::istream& is, Zkp& self) { - int ioMode = fp::detectIoMode(Ec::Fp::BaseFp::getIoMode(), is); + int ioMode = fp::detectIoMode(Zn::getIoMode(), is); return self.readStream(is, ioMode); } // obsolete @@ -282,9 +282,9 @@ struct ElgamalT { os << R01 << R02 << R11 << R12 << c.c1 << c.c2 << f << g << h; hash.update(os.str()); const std::string digest = hash.digest(); - Zn c; - c.setArrayMask(digest.c_str(), digest.size()); - zkp.c0 = c - zkp.c1; + Zn cc; + cc.setArrayMask(digest.c_str(), digest.size()); + zkp.c0 = cc - zkp.c1; zkp.s0 = r0 + zkp.c0 * u; } } @@ -384,12 +384,12 @@ struct ElgamalT { } friend inline std::ostream& operator<<(std::ostream& os, const PublicKey& self) { - int ioMode = fp::detectIoMode(Ec::Fp::BaseFp::getIoMode(), os); + int ioMode = fp::detectIoMode(Ec::getIoMode(), os); return os << self.getStr(ioMode); } friend inline std::istream& operator>>(std::istream& is, PublicKey& self) { - int ioMode = fp::detectIoMode(Ec::Fp::BaseFp::getIoMode(), is); + int ioMode = fp::detectIoMode(Ec::getIoMode(), is); return self.readStream(is, ioMode); } // obsolete @@ -578,12 +578,12 @@ struct ElgamalT { } friend inline std::ostream& operator<<(std::ostream& os, const PrivateKey& self) { - int ioMode = fp::detectIoMode(Ec::Fp::BaseFp::getIoMode(), os); + int ioMode = fp::detectIoMode(Ec::getIoMode(), os); return os << self.getStr(ioMode); } friend inline std::istream& operator>>(std::istream& is, PrivateKey& self) { - int ioMode = fp::detectIoMode(Ec::Fp::BaseFp::getIoMode(), is); + int ioMode = fp::detectIoMode(Ec::getIoMode(), is); return self.readStream(is, ioMode); } std::string toStr() const { return getStr(); } diff --git a/test/elgamal_test.cpp b/test/elgamal_test.cpp index 7da303c..225ccee 100644 --- a/test/elgamal_test.cpp +++ b/test/elgamal_test.cpp @@ -83,10 +83,12 @@ CYBOZU_TEST_AUTO(testEc) prv.dec(dec1, c1); CYBOZU_TEST_EQUAL(dec1, m1 + m2); // enc(m1) x = enc(m1 + x) - const int x = 555; - pub.add(c1, x); - prv.dec(dec1, c1); - CYBOZU_TEST_EQUAL(dec1, m1 + m2 + x); + { + const int x = 555; + pub.add(c1, x); + prv.dec(dec1, c1); + CYBOZU_TEST_EQUAL(dec1, m1 + m2 + x); + } // rerandomize c1 = c2; pub.rerandomize(c1, rg); |