Skip to content

Commit

Permalink
support BLS12-381
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Apr 8, 2018
1 parent fd809fb commit d5a7a26
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bls
2 changes: 1 addition & 1 deletion build/bls_lib.js

Large diffs are not rendered by default.

Binary file modified build/bls_lib.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion build/build.ninja
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cflags = -I../mcl/include/ -I../cybozulib/include -I../bls/include -I../bls

rule buildExLib
command = emcc -O3 -o $out ../bls/src/bls_c.cpp ../mcl/src/fp.cpp --pre-js ../pre.js $cflags -s WASM=1 -DMCLBN_FP_UNIT_SIZE=6 -DMCL_MAX_BIT_SIZE=384 -DNDEBUG -DMCLBN_USE_NEW_DESERIALIZE_API
command = emcc -O3 -o $out ../bls/src/bls_c.cpp ../mcl/src/fp.cpp --pre-js ../pre.js $cflags -s WASM=1 -DMCLBN_FP_UNIT_SIZE=6 -DMCL_MAX_BIT_SIZE=384 -DNDEBUG -s DISABLE_EXCEPTION_CATCHING=0

build bls_lib.js : buildExLib
17 changes: 14 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ exports.MCLBN_CURVE_FP382_1 = 1
*/
exports.MCLBN_CURVE_FP382_2 = 2

/**
* The BLS12-381 curve
*/
exports.MCL_BLS12_381 = 5

const MCLBN_FP_UNIT_SIZE = 6
const FR_SIZE = MCLBN_FP_UNIT_SIZE * 8
const ID_SIZE = FR_SIZE
Expand Down Expand Up @@ -354,12 +359,18 @@ function wrapOutput (func, size) {
}
}

function memcpy (dst, src, size) {
for (let i = 0; i < size; i++) {
mod.HEAP8[dst + i] = mod.HEAP8[src + i]
}
}

function wrapKeyShare (func, dataSize) {
return function (x, vec, id) {
const k = vec.length
const p = mod._malloc(dataSize * k)
for (let i = 0; i < k; i++) {
mod._memcpy(p + i * dataSize, vec[i], dataSize)
memcpy(p + i * dataSize, vec[i], dataSize)
}
const r = func(x, p, k, id)
mod._free(p)
Expand All @@ -373,8 +384,8 @@ function wrapRecover (func, dataSize, idDataSize) {
const p = mod._malloc(dataSize * n)
const q = mod._malloc(idDataSize * n)
for (let i = 0; i < n; i++) {
mod._memcpy(p + i * dataSize, vec[i], dataSize)
mod._memcpy(q + i * idDataSize, idVec[i], idDataSize)
memcpy(p + i * dataSize, vec[i], dataSize)
memcpy(q + i * idDataSize, idVec[i], idDataSize)
}
const r = func(x, p, q, n)
mod._free(q)
Expand Down
2 changes: 1 addition & 1 deletion mcl
Submodule mcl updated 54 files
+2 −0 .gitignore
+2 −2 CMakeLists.txt
+34 −10 Makefile
+114 −0 bench.txt
+7 −4 ffi/go/mcl/mcl.go
+2 −2 ffi/go/mcl/mcl_test.go
+0 −1 ffi/js/exported-mcl.txt
+268 −0 include/mcl/aggregate_sig.hpp
+2 −3 include/mcl/ahe.hpp
+57 −35 include/mcl/bn.h
+890 −583 include/mcl/bn.hpp
+1 −6 include/mcl/bn256.hpp
+1 −6 include/mcl/bn384.hpp
+1 −1 include/mcl/bn512.hpp
+17 −0 include/mcl/curve_type.h
+58 −119 include/mcl/ec.hpp
+103 −87 include/mcl/elgamal.hpp
+85 −68 include/mcl/fp.hpp
+55 −156 include/mcl/fp_tower.hpp
+8 −5 include/mcl/gmp_util.hpp
+17 −9 include/mcl/op.hpp
+39 −1 include/mcl/operator.hpp
+4 −4 include/mcl/paillier.hpp
+96 −0 include/mcl/randgen.hpp
+0 −34 include/mcl/random.hpp
+83 −4 include/mcl/she.h
+591 −467 include/mcl/she.hpp
+0 −40 include/mcl/util.hpp
+7 −17 include/mcl/vint.hpp
+58 −39 readme.md
+1 −1 sample/pairing_c.c
+69 −0 sample/she_make_dlp_table.cpp
+7 −7 sample/she_smpl.cpp
+6 −0 src/bn_c512.cpp
+45 −37 src/bn_c_impl.hpp
+47 −34 src/fp.cpp
+64 −63 src/fp_generator.hpp
+288 −20 src/she_c_impl.hpp
+74 −0 test/aggregate_sig_test.cpp
+60 −0 test/bench.hpp
+642 −0 test/bls12_test.cpp
+12 −15 test/bn384_test.cpp
+11 −49 test/bn512_test.cpp
+6 −0 test/bn_c512_test.cpp
+27 −47 test/bn_c_test.hpp
+57 −72 test/bn_test.cpp
+13 −7 test/ec_test.cpp
+5 −0 test/fp_test.cpp
+70 −8 test/fp_util_test.cpp
+7 −7 test/glv_test.cpp
+8 −0 test/gmp_test.cpp
+3 −5 test/paillier_test.cpp
+187 −4 test/she_c_test.hpp
+304 −41 test/she_test.cpp
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bls-lib",
"version": "0.3.1",
"version": "0.3.2",
"description": "this library provides primitives for creating and verifying BLS threshold signatures",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ bls.onModuleInit(() => {
const secArray = Buffer.from(secString, 'hex')
const sec = bls.secretKeyImport(secArray)

const pubString = '7ca19ff032c22a00b3d79d8961495af4c6c93c9c2b62bd7279570fcc2ca8d120fc75fd16f55ded79f6392a0769496817cded4760ed658d62627b9e6852b1100d'
const pubString = 'cd995480d3287eb8626b1a40b224ed9ada052cae3472665eba297b9785929a1f8ecee5b65dd580f12f239a7183490c4470595ec73cde697cb92d15f1b666c597'

const pub = bls.publicKeyImport(Buffer.from(pubString, 'hex'))

Expand Down

0 comments on commit d5a7a26

Please sign in to comment.