change int64_t to int

dev
MITSUNARI Shigeo 8 years ago
parent e98e8ce299
commit c5121c66e8
  1. 40
      include/mcl/bgn.hpp

@ -48,23 +48,24 @@ public:
/* /*
compute log_P(xP) for |x| <= hashSize * tryNum compute log_P(xP) for |x| <= hashSize * tryNum
*/ */
void init(const G& P, int hashSize, size_t tryNum = 0) void init(const G& P, size_t hashSize, size_t tryNum = 0)
{ {
if (hashSize == 0) { if (hashSize == 0) {
kcv.clear(); kcv.clear();
return; return;
} }
if (hashSize >= 0x80000000u) throw cybozu::Exception("EcHashTable:init:hashSize is too large");
this->P = P; this->P = P;
this->hashSize = hashSize; this->hashSize = (int)hashSize;
this->tryNum = tryNum; this->tryNum = tryNum;
kcv.resize(hashSize); kcv.resize(hashSize);
G xP; G xP;
xP.clear(); xP.clear();
for (int i = 1; i <= hashSize; i++) { for (size_t i = 1; i <= (int)hashSize; i++) {
xP += P; xP += P;
xP.normalize(); xP.normalize();
kcv[i - 1].key = uint32_t(*xP.x.getUnit()); kcv[i - 1].key = uint32_t(*xP.x.getUnit());
kcv[i - 1].count = xP.y.isOdd() ? i : -i; kcv[i - 1].count = xP.y.isOdd() ? i : -1;
} }
nextP = xP; nextP = xP;
G::dbl(nextP, nextP); G::dbl(nextP, nextP);
@ -121,7 +122,7 @@ 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 int log(const G& xP) const
{ {
bool ok; bool ok;
int c = basicLog(xP, &ok); int c = basicLog(xP, &ok);
@ -129,9 +130,9 @@ public:
return c; return c;
} }
G posP = xP, negP = xP; G posP = xP, negP = xP;
int64_t posCenter = 0; int posCenter = 0;
int64_t negCenter = 0; int negCenter = 0;
int64_t next = hashSize * 2 + 1; int next = hashSize * 2 + 1;
for (size_t i = 1; i < tryNum; i++) { for (size_t i = 1; i < tryNum; i++) {
posP -= nextP; posP -= nextP;
posCenter += next; posCenter += next;
@ -164,18 +165,19 @@ public:
/* /*
compute log_P(g^x) for |x| <= hashSize * tryNum compute log_P(g^x) for |x| <= hashSize * tryNum
*/ */
void init(const GT& g, int hashSize, size_t tryNum = 0) void init(const GT& g, size_t hashSize, size_t tryNum = 0)
{ {
if (hashSize == 0) { if (hashSize == 0) {
kcv.clear(); kcv.clear();
return; return;
} }
if (hashSize >= 0x80000000u) throw cybozu::Exception("GTHashTable:init:hashSize is too large");
this->g = g; this->g = g;
this->hashSize = hashSize; this->hashSize = (int)hashSize;
this->tryNum = tryNum; this->tryNum = tryNum;
kcv.resize(hashSize); kcv.resize(hashSize);
GT gx = 1; GT gx = 1;
for (int i = 1; i <= hashSize; i++) { for (int i = 1; i <= (int)hashSize; i++) {
gx *= g; gx *= g;
kcv[i - 1].key = uint32_t(*gx.getFp0()->getUnit()); kcv[i - 1].key = uint32_t(*gx.getFp0()->getUnit());
kcv[i - 1].count = gx.b.a.a.isOdd() ? i : -i; kcv[i - 1].count = gx.b.a.a.isOdd() ? i : -i;
@ -233,7 +235,7 @@ public:
compute log_P(g^x) compute log_P(g^x)
call basicLog at most 2 * tryNum call basicLog at most 2 * tryNum
*/ */
int64_t log(const GT& gx) const int log(const GT& gx) const
{ {
bool ok; bool ok;
int c = basicLog(gx, &ok); int c = basicLog(gx, &ok);
@ -241,9 +243,9 @@ public:
return c; return c;
} }
GT pos = gx, neg = gx; GT pos = gx, neg = gx;
int64_t posCenter = 0; int posCenter = 0;
int64_t negCenter = 0; int negCenter = 0;
int64_t next = hashSize * 2 + 1; int next = hashSize * 2 + 1;
for (size_t i = 1; i < tryNum; i++) { for (size_t i = 1; i < tryNum; i++) {
pos *= nextgInv; pos *= nextgInv;
posCenter += next; posCenter += next;
@ -484,7 +486,7 @@ public:
throw cybozu::Exception("BGN:dec:log:not found"); throw cybozu::Exception("BGN:dec:log:not found");
} }
#endif #endif
int64_t dec(const CipherTextG1& c) const int dec(const CipherTextG1& c) const
{ {
/* /*
S = myP + rP S = myP + rP
@ -496,11 +498,11 @@ public:
R -= c.T; R -= c.T;
return g1HashTbl.log(R); return g1HashTbl.log(R);
} }
int64_t dec(const CipherTextA& c) const int dec(const CipherTextA& c) const
{ {
return dec(c.c1); return dec(c.c1);
} }
int64_t dec(const CipherTextM& c) const int dec(const CipherTextM& c) const
{ {
/* /*
(s, t, u, v) := (e(S, S'), e(S, T'), e(T, S'), e(T, T')) (s, t, u, v) := (e(S, S'), e(S, T'), e(T, S'), e(T, T'))
@ -522,7 +524,7 @@ public:
return gtHashTbl.log(s); return gtHashTbl.log(s);
// return log(g, s); // return log(g, s);
} }
int64_t dec(const CipherText& c) const int dec(const CipherText& c) const
{ {
if (c.isMultiplied()) { if (c.isMultiplied()) {
return dec(c.m); return dec(c.m);

Loading…
Cancel
Save