diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-04-18 15:15:01 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-04-18 15:15:01 +0800 |
commit | 265b4649f4b456e3fe5fcdce4ca436167adc78e4 (patch) | |
tree | 031a4da283fd096c7ca1945f1ee8655809143f41 | |
parent | f0140dee83d9902d03007abc786c5f3d286da4fa (diff) | |
download | dexon-mcl-265b4649f4b456e3fe5fcdce4ca436167adc78e4.tar.gz dexon-mcl-265b4649f4b456e3fe5fcdce4ca436167adc78e4.tar.zst dexon-mcl-265b4649f4b456e3fe5fcdce4ca436167adc78e4.zip |
define BN::** in mcl::bn**
-rw-r--r-- | include/mcl/aggregate_sig.hpp | 49 | ||||
-rw-r--r-- | include/mcl/bn256.hpp | 17 | ||||
-rw-r--r-- | include/mcl/bn384.hpp | 17 | ||||
-rw-r--r-- | include/mcl/bn512.hpp | 17 | ||||
-rw-r--r-- | include/mcl/bn_common.hpp | 88 | ||||
-rw-r--r-- | include/mcl/she.hpp | 88 | ||||
-rw-r--r-- | java/bn256_impl.hpp | 2 | ||||
-rw-r--r-- | readme.md | 6 | ||||
-rw-r--r-- | sample/bls_sig.cpp | 8 | ||||
-rw-r--r-- | sample/pairing.cpp | 18 | ||||
-rw-r--r-- | sample/tri-dh.cpp | 4 | ||||
-rw-r--r-- | src/bn_c_impl.hpp | 14 | ||||
-rw-r--r-- | test/bls12_test.cpp | 80 | ||||
-rw-r--r-- | test/bn384_test.cpp | 8 | ||||
-rw-r--r-- | test/bn512_test.cpp | 8 | ||||
-rw-r--r-- | test/bn_test.cpp | 64 | ||||
-rw-r--r-- | test/glv_test.cpp | 12 | ||||
-rw-r--r-- | test/she_test.cpp | 48 |
18 files changed, 296 insertions, 252 deletions
diff --git a/include/mcl/aggregate_sig.hpp b/include/mcl/aggregate_sig.hpp index f161f14..f314057 100644 --- a/include/mcl/aggregate_sig.hpp +++ b/include/mcl/aggregate_sig.hpp @@ -17,17 +17,17 @@ #if MCLBN_FP_UNIT_SIZE == 4 #include <mcl/bn256.hpp> namespace mcl { -namespace bn_current = mcl::bn256; +using namespace mcl::bn256; } #elif MCLBN_FP_UNIT_SIZE == 6 #include <mcl/bn384.hpp> namespace mcl { -namespace bn_current = mcl::bn384; +using namespace mcl::bn384; } #elif MCLBN_FP_UNIT_SIZE == 8 #include <mcl/bn512.hpp> namespace mcl { -namespace bn_current = mcl::bn512; +using namespace mcl::bn512; } #else #error "MCLBN_FP_UNIT_SIZE must be 4, 6, or 8" @@ -38,12 +38,9 @@ namespace mcl { namespace aggs { /* AGGregate Signature Template class */ -template<class BN, class Fr> +template<size_t dummyImpl = 0> struct AGGST { - typedef typename BN::G1 G1; typedef typename G1::BaseFp Fp; - typedef typename BN::G2 G2; - typedef typename BN::Fp12 GT; class SecretKey; class PublicKey; @@ -51,14 +48,14 @@ struct AGGST { static G1 P_; static G2 Q_; - static std::vector<bn_current::Fp6> Qcoeff_; + static std::vector<Fp6> Qcoeff_; public: static void init(const mcl::CurveParam& cp = mcl::BN254) { - bn_current::initPairing(cp); - BN::hashAndMapToG1(P_, "0"); - BN::hashAndMapToG2(Q_, "0"); - BN::precomputeG2(Qcoeff_, Q_); + initPairing(cp); + hashAndMapToG1(P_, "0"); + hashAndMapToG2(Q_, "0"); + precomputeG2(Qcoeff_, Q_); } class Signature : public fp::Serializable<Signature> { G1 S_; @@ -121,22 +118,22 @@ public: h.setHashOf(msgVec[i], sizeVec[i]); std::pair<typename FpSet::iterator, bool> ret = msgSet.insert(h); if (!ret.second) throw cybozu::Exception("aggs::verify:same msg"); - BN::mapToG1(hv[i], h); + mapToG1(hv[i], h); } /* e(aggSig, xQ) = prod_i e(hv[i], pub[i].Q) <=> finalExp(e(-aggSig, xQ) * prod_i millerLoop(hv[i], pub[i].xQ)) == 1 */ GT e1, e2; - BN::precomputedMillerLoop(e1, -S_, Qcoeff_); - BN::millerLoop(e2, hv[0], pubVec[0].xQ_); + precomputedMillerLoop(e1, -S_, Qcoeff_); + millerLoop(e2, hv[0], pubVec[0].xQ_); for (size_t i = 1; i < n; i++) { GT e; - BN::millerLoop(e, hv[i], pubVec[i].xQ_); + millerLoop(e, hv[i], pubVec[i].xQ_); e2 *= e; } e1 *= e2; - BN::finalExp(e1, e1); + finalExp(e1, e1); return e1.isOne(); } bool verify(const std::vector<std::string>& msgVec, const std::vector<PublicKey>& pubVec) const @@ -192,13 +189,13 @@ public: <=> finalExp(millerLoop(S, Q)e(-H, x)) = 1 */ G1 H; - BN::hashAndMapToG1(H, m, mSize); + hashAndMapToG1(H, m, mSize); G1::neg(H, H); GT e1, e2; - BN::precomputedMillerLoop(e1, sig.S_, Qcoeff_); - BN::millerLoop(e2, H, xQ_); + precomputedMillerLoop(e1, sig.S_, Qcoeff_); + millerLoop(e2, H, xQ_); e1 *= e2; - BN::finalExp(e1, e1); + finalExp(e1, e1); return e1.isOne(); } bool verify(const Signature& sig, const std::string& m) const @@ -246,7 +243,7 @@ public: } void sign(Signature& sig, const void *m, size_t mSize) const { - BN::hashAndMapToG1(sig.S_, m, mSize); + hashAndMapToG1(sig.S_, m, mSize); G1::mul(sig.S_, sig.S_, x_); } void sign(Signature& sig, const std::string& m) const @@ -256,11 +253,11 @@ public: }; }; -template<class BN, class Fr> typename BN::G1 AGGST<BN, Fr>::P_; -template<class BN, class Fr> typename BN::G2 AGGST<BN, Fr>::Q_; -template<class BN, class Fr> std::vector<bn_current::Fp6> AGGST<BN, Fr>::Qcoeff_; +template<size_t dummyImpl> G1 AGGST<dummyImpl>::P_; +template<size_t dummyImpl> G2 AGGST<dummyImpl>::Q_; +template<size_t dummyImpl> std::vector<Fp6> AGGST<dummyImpl>::Qcoeff_; -typedef AGGST<bn_current::BN, bn_current::Fr> AGGS; +typedef AGGST<> AGGS; typedef AGGS::SecretKey SecretKey; typedef AGGS::PublicKey PublicKey; typedef AGGS::Signature Signature; diff --git a/include/mcl/bn256.hpp b/include/mcl/bn256.hpp index ac44e70..ef0a324 100644 --- a/include/mcl/bn256.hpp +++ b/include/mcl/bn256.hpp @@ -16,24 +16,9 @@ struct FrTag; } typedef mcl::FpT<local::FpTag, 256> Fp; -typedef mcl::bn::BNT<Fp> BN; -typedef BN::Fp2 Fp2; -typedef BN::Fp6 Fp6; -typedef BN::Fp12 Fp12; -typedef BN::G1 G1; -typedef BN::G2 G2; -typedef BN::Fp12 GT; - -/* the order of G1 is r */ typedef mcl::FpT<local::FrTag, 256> Fr; -static inline void initPairing(const mcl::CurveParam& cp = mcl::BN254, fp::Mode mode = fp::FP_AUTO) -{ - BN::init(cp, mode); - G1::setCompressedExpression(); - G2::setCompressedExpression(); - Fr::init(BN::param.r); -} +#include <mcl/bn_common.hpp> } } // mcl::bn256 diff --git a/include/mcl/bn384.hpp b/include/mcl/bn384.hpp index 21800c6..cda2ad6 100644 --- a/include/mcl/bn384.hpp +++ b/include/mcl/bn384.hpp @@ -16,24 +16,9 @@ struct FrTag; } typedef mcl::FpT<local::FpTag, 384> Fp; -typedef mcl::bn::BNT<Fp> BN; -typedef BN::Fp2 Fp2; -typedef BN::Fp6 Fp6; -typedef BN::Fp12 Fp12; -typedef BN::G1 G1; -typedef BN::G2 G2; -typedef BN::Fp12 GT; - -/* the order of G1 is r */ typedef mcl::FpT<local::FrTag, 384> Fr; -static inline void initPairing(const mcl::CurveParam& cp = mcl::BN381_1, fp::Mode mode = fp::FP_AUTO) -{ - BN::init(cp, mode); - G1::setCompressedExpression(); - G2::setCompressedExpression(); - Fr::init(BN::param.r); -} +#include <mcl/bn_common.hpp> } } // mcl::bn384 diff --git a/include/mcl/bn512.hpp b/include/mcl/bn512.hpp index 2a5d3f7..3a990b1 100644 --- a/include/mcl/bn512.hpp +++ b/include/mcl/bn512.hpp @@ -16,24 +16,9 @@ struct FrTag; } typedef mcl::FpT<local::FpTag, 512> Fp; -typedef mcl::bn::BNT<Fp> BN; -typedef BN::Fp2 Fp2; -typedef BN::Fp6 Fp6; -typedef BN::Fp12 Fp12; -typedef BN::G1 G1; -typedef BN::G2 G2; -typedef BN::Fp12 GT; - -/* the order of G1 is r */ typedef mcl::FpT<local::FrTag, 512> Fr; -static inline void initPairing(const mcl::CurveParam& cp = mcl::BN462, fp::Mode mode = fp::FP_AUTO) -{ - BN::init(cp, mode); - G1::setCompressedExpression(); - G2::setCompressedExpression(); - Fr::init(BN::param.r); -} +#include <mcl/bn_common.hpp> } } // mcl::bn512 diff --git a/include/mcl/bn_common.hpp b/include/mcl/bn_common.hpp new file mode 100644 index 0000000..162076a --- /dev/null +++ b/include/mcl/bn_common.hpp @@ -0,0 +1,88 @@ +/* + included by mcl/bnXXX.hpp +*/ +typedef mcl::bn::BNT<Fp> BN; +typedef BN::Fp2 Fp2; +typedef BN::Fp6 Fp6; +typedef BN::Fp12 Fp12; +typedef BN::G1 G1; +typedef BN::G2 G2; +typedef BN::Fp12 GT; + +inline void initPairing(const mcl::CurveParam& cp = mcl::BN254, fp::Mode mode = fp::FP_AUTO) +{ + BN::init(cp, mode); + G1::setCompressedExpression(); + G2::setCompressedExpression(); + Fr::init(BN::param.r); +} + +inline void finalExp(Fp12& y, const Fp12& x) +{ + BN::finalExp(y, x); +} + +inline void hashAndMapToG1(G1& P, const void *buf, size_t bufSize) +{ + BN::hashAndMapToG1(P, buf, bufSize); +} + +inline void hashAndMapToG1(G1& P, const std::string& str) +{ + BN::hashAndMapToG1(P, str); +} + +inline void hashAndMapToG2(G2& P, const void *buf, size_t bufSize) +{ + BN::hashAndMapToG2(P, buf, bufSize); +} + +inline void hashAndMapToG2(G2& P, const std::string& str) +{ + BN::hashAndMapToG2(P, str); +} + +inline void mapToG1(G1& P, const Fp& x) +{ + BN::mapToG1(P, x); +} + +inline void mapToG2(G2& P, const Fp2& x) +{ + BN::mapToG2(P, x); +} + +inline void millerLoop(Fp12& f, const G1& P, const G2& Q) +{ + BN::millerLoop(f, P, Q); +} +inline void pairing(Fp12& f, const G1& P, const G2& Q) +{ + BN::pairing(f, P, Q); +} + +inline void precomputeG2(std::vector<Fp6>& Qcoeff, const G2& Q) +{ + BN::precomputeG2(Qcoeff, Q); +} + +inline void precomputedMillerLoop(Fp12& f, const G1& P, const std::vector<Fp6>& Qcoeff) +{ + BN::precomputedMillerLoop(f, P, Qcoeff); +} + +inline void precomputedMillerLoop2(Fp12& f, const G1& P1, const std::vector<Fp6>& Q1coeff, const G1& P2, const std::vector<Fp6>& Q2coeff) +{ + BN::precomputedMillerLoop2(f, P1, Q1coeff, P2, Q2coeff); +} + +inline void verifyOrderG1(bool doVerify) +{ + BN::verifyOrderG1(doVerify); +} + +inline void verifyOrderG2(bool doVerify) +{ + BN::verifyOrderG2(doVerify); +} + diff --git a/include/mcl/she.hpp b/include/mcl/she.hpp index d9ba5d4..5942b80 100644 --- a/include/mcl/she.hpp +++ b/include/mcl/she.hpp @@ -37,6 +37,8 @@ namespace bn_current = mcl::bn512; namespace mcl { namespace she { +using namespace mcl::bn_current; + namespace local { #ifndef MCLSHE_WIN_SIZE @@ -255,7 +257,7 @@ public: template<class OutputStream> void save(OutputStream& os) const { - cybozu::save(os, bn_current::BN::param.cp.curveType); + cybozu::save(os, BN::param.cp.curveType); cybozu::writeChar(os, GtoChar<G>()); cybozu::save(os, kcv_.size()); cybozu::write(os, &kcv_[0], sizeof(kcv_[0]) * kcv_.size()); @@ -276,7 +278,7 @@ public: { int curveType; cybozu::load(curveType, is); - if (curveType != bn_current::BN::param.cp.curveType) throw cybozu::Exception("HashTable:bad curveType") << curveType; + if (curveType != BN::param.cp.curveType) throw cybozu::Exception("HashTable:bad curveType") << curveType; char c = 0; if (!cybozu::readChar(&c, is) || c != GtoChar<G>()) throw cybozu::Exception("HashTable:bad c") << (int)c; size_t kcvSize; @@ -325,12 +327,8 @@ int log(const G& P, const G& xP) } // mcl::she::local -template<class BN, class Fr> +template<size_t dummyInpl = 0> struct SHET { - typedef typename BN::G1 G1; - typedef typename BN::G2 G2; - typedef typename BN::Fp12 GT; - class SecretKey; class PublicKey; class PrecomputedPublicKey; @@ -342,7 +340,7 @@ struct SHET { static G1 P_; static G2 Q_; static GT ePQ_; // e(P, Q) - static std::vector<bn_current::Fp6> Qcoeff_; + static std::vector<Fp6> Qcoeff_; static local::HashTable<G1> PhashTbl_; static local::HashTable<G2> QhashTbl_; static mcl::fp::WindowMethod<G2> Qwm_; @@ -440,19 +438,19 @@ private: static void doubleMillerLoop(GT& g1, GT& g2, const G1& P1, const G1& P2, const G2& Q) { #if 1 - std::vector<bn_current::Fp6> Qcoeff; - BN::precomputeG2(Qcoeff, Q); - BN::precomputedMillerLoop(g1, P1, Qcoeff); - BN::precomputedMillerLoop(g2, P2, Qcoeff); + std::vector<Fp6> Qcoeff; + precomputeG2(Qcoeff, Q); + precomputedMillerLoop(g1, P1, Qcoeff); + precomputedMillerLoop(g2, P2, Qcoeff); #else - BN::millerLoop(g1, P1, Q); - BN::millerLoop(g2, P2, Q); + millerLoop(g1, P1, Q); + millerLoop(g2, P2, Q); #endif } static void finalExp4(GT out[4], const GT in[4]) { for (int i = 0; i < 4; i++) { - BN::finalExp(out[i], in[i]); + finalExp(out[i], in[i]); } } static void tensorProductML(GT g[4], const G1& S1, const G1& T1, const G2& S2, const G2& T2) @@ -508,11 +506,11 @@ public: static void init(const mcl::CurveParam& cp = mcl::BN254, size_t hashSize = 1024, size_t tryNum = local::defaultTryNum) { - bn_current::initPairing(cp); - BN::hashAndMapToG1(P_, "0"); - BN::hashAndMapToG2(Q_, "0"); - BN::pairing(ePQ_, P_, Q_); - BN::precomputeG2(Qcoeff_, Q_); + initPairing(cp); + hashAndMapToG1(P_, "0"); + hashAndMapToG2(Q_, "0"); + pairing(ePQ_, P_, Q_); + precomputeG2(Qcoeff_, Q_); setRangeForDLP(hashSize); setTryNum(tryNum); } @@ -659,7 +657,7 @@ public: G1::mul(R, c.T_, x_); G1::sub(R, c.S_, R); GT v; - BN::pairing(v, R, Q_); + pairing(v, R, Q_); return ePQhashTbl_.log(v); } int64_t decViaGT(const CipherTextG2& c) const @@ -668,7 +666,7 @@ public: G2::mul(R, c.T_, y_); G2::sub(R, c.S_, R); GT v; - BN::pairing(v, P_, R); + pairing(v, P_, R); return ePQhashTbl_.log(v); } int64_t dec(const CipherText& c) const @@ -925,10 +923,10 @@ private: Enc(1) = (S, T) = (Q + r yQ, rQ) = (Q, 0) if r = 0 cm = c1 * (Q, 0) = (S, T) * (Q, 0) = (e(S, Q), 1, e(T, Q), 1) */ - BN::precomputedMillerLoop(cm.g_[0], c1.getS(), Qcoeff_); - BN::finalExp(cm.g_[0], cm.g_[0]); - BN::precomputedMillerLoop(cm.g_[2], c1.getT(), Qcoeff_); - BN::finalExp(cm.g_[2], cm.g_[2]); + precomputedMillerLoop(cm.g_[0], c1.getS(), Qcoeff_); + finalExp(cm.g_[0], cm.g_[0]); + precomputedMillerLoop(cm.g_[2], c1.getT(), Qcoeff_); + finalExp(cm.g_[2], cm.g_[2]); cm.g_[1] = cm.g_[3] = 1; } @@ -941,8 +939,8 @@ private: Enc(1) = (S, T) = (P + r xP, rP) = (P, 0) if r = 0 cm = (P, 0) * c2 = (e(P, S), e(P, T), 1, 1) */ - BN::pairing(cm.g_[0], P_, c2.getS()); - BN::pairing(cm.g_[1], P_, c2.getT()); + pairing(cm.g_[0], P_, c2.getS()); + pairing(cm.g_[1], P_, c2.getT()); cm.g_[2] = cm.g_[3] = 1; } void convert(CipherTextGT& cm, const CipherTextA& ca) const @@ -1037,15 +1035,15 @@ public: PhashTbl_.mulByWindowMethod(P2, m); P1 += P2; } -// BN::millerLoop(c.g[0], P1, Q); - BN::precomputedMillerLoop(c.g_[0], P1, Qcoeff_); +// millerLoop(c.g[0], P1, Q); + precomputedMillerLoop(c.g_[0], P1, Qcoeff_); // G1::mul(P1, P, rb); PhashTbl_.mulByWindowMethod(P1, rb); G1::mul(P2, xP_, rc); P1 -= P2; - BN::millerLoop(e, P1, yQ_); + millerLoop(e, P1, yQ_); c.g_[0] *= e; - BN::finalExp(c.g_[0], c.g_[0]); + finalExp(c.g_[0], c.g_[0]); #if 1 ePQhashTbl_.mulByWindowMethod(c.g_[1], rb); ePQhashTbl_.mulByWindowMethod(c.g_[2], ra); @@ -1140,9 +1138,9 @@ public: public: void init(const PublicKey& pub) { - BN::pairing(exPQ_, pub.xP_, Q_); - BN::pairing(eyPQ_, P_, pub.yQ_); - BN::pairing(exyPQ_, pub.xP_, pub.yQ_); + pairing(exPQ_, pub.xP_, Q_); + pairing(eyPQ_, P_, pub.yQ_); + pairing(exyPQ_, pub.xP_, pub.yQ_); const size_t bitSize = Fr::getBitSize(); exPQwm_.init(static_cast<const GTasEC&>(exPQ_), bitSize, local::winSize); eyPQwm_.init(static_cast<const GTasEC&>(eyPQ_), bitSize, local::winSize); @@ -1463,16 +1461,16 @@ public: }; }; -template<class BN, class Fr> typename BN::G1 SHET<BN, Fr>::P_; -template<class BN, class Fr> typename BN::G2 SHET<BN, Fr>::Q_; -template<class BN, class Fr> typename BN::Fp12 SHET<BN, Fr>::ePQ_; -template<class BN, class Fr> std::vector<bn_current::Fp6> SHET<BN, Fr>::Qcoeff_; -template<class BN, class Fr> local::HashTable<typename BN::G1> SHET<BN, Fr>::PhashTbl_; -template<class BN, class Fr> local::HashTable<typename BN::G2> SHET<BN, Fr>::QhashTbl_; -template<class BN, class Fr> local::HashTable<typename BN::Fp12, false> SHET<BN, Fr>::ePQhashTbl_; -template<class BN, class Fr> bool SHET<BN, Fr>::useDecG1ViaGT_; -template<class BN, class Fr> bool SHET<BN, Fr>::useDecG2ViaGT_; -typedef mcl::she::SHET<bn_current::BN, bn_current::Fr> SHE; +template<size_t dummyInpl> G1 SHET<dummyInpl>::P_; +template<size_t dummyInpl> G2 SHET<dummyInpl>::Q_; +template<size_t dummyInpl> Fp12 SHET<dummyInpl>::ePQ_; +template<size_t dummyInpl> std::vector<Fp6> SHET<dummyInpl>::Qcoeff_; +template<size_t dummyInpl> local::HashTable<G1> SHET<dummyInpl>::PhashTbl_; +template<size_t dummyInpl> local::HashTable<G2> SHET<dummyInpl>::QhashTbl_; +template<size_t dummyInpl> local::HashTable<Fp12, false> SHET<dummyInpl>::ePQhashTbl_; +template<size_t dummyInpl> bool SHET<dummyInpl>::useDecG1ViaGT_; +template<size_t dummyInpl> bool SHET<dummyInpl>::useDecG2ViaGT_; +typedef mcl::she::SHET<> SHE; typedef SHE::SecretKey SecretKey; typedef SHE::PublicKey PublicKey; typedef SHE::PrecomputedPublicKey PrecomputedPublicKey; diff --git a/java/bn256_impl.hpp b/java/bn256_impl.hpp index 33cea4e..c4caaf3 100644 --- a/java/bn256_impl.hpp +++ b/java/bn256_impl.hpp @@ -245,5 +245,5 @@ void pow(GT& z, const GT& x, const Fr& y) } void pairing(GT& e, const G1& P, const G2& Q) { - mcl::bn256::BN::pairing(e.self_, P.self_, Q.self_); + mcl::bn256::pairing(e.self_, P.self_, Q.self_); } @@ -205,7 +205,7 @@ mcl::bn256::initPairing(cp); mcl::bn256::G1 P(...);
mcl::bn256::G2 Q(...);
mcl::bn256::Fp12 e;
-mcl::bn256::BN::pairing(e, P, Q);
+mcl::bn256::pairing(e, P, Q);
```
1. (BN254) a BN curve over the 254-bit prime p = p(z) where z = -(2^62 + 2^55 + 1).
2. (BN_SNARK1) a BN curve over a 254-bit prime p such that n := p + 1 - t has high 2-adicity.
@@ -266,8 +266,8 @@ Use `Fp12::mulGeneric` for x in Fp12 - GT. ## Map To points
-* BN::mapToG1(G1& P, const Fp& x);
-* BN::mapToG2(G2& P, const Fp2& x);
+* mapToG1(G1& P, const Fp& x);
+* mapToG2(G2& P, const Fp2& x);
These functions maps x into Gi according to [_Faster hashing to G2_].
diff --git a/sample/bls_sig.cpp b/sample/bls_sig.cpp index acc4a70..c574087 100644 --- a/sample/bls_sig.cpp +++ b/sample/bls_sig.cpp @@ -23,7 +23,7 @@ void Hash(G1& P, const std::string& m) { Fp t; t.setHashOf(m); - BN::mapToG1(P, t); + mapToG1(P, t); } void KeyGen(Fr& s, G2& pub, const G2& Q) @@ -44,8 +44,8 @@ bool Verify(const G1& sign, const G2& Q, const G2& pub, const std::string& m) Fp12 e1, e2; G1 Hm; Hash(Hm, m); - BN::pairing(e1, sign, Q); // e1 = e(sign, Q) - BN::pairing(e2, Hm, pub); // e2 = e(Hm, sQ) + pairing(e1, sign, Q); // e1 = e(sign, Q) + pairing(e2, Hm, pub); // e2 = e(Hm, sQ) return e1 == e2; } @@ -56,7 +56,7 @@ int main(int argc, char *argv[]) // setup parameter initPairing(); G2 Q; - BN::mapToG2(Q, 1); + mapToG2(Q, 1); // generate secret key and public key Fr s; diff --git a/sample/pairing.cpp b/sample/pairing.cpp index b18a17f..230583b 100644 --- a/sample/pairing.cpp +++ b/sample/pairing.cpp @@ -7,12 +7,12 @@ void minimum_sample(const G1& P, const G2& Q) const mpz_class a = 123; const mpz_class b = 456; Fp12 e1, e2; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); G2 aQ; G1 bP; G2::mul(aQ, Q, a); G1::mul(bP, P, b); - BN::pairing(e2, bP, aQ); + pairing(e2, bP, aQ); Fp12::pow(e1, e1, a * b); printf("%s\n", e1 == e2 ? "ok" : "ng"); } @@ -20,21 +20,21 @@ void minimum_sample(const G1& P, const G2& Q) void miller_and_finel_exp(const G1& P, const G2& Q) { Fp12 e1, e2; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); - BN::millerLoop(e2, P, Q); - BN::finalExp(e2, e2); + millerLoop(e2, P, Q); + finalExp(e2, e2); printf("%s\n", e1 == e2 ? "ok" : "ng"); } void precomputed(const G1& P, const G2& Q) { Fp12 e1, e2; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); std::vector<Fp6> Qcoeff; - BN::precomputeG2(Qcoeff, Q); - BN::precomputedMillerLoop(e2, P, Qcoeff); - BN::finalExp(e2, e2); + precomputeG2(Qcoeff, Q); + precomputedMillerLoop(e2, P, Qcoeff); + finalExp(e2, e2); printf("%s\n", e1 == e2 ? "ok" : "ng"); } diff --git a/sample/tri-dh.cpp b/sample/tri-dh.cpp index 3859344..8b720ed 100644 --- a/sample/tri-dh.cpp +++ b/sample/tri-dh.cpp @@ -65,11 +65,11 @@ void share(const std::string& skFile, const std::string& pk1File, const std::str load(P1, Q1, pk1File); load(P2, Q2, pk2File); Fp12 e; - BN::pairing(e, P1, Q2); + pairing(e, P1, Q2); { // verify(not necessary) Fp12 e2; - BN::pairing(e2, P2, Q1); + pairing(e2, P2, Q1); if (e != e2) { throw cybozu::Exception("share:bad public key file") << e << e2; } diff --git a/src/bn_c_impl.hpp b/src/bn_c_impl.hpp index ecddaf5..3ddb911 100644 --- a/src/bn_c_impl.hpp +++ b/src/bn_c_impl.hpp @@ -314,7 +314,7 @@ int mclBnG1_isZero(const mclBnG1 *x) int mclBnG1_hashAndMapTo(mclBnG1 *x, const void *buf, mclSize bufSize) try { - BN::hashAndMapToG1(*cast(x), buf, bufSize); + hashAndMapToG1(*cast(x), buf, bufSize); return 0; } catch (std::exception& e) { if (g_fp) fprintf(g_fp, "mclBnG1_hashAndMapTo %s\n", e.what()); @@ -393,7 +393,7 @@ int mclBnG2_isZero(const mclBnG2 *x) int mclBnG2_hashAndMapTo(mclBnG2 *x, const void *buf, mclSize bufSize) try { - BN::hashAndMapToG2(*cast(x), buf, bufSize); + hashAndMapToG2(*cast(x), buf, bufSize); return 0; } catch (std::exception& e) { if (g_fp) fprintf(g_fp, "mclBnG2_hashAndMapTo %s\n", e.what()); @@ -528,15 +528,15 @@ void mclBnGT_powGeneric(mclBnGT *z, const mclBnGT *x, const mclBnFr *y) void mclBn_pairing(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y) { - BN::pairing(*cast(z), *cast(x), *cast(y)); + pairing(*cast(z), *cast(x), *cast(y)); } void mclBn_finalExp(mclBnGT *y, const mclBnGT *x) { - BN::finalExp(*cast(y), *cast(x)); + finalExp(*cast(y), *cast(x)); } void mclBn_millerLoop(mclBnGT *z, const mclBnG1 *x, const mclBnG2 *y) { - BN::millerLoop(*cast(z), *cast(x), *cast(y)); + millerLoop(*cast(z), *cast(x), *cast(y)); } int mclBn_getUint64NumToPrecompute(void) { @@ -615,11 +615,11 @@ int mclBn_G2EvaluatePolynomial(mclBnG2 *out, const mclBnG2 *cVec, mclSize cSize, void mclBn_verifyOrderG1(int doVerify) { - BN::verifyOrderG1(doVerify != 0); + verifyOrderG1(doVerify != 0); } void mclBn_verifyOrderG2(int doVerify) { - BN::verifyOrderG2(doVerify != 0); + verifyOrderG2(doVerify != 0); } diff --git a/test/bls12_test.cpp b/test/bls12_test.cpp index b0344fe..261d10c 100644 --- a/test/bls12_test.cpp +++ b/test/bls12_test.cpp @@ -95,8 +95,8 @@ void finalExpC(Fp12& y, const Fp12& x) void pairingC(Fp12& e, const G1& P, const G2& Q) { - BN::millerLoop(e, P, Q); - BN::finalExp(e, e); + millerLoop(e, P, Q); + finalExp(e, e); } void testIoAll(const G1& P, const G2& Q) { @@ -152,7 +152,7 @@ void testMapToG1() { G1 g; for (int i = 1; i < 10; i++) { - BN::mapToG1(g, i); + mapToG1(g, i); CYBOZU_TEST_ASSERT(!g.isZero()); G1 gr; G1::mul(gr, g, BN::param.r); @@ -164,7 +164,7 @@ void testMapToG2() { G2 g; for (int i = 1; i < 10; i++) { - BN::mapToG2(g, i); + mapToG2(g, i); CYBOZU_TEST_ASSERT(!g.isZero()); G2 gr; G2::mul(gr, g, BN::param.r); @@ -172,18 +172,18 @@ void testMapToG2() } Fp x; x.setHashOf("abc"); - BN::mapToG2(g, Fp2(x, 0)); + mapToG2(g, Fp2(x, 0)); CYBOZU_TEST_ASSERT(g.isValid()); } void testPrecomputed(const G1& P, const G2& Q) { Fp12 e1, e2; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); std::vector<Fp6> Qcoeff; - BN::precomputeG2(Qcoeff, Q); - BN::precomputedMillerLoop(e2, P, Qcoeff); - BN::finalExp(e2, e2); + precomputeG2(Qcoeff, Q); + precomputedMillerLoop(e2, P, Qcoeff); + finalExp(e2, e2); CYBOZU_TEST_EQUAL(e1, e2); } @@ -191,7 +191,7 @@ void testPrecomputed(const G1& P, const G2& Q) void testFp12pow(const G1& P, const G2& Q) { Fp12 e, e1, e2; - BN::pairing(e, P, Q); + pairing(e, P, Q); cybozu::XorShift rg; for (int i = -10; i < 10; i++) { mpz_class xm = i; @@ -204,7 +204,7 @@ void testFp12pow(const G1& P, const G2& Q) x.setRand(rg); mpz_class xm = x.getMpz(); Fp12::pow(e1, e, xm); - BN::param.glv2.pow(e2, e, xm); + param.glv2.pow(e2, e, xm); CYBOZU_TEST_EQUAL(e1, e2); } } @@ -219,22 +219,22 @@ void testMillerLoop2(const G1& P1, const G2& Q1) G1 P2; G2::mul(Q2, Q1, c1); G1::mul(P2, P1, c2); - BN::pairing(e1, P1, Q1); - BN::pairing(e2, P2, Q2); + pairing(e1, P1, Q1); + pairing(e2, P2, Q2); e1 *= e2; std::vector<Fp6> Q1coeff, Q2coeff; - BN::precomputeG2(Q1coeff, Q1); - BN::precomputeG2(Q2coeff, Q2); - BN::precomputedMillerLoop2(e2, P1, Q1coeff, P2, Q2coeff); - BN::finalExp(e2, e2); + precomputeG2(Q1coeff, Q1); + precomputeG2(Q2coeff, Q2); + precomputedMillerLoop2(e2, P1, Q1coeff, P2, Q2coeff); + finalExp(e2, e2); CYBOZU_TEST_EQUAL(e1, e2); } void testPairing(const G1& P, const G2& Q, const char *eStr) { Fp12 e1; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); Fp12 e2; { std::stringstream ss(eStr); @@ -261,8 +261,8 @@ void testPairing(const G1& P, const G2& Q, const char *eStr) G1 T; G1::mulCT(T, P, a); CYBOZU_TEST_EQUAL(Pa, T); - BN::pairing(e1, Pa, Q); - BN::pairing(e2, P, Qa); + pairing(e1, Pa, Q); + pairing(e2, P, Qa); CYBOZU_TEST_EQUAL(ea, e1); CYBOZU_TEST_EQUAL(ea, e2); } @@ -273,22 +273,22 @@ void testTrivial(const G1& P, const G2& Q) G1 Z1; Z1.clear(); G2 Z2; Z2.clear(); Fp12 e; - BN::pairing(e, Z1, Q); + pairing(e, Z1, Q); CYBOZU_TEST_EQUAL(e, 1); - BN::pairing(e, P, Z2); + pairing(e, P, Z2); CYBOZU_TEST_EQUAL(e, 1); - BN::pairing(e, Z1, Z2); + pairing(e, Z1, Z2); CYBOZU_TEST_EQUAL(e, 1); std::vector<Fp6> Qcoeff; - BN::precomputeG2(Qcoeff, Z2); - BN::precomputedMillerLoop(e, P, Qcoeff); - BN::finalExp(e, e); + precomputeG2(Qcoeff, Z2); + precomputedMillerLoop(e, P, Qcoeff); + finalExp(e, e); CYBOZU_TEST_EQUAL(e, 1); - BN::precomputeG2(Qcoeff, Q); - BN::precomputedMillerLoop(e, Z1, Qcoeff); - BN::finalExp(e, e); + precomputeG2(Qcoeff, Q); + precomputedMillerLoop(e, Z1, Qcoeff); + finalExp(e, e); CYBOZU_TEST_EQUAL(e, 1); } @@ -305,7 +305,7 @@ CYBOZU_TEST_AUTO(naive) #ifdef ONLY_BENCH { Fp12 e; - for (int i = 0; i < 1000; i++) BN::pairing(e, P, Q); + for (int i = 0; i < 1000; i++) pairing(e, P, Q); } clk.put(); return; @@ -362,10 +362,10 @@ const char *e1Str = Fp12 e0, e1, e2; e0.setStr(e0Str, 16); e1.setStr(e1Str, 16); - BN::finalExp(e2, e0); + finalExp(e2, e0); // finalExpC(e2, e0); CYBOZU_TEST_EQUAL(e1, e2); - CYBOZU_BENCH_C("finalExp", 100, BN::finalExp, e2, e0); + CYBOZU_BENCH_C("finalExp", 100, finalExp, e2, e0); } CYBOZU_TEST_AUTO(addLine) @@ -589,7 +589,7 @@ const char *eStr = Q.setStr(qStr, mode); Fp12 e1, e2; e1.setStr(eStr, 16); - BN::pairing(e2, P, Q); + pairing(e2, P, Q); CYBOZU_TEST_EQUAL(e1, e2); } @@ -598,10 +598,10 @@ void testCurve(const mcl::CurveParam& cp) initPairing(cp, g_mode); G1 P; G2 Q; - BN::mapToG1(P, 1); - BN::mapToG2(Q, 1); + mapToG1(P, 1); + mapToG2(Q, 1); GT e1, e2; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); cybozu::XorShift rg; mpz_class a, b; Fr r; @@ -611,7 +611,7 @@ void testCurve(const mcl::CurveParam& cp) G2 bQ; G1::mul(aP, P, a); G2::mul(bQ, Q, b); - BN::pairing(e2, aP, bQ); + pairing(e2, aP, bQ); GT::pow(e1, e1, a * b); CYBOZU_TEST_EQUAL(e1, e2); } @@ -623,6 +623,12 @@ CYBOZU_TEST_AUTO(multi) testCurve(mcl::BLS12_381); } +CYBOZU_TEST_AUTO(BLS12_G1mulCofactor) +{ + if (BN::param.cp.curveType != MCL_BLS12_381) return; + +} + int main(int argc, char *argv[]) try { diff --git a/test/bn384_test.cpp b/test/bn384_test.cpp index a3c5a48..ab93c14 100644 --- a/test/bn384_test.cpp +++ b/test/bn384_test.cpp @@ -17,10 +17,10 @@ void testCurve(const mcl::CurveParam& cp) initPairing(cp, g_mode); G1 P; G2 Q; - BN::mapToG1(P, 1); - BN::mapToG2(Q, 1); + mapToG1(P, 1); + mapToG2(Q, 1); GT e1, e2; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); cybozu::XorShift rg; mpz_class a, b; Fr r; @@ -30,7 +30,7 @@ void testCurve(const mcl::CurveParam& cp) G2 bQ; G1::mul(aP, P, a); G2::mul(bQ, Q, b); - BN::pairing(e2, aP, bQ); + pairing(e2, aP, bQ); GT::pow(e1, e1, a * b); CYBOZU_TEST_EQUAL(e1, e2); testBench<BN>(P, Q); diff --git a/test/bn512_test.cpp b/test/bn512_test.cpp index 3f42ea5..f3e6799 100644 --- a/test/bn512_test.cpp +++ b/test/bn512_test.cpp @@ -17,10 +17,10 @@ void testCurve(const mcl::CurveParam& cp) initPairing(cp, g_mode); G1 P; G2 Q; - BN::mapToG1(P, 1); - BN::mapToG2(Q, 1); + mapToG1(P, 1); + mapToG2(Q, 1); GT e1, e2; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); cybozu::XorShift rg; mpz_class a, b; Fr r; @@ -30,7 +30,7 @@ void testCurve(const mcl::CurveParam& cp) G2 bQ; G1::mul(aP, P, a); G2::mul(bQ, Q, b); - BN::pairing(e2, aP, bQ); + pairing(e2, aP, bQ); GT::pow(e1, e1, a * b); CYBOZU_TEST_EQUAL(e1, e2); testBench<BN>(P, Q); diff --git a/test/bn_test.cpp b/test/bn_test.cpp index 8e31b8a..f7a1452 100644 --- a/test/bn_test.cpp +++ b/test/bn_test.cpp @@ -110,7 +110,7 @@ void testMapToG1() { G1 g; for (int i = 1; i < 10; i++) { - BN::mapToG1(g, i); + mapToG1(g, i); CYBOZU_TEST_ASSERT(!g.isZero()); G1 gr; G1::mulGeneric(gr, g, BN::param.r); @@ -118,9 +118,9 @@ void testMapToG1() } #ifndef MCL_AVOID_EXCEPTION_TEST if (BN::param.cp.b == 2) { - CYBOZU_TEST_EXCEPTION(BN::mapToG1(g, 0), cybozu::Exception); - CYBOZU_TEST_EXCEPTION(BN::mapToG1(g, BN::param.mapTo.c1_), cybozu::Exception); - CYBOZU_TEST_EXCEPTION(BN::mapToG1(g, -BN::param.mapTo.c1_), cybozu::Exception); + CYBOZU_TEST_EXCEPTION(mapToG1(g, 0), cybozu::Exception); + CYBOZU_TEST_EXCEPTION(mapToG1(g, BN::param.mapTo.c1_), cybozu::Exception); + CYBOZU_TEST_EXCEPTION(mapToG1(g, -BN::param.mapTo.c1_), cybozu::Exception); } #endif } @@ -129,7 +129,7 @@ void testMapToG2() { G2 g; for (int i = 1; i < 10; i++) { - BN::mapToG2(g, i); + mapToG2(g, i); CYBOZU_TEST_ASSERT(!g.isZero()); G2 gr; G2::mulGeneric(gr, g, BN::param.r); @@ -137,12 +137,12 @@ void testMapToG2() } #ifndef MCL_AVOID_EXCEPTION_TEST if (BN::param.cp.b == 2) { - CYBOZU_TEST_EXCEPTION(BN::mapToG2(g, 0), cybozu::Exception); + CYBOZU_TEST_EXCEPTION(mapToG2(g, 0), cybozu::Exception); } #endif Fp x; x.setHashOf("abc"); - BN::mapToG2(g, Fp2(x, 0)); + mapToG2(g, Fp2(x, 0)); CYBOZU_TEST_ASSERT(g.isValid()); } @@ -170,7 +170,7 @@ void testCompress(const G1& P, const G2& Q) { if (BN::param.cp.curveType != MCL_BN254) return; Fp12 a; - BN::pairing(a, P, Q); + pairing(a, P, Q); BN::mapToCyclotomic(a, a); Fp12 b; Compress::fixed_power(b, a); @@ -182,18 +182,18 @@ void testCompress(const G1& P, const G2& Q) void testPrecomputed(const G1& P, const G2& Q) { Fp12 e1, e2; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); std::vector<Fp6> Qcoeff; - BN::precomputeG2(Qcoeff, Q); - BN::precomputedMillerLoop(e2, P, Qcoeff); - BN::finalExp(e2, e2); + precomputeG2(Qcoeff, Q); + precomputedMillerLoop(e2, P, Qcoeff); + finalExp(e2, e2); CYBOZU_TEST_EQUAL(e1, e2); } void testFp12pow(const G1& P, const G2& Q) { Fp12 e, e1, e2; - BN::pairing(e, P, Q); + pairing(e, P, Q); cybozu::XorShift rg; for (int i = -10; i < 10; i++) { mpz_class xm = i; @@ -220,22 +220,22 @@ void testMillerLoop2(const G1& P1, const G2& Q1) G1 P2; G2::mul(Q2, Q1, c1); G1::mul(P2, P1, c2); - BN::pairing(e1, P1, Q1); - BN::pairing(e2, P2, Q2); + pairing(e1, P1, Q1); + pairing(e2, P2, Q2); e1 *= e2; std::vector<Fp6> Q1coeff, Q2coeff; - BN::precomputeG2(Q1coeff, Q1); - BN::precomputeG2(Q2coeff, Q2); - BN::precomputedMillerLoop2(e2, P1, Q1coeff, P2, Q2coeff); - BN::finalExp(e2, e2); + precomputeG2(Q1coeff, Q1); + precomputeG2(Q2coeff, Q2); + precomputedMillerLoop2(e2, P1, Q1coeff, P2, Q2coeff); + finalExp(e2, e2); CYBOZU_TEST_EQUAL(e1, e2); } void testPairing(const G1& P, const G2& Q, const char *eStr) { Fp12 e1; - BN::pairing(e1, P, Q); + pairing(e1, P, Q); Fp12 e2; { std::stringstream ss(eStr); @@ -263,8 +263,8 @@ void testPairing(const G1& P, const G2& Q, const char *eStr) G1 T; G1::mulCT(T, P, a); CYBOZU_TEST_EQUAL(Pa, T); - BN::pairing(e1, Pa, Q); - BN::pairing(e2, P, Qa); + pairing(e1, Pa, Q); + pairing(e2, P, Qa); CYBOZU_TEST_EQUAL(ea, e1); CYBOZU_TEST_EQUAL(ea, e2); } @@ -275,22 +275,22 @@ void testTrivial(const G1& P, const G2& Q) G1 Z1; Z1.clear(); G2 Z2; Z2.clear(); Fp12 e; - BN::pairing(e, Z1, Q); + pairing(e, Z1, Q); CYBOZU_TEST_EQUAL(e, 1); - BN::pairing(e, P, Z2); + pairing(e, P, Z2); CYBOZU_TEST_EQUAL(e, 1); - BN::pairing(e, Z1, Z2); + pairing(e, Z1, Z2); CYBOZU_TEST_EQUAL(e, 1); std::vector<Fp6> Qcoeff; - BN::precomputeG2(Qcoeff, Z2); - BN::precomputedMillerLoop(e, P, Qcoeff); - BN::finalExp(e, e); + precomputeG2(Qcoeff, Z2); + precomputedMillerLoop(e, P, Qcoeff); + finalExp(e, e); CYBOZU_TEST_EQUAL(e, 1); - BN::precomputeG2(Qcoeff, Q); - BN::precomputedMillerLoop(e, Z1, Qcoeff); - BN::finalExp(e, e); + precomputeG2(Qcoeff, Q); + precomputedMillerLoop(e, Z1, Qcoeff); + finalExp(e, e); CYBOZU_TEST_EQUAL(e, 1); } @@ -344,7 +344,7 @@ CYBOZU_TEST_AUTO(naive) #ifdef ONLY_BENCH { Fp12 e; - for (int i = 0; i < 1000; i++) BN::pairing(e, P, Q); + for (int i = 0; i < 1000; i++) pairing(e, P, Q); } clk.put(); return; diff --git a/test/glv_test.cpp b/test/glv_test.cpp index d6a8401..c321fa5 100644 --- a/test/glv_test.cpp +++ b/test/glv_test.cpp @@ -113,7 +113,7 @@ void compareLength(const GLV1& rhs, const GLV2& lhs) void testGLV1() { G1 P0, P1, P2; - BN::mapToG1(P0, 1); + mapToG1(P0, 1); cybozu::XorShift rg; oldGLV oldGlv; @@ -124,7 +124,7 @@ void testGLV1() compareLength(glv, oldGlv); for (int i = 1; i < 100; i++) { - BN::mapToG1(P0, i); + mapToG1(P0, i); Fr s; s.setRand(rg); mpz_class ss = s.getMpz(); @@ -145,7 +145,7 @@ void testGLV1() CYBOZU_TEST_EQUAL(P1, P2); } Fr s; - BN::mapToG1(P0, 123); + mapToG1(P0, 123); CYBOZU_BENCH_C("Ec::mul", 100, P1 = P0; s.setRand(rg); G1::mulGeneric, P2, P1, s.getMpz()); CYBOZU_BENCH_C("Ec::glv", 100, P1 = P0; s.setRand(rg); glv.mul, P2, P1, s.getMpz()); } @@ -164,7 +164,7 @@ void testGLV2() glv2.init(r, z); mpz_class n; cybozu::XorShift rg; - BN::mapToG2(Q0, 1); + mapToG2(Q0, 1); for (int i = -10; i < 10; i++) { n = i; G2::mulGeneric(Q1, Q0, n); @@ -174,13 +174,13 @@ void testGLV2() for (int i = 1; i < 100; i++) { mcl::gmp::getRand(n, glv2.m, rg); n %= r; - BN::mapToG2(Q0, i); + mapToG2(Q0, i); G2::mulGeneric(Q1, Q0, n); glv2.mul(Q2, Q0, n); CYBOZU_TEST_EQUAL(Q1, Q2); } Fr s; - BN::mapToG2(Q0, 123); + mapToG2(Q0, 123); CYBOZU_BENCH_C("G2::mul", 1000, Q2 = Q0; s.setRand(rg); G2::mulGeneric, Q2, Q1, s.getMpz()); CYBOZU_BENCH_C("G2::glv", 1000, Q1 = Q0; s.setRand(rg); glv2.mul, Q2, Q1, s.getMpz()); } diff --git a/test/she_test.cpp b/test/she_test.cpp index e1851a8..aedadc0 100644 --- a/test/she_test.cpp +++ b/test/she_test.cpp @@ -23,9 +23,9 @@ CYBOZU_TEST_AUTO(log) const mcl::CurveParam& cp = mcl::BN462; puts("BN462"); #endif - SHE::init(cp); + init(cp); G1 P; - BN::hashAndMapToG1(P, "abc"); + hashAndMapToG1(P, "abc"); for (int i = -5; i < 5; i++) { G1 iP; G1::mul(iP, P, i); @@ -43,15 +43,15 @@ double clk2msec(const cybozu::CpuClock& clk, int n) CYBOZU_TEST_AUTO(bench2) { - SHE::setRangeForDLP(1 << 21); - SHE::setTryNum(1 << 16); - SHE::useDecG1ViaGT(true); - SHE::useDecG2ViaGT(true); + setRangeForDLP(1 << 21); + setTryNum(1 << 16); + useDecG1ViaGT(true); + useDecG2ViaGT(true); #if 0 { const char *tblName = "../she-dlp-table/she-dlp-0-20-gt.bin"; std::ifstream ifs(tblName, std::ios::binary); - SHE::ePQhashTbl_.load(ifs); + ePQhashTbl_.load(ifs); } #endif SecretKey sec; @@ -144,9 +144,9 @@ void HashTableTest(const G& P) CYBOZU_TEST_AUTO(HashTable) { G1 P; - BN::hashAndMapToG1(P, "abc"); + hashAndMapToG1(P, "abc"); G2 Q; - BN::hashAndMapToG2(Q, "abc"); + hashAndMapToG2(Q, "abc"); HashTableTest(P); HashTableTest(Q); } @@ -157,10 +157,10 @@ CYBOZU_TEST_AUTO(GTHashTable) GT g; { G1 P; - BN::hashAndMapToG1(P, "abc"); + hashAndMapToG1(P, "abc"); G2 Q; - BN::hashAndMapToG2(Q, "abc"); - BN::pairing(g, P, Q); + hashAndMapToG2(Q, "abc"); + pairing(g, P, Q); } const int maxSize = 100; const int tryNum = 3; @@ -188,7 +188,7 @@ CYBOZU_TEST_AUTO(enc_dec) { SecretKey& sec = g_sec; sec.setByCSPRNG(); - SHE::setRangeForDLP(1024); + setRangeForDLP(1024); PublicKey pub; sec.getPublicKey(pub); CipherText c; @@ -483,7 +483,7 @@ T testIo(const T& x) CYBOZU_TEST_AUTO(io) { - SHE::setRangeForDLP(100); + setRangeForDLP(100); int64_t m; for (int i = 0; i < 2; i++) { if (i == 1) { @@ -536,7 +536,7 @@ CYBOZU_TEST_AUTO(bench) CYBOZU_TEST_AUTO(saveHash) { - mcl::she::local::HashTable<SHE::G1> hashTbl1, hashTbl2; + mcl::she::local::HashTable<G1> hashTbl1, hashTbl2; hashTbl1.init(SHE::P_, 1234, 123); std::stringstream ss; hashTbl1.save(ss); @@ -578,15 +578,15 @@ CYBOZU_TEST_AUTO(hashBench) const size_t hashSize = 1u << 21; clock_t begin = clock(), end; - SHE::setRangeForG1DLP(hashSize); + setRangeForG1DLP(hashSize); end = clock(); printf("init G1 DLP %f\n", double(end - begin) / CLOCKS_PER_SEC); begin = end; - SHE::setRangeForG2DLP(hashSize); + setRangeForG2DLP(hashSize); end = clock(); printf("init G2 DLP %f\n", double(end - begin) / CLOCKS_PER_SEC); begin = end; - SHE::setRangeForGTDLP(hashSize); + setRangeForGTDLP(hashSize); end = clock(); printf("init GT DLP %f\n", double(end - begin) / CLOCKS_PER_SEC); @@ -615,9 +615,9 @@ CYBOZU_TEST_AUTO(hashBench) r.setRand(); mr = r.getMpz(); } - BN::hashAndMapToG1(P, "abc"); - BN::hashAndMapToG2(Q, "abc"); - BN::pairing(e, P, Q); + hashAndMapToG1(P, "abc"); + hashAndMapToG2(Q, "abc"); + pairing(e, P, Q); P2.clear(); Q2.clear(); e2 = 1; @@ -645,9 +645,9 @@ CYBOZU_TEST_AUTO(hashBench) // CYBOZU_BENCH_C("GTwindow", C, wm.mul, static_cast<AG&>(e), mr); #endif - CYBOZU_BENCH_C("miller ", C, BN::millerLoop, e, P, Q); - CYBOZU_BENCH_C("finalExp", C, BN::finalExp, e, e); - CYBOZU_BENCH_C("precomML", C, BN::precomputedMillerLoop, e, P, SHE::Qcoeff_); + CYBOZU_BENCH_C("miller ", C, millerLoop, e, P, Q); + CYBOZU_BENCH_C("finalExp", C, finalExp, e, e); + CYBOZU_BENCH_C("precomML", C, precomputedMillerLoop, e, P, SHE::Qcoeff_); CipherTextG1 c1; CipherTextG2 c2; |