diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2017-07-21 10:02:04 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2017-07-21 10:02:04 +0800 |
commit | 54f67cadaa6314ee5b87e757491bf00d2270c893 (patch) | |
tree | 9c7d80efabeab2ee98ff8e14dd8122602df78d21 | |
parent | f7b648200381a9dd3d2f648b0b003a0beb085c4d (diff) | |
download | dexon-mcl-54f67cadaa6314ee5b87e757491bf00d2270c893.tar.gz dexon-mcl-54f67cadaa6314ee5b87e757491bf00d2270c893.tar.zst dexon-mcl-54f67cadaa6314ee5b87e757491bf00d2270c893.zip |
setRangeForDLP does not depend on secretkey
-rw-r--r-- | include/mcl/bgn.hpp | 87 | ||||
-rw-r--r-- | test/bgn_test.cpp | 6 |
2 files changed, 43 insertions, 50 deletions
diff --git a/include/mcl/bgn.hpp b/include/mcl/bgn.hpp index 2885ec2..1dc9107 100644 --- a/include/mcl/bgn.hpp +++ b/include/mcl/bgn.hpp @@ -313,7 +313,9 @@ struct BGNT { static G1 P; static G2 Q; - + static GT ePQ; // e(P, Q) + static local::EcHashTable<G1> g1HashTbl; + static local::GTHashTable<GT> gtHashTbl; private: template<class G> class CipherTextAT { @@ -328,7 +330,7 @@ private: S.clear(); T.clear(); } - static inline void add(CipherTextAT& z, const CipherTextAT& x, const CipherTextAT& y) + static void add(CipherTextAT& z, const CipherTextAT& x, const CipherTextAT& y) { /* (S, T) + (S', T') = (S + S', T + T') @@ -336,7 +338,7 @@ private: G::add(z.S, x.S, y.S); G::add(z.T, x.T, y.T); } - static inline void sub(CipherTextAT& z, const CipherTextAT& x, const CipherTextAT& y) + static void sub(CipherTextAT& z, const CipherTextAT& x, const CipherTextAT& y) { /* (S, T) - (S', T') = (S - S', T - T') @@ -344,7 +346,7 @@ private: G::sub(z.S, x.S, y.S); G::sub(z.T, x.T, y.T); } - static inline void neg(CipherTextAT& y, const CipherTextAT& x) + static void neg(CipherTextAT& y, const CipherTextAT& x) { G::neg(y.S, x.S); G::neg(y.T, x.T); @@ -393,7 +395,7 @@ private: g1 = millerLoop(P1, Q) g2 = millerLoop(P2, Q) */ - static inline void doubleMillerLoop(GT& g1, GT& g2, const G1& P1, const G1& P2, const G2& Q) + static void doubleMillerLoop(GT& g1, GT& g2, const G1& P1, const G1& P2, const G2& Q) { #if 1 #ifdef MCL_USE_BN384 @@ -409,7 +411,7 @@ private: BN::millerLoop(g2, P2, Q); #endif } - static inline void tensorProduct(GT g[4], const G1& S1, const G1& T1, const G2& S2, const G2& T2) + static void tensorProduct(GT g[4], const G1& S1, const G1& T1, const G2& S2, const G2& T2) { /* (S1, T1) x (S2, T2) = (e(S1, S2), e(S1, T2), e(T1, S2), e(T1, T2)) @@ -422,7 +424,7 @@ public: typedef CipherTextAT<G1> CipherTextG1; typedef CipherTextAT<G2> CipherTextG2; - static inline void init(const mcl::bn::CurveParam& cp = mcl::bn::CurveFp254BNb) + static void init(const mcl::bn::CurveParam& cp = mcl::bn::CurveFp254BNb) { #ifdef MCL_USE_BN256 mcl::bn256::bn256init(cp); @@ -432,52 +434,45 @@ public: #endif BN::hashAndMapToG1(P, "0"); BN::hashAndMapToG2(Q, "0"); + BN::pairing(ePQ, P, Q); + } + /* + set range for G1-DLP + */ + static void setRangeForG1DLP(size_t hashSize, size_t tryNum = 0) + { + g1HashTbl.init(P, hashSize, tryNum); + } + /* + set range for GT-DLP + */ + static void setRangeForGTDLP(size_t hashSize, size_t tryNum = 0) + { + gtHashTbl.init(ePQ, hashSize, tryNum); + } + /* + set range for G1/GT DLP + decode message m for |m| <= hasSize * tryNum + decode time = O(log(hasSize) * tryNum) + @note if tryNum = 0 then fast but require more memory(TBD) + */ + static void setRangeForDLP(size_t hashSize, size_t tryNum = 0) + { + setRangeForG1DLP(hashSize, tryNum); + setRangeForGTDLP(hashSize, tryNum); } class SecretKey { Fr x, y; - GT g; // e(P, Q) - local::EcHashTable<G1> g1HashTbl; - local::GTHashTable<GT> gtHashTbl; - void initInner() - { - BN::pairing(g, P, Q); - } public: template<class RG> void setByCSPRNG(RG& rg) { x.setRand(rg); y.setRand(rg); - initInner(); } void setByCSPRNG() { setByCSPRNG(local::g_rg); } /* - set range for G1-DLP - */ - void setRangeForG1DLP(size_t hashSize, size_t tryNum = 0) - { - g1HashTbl.init(P, hashSize, tryNum); - } - /* - set range for GT-DLP - */ - void setRangeForGTDLP(size_t hashSize, size_t tryNum = 0) - { - gtHashTbl.init(g, hashSize, tryNum); - } - /* - set range for G1/GT DLP - decode message m for |m| <= hasSize * tryNum - decode time = O(log(hasSize) * tryNum) - @note if tryNum = 0 then fast but require more memory(TBD) - */ - void setRangeForDLP(size_t hashSize, size_t tryNum = 0) - { - setRangeForG1DLP(hashSize, tryNum); - setRangeForGTDLP(hashSize, tryNum); - } - /* set xP and yQ */ void getPublicKey(PublicKey& pub) const @@ -552,7 +547,6 @@ public: { x.readStream(is, ioMode); y.readStream(is, ioMode); - initInner(); return is; } void getStr(std::string& str, int ioMode = 0) const @@ -1019,12 +1013,11 @@ public: }; }; -template<class BN, class Fr> -typename BN::G1 BGNT<BN, Fr>::P; - -template<class BN, class Fr> -typename BN::G2 BGNT<BN, Fr>::Q; - +template<class BN, class Fr> typename BN::G1 BGNT<BN, Fr>::P; +template<class BN, class Fr> typename BN::G2 BGNT<BN, Fr>::Q; +template<class BN, class Fr> typename BN::Fp12 BGNT<BN, Fr>::ePQ; +template<class BN, class Fr> local::EcHashTable<typename BN::G1> BGNT<BN, Fr>::g1HashTbl; +template<class BN, class Fr> local::GTHashTable<typename BN::Fp12> BGNT<BN, Fr>::gtHashTbl; #ifdef MCL_USE_BN384 typedef mcl::bgn::BGNT<mcl::bn384::BN, mcl::bn256::Fr> BGN; #else diff --git a/test/bgn_test.cpp b/test/bgn_test.cpp index fdfc973..58338d7 100644 --- a/test/bgn_test.cpp +++ b/test/bgn_test.cpp @@ -70,7 +70,7 @@ CYBOZU_TEST_AUTO(enc_dec) { SecretKey& sec = g_sec; sec.setByCSPRNG(); - sec.setRangeForDLP(1024); + BGN::setRangeForDLP(1024); PublicKey pub; sec.getPublicKey(pub); CipherText c; @@ -156,6 +156,7 @@ T testIo(const T& x) CYBOZU_TEST_AUTO(io) { + BGN::setRangeForDLP(100, 2); int m; for (int i = 0; i < 2; i++) { if (i == 1) { @@ -164,7 +165,6 @@ CYBOZU_TEST_AUTO(io) } SecretKey sec; sec.setByCSPRNG(); - sec.setRangeForDLP(100, 2); testIo(sec); PublicKey pub; sec.getPublicKey(pub); @@ -209,7 +209,7 @@ CYBOZU_TEST_AUTO(hashBench) { SecretKey& sec = g_sec; sec.setByCSPRNG(); - sec.setRangeForDLP(100, 1000); + BGN::setRangeForDLP(100, 1000); PublicKey pub; sec.getPublicKey(pub); int x = 100; |