diff options
author | MITSUNARI Shigeo <herumi@nifty.com> | 2018-04-19 07:25:04 +0800 |
---|---|---|
committer | MITSUNARI Shigeo <herumi@nifty.com> | 2018-04-19 07:25:04 +0800 |
commit | d8848ee4a10166bdbff9596f6c3d5c57e0f2a7fc (patch) | |
tree | fd28e7ab8e32503df45300361073fbfc2998e0a6 | |
parent | ed7b141f6ef2701712becc59d6e987b1ab6a1785 (diff) | |
download | dexon-bls-d8848ee4a10166bdbff9596f6c3d5c57e0f2a7fc.tar dexon-bls-d8848ee4a10166bdbff9596f6c3d5c57e0f2a7fc.tar.gz dexon-bls-d8848ee4a10166bdbff9596f6c3d5c57e0f2a7fc.tar.bz2 dexon-bls-d8848ee4a10166bdbff9596f6c3d5c57e0f2a7fc.tar.lz dexon-bls-d8848ee4a10166bdbff9596f6c3d5c57e0f2a7fc.tar.xz dexon-bls-d8848ee4a10166bdbff9596f6c3d5c57e0f2a7fc.tar.zst dexon-bls-d8848ee4a10166bdbff9596f6c3d5c57e0f2a7fc.zip |
BN:: is not necessary now
-rw-r--r-- | Makefile | 3 | ||||
-rw-r--r-- | src/bls.cpp | 21 | ||||
-rw-r--r-- | src/bls_c.cpp | 14 |
3 files changed, 19 insertions, 19 deletions
@@ -93,6 +93,9 @@ JS_DEP=src/bls_c.cpp ../mcl/src/fp.cpp Makefile ../bls-wasm/bls_c.js: $(JS_DEP) emcc -o $@ src/bls_c.cpp ../mcl/src/fp.cpp $(EMCC_OPT) -s "MODULARIZE=1" +bls-wasm: + $(MAKE) ../bls-wasm/bls_c.js + clean: $(RM) $(BLS_LIB) $(OBJ_DIR)/*.d $(OBJ_DIR)/*.o $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_SRC) $(ASM_OBJ) $(LIB_OBJ) $(LLVM_SRC) $(BLS384_SLIB) diff --git a/src/bls.cpp b/src/bls.cpp index 71bcb3b..5bfb744 100644 --- a/src/bls.cpp +++ b/src/bls.cpp @@ -31,7 +31,7 @@ static void HashAndMapToG1(G1& P, const std::string& m) { Fp t; t.setHashOf(m); - BN::mapToG1(P, t); + mapToG1(P, t); } template<class T, class G, class Vec> @@ -172,10 +172,7 @@ void init(int curve, int maxUnitSize) default: throw cybozu::Exception("bls:init:bad curve") << curve; } - BN::init(cp); - G1::setCompressedExpression(); - G2::setCompressedExpression(); - Fr::init(BN::param.r); + initPairing(cp); assert(sizeof(Id) == sizeof(impl::Id)); assert(sizeof(SecretKey) == sizeof(impl::SecretKey)); assert(sizeof(PublicKey) == sizeof(impl::PublicKey)); @@ -187,11 +184,11 @@ void init(int curve, int maxUnitSize) Fp2("13891744915211034074451795021214165905772212241412891944830863846330766296736", "7937318970632701341203597196594272556916396164729705624521405069090520231616") ); } else { - BN::mapToG2(Q, 1); + mapToG2(Q, 1); } static std::vector<Fp6> Qcoeff; - BN::precomputeG2(Qcoeff, Q); + precomputeG2(Qcoeff, Q); g_pQ = &Q; g_pQcoeff = &Qcoeff; } @@ -289,14 +286,14 @@ bool Signature::verify(const PublicKey& pub, const std::string& m) const */ Fp12 e; std::vector<Fp6> Q2coeff; - BN::precomputeG2(Q2coeff, pub.getInner().sQ); - BN::precomputedMillerLoop2(e, getInner().sHm, getQcoeff(), -Hm, Q2coeff); - BN::finalExp(e, e); + precomputeG2(Q2coeff, pub.getInner().sQ); + precomputedMillerLoop2(e, getInner().sHm, getQcoeff(), -Hm, Q2coeff); + finalExp(e, e); return e.isOne(); #else Fp12 e1, e2; - BN::pairing(e1, getInner().sHm, getQ()); // e(s Hm, Q) - BN::pairing(e2, Hm, pub.getInner().sQ); // e(Hm, sQ) + pairing(e1, getInner().sHm, getQ()); // e(s Hm, Q) + pairing(e2, Hm, pub.getInner().sQ); // e(Hm, sQ) return e1 == e2; #endif } diff --git a/src/bls_c.cpp b/src/bls_c.cpp index 568a49d..2135a8a 100644 --- a/src/bls_c.cpp +++ b/src/bls_c.cpp @@ -29,8 +29,8 @@ int blsInitNotThreadSafe(int curve, int maxUnitSize) try { if (mclBn_init(curve, maxUnitSize) != 0) return -1; - BN::mapToG2(g_Q, 1); - BN::precomputeG2(g_Qcoeff, getQ()); + mapToG2(g_Q, 1); + precomputeG2(g_Qcoeff, getQ()); return 0; } catch (std::exception&) { return -1; @@ -77,10 +77,10 @@ static inline const mclBnG2 *cast(const G2* x) { return (const mclBnG2*)x; } bool isEqualTwoPairings(const G1& P1, const Fp6* Q1coeff, const G1& P2, const G2& Q2) { std::vector<Fp6> Q2coeff; - BN::precomputeG2(Q2coeff, Q2); + precomputeG2(Q2coeff, Q2); Fp12 e; - BN::precomputedMillerLoop2(e, P1, Q1coeff, -P2, Q2coeff.data()); - BN::finalExp(e, e); + precomputedMillerLoop2(e, P1, Q1coeff, -P2, Q2coeff.data()); + finalExp(e, e); return e.isOne(); } @@ -131,7 +131,7 @@ void blsGetPublicKey(blsPublicKey *pub, const blsSecretKey *sec) void blsSign(blsSignature *sig, const blsSecretKey *sec, const void *m, mclSize size) { G1 Hm; - BN::hashAndMapToG1(Hm, m, size); + hashAndMapToG1(Hm, m, size); mclBnG1_mulCT(&sig->v, cast(&Hm), &sec->v); } int blsSecretKeyShare(blsSecretKey *sec, const blsSecretKey* msk, mclSize k, const blsId *id) @@ -169,7 +169,7 @@ int blsSignatureRecover(blsSignature *sig, const blsSignature *sigVec, const bls int blsVerify(const blsSignature *sig, const blsPublicKey *pub, const void *m, mclSize size) { G1 Hm; - BN::hashAndMapToG1(Hm, m, size); + hashAndMapToG1(Hm, m, size); /* e(sHm, Q) = e(Hm, sQ) e(sig, Q) = e(Hm, pub) |