diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-09-28 16:42:06 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-09-28 16:42:06 +0800 |
commit | d0696009d77ac010aa5a6c4419734092bdfa847e (patch) | |
tree | 4bae6915e383b8c267a7fb149cbc57a261225aec | |
parent | 69cee3394c742f8c5d4df5a7df9fe2a802bdc708 (diff) | |
download | dexon-mcl-d0696009d77ac010aa5a6c4419734092bdfa847e.tar.gz dexon-mcl-d0696009d77ac010aa5a6c4419734092bdfa847e.tar.zst dexon-mcl-d0696009d77ac010aa5a6c4419734092bdfa847e.zip |
support int64_t for G::pow
-rw-r--r-- | include/mcl/ec.hpp | 9 | ||||
-rw-r--r-- | include/mcl/operator.hpp | 9 | ||||
-rw-r--r-- | include/mcl/she.hpp | 12 | ||||
-rw-r--r-- | include/mcl/vint.hpp | 13 | ||||
-rw-r--r-- | include/mcl/window_method.hpp | 3 |
5 files changed, 34 insertions, 12 deletions
diff --git a/include/mcl/ec.hpp b/include/mcl/ec.hpp index 2001654..91508d2 100644 --- a/include/mcl/ec.hpp +++ b/include/mcl/ec.hpp @@ -586,10 +586,17 @@ public: y.getBlock(b); mulArray(z, x, b.p, b.n, false); } - static inline void mul(EcT& z, const EcT& x, int y) + static inline void mul(EcT& z, const EcT& x, int64_t y) { +#if MCL_SIZEOF_UNIT == 8 const fp::Unit u = abs(y); mulArray(z, x, &u, 1, y < 0); +#else + uint64_t ua = std::abs(y); + Unit u[2] = { uint32_t(ua), uint32_t(ua >> 32) }; + size_t un = u[1] ? 2 : 1; + mulArray(z, u, un, y < 0); +#endif } static inline void mul(EcT& z, const EcT& x, const mpz_class& y) { diff --git a/include/mcl/operator.hpp b/include/mcl/operator.hpp index 5f78911..c14c9d1 100644 --- a/include/mcl/operator.hpp +++ b/include/mcl/operator.hpp @@ -61,10 +61,17 @@ struct Operator : E { y.getBlock(b); powArray(z, x, b.p, b.n, false, true); } - static void pow(T& z, const T& x, int y) + static void pow(T& z, const T& x, int64_t y) { +#if MCL_SIZEOF_UNIT == 8 const Unit u = abs(y); powArray(z, x, &u, 1, y < 0, false); +#else + uint64_t ua = std::abs(y); + Unit u[2] = { uint32_t(ua), uint32_t(ua >> 32) }; + size_t un = u[1] ? 2 : 1; + powArray(z, x, u, un, y < 0, false); +#endif } static void pow(T& z, const T& x, const mpz_class& y) { diff --git a/include/mcl/she.hpp b/include/mcl/she.hpp index d304ef1..c6bfc1d 100644 --- a/include/mcl/she.hpp +++ b/include/mcl/she.hpp @@ -87,7 +87,7 @@ struct InterfaceForHashTable : G { static void dbl(G& Q, const G& P) { G::dbl(Q, P); } static void neg(G& Q, const G& P) { G::neg(Q, P); } static void add(G& R, const G& P, const G& Q) { G::add(R, P, Q); } - static void mul(G& Q, const G& P, int x) { G::mul(Q, P, x); } + static void mul(G& Q, const G& P, int64_t x) { G::mul(Q, P, x); } }; /* @@ -110,7 +110,7 @@ struct InterfaceForHashTable<G, false> : G { static void dbl(G& y, const G& x) { G::sqr(y, x); } static void neg(G& Q, const G& P) { G::unitaryInv(Q, P); } static void add(G& z, const G& x, const G& y) { G::mul(z, x, y); } - static void mul(G& z, const G& x, int y) { G::pow(z, x, y); } + static void mul(G& z, const G& x, int64_t y) { G::pow(z, x, y); } }; /* @@ -371,7 +371,7 @@ private: G::sub(z.S_, x.S_, y.S_); G::sub(z.T_, x.T_, y.T_); } - static void mul(CipherTextAT& z, const CipherTextAT& x, int y) + static void mul(CipherTextAT& z, const CipherTextAT& x, int64_t y) { G::mul(z.S_, x.S_, y); G::mul(z.T_, x.T_, y); @@ -873,7 +873,7 @@ public: CipherTextG1::sub(z.c1_, x.c1_, y.c1_); CipherTextG2::sub(z.c2_, x.c2_, y.c2_); } - static void mul(CipherTextA& z, const CipherTextA& x, int y) + static void mul(CipherTextA& z, const CipherTextA& x, int64_t y) { CipherTextG1::mul(z.c1_, x.c1_, y); CipherTextG2::mul(z.c2_, x.c2_, y); @@ -967,7 +967,7 @@ public: { mul(z, x.c1_, y.c2_); } - static void mul(CipherTextM& z, const CipherTextM& x, int y) + static void mul(CipherTextM& z, const CipherTextM& x, int64_t y) { for (int i = 0; i < 4; i++) { GT::pow(z.g_[i], x.g_[i], y); @@ -1075,7 +1075,7 @@ public: z.isMultiplied_ = true; CipherTextM::mul(z.m_, x.a_, y.a_); } - static void mul(CipherText& z, const CipherText& x, int y) + static void mul(CipherText& z, const CipherText& x, int64_t y) { if (x.isMultiplied()) { CipherTextM::mul(z.m_, x.m_, y); diff --git a/include/mcl/vint.hpp b/include/mcl/vint.hpp index 2a3cd81..d1b1648 100644 --- a/include/mcl/vint.hpp +++ b/include/mcl/vint.hpp @@ -1586,13 +1586,20 @@ public: z = 1; mcl::fp::powGeneric(z, xx, &y.buf_[0], y.size(), mul, sqr, (void (*)(VintT&, const VintT&))0); } - static void pow(VintT& z, const VintT& x, int y) + static void pow(VintT& z, const VintT& x, int64_t y) { if (y < 0) throw cybozu::Exception("Vint::pow:negative y") << y; const VintT xx = x; - Unit absY = std::abs(y); z = 1; - mcl::fp::powGeneric(z, xx, &absY, 1, mul, sqr, (void (*)(VintT&, const VintT&))0); +#if MCL_SIZEOF_UNIT == 8 + Unit ua = std::abs(y); + mcl::fp::powGeneric(z, xx, &ua, 1, mul, sqr, (void (*)(VintT&, const VintT&))0); +#else + uint64_t ua = std::abs(y); + Unit u[2] = { uint32_t(ua), uint32_t(ua >> 32) }; + size_t un = u[1] ? 2 : 1; + mcl::fp::powGeneric(z, xx, u, un, mul, sqr, (void (*)(VintT&, const VintT&))0); +#endif } /* z = x ^ y mod m diff --git a/include/mcl/window_method.hpp b/include/mcl/window_method.hpp index 433578a..1393485 100644 --- a/include/mcl/window_method.hpp +++ b/include/mcl/window_method.hpp @@ -129,7 +129,8 @@ public: #else uint64_t ua = std::abs(y); Unit u[2] = { uint32_t(ua), uint32_t(ua >> 32) }; - powArray(z, u, 2, y < 0); + size_t un = u[1] ? 2 : 1; + powArray(z, u, un, y < 0); #endif } void mul(Ec& z, const mpz_class& y) const |