she ; add isZero

dev
MITSUNARI Shigeo 7 years ago
parent db9488e061
commit cbe02b4961
  1. 65
      include/mcl/she.hpp
  2. 7
      test/she_test.cpp

@ -354,6 +354,12 @@ private:
friend class PrecomputedPublicKey;
friend class CipherTextA;
friend class CipherTextGT;
bool isZero(const Fr& x) const
{
G xT;
G::mul(xT, T_, x);
return S_ == xT;
}
public:
void clear()
{
@ -505,6 +511,23 @@ public:
*/
class SecretKey {
Fr x_, y_;
void getPowOfePQ(GT& v, const CipherTextGT& c) const
{
/*
(s, t, u, v) := (e(S, S'), e(S, T'), e(T, S'), e(T, T'))
s v^(xy) / (t^y u^x) = s (v^x / t) ^ y / u^x
= e(P, Q)^(mm')
*/
GT t, u;
GT::unitaryInv(t, c.g_[1]);
GT::unitaryInv(u, c.g_[2]);
GT::pow(v, c.g_[3], x_);
v *= t;
GT::pow(v, v, y_);
GT::pow(u, u, x_);
v *= u;
v *= c.g_[0];
}
public:
template<class RG>
void setByCSPRNG(RG& rg)
@ -564,20 +587,8 @@ public:
}
int64_t dec(const CipherTextGT& c) const
{
/*
(s, t, u, v) := (e(S, S'), e(S, T'), e(T, S'), e(T, T'))
s v^(xy) / (t^y u^x) = s (v^x / t) ^ y / u^x
= e(P, Q)^(mm')
*/
GT t, u, v;
GT::unitaryInv(t, c.g_[1]);
GT::unitaryInv(u, c.g_[2]);
GT::pow(v, c.g_[3], x_);
v *= t;
GT::pow(v, v, y_);
GT::pow(u, u, x_);
v *= u;
v *= c.g_[0];
GT v;
getPowOfePQ(v, c);
return ePQhashTbl_.log(v);
// return log(g, v);
}
@ -589,6 +600,32 @@ public:
return dec(c.a_);
}
}
bool isZero(const CipherTextG1& c) const
{
return c.isZero(x_);
}
bool isZero(const CipherTextG2& c) const
{
return c.isZero(y_);
}
bool isZero(const CipherTextA& c) const
{
return c.c1_.isZero(x_);
}
bool isZero(const CipherTextGT& c) const
{
GT v;
getPowOfePQ(v, c);
return v.isOne();
}
bool isZero(const CipherText& c) const
{
if (c.isMultiplied()) {
return isZero(c.m_);
} else {
return isZero(c.a_);
}
}
std::istream& readStream(std::istream& is, int ioMode)
{
x_.readStream(is, ioMode);

@ -95,17 +95,22 @@ CYBOZU_TEST_AUTO(enc_dec)
PrecomputedPublicKey ppub;
ppub.init(pub);
CipherTextG1 c1;
CipherTextG1 c2;
CipherTextG2 c2;
CipherTextGT ct1, ct2;
for (int i = -5; i < 5; i++) {
pub.enc(ct1, i);
CYBOZU_TEST_EQUAL(sec.dec(ct1), i);
CYBOZU_TEST_EQUAL(sec.isZero(ct1), i == 0);
ppub.enc(ct2, i);
CYBOZU_TEST_EQUAL(sec.dec(ct2), i);
ppub.enc(c1, i);
CYBOZU_TEST_EQUAL(sec.dec(c1), i);
CYBOZU_TEST_EQUAL(sec.isZero(c1), i == 0);
ppub.enc(c2, i);
CYBOZU_TEST_EQUAL(sec.dec(c2), i);
CYBOZU_TEST_EQUAL(sec.isZero(c2), i == 0);
pub.enc(c, i);
CYBOZU_TEST_EQUAL(sec.isZero(c), i == 0);
}
}

Loading…
Cancel
Save