|
|
@ -170,9 +170,9 @@ public: |
|
|
|
find range which has same hash of xP in kcv_, |
|
|
|
find range which has same hash of xP in kcv_, |
|
|
|
and detect it |
|
|
|
and detect it |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int basicLog(G xP, bool *ok = 0) const |
|
|
|
int basicLog(G xP, bool *pok = 0) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (ok) *ok = true; |
|
|
|
if (pok) *pok = true; |
|
|
|
if (I::isZero(xP)) return 0; |
|
|
|
if (I::isZero(xP)) return 0; |
|
|
|
typedef KeyCountVec::const_iterator Iter; |
|
|
|
typedef KeyCountVec::const_iterator Iter; |
|
|
|
KeyCount kc; |
|
|
|
KeyCount kc; |
|
|
@ -205,8 +205,8 @@ public: |
|
|
|
prev = abs_c; |
|
|
|
prev = abs_c; |
|
|
|
++p.first; |
|
|
|
++p.first; |
|
|
|
} |
|
|
|
} |
|
|
|
if (ok) { |
|
|
|
if (pok) { |
|
|
|
*ok = false; |
|
|
|
*pok = false; |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
throw cybozu::Exception("HashTable:basicLog:not found"); |
|
|
|
throw cybozu::Exception("HashTable:basicLog:not found"); |
|
|
@ -215,11 +215,12 @@ public: |
|
|
|
compute log_P(xP) |
|
|
|
compute log_P(xP) |
|
|
|
call basicLog at most 2 * tryNum |
|
|
|
call basicLog at most 2 * tryNum |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
int64_t log(const G& xP) const |
|
|
|
int64_t log(const G& xP, bool *pok = 0) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool ok; |
|
|
|
bool ok; |
|
|
|
int c = basicLog(xP, &ok); |
|
|
|
int c = basicLog(xP, &ok); |
|
|
|
if (ok) { |
|
|
|
if (ok) { |
|
|
|
|
|
|
|
if (pok) *pok = true; |
|
|
|
return c; |
|
|
|
return c; |
|
|
|
} |
|
|
|
} |
|
|
|
G posP = xP, negP = xP; |
|
|
|
G posP = xP, negP = xP; |
|
|
@ -231,15 +232,21 @@ public: |
|
|
|
posCenter += next; |
|
|
|
posCenter += next; |
|
|
|
c = basicLog(posP, &ok); |
|
|
|
c = basicLog(posP, &ok); |
|
|
|
if (ok) { |
|
|
|
if (ok) { |
|
|
|
|
|
|
|
if (pok) *pok = true; |
|
|
|
return posCenter + c; |
|
|
|
return posCenter + c; |
|
|
|
} |
|
|
|
} |
|
|
|
I::add(negP, negP, nextP_); |
|
|
|
I::add(negP, negP, nextP_); |
|
|
|
negCenter -= next; |
|
|
|
negCenter -= next; |
|
|
|
c = basicLog(negP, &ok); |
|
|
|
c = basicLog(negP, &ok); |
|
|
|
if (ok) { |
|
|
|
if (ok) { |
|
|
|
|
|
|
|
if (pok) *pok = true; |
|
|
|
return negCenter + c; |
|
|
|
return negCenter + c; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (pok) { |
|
|
|
|
|
|
|
*pok = false; |
|
|
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
} |
|
|
|
throw cybozu::Exception("HashTable:log:not found"); |
|
|
|
throw cybozu::Exception("HashTable:log:not found"); |
|
|
|
} |
|
|
|
} |
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -683,7 +690,7 @@ public: |
|
|
|
throw cybozu::Exception("she:dec:log:not found"); |
|
|
|
throw cybozu::Exception("she:dec:log:not found"); |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
int64_t dec(const CipherTextG1& c) const |
|
|
|
int64_t dec(const CipherTextG1& c, bool *pok = 0) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (useDecG1ViaGT_) return decViaGT(c); |
|
|
|
if (useDecG1ViaGT_) return decViaGT(c); |
|
|
|
/*
|
|
|
|
/*
|
|
|
@ -694,51 +701,51 @@ public: |
|
|
|
G1 R; |
|
|
|
G1 R; |
|
|
|
G1::mul(R, c.T_, x_); |
|
|
|
G1::mul(R, c.T_, x_); |
|
|
|
G1::sub(R, c.S_, R); |
|
|
|
G1::sub(R, c.S_, R); |
|
|
|
return PhashTbl_.log(R); |
|
|
|
return PhashTbl_.log(R, pok); |
|
|
|
} |
|
|
|
} |
|
|
|
int64_t dec(const CipherTextG2& c) const |
|
|
|
int64_t dec(const CipherTextG2& c, bool *pok = 0) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (useDecG2ViaGT_) return decViaGT(c); |
|
|
|
if (useDecG2ViaGT_) return decViaGT(c); |
|
|
|
G2 R; |
|
|
|
G2 R; |
|
|
|
G2::mul(R, c.T_, y_); |
|
|
|
G2::mul(R, c.T_, y_); |
|
|
|
G2::sub(R, c.S_, R); |
|
|
|
G2::sub(R, c.S_, R); |
|
|
|
return QhashTbl_.log(R); |
|
|
|
return QhashTbl_.log(R, pok); |
|
|
|
} |
|
|
|
} |
|
|
|
int64_t dec(const CipherTextA& c) const |
|
|
|
int64_t dec(const CipherTextA& c, bool *pok = 0) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return dec(c.c1_); |
|
|
|
return dec(c.c1_, pok); |
|
|
|
} |
|
|
|
} |
|
|
|
int64_t dec(const CipherTextGT& c) const |
|
|
|
int64_t dec(const CipherTextGT& c, bool *pok = 0) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
GT v; |
|
|
|
GT v; |
|
|
|
getPowOfePQ(v, c); |
|
|
|
getPowOfePQ(v, c); |
|
|
|
return ePQhashTbl_.log(v); |
|
|
|
return ePQhashTbl_.log(v, pok); |
|
|
|
// return log(g, v);
|
|
|
|
// return log(g, v);
|
|
|
|
} |
|
|
|
} |
|
|
|
int64_t decViaGT(const CipherTextG1& c) const |
|
|
|
int64_t decViaGT(const CipherTextG1& c, bool *pok = 0) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
G1 R; |
|
|
|
G1 R; |
|
|
|
G1::mul(R, c.T_, x_); |
|
|
|
G1::mul(R, c.T_, x_); |
|
|
|
G1::sub(R, c.S_, R); |
|
|
|
G1::sub(R, c.S_, R); |
|
|
|
GT v; |
|
|
|
GT v; |
|
|
|
pairing(v, R, Q_); |
|
|
|
pairing(v, R, Q_); |
|
|
|
return ePQhashTbl_.log(v); |
|
|
|
return ePQhashTbl_.log(v, pok); |
|
|
|
} |
|
|
|
} |
|
|
|
int64_t decViaGT(const CipherTextG2& c) const |
|
|
|
int64_t decViaGT(const CipherTextG2& c, bool *pok = 0) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
G2 R; |
|
|
|
G2 R; |
|
|
|
G2::mul(R, c.T_, y_); |
|
|
|
G2::mul(R, c.T_, y_); |
|
|
|
G2::sub(R, c.S_, R); |
|
|
|
G2::sub(R, c.S_, R); |
|
|
|
GT v; |
|
|
|
GT v; |
|
|
|
pairing(v, P_, R); |
|
|
|
pairing(v, P_, R); |
|
|
|
return ePQhashTbl_.log(v); |
|
|
|
return ePQhashTbl_.log(v, pok); |
|
|
|
} |
|
|
|
} |
|
|
|
int64_t dec(const CipherText& c) const |
|
|
|
int64_t dec(const CipherText& c, bool *pok = 0) const |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (c.isMultiplied()) { |
|
|
|
if (c.isMultiplied()) { |
|
|
|
return dec(c.m_); |
|
|
|
return dec(c.m_, pok); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
return dec(c.a_); |
|
|
|
return dec(c.a_, pok); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
bool isZero(const CipherTextG1& c) const |
|
|
|
bool isZero(const CipherTextG1& c) const |
|
|
|