change ioMode for Ec

dev
MITSUNARI Shigeo 7 years ago
parent 07d2febc32
commit d1c59fd632
  1. 2
      include/mcl/ec.hpp
  2. 22
      include/mcl/elgamal.hpp
  3. 10
      test/elgamal_test.cpp

@ -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';

@ -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(); }

@ -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);

Loading…
Cancel
Save