remove visual studio warnings

pull/2/head
MITSUNARI Shigeo 6 years ago
parent 8cbdc129f6
commit 26260f5985
  1. 18
      include/mcl/ec.hpp
  2. 26
      test/elgamal_test.cpp

@ -731,18 +731,18 @@ public:
if (ioMode & (IoSerialize | IoSerializeHexStr)) { if (ioMode & (IoSerialize | IoSerializeHexStr)) {
const size_t n = Fp::getByteSize(); const size_t n = Fp::getByteSize();
const size_t adj = isMSBserialize() ? 0 : 1; const size_t adj = isMSBserialize() ? 0 : 1;
char buf[sizeof(Fp) + 1]; uint8_t buf[sizeof(Fp) + 1];
if (Fp::BaseFp::isETHserialization()) { if (Fp::BaseFp::isETHserialization()) {
const char c_flag = 0x80; const uint8_t c_flag = 0x80;
const char b_flag = 0x40; const uint8_t b_flag = 0x40;
const char a_flag = 0x20; const uint8_t a_flag = 0x20;
if (P.isZero()) { if (P.isZero()) {
buf[0] = c_flag | b_flag; buf[0] = c_flag | b_flag;
memset(buf + 1, 0, n - 1); memset(buf + 1, 0, n - 1);
} else { } else {
cybozu::MemoryOutputStream mos(buf, n); cybozu::MemoryOutputStream mos(buf, n);
P.x.save(pb, mos, IoSerialize); if (!*pb) return; P.x.save(pb, mos, IoSerialize); if (!*pb) return;
char cba = c_flag; uint8_t cba = c_flag;
if (ec::local::get_a_flag(P.y)) cba |= a_flag; if (ec::local::get_a_flag(P.y)) cba |= a_flag;
buf[0] |= cba; buf[0] |= cba;
} }
@ -815,7 +815,7 @@ public:
const size_t n = Fp::getByteSize(); const size_t n = Fp::getByteSize();
const size_t adj = isMSBserialize() ? 0 : 1; const size_t adj = isMSBserialize() ? 0 : 1;
const size_t n1 = n + adj; const size_t n1 = n + adj;
char buf[sizeof(Fp) + 1]; uint8_t buf[sizeof(Fp) + 1];
size_t readSize; size_t readSize;
if (ioMode & IoSerializeHexStr) { if (ioMode & IoSerializeHexStr) {
readSize = mcl::fp::readHexStr(buf, n1, is); readSize = mcl::fp::readHexStr(buf, n1, is);
@ -827,9 +827,9 @@ public:
return; return;
} }
if (Fp::BaseFp::isETHserialization()) { if (Fp::BaseFp::isETHserialization()) {
const char c_flag = 0x80; const uint8_t c_flag = 0x80;
const char b_flag = 0x40; const uint8_t b_flag = 0x40;
const char a_flag = 0x20; const uint8_t a_flag = 0x20;
*pb = false; *pb = false;
if ((buf[0] & c_flag) == 0) { // assume compressed if ((buf[0] & c_flag) == 0) { // assume compressed
return; return;

@ -11,7 +11,7 @@ typedef mcl::EcT<Fp> Ec;
typedef mcl::ElgamalT<Ec, Zn> ElgamalEc; typedef mcl::ElgamalT<Ec, Zn> ElgamalEc;
const mcl::EcParam& para = mcl::ecparam::secp192k1; const mcl::EcParam& para = mcl::ecparam::secp192k1;
cybozu::RandomGenerator rg; cybozu::RandomGenerator g_rg;
CYBOZU_TEST_AUTO(testEc) CYBOZU_TEST_AUTO(testEc)
{ {
@ -26,15 +26,15 @@ CYBOZU_TEST_AUTO(testEc)
Zn = <P> Zn = <P>
*/ */
ElgamalEc::PrivateKey prv; ElgamalEc::PrivateKey prv;
prv.init(P, bitSize, rg); prv.init(P, bitSize, g_rg);
prv.setCache(0, 60000); prv.setCache(0, 60000);
const ElgamalEc::PublicKey& pub = prv.getPublicKey(); const ElgamalEc::PublicKey& pub = prv.getPublicKey();
const int m1 = 12345; const int m1 = 12345;
const int m2 = 17655; const int m2 = 17655;
ElgamalEc::CipherText c1, c2; ElgamalEc::CipherText c1, c2;
pub.enc(c1, m1, rg); pub.enc(c1, m1, g_rg);
pub.enc(c2, m2, rg); pub.enc(c2, m2, g_rg);
Zn dec1, dec2; Zn dec1, dec2;
prv.dec(dec1, c1); prv.dec(dec1, c1);
prv.dec(dec2, c2); prv.dec(dec2, c2);
@ -69,7 +69,7 @@ CYBOZU_TEST_AUTO(testEc)
ss << pub; ss << pub;
ss >> pub2; ss >> pub2;
} }
pub2.enc(cc2, m2, rg); pub2.enc(cc2, m2, g_rg);
prv.dec(d, cc2); prv.dec(d, cc2);
CYBOZU_TEST_EQUAL(d, m2); CYBOZU_TEST_EQUAL(d, m2);
} }
@ -86,7 +86,7 @@ CYBOZU_TEST_AUTO(testEc)
} }
// rerandomize // rerandomize
c1 = c2; c1 = c2;
pub.rerandomize(c1, rg); pub.rerandomize(c1, g_rg);
// verify c1 != c2 // verify c1 != c2
CYBOZU_TEST_ASSERT(c1.c1 != c2.c1); CYBOZU_TEST_ASSERT(c1.c1 != c2.c1);
CYBOZU_TEST_ASSERT(c1.c2 != c2.c2); CYBOZU_TEST_ASSERT(c1.c2 != c2.c2);
@ -98,7 +98,7 @@ CYBOZU_TEST_AUTO(testEc)
{ {
ElgamalEc::CipherText c; ElgamalEc::CipherText c;
Zn m = 1234; Zn m = 1234;
pub.enc(c, m, rg); pub.enc(c, m, g_rg);
c.neg(); c.neg();
Zn dec; Zn dec;
prv.dec(dec, c); prv.dec(dec, c);
@ -109,7 +109,7 @@ CYBOZU_TEST_AUTO(testEc)
ElgamalEc::CipherText c; ElgamalEc::CipherText c;
Zn m = 123; Zn m = 123;
int x = 111; int x = 111;
pub.enc(c, m, rg); pub.enc(c, m, g_rg);
Zn dec; Zn dec;
prv.dec(dec, c); prv.dec(dec, c);
c.mul(x); c.mul(x);
@ -122,7 +122,7 @@ CYBOZU_TEST_AUTO(testEc)
for (int i = -10; i < 10; i++) { for (int i = -10; i < 10; i++) {
ElgamalEc::CipherText c; ElgamalEc::CipherText c;
const Zn mm = i; const Zn mm = i;
pub.enc(c, mm, rg); pub.enc(c, mm, g_rg);
Zn dec; Zn dec;
prv.dec(dec, c, 1000); prv.dec(dec, c, 1000);
CYBOZU_TEST_EQUAL(dec, mm); CYBOZU_TEST_EQUAL(dec, mm);
@ -131,7 +131,7 @@ CYBOZU_TEST_AUTO(testEc)
// isZeroMessage // isZeroMessage
for (int m = 0; m < 10; m++) { for (int m = 0; m < 10; m++) {
ElgamalEc::CipherText c0; ElgamalEc::CipherText c0;
pub.enc(c0, m, rg); pub.enc(c0, m, g_rg);
if (m == 0) { if (m == 0) {
CYBOZU_TEST_ASSERT(prv.isZeroMessage(c0)); CYBOZU_TEST_ASSERT(prv.isZeroMessage(c0));
} else { } else {
@ -142,14 +142,14 @@ CYBOZU_TEST_AUTO(testEc)
{ {
ElgamalEc::Zkp zkp; ElgamalEc::Zkp zkp;
ElgamalEc::CipherText c; ElgamalEc::CipherText c;
pub.encWithZkp(c, zkp, 0, rg); pub.encWithZkp(c, zkp, 0, g_rg);
CYBOZU_TEST_ASSERT(pub.verify(c, zkp)); CYBOZU_TEST_ASSERT(pub.verify(c, zkp));
zkp.s0 += 1; zkp.s0 += 1;
CYBOZU_TEST_ASSERT(!pub.verify(c, zkp)); CYBOZU_TEST_ASSERT(!pub.verify(c, zkp));
pub.encWithZkp(c, zkp, 1, rg); pub.encWithZkp(c, zkp, 1, g_rg);
CYBOZU_TEST_ASSERT(pub.verify(c, zkp)); CYBOZU_TEST_ASSERT(pub.verify(c, zkp));
zkp.s0 += 1; zkp.s0 += 1;
CYBOZU_TEST_ASSERT(!pub.verify(c, zkp)); CYBOZU_TEST_ASSERT(!pub.verify(c, zkp));
CYBOZU_TEST_EXCEPTION_MESSAGE(pub.encWithZkp(c, zkp, 2, rg), cybozu::Exception, "encWithZkp"); CYBOZU_TEST_EXCEPTION_MESSAGE(pub.encWithZkp(c, zkp, 2, g_rg), cybozu::Exception, "encWithZkp");
} }
} }

Loading…
Cancel
Save