From 6b889517c31bb773e4ad1cb8c139c5d924520c2e Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Thu, 24 May 2018 20:53:17 +0900 Subject: remove std::vector --- Makefile | 4 ++-- src/bls_c.cpp | 30 ++++++++++++++++++------------ 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 019ae3a..caecbd4 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,7 @@ endif test_go: ffi/go/bls/bls.go ffi/go/bls/bls_test.go $(BLS384_SLIB) cd ffi/go/bls && ln -sf ../../../lib . && env LD_RUN_PATH="../../../lib" CGO_CFLAGS="-I../../../include -I../../../../mcl/include" CGO_LDFLAGS="-L../../../lib -L../../../mcl/lib" go test $(MAC_GO_LDFLAGS) . -EMCC_OPT=-I./include -I./src -I../cybozulib/include -I../mcl/include -I./ +EMCC_OPT=-I./include -I./src -I../cybozulib/include -I../mcl/include -I./ -Wall -Wextra EMCC_OPT+=-O3 -DNDEBUG -DMCLBN_FP_UNIT_SIZE=6 -DMCL_MAX_BIT_SIZE=384 -Os EMCC_OPT+=-s WASM=1 -s DISABLE_EXCEPTION_CATCHING=1 -s NO_EXIT_RUNTIME=1 -s MODULARIZE=1 EMCC_OPT+=-DCYBOZU_MINIMUM_EXCEPTION @@ -96,7 +96,7 @@ EMCC_OPT+=-s ABORTING_MALLOC=0 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) + emcc -o $@ src/bls_c.cpp $(EMCC_OPT) bls-wasm: $(MAKE) ../bls-wasm/bls_c.js diff --git a/src/bls_c.cpp b/src/bls_c.cpp index d443eaa..ae86508 100644 --- a/src/bls_c.cpp +++ b/src/bls_c.cpp @@ -1,11 +1,10 @@ -#include -#include -#include -#include -#include -#include -#include +#ifdef __EMSCRIPTEN__ +#define MCLBN_DONT_EXPORT +#include "../mcl/src/fp.cpp" +#endif + #include "../mcl/src/bn_c_impl.hpp" + #define BLS_DLL_EXPORT #include @@ -21,9 +20,9 @@ */ static G2 g_Q; -static std::vector g_Qcoeff; // precomputed Q +static mcl::Vector g_Qcoeff; // precomputed Q static const G2& getQ() { return g_Q; } -static const std::vector& getQcoeff() { return g_Qcoeff; } +static const mcl::Vector& getQcoeff() { return g_Qcoeff; } int blsInitNotThreadSafe(int curve, int maxUnitSize) { @@ -32,10 +31,17 @@ int blsInitNotThreadSafe(int curve, int maxUnitSize) bool b; mapToG2(&b, g_Q, 1); if (!b) return -100; - precomputeG2(g_Qcoeff, getQ()); + if (!precomputeG2(g_Qcoeff, getQ())) return -101; return 0; } +#ifdef __EMSCRIPTEN__ +extern "C" BLS_DLL_API void blsFree(void *p) +{ + free(p); +} +#endif + #ifndef __EMSCRIPTEN__ #if defined(CYBOZU_CPP_VERSION) && CYBOZU_CPP_VERSION >= CYBOZU_CPP_VERSION_CPP11 #include @@ -76,8 +82,8 @@ 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 Q2coeff; - precomputeG2(Q2coeff, Q2); + mcl::Vector Q2coeff; + if (!precomputeG2(Q2coeff, Q2)) return false; Fp12 e; precomputedMillerLoop2(e, P1, Q1coeff, -P2, Q2coeff.data()); finalExp(e, e); -- cgit v1.2.3