From 99dae4167e29d22cf9049480b9ca89d97a6289f3 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Sun, 1 Oct 2017 17:16:32 +0900 Subject: [PATCH] [she] add remove old pages --- Makefile | 11 +- docs/demo/pairing.html | 87 ----------- docs/demo/pairing.js | 306 ------------------------------------- ffi/js/export-functions.py | 2 - ffi/js/she-re.txt | 2 +- readme.md | 1 - 6 files changed, 9 insertions(+), 400 deletions(-) delete mode 100644 docs/demo/pairing.html delete mode 100644 docs/demo/pairing.js diff --git a/Makefile b/Makefile index 376987a..9e61368 100644 --- a/Makefile +++ b/Makefile @@ -207,8 +207,9 @@ test: $(TEST_EXE) EXPORTED_SHE_JS=docs/demo/exported-she.js SHE_TXT=ffi/js/she.txt -EXPORT_OPT=-re ffi/js/she-re.txt -$(SHE_TXT): ./include/mcl/she.h +SHE_RE_TXT=ffi/js/she-re.txt +EXPORT_OPT=-re $(SHE_RE_TXT) +$(SHE_TXT): ./include/mcl/she.h $(SHE_RE_TXT) python ffi/js/export-functions.py $(EXPORT_OPT) $< > $@ $(EXPORTED_SHE_JS): ./include/mcl/she.h @@ -222,8 +223,12 @@ docs/demo/mclshe.js: src/fp.cpp src/she_c256.cpp $(SHE_TXT) $(EXPORTED_SHE_JS) demo: $(MAKE) docs/demo/mclshe.js +clean_demo: + $(RM) $(EXPORTED_SHE_JS) $(SHE_TXT) docs/demo/mclshe.js docs/demo/mclshe.wasm + clean: - $(RM) $(MCL_LIB) $(MCL_SLIB) $(BN256_LIB) $(BN256_SLIB) $(BN384_LIB) $(BN384_SLIB) $(OBJ_DIR)/*.o $(OBJ_DIR)/*.d $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_OBJ) $(LIB_OBJ) $(BN256_OBJ) $(BN384_OBJ) $(LLVM_SRC) $(FUNC_LIST) src/*.ll $(EXPORTED_SHE_JS) $(SHE_TXT) docs/demo/mclshe.js docs/demo/mclshe.wasm + $(MAKE) clean_demo + $(RM) $(MCL_LIB) $(MCL_SLIB) $(BN256_LIB) $(BN256_SLIB) $(BN384_LIB) $(BN384_SLIB) $(OBJ_DIR)/*.o $(OBJ_DIR)/*.d $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_OBJ) $(LIB_OBJ) $(BN256_OBJ) $(BN384_OBJ) $(LLVM_SRC) $(FUNC_LIST) src/*.ll ALL_SRC=$(SRC_SRC) $(TEST_SRC) $(SAMPLE_SRC) DEPEND_FILE=$(addprefix $(OBJ_DIR)/, $(addsuffix .d,$(basename $(ALL_SRC)))) diff --git a/docs/demo/pairing.html b/docs/demo/pairing.html deleted file mode 100644 index d0e9a8c..0000000 --- a/docs/demo/pairing.html +++ /dev/null @@ -1,87 +0,0 @@ - - - - -pairing sample - - - - - - -

-See BLS signature demo. This page is obsolete. -

-
-library status initializing... -
-

optimal Ate pairing over 256-bit BN curve

- -
pairing time : 0msec
-
G1 scalar mul : 0msec
-
G2 scalar mul : 0msec
-
-
-a =
-b =
-ab = 0
-
-
-P = hashAndMapToG1() = 0
-Q = hashAndMapToG2() = 0
-aP = 0
-bQ = 0
-
-
-
-e(P, Q) = 0
-e(aP, bQ) = 0
-e(P, Q)^ab = 0
-
-
-
-e(aP, bQ) == e(P, Q)^ab is -
-

Fr

- -
-x = -
-y = - -
-
-x + y =
-x - y =
-x * y =
-x / y =
-
-
-hash() = -
-

G1

- -
-P1 = hashAndMapToG1() = 0
-P2 = hashAndMapToG1() = 0
-
-
-
-P1 + P2 =
-P1 - P2 =
-P1 * x =
-
-

G2

- -
-Q1 = hashAndMapToG2() = 0
-Q2 = hashAndMapToG2() = 0
-
-
-
-Q1 + Q2 =
-Q1 - Q2 =
-Q1 * x =
-
- - diff --git a/docs/demo/pairing.js b/docs/demo/pairing.js deleted file mode 100644 index 812a8fd..0000000 --- a/docs/demo/pairing.js +++ /dev/null @@ -1,306 +0,0 @@ -function getValue(name) { return document.getElementsByName(name)[0].value } -function setValue(name, val) { document.getElementsByName(name)[0].value = val } -function getText(name) { return document.getElementsByName(name)[0].innerText } -function setText(name, val) { document.getElementsByName(name)[0].innerText = val } - -function setupWasm(fileName, nameSpace, setupFct) { - console.log('setupWasm ' + fileName) - var mod = {} - fetch(fileName) - .then(response => response.arrayBuffer()) - .then(buffer => new Uint8Array(buffer)) - .then(binary => { - mod['wasmBinary'] = binary - mod['onRuntimeInitialized'] = function() { - setupFct(mod, nameSpace) - console.log('setupWasm end') - } - Module(mod) - }) - return mod -} - -var MCLBN_FP_UNIT_SIZE = 4 - -var module = setupWasm('mclbn.wasm', null, function(mod, ns) { - define_exported_mcl(mod) - define_extra_functions(mod) - var r = mclBn_init(0) - setText('status', r ? 'err:' + r : 'ok') -}) - -function define_extra_functions(mod) { - gen_setStr = function(func) { - return function(x, buf, ioMode) { - if (ioMode == null) { ioMode = 0 } - var stack = mod.Runtime.stackSave() - var pos = mod.Runtime.stackAlloc(buf.length) - for (var i = 0; i < buf.length; i++) { - mod.HEAP8[pos + i] = buf.charCodeAt(i) - } - r = func(x, pos, buf.length, ioMode) - mod.Runtime.stackRestore(stack) - if (r) console.log('err gen_setStr ' + r) - } - } - gen_getStr = function(func) { - return function(x, ioMode) { - if (ioMode == null) { ioMode = 0 } - var maxBufSize = 2048 - var stack = mod.Runtime.stackSave() - var pos = mod.Runtime.stackAlloc(maxBufSize) - var n = func(pos, maxBufSize, x, ioMode) - if (n < 0) { - console.log('err gen_getStr') - return '' - } - var s = '' - for (var i = 0; i < n; i++) { - s += String.fromCharCode(mod.HEAP8[pos + i]) - } - mod.Runtime.stackRestore(stack) - return s - } - } - gen_deserialize = function(func) { - return function(x, buf) { - var stack = mod.Runtime.stackSave() - var pos = mod.Runtime.stackAlloc(buf.length) - if (typeof(buf) == "string") { - for (var i = 0; i < buf.length; i++) { - mod.HEAP8[pos + i] = buf.charCodeAt(i) - } - } else { - for (var i = 0; i < buf.length; i++) { - mod.HEAP8[pos + i] = buf[i] - } - } - r = func(x, pos, buf.length) - mod.Runtime.stackRestore(stack) - if (r) console.log('err gen_deserialize ' + r) - } - } - gen_serialize = function(func) { - return function(x) { - var maxBufSize = 2048 - var stack = mod.Runtime.stackSave() - var pos = mod.Runtime.stackAlloc(maxBufSize) - var n = func(pos, maxBufSize, x) - if (n < 0) { - console.log('err gen_serialize') - return '' - } - var a = new Uint8Array(n) - for (var i = 0; i < n; i++) { - a[i] = mod.HEAP8[pos + i] - } - mod.Runtime.stackRestore(stack) - return a - } - } - /////////////////////////////////////////////////////////////// - mclBn_init = function(curveType) { - _mclBn_init(curveType, MCLBN_FP_UNIT_SIZE) - } - mclBnFr_malloc = function() { - return mod._malloc(MCLBN_FP_UNIT_SIZE * 8) - } - mclBnFr_free = function(x) { - mod._free(x) - } - mclBnFr_deserialize = gen_deserialize(_mclBnFr_deserialize) - mclBnFr_setLittleEndian = gen_deserialize(_mclBnFr_setLittleEndian) - mclBnFr_setStr = gen_setStr(_mclBnFr_setStr) - mclBnFr_getStr = gen_getStr(_mclBnFr_getStr) - mclBnFr_setHashOf = gen_deserialize(_mclBnFr_setHashOf) - - /////////////////////////////////////////////////////////////// - mclBnG1_malloc = function() { - return mod._malloc(MCLBN_FP_UNIT_SIZE * 8 * 3) - } - mclBnG1_free = function(x) { - mod._free(x) - } - mclBnG1_setStr = gen_setStr(_mclBnG1_setStr) - mclBnG1_getStr = gen_getStr(_mclBnG1_getStr) - mclBnG1_deserialize = gen_deserialize(_mclBnG1_deserialize) - mclBnG1_serialize = gen_serialize(_mclBnG1_serialize) - mclBnG1_hashAndMapTo = gen_deserialize(_mclBnG1_hashAndMapTo) - - /////////////////////////////////////////////////////////////// - mclBnG2_malloc = function() { - return mod._malloc(MCLBN_FP_UNIT_SIZE * 8 * 2 * 3) - } - mclBnG2_free = function(x) { - mod._free(x) - } - mclBnG2_setStr = gen_setStr(_mclBnG2_setStr) - mclBnG2_getStr = gen_getStr(_mclBnG2_getStr) - mclBnG2_deserialize = gen_deserialize(_mclBnG2_deserialize) - mclBnG2_serialize = gen_serialize(_mclBnG2_serialize) - mclBnG2_hashAndMapTo = gen_deserialize(_mclBnG2_hashAndMapTo) - - /////////////////////////////////////////////////////////////// - mclBnGT_malloc = function() { - return mod._malloc(MCLBN_FP_UNIT_SIZE * 8 * 12) - } - mclBnGT_free = function(x) { - mod._free(x) - } - mclBnGT_deserialize = gen_deserialize(_mclBnGT_deserialize) - mclBnGT_serialize = gen_serialize(_mclBnGT_serialize) - mclBnGT_setStr = gen_setStr(_mclBnGT_setStr) - mclBnGT_getStr = gen_getStr(_mclBnGT_getStr) -} - -function rand(val) { - var x = mclBnFr_malloc() - mclBnFr_setByCSPRNG(x) - setValue(val, mclBnFr_getStr(x)) - mclBnFr_free(x) -} - -function TestFr() { - var x = mclBnFr_malloc() - var y = mclBnFr_malloc() - var z = mclBnFr_malloc() - - - mclBnFr_setStr(x, getValue('x')) -// mclBnFr_setInt(x, getValue('x') | 0) - mclBnFr_setStr(y, getValue('y')) - mclBnFr_add(z, x, y) - setText('ret_add', mclBnFr_getStr(z)) - mclBnFr_sub(z, x, y) - setText('ret_sub', mclBnFr_getStr(z)) - mclBnFr_mul(z, x, y) - setText('ret_mul', mclBnFr_getStr(z)) - if (!mclBnFr_isZero(y)) { - mclBnFr_div(z, x, y) - setText('ret_div', mclBnFr_getStr(z)) - } else { - setText('ret_div', 'err : y is zero') - } - mclBnFr_setHashOf(x, getValue('hash_x')) - setText('ret_hash_x', mclBnFr_getStr(x)) - - - mclBnFr_free(x) - mclBnFr_free(y) - mclBnFr_free(z) -} - -function TestG1() { - var P1 = mclBnG1_malloc() - var P2 = mclBnG1_malloc() - var P3 = mclBnG1_malloc() - var x = mclBnFr_malloc() - - mclBnG1_hashAndMapTo(P1, getValue('hash_P1')) - setText('P1', mclBnG1_getStr(P1)) - - mclBnG1_hashAndMapTo(P2, getValue('hash_P2')) - setText('P2', mclBnG1_getStr(P2)) - - mclBnG1_add(P3, P1, P2) - setText('P1addP2', mclBnG1_getStr(P3)) - - mclBnG1_sub(P3, P1, P2) - setText('P1subP2', mclBnG1_getStr(P3)) - - mclBnFr_setStr(x, getValue('x')) - mclBnG1_mul(P3, P1, x) - setText('P1mulx', mclBnG1_getStr(P3)) - - mclBnFr_free(x) - mclBnG1_free(P1) - mclBnG1_free(P2) - mclBnG1_free(P3) -} - -function TestG2() { - var Q1 = mclBnG2_malloc() - var Q2 = mclBnG2_malloc() - var Q3 = mclBnG2_malloc() - var x = mclBnFr_malloc() - - mclBnG2_hashAndMapTo(Q1, getValue('hash_Q1')) - setText('Q1', mclBnG2_getStr(Q1)) - - mclBnG2_hashAndMapTo(Q2, getValue('hash_Q2')) - setText('Q2', mclBnG2_getStr(Q2)) - - mclBnG2_add(Q3, Q1, Q2) - setText('Q1addQ2', mclBnG2_getStr(Q3)) - - mclBnG2_sub(Q3, Q1, Q2) - setText('Q1subQ2', mclBnG2_getStr(Q3)) - - mclBnFr_setStr(x, getValue('x')) - mclBnG2_mul(Q3, Q1, x) - setText('Q1mulx', mclBnG2_getStr(Q3)) - - mclBnFr_free(x) - mclBnG2_free(Q1) - mclBnG2_free(Q2) - mclBnG2_free(Q3) -} - -function bench(label, count, func) { - var start = Date.now() - for (var i = 0; i < count; i++) { - func() - } - var end = Date.now() - var t = (end - start) / count - setText(label, t) -} - -function TestPairing() { - var a = mclBnFr_malloc() - var b = mclBnFr_malloc() - var ab = mclBnFr_malloc() - var P = mclBnG1_malloc() - var aP = mclBnG1_malloc() - var Q = mclBnG2_malloc() - var bQ = mclBnG2_malloc() - var e1 = mclBnGT_malloc() - var e2 = mclBnGT_malloc() - - mclBnFr_setStr(a, getValue('a')) - mclBnFr_setStr(b, getValue('b')) - mclBnFr_mul(ab, a, b) - setText('ab', mclBnFr_getStr(ab)) - - mclBnG1_hashAndMapTo(P, getValue('hash_P')) - setText('P', mclBnG1_getStr(P)) - mclBnG2_hashAndMapTo(Q, getValue('hash_Q')) - setText('Q', mclBnG2_getStr(Q)) - mclBnG1_mul(aP, P, a) - setText('aP', mclBnG1_getStr(aP)) - mclBnG2_mul(bQ, Q, b) - setText('bQ', mclBnG2_getStr(bQ)) - - mclBn_pairing(e1, P, Q); - setText('ePQ', mclBnGT_getStr(e1)) - mclBn_pairing(e2, aP, bQ); - setText('eaPbQ', mclBnGT_getStr(e2)) - mclBnGT_pow(e1, e1, ab) - setText('ePQab', mclBnGT_getStr(e1)) - setText('verify_pairing', !!mclBnGT_isEqual(e1, e2)) - - bench('time_pairing', 50, () => mclBn_pairing(e1, P, Q)) - mclBnFr_setByCSPRNG(a) - bench('time_g1mul', 50, () => mclBnG1_mulCT(aP, P, a)) - bench('time_g2mul', 50, () => mclBnG2_mulCT(bQ, Q, a)) - - mclBnGT_free(e2) - mclBnGT_free(e1) - mclBnG2_free(bQ) - mclBnG2_free(Q) - mclBnG1_free(aP) - mclBnG1_free(P) - mclBnFr_free(ab) - mclBnFr_free(b) - mclBnFr_free(a) -} diff --git a/ffi/js/export-functions.py b/ffi/js/export-functions.py index d6ff1f8..fae9cb7 100644 --- a/ffi/js/export-functions.py +++ b/ffi/js/export-functions.py @@ -45,10 +45,8 @@ def main(): reToAddUnderscore = '' if args.re: reToAddUnderscore = open(args.re).read().strip() - print 'RE', reToAddUnderscore export_functions(args.js, args.header, reToAddUnderscore) if __name__ == '__main__': main() - diff --git a/ffi/js/she-re.txt b/ffi/js/she-re.txt index 036ffb2..a78719d 100644 --- a/ffi/js/she-re.txt +++ b/ffi/js/she-re.txt @@ -1 +1 @@ -sheInit|erialize|Str +sheInit|erialize|Str|sheDec diff --git a/readme.md b/readme.md index e99bd85..8dfbf50 100644 --- a/readme.md +++ b/readme.md @@ -95,7 +95,6 @@ msbuild mcl.sln /p:Configuration=Release /m ## Build for WASM(WebAssembly) (experimental) mcl supports emcc (Emscripten) and `test/bn_test.cpp` runs on browers such as Firefox, Chrome and Edge(enable extended JavaScript at about:config). -* [pairing on brower](http://herumi.github.io/mcl/demo/pairing.html) * [BLS signature on brower](http://herumi.github.io/bls/demo/bls.html)