diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-09-25 14:04:05 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-09-25 14:04:05 +0800 |
commit | 60e92db5d8ac00a80267d79867fdbef9ef1dcfe9 (patch) | |
tree | 8e2e911cd372030ba0b956769cd905f595255983 | |
parent | 9d93ce1c511b2a534d46c22acca94029136a5195 (diff) | |
download | dexon-mcl-60e92db5d8ac00a80267d79867fdbef9ef1dcfe9.tar.gz dexon-mcl-60e92db5d8ac00a80267d79867fdbef9ef1dcfe9.tar.zst dexon-mcl-60e92db5d8ac00a80267d79867fdbef9ef1dcfe9.zip |
[generic] disable XBYAK if sizeof(Unit) == 4
-rw-r--r-- | include/mcl/op.hpp | 2 | ||||
-rw-r--r-- | include/mcl/she.hpp | 38 | ||||
-rw-r--r-- | include/mcl/window_method.hpp | 8 | ||||
-rw-r--r-- | test/she_test.cpp | 7 |
4 files changed, 34 insertions, 21 deletions
diff --git a/include/mcl/op.hpp b/include/mcl/op.hpp index b5d7045..eb9dfbe 100644 --- a/include/mcl/op.hpp +++ b/include/mcl/op.hpp @@ -15,7 +15,7 @@ #define MCL_DONT_USE_XBYAK #define MCL_DONT_USE_OPENSSL #endif -#if !defined(MCL_DONT_USE_XBYAK) && (defined(_WIN64) || defined(__x86_64__)) +#if !defined(MCL_DONT_USE_XBYAK) && (defined(_WIN64) || defined(__x86_64__)) && (MCL_SIZEOF_UNIT == 8) #define MCL_USE_XBYAK #endif diff --git a/include/mcl/she.hpp b/include/mcl/she.hpp index 3c32cdd..a7f2550 100644 --- a/include/mcl/she.hpp +++ b/include/mcl/she.hpp @@ -244,7 +244,7 @@ public: compute log_P(xP) call basicLog at most 2 * tryNum */ - int log(const G& xP) const + int64_t log(const G& xP) const { bool ok; int c = basicLog(xP, &ok); @@ -252,9 +252,9 @@ public: return c; } G posP = xP, negP = xP; - int posCenter = 0; - int negCenter = 0; - int next = (int)kcv.size() * 2 + 1; + int64_t posCenter = 0; + int64_t negCenter = 0; + int64_t next = (int64_t)kcv.size() * 2 + 1; for (size_t i = 1; i < tryNum_; i++) { I::add(posP, posP, nextNegP_); posCenter += next; @@ -530,7 +530,7 @@ public: throw cybozu::Exception("she:dec:log:not found"); } #endif - int dec(const CipherTextG1& c) const + int64_t dec(const CipherTextG1& c) const { /* S = mP + rxP @@ -542,11 +542,11 @@ public: G1::sub(R, c.S_, R); return PhashTbl_.log(R); } - int dec(const CipherTextA& c) const + int64_t dec(const CipherTextA& c) const { return dec(c.c1_); } - int dec(const CipherTextM& c) const + int64_t dec(const CipherTextM& c) const { /* (s, t, u, v) := (e(S, S'), e(S, T'), e(T, S'), e(T, T')) @@ -566,7 +566,7 @@ public: return ePQhashTbl_.log(v); // return log(g, v); } - int dec(const CipherText& c) const + int64_t dec(const CipherText& c) const { if (c.isMultiplied()) { return dec(c.m_); @@ -621,7 +621,7 @@ public: (S, T) = (m P + r xP, rP) */ template<class G, class RG, class I> - static void enc1(G& S, G& T, const G& /*P*/, const G& xP, int m, RG& rg, const mcl::fp::WindowMethod<I>& wm) + static void enc1(G& S, G& T, const G& /*P*/, const G& xP, int64_t m, RG& rg, const mcl::fp::WindowMethod<I>& wm) { Fr r; r.setRand(rg); @@ -641,23 +641,23 @@ public: } public: template<class RG> - void enc(CipherTextG1& c, int m, RG& rg) const + void enc(CipherTextG1& c, int64_t m, RG& rg) const { enc1(c.S_, c.T_, P_, xP_, m, rg, PhashTbl_.getWM()); } template<class RG> - void enc(CipherTextG2& c, int m, RG& rg) const + void enc(CipherTextG2& c, int64_t m, RG& rg) const { enc1(c.S_, c.T_, Q_, yQ_, m, rg, Qwm_); } template<class RG> - void enc(CipherTextA& c, int m, RG& rg) const + void enc(CipherTextA& c, int64_t m, RG& rg) const { enc(c.c1_, m, rg); enc(c.c2_, m, rg); } template<class RG> - void enc(CipherTextM& c, int m, RG& rg) const + void enc(CipherTextM& c, int64_t m, RG& rg) const { /* (s, t, u, v) = ((e^x)^a (e^y)^b (e^-xy)^c e^m, e^b, e^a, e^c) @@ -704,7 +704,7 @@ public: #endif } template<class RG> - void enc(CipherText& c, int m, RG& rg, bool multiplied = false) const + void enc(CipherText& c, int64_t m, RG& rg, bool multiplied = false) const { c.isMultiplied_ = multiplied; if (multiplied) { @@ -713,11 +713,11 @@ public: enc(c.a_, m, rg); } } - void enc(CipherTextG1& c, int m) const { return enc(c, m, local::g_rg); } - void enc(CipherTextG2& c, int m) const { return enc(c, m, local::g_rg); } - void enc(CipherTextA& c, int m) const { return enc(c, m, local::g_rg); } - void enc(CipherTextM& c, int m) const { return enc(c, m, local::g_rg); } - void enc(CipherText& c, int m, bool multiplied = false) const { return enc(c, m, local::g_rg, multiplied); } + void enc(CipherTextG1& c, int64_t m) const { return enc(c, m, local::g_rg); } + void enc(CipherTextG2& c, int64_t m) const { return enc(c, m, local::g_rg); } + void enc(CipherTextA& c, int64_t m) const { return enc(c, m, local::g_rg); } + void enc(CipherTextM& c, int64_t m) const { return enc(c, m, local::g_rg); } + void enc(CipherText& c, int64_t m, bool multiplied = false) const { return enc(c, m, local::g_rg, multiplied); } /* convert from CipherTextG1 to CipherTextM */ diff --git a/include/mcl/window_method.hpp b/include/mcl/window_method.hpp index 13d9721..433578a 100644 --- a/include/mcl/window_method.hpp +++ b/include/mcl/window_method.hpp @@ -121,10 +121,16 @@ public: y.getBlock(b); powArray(z, b.p, b.n, false); } - void mul(Ec& z, int y) const + void mul(Ec& z, int64_t y) const { +#if MCL_SIZEOF_UNIT == 8 Unit u = std::abs(y); powArray(z, &u, 1, y < 0); +#else + uint64_t ua = std::abs(y); + Unit u[2] = { uint32_t(ua), uint32_t(ua >> 32) }; + powArray(z, u, 2, y < 0); +#endif } void mul(Ec& z, const mpz_class& y) const { diff --git a/test/she_test.cpp b/test/she_test.cpp index 2c0ba59..8110bea 100644 --- a/test/she_test.cpp +++ b/test/she_test.cpp @@ -295,6 +295,13 @@ CYBOZU_TEST_AUTO(hashBench) printf("i=%2d dec(c2)=%08x ", i, expect); CYBOZU_BENCH_C("dec", 100, sec.dec, c2); } + // larger than int32_t + int64_t mTbl[] = { -0x80000003ll, 0x80000000ll, 0x80000005ll }; + for (size_t i = 0; i < CYBOZU_NUM_OF_ARRAY(mTbl); i++) { + int64_t m = mTbl[i]; + pub.enc(c1, m); + CYBOZU_TEST_EQUAL(sec.dec(c1), m); + } } G1 P, P2; |