Giter Site home page Giter Site logo

bls's Introduction

Build Status

BLS threshold signature

This library is an implementation of BLS threshold signature, which supports the new BLS Signatures specified at Ethereum 2.0 Phase 0.

News

  • 2023/Aug/17 The performance of Sign is improved.
  • 2022/Apr/20 The performance of MulVec got 2x speed for n >= 256, but const attribute of some arguments of MulVec and MultiVerify is removed.
    • They may be normalized in processing but the value are not changed.
  • 2021/Sep/16 update mcl and improve performance of isValidOrder, which is called from setStr/deserialize.
  • 2021/Apr/28 add blsSetGeneratorOfPublicKey to change the generator.
  • 2021/Jan/28 check zero public key on BLS_ETH mode
  • 2020/Oct/07 add blsMultiVerify to process many verification all togather with multi thread.

Support architectures

  • Windows Visual Studio / MSYS2(MinGW-w64)
  • Linux
  • macOS
  • Android
  • iOS
  • WebAssembly

Choice of groups

This library supports type-3 pairings such as BN curves and BLS curves. G1, G2, and GT are a cyclic group of prime order r.

e : G1 x G2 -> GT ; pairing

There are two ways for BLS signature.

type SecretKey PublicKey Signature
default Fr G2 G1
ETH2.0 spec (BLS_ETH=1) Fr G1 G2

If you need ETH2.0 spec, then use this library with BLS_ETH=1 mode.

Interoperability of BLS signature on BLS12-381 pairing

If you want to use the same parameters as Ethereum 2.0, just define BLS_ETH. If you want to use mcl/bls without BLS_ETH, then check the following settings.

  • Serialization/Deserialization between Fr/G1/G2 and byte sequences.
    • call blsSetETHserialization(1); to use the same specification as ETH2.0.
    • Serialize() compresses a point of G1/G2.
  • The generator of G1/G2.
    • call blsPublicKeySetHexStr.
  • Hash function from arbitrary byte sequences to G1/G2.
    • call blsSetMapToMode(MCL_MAP_TO_MODE_HASH_TO_CURVE); to use the same specification as ETH2.0.
    • call mclBnG1_setDst to set up domain separation.

For example, see initForDFINITY for DFINITY compatibility.

Support language bindings

language ETH2.0 spec (PublicKey = G1) default (PublicKey = G2)
Go bls-eth-go-binary bls-go-binary
WebAssembly (Node.js) bls-eth-wasm bls-wasm
Rust bls-eth-rust -

Compiled static library with BLS_ETH=1

The compiled static libraries with BLS_ETH=1 mode for {windows, darwin}/amd64, linux/{amd64, arm64} and android/{arm64-v8a, armeabi-v7a} are provided at bls-eth-go-binary/bls/lib.

Basic C API

Header files

#define BLS_ETH
#include <mcl/bn384_256.h>
#include <bls/bls.h>

Remark: BLS_ETH must always be defined before including bls/bls.h if you need ETH2.0 spec mode.

Initialization

// init library at once before calling the other APIs
int err = blsInit(MCL_BLS12_381, MCLBN_COMPILED_TIME_VAR);
if (err != 0) {
  printf("blsInit err %d\n", err);
  exit(1);
}

// use the latest eth2.0 spec
blsSetETHmode(BLS_ETH_MODE_LATEST);

Remark:

  • blsInit and some functions which modify global settings such as blsSetETHmode are NOT thread-safe. The other functions are all thread-safe.
  • blsSetETHmode is available for only BLS_ETH=1 mode.

KeyGen

Init a secret key sec and create a public key pub.

blsSecretKey sec;
blsPublicKey pub;

// init SecretKey sec by random number
blsSecretKeySetByCSPRNG(&sec);

// get PublicKey pub from SecretKey sec
blsGetPublicKey(&pub, &sec);

Sign

Make a signature sig of a message msg[0..msgSize-1] by the secret key sec.

blsSignature sig;
char msg[] = "hello";
const size_t msgSize = strlen(msg);

blsSign(&sig, &sec, msg, msgSize);

msg may contain \x00 if the correct msgSize is specified.

Verify

Verify the signature sig of the message msg[0..msgSize-1] by the public key pub.

// return 1 if it is valid else 0
int blsVerify(&sig, &pub, msg, msgSize);

Aggregate Signature

Aggregate Signatures sigVec[0], ..., sigVec[n-1] to aggSig. aggSig is cleared if n = 0.

void blsAggregateSignature(
  blsSignature *aggSig,
  const blsSignature *sigVec,
  mclSize n
);

FastAggregateVerify

Verify a signature sig of a message msg[0..msgSize-1] by pubVec[0], ..., pubVec[n-1].

int blsFastAggregateVerify(
  const blsSignature *sig,
  const blsPublicKey *pubVec,
  mclSize n,
  const void *msg,
  mclSize msgSize
);

AggregateVerify

  • pubVec is n array of PublicKey
  • msgVec is n * msgSize-byte array, which concatenates n-byte messages of length msgSize.

Verify Signature sig of (Message msgVec[msgSize * i..msgSize * (i+1)-1] and pubVec[i]) for i = 0, ..., n-1.

int blsAggregateVerifyNoCheck(
  const blsSignature *sig,
  const blsPublicKey *pubVec,
  const void *msgVec,
  mclSize msgSize,
  mclSize n
);

REMARK : blsAggregateVerifyNoCheck does not check

  • sig has the correct order
  • every n-byte messages of length msgSize are different from each other

Check them at the caller if necessary.

Functions corresponding to ETH2.0 spec names

bls.h eth2.0 spec name
blsSign Sign
blsVerify Verify
blsAggregateSignature Aggregate
blsFastAggregateVerify FastAggregateVerify
blsAggregateVerifyNoCheck AggregateVerify

Setter

int blsSecretKeySetLittleEndianMod(blsSecretKey *sec, const void *buf, mclSize bufSize);

Set sec to (buf[0..bufSize-1] as little endian) mod r and return 0 if bufSize <= 64 else -1.

Serialization

mclSize blsSecretKeySerialize(void *buf, mclSize maxBufSize, const blsSecretKey *sec);
mclSize blsPublicKeySerialize(void *buf, mclSize maxBufSize, const blsPublicKey *pub);
mclSize blsSignatureSerialize(void *buf, mclSize maxBufSize, const blsSignature *sig);

Serialize the instance to buf[0..maxBufSize-1] and return written byte size if success else 0.

mclSize blsSecretKeyDeserialize(blsSecretKey *sec, const void *buf, mclSize bufSize);
mclSize blsPublicKeyDeserialize(blsPublicKey *pub, const void *buf, mclSize bufSize);
mclSize blsSignatureDeserialize(blsSignature *sig, const void *buf, mclSize bufSize);

Deserialize buf[0..bufSize-1] to the instance and return read byte size if success else 0.

Check order

Check whether sig and pub have the correct order r.

// return 1 if it is valid else 0
int blsSignatureIsValidOrder(const blsSignature *sig);
int blsPublicKeyIsValidOrder(const blsPublicKey *pub);

API for k-of-n threshold signature

  1. Prepare k secret keys (msk).
  2. Make n secret keys from msk by blsSecretKeyShare.
  3. Each user makes the public key from the given secret key.
  4. Each user makes a signature for the same message.
  5. Any k subset of n signatures can recover the master signature by blsSignatureRecover.

See sample/minsample.c for the details.

int blsSecretKeyShare(blsSecretKey *sec, const blsSecretKey *msk, mclSize k, const blsId *id);

Make sec corresponding to id from {msk[i] for i = 0, ..., k-1}.

int blsSignatureRecover(blsSignature *sig, const blsSignature *sigVec, const blsId *idVec, mclSize n);

Recover sig from {(sigVec[i], idVec[i]) for i = 0, ..., n-1}.

Multi aggregate signature (experimental)

blsMultiAggregateSignature and blsMultiAggregatePublicKey are provided for BLS Multi-Signatures With Public-Key Aggregation. The hash function is temporary. See blsMultiAggregateTest.

void blsMultiAggregateSignature(
  blsSignature *aggSig,
  blsSignature *sigVec,
  blsPublicKey *pubVec,
  mclSize n
);

Set aggSig = sum_{i=0^n-1} sigVec[i] t_i, where (t_1, ..., t_n) = Hash({pubVec[0..n-1]}).

void blsMultiAggregatePublicKey(
  blsPublicKey *aggPub,
  blsPublicKey *pubVec,
  mclSize n
);

Set aggPub = sum_{i=0^n-1} pubVec[i] t_i, where (t_1, ..., t_n) = Hash({pubVec[0..n-1]}).

How to build a static library by ownself

The following description is for BLS_ETH=1 mode. Remove it if you need PublicKey as G1.

Preliminaries

git clone --recursive https://github.com/herumi/bls

Build static library for Linux and macOS

make -C mcl lib/libmcl.a
make BLS_ETH=1 lib/libbls384_256.a

If the option MCL_USE_GMP=0 (resp.MCL_USE_OPENSSL=0) is used then GMP (resp. OpenSSL) is not used.

Build library for Windows

static library

mklib eth

dynamic library

mklib dll eth

Build static library for Android

See bls-eth-go-binary

History

  • 2020/May/13 : blsSetETHmode() supports BLS_ETH_MODE_DRAFT_07 defined at BLS12381G2_XMD:SHA-256_SSWU_RO_.
  • 2020/Apr/02 : experimental add blsMultiAggregateSignature/blsMultiAggregatePublicKey multiSig
    • The hash function is temporary, which may be modified in the future.
  • 2020/Mar/26 : DST of hash-to-curve of mcl is changed, so the output has also changed for BLS_ETH_MODE_DRAFT_06.
  • 2020/Mar/15 : blsSetETHmode() supports BLS_ETH_MODE_DRAFT_06 defined at draft-irtf-cfrg-hash-to-curve at March 2020. But it has not yet fully tested.

License

modified new BSD License http://opensource.org/licenses/BSD-3-Clause

Author

MITSUNARI Shigeo([email protected])

Sponsors welcome

GitHub Sponsor

bls's People

Contributors

amin-jabri avatar dapplion avatar fxfactorial avatar herumi avatar infinity0 avatar mpetrunic avatar rhysd avatar spiderpowa avatar tkstanczak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bls's Issues

Fast verification of multiple BLS signatures

In the context of Eth2.0 Vitalik Buterin proposes a technique for optimizing the verification of all n signatures at the same time, especially in the case where the same message is signed by many public keys.

https://ethresear.ch/t/fast-verification-of-multiple-bls-signatures/5407

I am implementing support for this technique for Lodestar, but since bls does not expose mcl functions we should wrap and load both wasms which is not optimal. Since this technique is really useful I believe it is appropriate to include it in this library directly. It is included in blst as verify_multiple_aggregate_signatures

I would love to contribute to the source library but my C++ knowledge is too limited. I would like to explore the interest in implementing it by the maintainer. I attach below a reference implementation in javascript consuming the WASM compile of bls and mcl, to illustrate the scope of this function.

function verifyMultipleAggregateSignatures(sigVec: Signature[], pubVec: PublicKey[], msgVec: Uint8Array[]) {
  const msgs: Uint8Array = concatUint8Array(msgVec);

  // Get and cast random values to Fr
  const randXs = Array.from({ length: sigVec.length }, (_, i) => {
    const x = new mcl.Fr();
    x.setByCSPRNG();
    return x;
  });

  // Multi scalar multiplication on: Sig * rand, as G2 points
  const sigVecG2s: G2[] = sigVec.map(castSigToG2);
  const aggSig: Signature = castG2ToSig(mcl.mulVec(sigVecG2s, randXs));

  // Scalar multiplication on: Pub * rand, as G1 points
  const multiKeys: PublicKey[] = pubVec.map((pub, i) =>
    castG1ToPub(mcl.mul(castPubToG1(pub), randXs[i]))
  );

  return aggSig.aggregateVerifyNoCheck(multiKeys, msgsConcat);
}

Thank you so much for your valuable contributions ❤️

error: use of undeclared identifier '_mm_popcnt_u32'

I build and test for Windows 10, have following issues:

\bls>mklib
make lib/lib384.lib
CFLAGS=/MT /DNOMINMAX /Ox /DNDEBUG /W4 /Zi /EHsc /nologo -I ./include -I../cybozulib/include -I../cybozulib_ext/include -I../mcl/include/ -I../mcl/src -I./ -I../xbyak/ /DMCLBN_FP_UNIT_SIZE=6 /DMCL_NO_AUTOLINK /DMCLBN_NO_AUTOLINK /DBLS_DONT_EXPORT
In file included from src/bls_c.cpp:6:
In file included from .\../mcl/src/bn_c_impl.hpp:7:
In file included from ../mcl/include\mcl/bn384.hpp:10:
In file included from ../mcl/include\mcl/bn.hpp:9:
In file included from ../mcl/include\mcl/fp_tower.hpp:9:
In file included from ../mcl/include\mcl/fp.hpp:30:
In file included from ../mcl/include\mcl/util.hpp:9:
../cybozulib/include\cybozu/bit_operation.hpp(121,31) :  error: use of undeclared identifier '_mm_popcnt_u32'
        return static_cast<uint32_t>(_mm_popcnt_u32(x));
                                     ^
1 error generated.
In file included from ../mcl/src/fp.cpp:2:
In file included from ../mcl/include\mcl/util.hpp:9:
../cybozulib/include\cybozu/bit_operation.hpp(121,31) :  error: use of undeclared identifier '_mm_popcnt_u32'
        return static_cast<uint32_t>(_mm_popcnt_u32(x));
                                     ^
1 error generated.
Microsoft (R) Library Manager Version 12.00.21005.1
Copyright (C) Microsoft Corporation.  All rights reserved.

LINK : fatal error LNK1181: 无法打开输入文件“obj/bls_c.obj”

Please solve it

the signature result is different with phoreproject's

signed the same msg with same private key, seems the signature result is different with
github.com/phoreproject/bls/g1pubs

i guess the algorithm to get hash of msg is different, is that true?
if need to keep consistency?

Support building from an installed mcl in any $(prefix) location

Currently the bls build depends on mcl but it is hard-coded it look for it in ../. This means it is hard to package for package managers like Debian or Nix.

It would be good if bls could just find mcl in the normal system directories. Usually if a dependency is installed there (e.g. /usr/include) then you don't even need to give any -I or -l flags.

How do we compile for Android platforms?

Hi,

I am trying to build for Android platforms (armv7-a, 8a, x86) and don't see instructions for building it. Do you have any instructions to build as libraries?

Thanks

How to compile bls and linked with cgo on windows?

We know that cgo only support for gcc, and bls need to be compiled with cl on windows.
How can i use cgo to compile bls to a single one binary executable program?
I compiled bls into a lib with mklib.bat, but i cannot use cgo to link this.
How can i do?

How to perform point subtraction and negation on BLS curve?

Hello! I'm curious how to perform point subtraction and negation on BLS curve.
I.e there are two signatures A and B, how to perform point subtraction & negation such as A - B, -B, etc in this repo? Thx!


I observed that this func might be used for signature subtraction:

void blsSignatureSub(blsSignature *sig, const blsSignature *rhs)

Could you please include this func into https://github.com/herumi/bls/blob/master/ffi/cs/bls.cs? Thx!

FN462

Can BN 462 be used? If so, how? Thanks!

make test fail when disable OpenSSL

make test fail when disable OpenSSL.

$ make MCL_USE_OPENSSL=0 clean test
rm -rf obj/*.d obj/*.o bin/*.exe     lib/libbls256.a lib/libbls256_dy.dylib lib/libbls384.a lib/libbls384_dy.dylib lib/libbls384_256.a lib/libbls384_256_dy.dylib result.txt sample/*.txt
c++ -I/usr/local/opt/openssl/include -I/usr/local/opt/gmp/include -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -O3  -DMCL_DONT_USE_OPENSSL -fPIC -std=c++11 -I../mcl/include -I./ -c src/bls_c256.cpp -o obj/bls_c256.o -MMD -MP -MF obj/bls_c256.d
ar r lib/libbls256.a obj/bls_c256.o
ar: creating archive lib/libbls256.a
c++ -I/usr/local/opt/openssl/include -I/usr/local/opt/gmp/include -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -m64 -I include -I test -fomit-frame-pointer -DNDEBUG -O3  -DMCL_DONT_USE_OPENSSL -fPIC -std=c++11 -I../mcl/include -I./ -c test/bls256_test.cpp -o obj/bls256_test.o -MMD -MP -MF obj/bls256_test.d
In file included from test/bls256_test.cpp:2:
test/bls_test.hpp:453:3: error: no matching constructor for initialization of 'cybozu::Sha256'
                cybozu::Sha256(msg, msgSize).get(h[i].data);
                ^              ~~~~~~~~~~~~
../mcl/include/cybozu/sha2.hpp:198:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
class Sha256 : public sha2_local::Common<Sha256> {
      ^
../mcl/include/cybozu/sha2.hpp:198:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
../mcl/include/cybozu/sha2.hpp:263:2: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
        Sha256()
        ^
1 error generated.
make: *** [obj/bls256_test.o] Error 1

128-bit signature

How about support of 128-bit length signature? Or configurable length in general.

arm64 support

Does this library support arm64 architecture?

I've hit a problem like

build constraints exclude all Go files in bls/ffi/go/bls

Is it safe to reuse same key for diff message ?

This is a question not a bug report. (don't know where to ask so I put it here)

for BLS12-381:

When I use G2 as public key, (minimizing signature size), is it safe use the same private key to signature a lot message ? (each message with a unique message id, so they are all different), the message quantity could be billion and still safe without leak private key ?

I read from blockchain document, the minimizing public key size variant use G1 as public key(48 byte), G2 as signatures(48 byte), and private key is 32 byte. So I guess the minimizing signature size public key size is 96byte, signature is 48 byte, private key still 32 byte, is this correct ?

Random verification results.

    blsInit(MCL_BLS12_381, MCLBN_COMPILED_TIME_VAR);
    blsSetETHmode(BLS_ETH_MODE_LATEST);

    int n = 7;
    const size_t k = 5;

    blsSecretKey masterSec;
    blsPublicKey masterPub;
    blsSecretKeySetByCSPRNG(&masterSec);
    blsGetPublicKey(&masterPub, &masterSec);

    blsSecretKey secs [n];
    blsPublicKey pubs [n];
    blsSignature sigs [n];
    blsId ids [n];

    char msg[] = "hello";
    const size_t msgSize = strlen(msg);

    for (int i = 0; i < n; i++)
    {
        blsId id;
        blsIdSetInt(&id, i + 1);
        ids[i] = id;

        blsSecretKeyShare(&secs[i], &masterSec, k, &id);
        blsPublicKeyShare(&pubs[i], &masterPub, k, &id);

        blsSign(&sigs[i], &secs[i], msg, msgSize);
    }

    blsSignature sig;
    cout << blsSignatureRecover(&sig, sigs, ids, n) << endl;
    cout << blsVerify(&sig, &masterPub, msg, msgSize) << endl;

So I wrote this little program to create a threshold signature and verify it.
The problem is that on random occasions verify spits out 1 and 0.

I also extended this further to check if it works down to the threshold and the same applies.

Short comment: It is very confusing that some methods return 0 and some methods return 1 on success. This could be more consistent.

Different version bls library produce different result

I used the bls library in my project, recently I update it to the newest version.
But I found that the same bls12-381 private key produce different public key in the two version, and use it to sign the same data produce different signature. The bls and mcl library I compiled passed all tests, both c and go.
Is it that in purpose? Is it a bug? Is the algorithm be changed? If the algorithm is changed, will it change in the future?

I previous use this version bls 06a8ffa and mcl herumi/mcl@4c92ce3, and now I use bls 5f21120 and mcl herumi/mcl@0a086ef.

And this is my test code, it will success on new version and failed in old version.

Result:

package test

import (
	"testing"

	"github.com/stretchr/testify/assert"

	"github.com/herumi/bls"
)

var (
	keyBytes = []byte{
		0x2f, 0x4e, 0x60, 0xb6, 0xf7, 0xd0, 0xf2, 0x8, 0x9d, 0x94, 0xfe, 0x6d, 0xb0, 0x6a, 0x34, 0xad,
		0x98, 0xc7, 0x61, 0x9c, 0x45, 0x82, 0xc8, 0x5d, 0xe5, 0x94, 0x6f, 0xaa, 0x4f, 0x11, 0x8f, 0x3e,
	}

	expectedPkeyBytes = []byte{
		0x9e, 0x9e, 0x3d, 0x83, 0xce, 0xc5, 0x60, 0x89, 0xe0, 0x7c, 0x1c, 0xe7, 0x7b, 0x84, 0xc2, 0x83,
		0x5f, 0xd5, 0x9f, 0x5c, 0x4f, 0xba, 0x17, 0x41, 0x97, 0x44, 0xc7, 0x11, 0x30, 0xe1, 0x72, 0x8c,
		0x98, 0xa2, 0x11, 0x2b, 0xd, 0xd3, 0x82, 0xf0, 0xe7, 0x4d, 0x88, 0x81, 0xdd, 0xad, 0x7, 0x13,
		0xc0, 0x4d, 0xb7, 0x20, 0xe6, 0xd2, 0x83, 0xd, 0x6a, 0x4c, 0xab, 0x8b, 0x30, 0x9c, 0xdd, 0x60,
		0x1c, 0xcf, 0x99, 0x62, 0xb2, 0xa1, 0x81, 0x6f, 0xde, 0x4, 0xd6, 0x9, 0xbc, 0x73, 0x49, 0xe9,
		0x93, 0x87, 0x42, 0xf4, 0xb5, 0x4d, 0xd, 0x5e, 0x24, 0x14, 0xd2, 0x1c, 0x95, 0xc6, 0x75, 0x8a,
	}

	data = []byte("abc")

	expectedSignBytes = []byte{
		0xa2, 0x4c, 0x86, 0xad, 0xeb, 0x7a, 0xdb, 0x51, 0x44, 0xc5, 0xad, 0x36, 0xea, 0xba, 0x13, 0xff,
		0xe1, 0x27, 0x7, 0x9c, 0xcd, 0xa9, 0x2, 0x13, 0x81, 0x47, 0xf6, 0x93, 0x76, 0x1b, 0x7b, 0xdf,
		0x44, 0x6, 0x8c, 0x7a, 0x6c, 0x61, 0xc7, 0xcd, 0x4, 0x5, 0x63, 0x5d, 0x59, 0x17, 0x57, 0x83,
	}
)

func TestBls(t *testing.T) {
	Init(bls.BLS12_381)

	var key bls.SecretKey
	key.SetLittleEndian(keyBytes)

	pkey := key.GetPublicKey()
	pkeyBytes := pkey.Serialize()
	assert.Equal(t, expectedPkeyBytes, pkeyBytes)

	sign := key.SignBytes(data)
	signBytes := sign.Serialize()
	assert.Equal(t, expectedSignBytes, signBytes)

	ok := sign.VerifyBytes(pkey, data)
	assert.True(t, ok)
}

Output:

=== RUN   TestBls
--- FAIL: TestBls (0.01s)
    bls_test.go:43: 
        	Error Trace:	bls_test.go:43
        	Error:      	Not equal: 
        	            	expected: []byte{0x9e, 0x9e, 0x3d, 0x83, 0xce, 0xc5, 0x60, 0x89, 0xe0, 0x7c, 0x1c, 0xe7, 0x7b, 0x84, 0xc2, 0x83, 0x5f, 0xd5, 0x9f, 0x5c, 0x4f, 0xba, 0x17, 0x41, 0x97, 0x44, 0xc7, 0x11, 0x30, 0xe1, 0x72, 0x8c, 0x98, 0xa2, 0x11, 0x2b, 0xd, 0xd3, 0x82, 0xf0, 0xe7, 0x4d, 0x88, 0x81, 0xdd, 0xad, 0x7, 0x13, 0xc0, 0x4d, 0xb7, 0x20, 0xe6, 0xd2, 0x83, 0xd, 0x6a, 0x4c, 0xab, 0x8b, 0x30, 0x9c, 0xdd, 0x60, 0x1c, 0xcf, 0x99, 0x62, 0xb2, 0xa1, 0x81, 0x6f, 0xde, 0x4, 0xd6, 0x9, 0xbc, 0x73, 0x49, 0xe9, 0x93, 0x87, 0x42, 0xf4, 0xb5, 0x4d, 0xd, 0x5e, 0x24, 0x14, 0xd2, 0x1c, 0x95, 0xc6, 0x75, 0x8a}
        	            	actual  : []byte{0xc7, 0x4c, 0x36, 0xca, 0x5f, 0xdb, 0x78, 0xf2, 0x74, 0x70, 0x42, 0xc2, 0x8e, 0x9c, 0xe5, 0xde, 0xef, 0xad, 0x6c, 0xae, 0xd4, 0x29, 0xa0, 0x89, 0xd0, 0x74, 0x3b, 0x81, 0x32, 0x14, 0x43, 0x1, 0x3f, 0xe7, 0x7c, 0xb, 0xba, 0xd8, 0x51, 0x22, 0x70, 0x27, 0xac, 0x14, 0xaf, 0xef, 0xe9, 0x9, 0xe1, 0x45, 0x58, 0x8e, 0x42, 0xeb, 0xc, 0x3a, 0x52, 0xe9, 0x20, 0xa8, 0xfd, 0x50, 0xe, 0x55, 0x70, 0x3e, 0x98, 0xb7, 0xa5, 0x8c, 0x98, 0x82, 0x83, 0x72, 0x75, 0x7f, 0xa1, 0xdb, 0x7a, 0x43, 0x85, 0xea, 0xd4, 0xc6, 0x43, 0x28, 0xda, 0x1c, 0xcd, 0x36, 0x92, 0x7f, 0x27, 0xc, 0xd1, 0x5}
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,8 +1,8 @@
        	            	 ([]uint8) (len=96) {
        	            	- 00000000  9e 9e 3d 83 ce c5 60 89  e0 7c 1c e7 7b 84 c2 83  |..=...`..|..{...|
        	            	- 00000010  5f d5 9f 5c 4f ba 17 41  97 44 c7 11 30 e1 72 8c  |_..\O..A.D..0.r.|
        	            	- 00000020  98 a2 11 2b 0d d3 82 f0  e7 4d 88 81 dd ad 07 13  |...+.....M......|
        	            	- 00000030  c0 4d b7 20 e6 d2 83 0d  6a 4c ab 8b 30 9c dd 60  |.M. ....jL..0..`|
        	            	- 00000040  1c cf 99 62 b2 a1 81 6f  de 04 d6 09 bc 73 49 e9  |...b...o.....sI.|
        	            	- 00000050  93 87 42 f4 b5 4d 0d 5e  24 14 d2 1c 95 c6 75 8a  |..B..M.^$.....u.|
        	            	+ 00000000  c7 4c 36 ca 5f db 78 f2  74 70 42 c2 8e 9c e5 de  |.L6._.x.tpB.....|
        	            	+ 00000010  ef ad 6c ae d4 29 a0 89  d0 74 3b 81 32 14 43 01  |..l..)...t;.2.C.|
        	            	+ 00000020  3f e7 7c 0b ba d8 51 22  70 27 ac 14 af ef e9 09  |?.|...Q"p'......|
        	            	+ 00000030  e1 45 58 8e 42 eb 0c 3a  52 e9 20 a8 fd 50 0e 55  |.EX.B..:R. ..P.U|
        	            	+ 00000040  70 3e 98 b7 a5 8c 98 82  83 72 75 7f a1 db 7a 43  |p>.......ru...zC|
        	            	+ 00000050  85 ea d4 c6 43 28 da 1c  cd 36 92 7f 27 0c d1 05  |....C(...6..'...|
        	            	 }
        	Test:       	TestBls
    bls_test.go:47: 
        	Error Trace:	bls_test.go:47
        	Error:      	Not equal: 
        	            	expected: []byte{0xa2, 0x4c, 0x86, 0xad, 0xeb, 0x7a, 0xdb, 0x51, 0x44, 0xc5, 0xad, 0x36, 0xea, 0xba, 0x13, 0xff, 0xe1, 0x27, 0x7, 0x9c, 0xcd, 0xa9, 0x2, 0x13, 0x81, 0x47, 0xf6, 0x93, 0x76, 0x1b, 0x7b, 0xdf, 0x44, 0x6, 0x8c, 0x7a, 0x6c, 0x61, 0xc7, 0xcd, 0x4, 0x5, 0x63, 0x5d, 0x59, 0x17, 0x57, 0x83}
        	            	actual  : []byte{0xdb, 0x2f, 0xd2, 0x46, 0xd6, 0x60, 0x8b, 0xd2, 0x11, 0xcc, 0x39, 0xe6, 0x1a, 0xfc, 0x95, 0x1b, 0x92, 0x28, 0xc4, 0x19, 0xf6, 0x89, 0x32, 0xc7, 0x70, 0x53, 0xd, 0x6e, 0x76, 0xaa, 0xe, 0xd8, 0xdf, 0x7f, 0x21, 0xb8, 0x3b, 0x1f, 0xf5, 0xce, 0xc6, 0x10, 0x87, 0x87, 0xd4, 0xe9, 0xd1, 0x83}
        	            	
        	            	Diff:
        	            	--- Expected
        	            	+++ Actual
        	            	@@ -1,5 +1,5 @@
        	            	 ([]uint8) (len=48) {
        	            	- 00000000  a2 4c 86 ad eb 7a db 51  44 c5 ad 36 ea ba 13 ff  |.L...z.QD..6....|
        	            	- 00000010  e1 27 07 9c cd a9 02 13  81 47 f6 93 76 1b 7b df  |.'.......G..v.{.|
        	            	- 00000020  44 06 8c 7a 6c 61 c7 cd  04 05 63 5d 59 17 57 83  |D..zla....c]Y.W.|
        	            	+ 00000000  db 2f d2 46 d6 60 8b d2  11 cc 39 e6 1a fc 95 1b  |./.F.`....9.....|
        	            	+ 00000010  92 28 c4 19 f6 89 32 c7  70 53 0d 6e 76 aa 0e d8  |.(....2.pS.nv...|
        	            	+ 00000020  df 7f 21 b8 3b 1f f5 ce  c6 10 87 87 d4 e9 d1 83  |..!.;...........|
        	            	 }
        	Test:       	TestBls
FAIL

Question About Using Project in Go Package

Hi @herumi,

Looks like the efficiency drop isn't too bad without GMP (barely noticeable), but we have another consideration. We plan on wrapping this project in a go wrapper called https://github.com/prysmaticlabs/go-bls which people can then import and use in their own projects through a go get github.com/prysmaticlabs/go-bls. We don't want our users to need to know much about its internals, they should just be able to go get and have it working.

The problem is that your system working relies on people running make to generate the static and shared object libraries, which are architecture dependent. Do you suggest then just precompiling these libraries for all major architectures and checking them into the lib/ folder to distribute? Is this a security concern?

Additionally, on Ubuntu, the tests expect me to have the lib in $LD_LIBRARY_PATH so I have to export LD_LIBRARY_PATH=mcl/lib:$LD_LIBRARY_PATH which we do not want people to need to do all the time. Do you have recommendations to get around this?

[usage] Does Usage of this wrapper(go version) correct ?

build failed loocally on my laptop (ubuntu 18.04)

PR: harmony-one/harmony#3644

import "github.com/herumi/bls-eth-go-binary/bls"

this PR use this library to bls sign verfiy and so forth. but it shows error message related herumi when buid:

../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:36:24: could not determine kind of name for C.BLS_ETH_MODE_DRAFT_05
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:37:24: could not determine kind of name for C.BLS_ETH_MODE_DRAFT_06
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:38:24: could not determine kind of name for C.BLS_ETH_MODE_DRAFT_07
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:39:23: could not determine kind of name for C.BLS_ETH_MODE_LATEST
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:35:20: could not determine kind of name for C.BLS_ETH_MODE_OLD
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:839:2: could not determine kind of name for C.blsAggregateSignature
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:971:9: could not determine kind of name for C.blsAggregateVerifyNoCheck
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:848:9: could not determine kind of name for C.blsFastAggregateVerify
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:818:9: could not determine kind of name for C.blsMultiVerifyFinal
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:781:4: could not determine kind of name for C.blsMultiVerifySub
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:912:9: could not determine kind of name for C.blsPublicKeyDeserializeUncompressed
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:457:9: could not determine kind of name for C.blsPublicKeyIsZero
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:891:7: could not determine kind of name for C.blsPublicKeySerializeUncompressed
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:299:9: could not determine kind of name for C.blsSecretKeyIsZero
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:934:12: could not determine kind of name for C.blsSetETHmode
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:922:9: could not determine kind of name for C.blsSignatureDeserializeUncompressed
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:560:9: could not determine kind of name for C.blsSignatureIsZero
../../../../pkg/mod/github.com/herumi/[email protected]/bls/bls.go:902:7: could not determine kind of name for C.blsSignatureSerializeUncompressed

How to fix it ?

I found the problem using google, there are many root cause. I tried some way, but it did not work

print public key got inconsistent result in go

I am using go-binding of bls in harmony-one/harmony project. I was trying to compare two public keys by checking the print out value in the log file. However, I found two public keys print out different values in string format even though they are deserialized from the same byte array.

I guess it is because the bls go-binding didn't implement the String function for golang.

Unwanted "1" at the start of blsPublicKeyGetHexStr

Hi,

I ported the Bls to Swift but when I am trying to run blsPublicKeyGetHexStr it returns with "1 " at the beginning of the string with 386 which should be 96.

1 118b23c5d8697d5aa6aaa4289c2d3dff33b072bcb9ba9be5bc276160b17676f6aa7decf8cfc35d0a359827b15c4df83a 499f44fec119bb675474f0785b5dc1ae14c6099d6871a8e131f6ab38fcf5a9c8db821daa4728d6b320f8a9379a8f6ef 10167dc41b78dc2e0642fcd980a5d73b170b2e494ad686d660ffe2c1ab821872feab05d266c0e5b4ce583b2064f43b26 12564e74ea12f05884c427e6784ab5c8d2f3492d24d9399dd88eaf9e72355f7ac13a70a32a51227fd44669ed89f58b55

        var pub = blsPublicKey.init()
        blsGetPublicKey(&pub, &sec);

        let PUBLIC_KEY_SIZE = 96
        var publicKeyBytes = Data(count: PUBLIC_KEY_SIZE).bytes // [UInt8]
        blsPublicKeySerialize(&publicKeyBytes, PUBLIC_KEY_SIZE, &pub)
        let hex = blsPublicKeyGetHexStr(unsafePointerpub,  2048, &pub)

Any idea how to resolve this?

Alpine linux support (link musl)

The Go-BLS build works for me, but when I run it on Alpine linux (no glibc, only musl), it fails to run.
Alpine is a widely used light-weight environment for docker-containers.

Can we build the Amd64 target without glibc, to enable Alpine linux?

This is what I get when I run it in my CI environment:

# github.com/herumi/bls-eth-go-binary/bls
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `Xbyak::util::Pack::sub(unsigned long, unsigned long) const [clone .constprop.401]':
fp.cpp:(.text+0x201): undefined reference to `__fprintf_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `mcl::fp::sha512(void*, unsigned int, void const*, unsigned int)':
fp.cpp:(.text+0xee9): undefined reference to `__memcpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `mcl::fp::Op::init(mcl::VintT<mcl::vint::FixedBuffer<unsigned long, 768ul> > const&, unsigned long, int, mcl::fp::Mode, unsigned long)':
fp.cpp:(.text+0xb50f): undefined reference to `__memset_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `Xbyak::util::Pack::append(Xbyak::Reg64 const&) [clone .part.58]':
fp.cpp:(.text.unlikely+0x1b1): undefined reference to `__fprintf_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `Xbyak::util::Pack::init(Xbyak::Reg64 const*, unsigned long) [clone .part.59]':
fp.cpp:(.text.unlikely+0x209): undefined reference to `__fprintf_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `mcl::fp::FpGenerator::mkLabel[abi:cxx11](char const*, int) const [clone .isra.296]':
fp.cpp:(.text._ZNK3mcl2fp11FpGenerator7mkLabelB5cxx11EPKci.isra.296[_ZN3mcl2fp11FpGenerator10gen_preInvEv]+0x49): undefined reference to `__snprintf_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `cybozu::sha2_local::hmac256_inner(void*, void const*, unsigned long, void const*, unsigned long, bool)':
fp.cpp:(.text._ZN6cybozu10sha2_local13hmac256_innerEPvPKvmS3_mb[_ZN6cybozu10sha2_local13hmac256_innerEPvPKvmS3_mb]+0x66a): undefined reference to `__memcpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: fp.cpp:(.text._ZN6cybozu10sha2_local13hmac256_innerEPvPKvmS3_mb[_ZN6cybozu10sha2_local13hmac256_innerEPvPKvmS3_mb]+0x889): undefined reference to `__memcpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `Xbyak::util::Pack::operator[](unsigned long) const':
fp.cpp:(.text._ZNK5Xbyak4util4PackixEm[_ZNK5Xbyak4util4PackixEm]+0x2e): undefined reference to `__fprintf_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `Xbyak::util::Pack::sub(unsigned long, unsigned long) const':
fp.cpp:(.text._ZNK5Xbyak4util4Pack3subEmm[_ZNK5Xbyak4util4Pack3subEmm]+0x17a): undefined reference to `__fprintf_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `Xbyak::util::Profiler::set(char const*, void const*)':
fp.cpp:(.text._ZN5Xbyak4util8Profiler3setEPKcPKv[_ZN5Xbyak4util8Profiler3setEPKcPKv]+0x4c): undefined reference to `__fprintf_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o): in function `mcl::fp::FpGenerator::cmovc_rr(Xbyak::util::Pack const&, Xbyak::util::Pack const&)':
fp.cpp:(.text._ZN3mcl2fp11FpGenerator8cmovc_rrERKN5Xbyak4util4PackES6_[_ZN3mcl2fp11FpGenerator8cmovc_rrERKN5Xbyak4util4PackES6_]+0x9d): undefined reference to `__fprintf_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: fp.cpp:(.text._ZN3mcl2fp11FpGenerator8cmovc_rrERKN5Xbyak4util4PackES6_[_ZN3mcl2fp11FpGenerator8cmovc_rrERKN5Xbyak4util4PackES6_]+0xf4): undefined reference to `__fprintf_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(fp.o):fp.cpp:(.text._ZN3mcl2fp11FpGenerator7load_rmIN5Xbyak6RegExpEEEvRKNS3_4util4PackERKT_[_ZN3mcl2fp11FpGenerator7load_rmIN5Xbyak6RegExpEEEvRKNS3_4util4PackERKT_]+0x28f): more undefined references to `__fprintf_chk' follow
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(bls_c384_256.o): in function `void mcl::EcT<mcl::FpT<mcl::bn::local::FpTag, 384ul> >::save<cybozu::MemoryOutputStream>(bool*, cybozu::MemoryOutputStream&, int) const [clone .constprop.101]':
bls_c384_256.cpp:(.text+0x7559): undefined reference to `__memset_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: bls_c384_256.cpp:(.text+0x7581): undefined reference to `__memset_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(bls_c384_256.o): in function `mcl::FpT<mcl::bn::local::FpTag, 384ul>::init(bool*, int, mcl::VintT<mcl::vint::FixedBuffer<unsigned long, 768ul> > const&, mcl::fp::Mode)':
bls_c384_256.cpp:(.text._ZN3mcl3FpTINS_2bn5local5FpTagELm384EE4initEPbiRKNS_5VintTINS_4vint11FixedBufferImLm768EEEEENS_2fp4ModeE[_ZN3mcl3FpTINS_2bn5local5FpTagELm384EE4initEPbiRKNS_5VintTINS_4vint11FixedBufferImLm768EEEEENS_2fp4ModeE]+0x174): undefined reference to `__memcpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(bls_c384_256.o): in function `mcl::FpT<mcl::bn::local::FrTag, 256ul>::init(bool*, int, mcl::VintT<mcl::vint::FixedBuffer<unsigned long, 768ul> > const&, mcl::fp::Mode)':
bls_c384_256.cpp:(.text._ZN3mcl3FpTINS_2bn5local5FrTagELm256EE4initEPbiRKNS_5VintTINS_4vint11FixedBufferImLm768EEEEENS_2fp4ModeE[_ZN3mcl3FpTINS_2bn5local5FrTagELm256EE4initEPbiRKNS_5VintTINS_4vint11FixedBufferImLm768EEEEENS_2fp4ModeE]+0x174): undefined reference to `__memcpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(bls_c384_256.o): in function `unsigned long mcl::fp::readHexStr<cybozu::MemoryInputStream>(void*, unsigned long, cybozu::MemoryInputStream&)':
bls_c384_256.cpp:(.text._ZN3mcl2fp10readHexStrIN6cybozu17MemoryInputStreamEEEmPvmRT_[_ZN3mcl2fp10readHexStrIN6cybozu17MemoryInputStreamEEEmPvmRT_]+0x58): undefined reference to `__memcpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(bls_c384_256.o): in function `unsigned long mcl::fp::arrayToDec<unsigned long>(char*, unsigned long, unsigned long const*, unsigned long)':
bls_c384_256.cpp:(.text._ZN3mcl2fp10arrayToDecImEEmPcmPKT_m[_ZN3mcl2fp10arrayToDecImEEmPcmPKT_m]+0x94): undefined reference to `__memcpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(bls_c384_256.o): in function `void mcl::EcT<mcl::FpT<mcl::bn::local::FpTag, 384ul> >::save<cybozu::MemoryOutputStream>(bool*, cybozu::MemoryOutputStream&, int) const':
bls_c384_256.cpp:(.text._ZNK3mcl3EcTINS_3FpTINS_2bn5local5FpTagELm384EEEE4saveIN6cybozu18MemoryOutputStreamEEEvPbRT_i[_ZNK3mcl3EcTINS_3FpTINS_2bn5local5FpTagELm384EEEE4saveIN6cybozu18MemoryOutputStreamEEEvPbRT_i]+0x5a1): undefined reference to `__memset_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: bls_c384_256.cpp:(.text._ZNK3mcl3EcTINS_3FpTINS_2bn5local5FpTagELm384EEEE4saveIN6cybozu18MemoryOutputStreamEEEvPbRT_i[_ZNK3mcl3EcTINS_3FpTINS_2bn5local5FpTagELm384EEEE4saveIN6cybozu18MemoryOutputStreamEEEvPbRT_i]+0x5ca): undefined reference to `__memset_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(bls_c384_256.o): in function `void mcl::EcT<mcl::Fp2T<mcl::FpT<mcl::bn::local::FpTag, 384ul> > >::save<cybozu::MemoryOutputStream>(bool*, cybozu::MemoryOutputStream&, int) const':
bls_c384_256.cpp:(.text._ZNK3mcl3EcTINS_4Fp2TINS_3FpTINS_2bn5local5FpTagELm384EEEEEE4saveIN6cybozu18MemoryOutputStreamEEEvPbRT_i[_ZNK3mcl3EcTINS_4Fp2TINS_3FpTINS_2bn5local5FpTagELm384EEEEEE4saveIN6cybozu18MemoryOutputStreamEEEvPbRT_i]+0x60f): undefined reference to `__memset_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: bls_c384_256.cpp:(.text._ZNK3mcl3EcTINS_4Fp2TINS_3FpTINS_2bn5local5FpTagELm384EEEEEE4saveIN6cybozu18MemoryOutputStreamEEEvPbRT_i[_ZNK3mcl3EcTINS_4Fp2TINS_3FpTINS_2bn5local5FpTagELm384EEEEEE4saveIN6cybozu18MemoryOutputStreamEEEvPbRT_i]+0x63e): undefined reference to `__memset_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(bls_c384_256.o): in function `void mcl::EcT<mcl::Fp2T<mcl::FpT<mcl::bn::local::FpTag, 384ul> > >::load<cybozu::MemoryInputStream>(bool*, cybozu::MemoryInputStream&, int)':
bls_c384_256.cpp:(.text._ZN3mcl3EcTINS_4Fp2TINS_3FpTINS_2bn5local5FpTagELm384EEEEEE4loadIN6cybozu17MemoryInputStreamEEEvPbRT_i[_ZN3mcl3EcTINS_4Fp2TINS_3FpTINS_2bn5local5FpTagELm384EEEEEE4loadIN6cybozu17MemoryInputStreamEEEvPbRT_i]+0x112): undefined reference to `__memcpy_chk'
/usr/lib/gcc/x86_64-alpine-linux-musl/9.2.0/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/github.com/herumi/[email protected]/bls/lib/linux/amd64/libbls384_256.a(bls_c384_256.o): in function `void mcl::EcT<mcl::FpT<mcl::bn::local::FpTag, 384ul> >::load<cybozu::MemoryInputStream>(bool*, cybozu::MemoryInputStream&, int)':
bls_c384_256.cpp:(.text._ZN3mcl3EcTINS_3FpTINS_2bn5local5FpTagELm384EEEE4loadIN6cybozu17MemoryInputStreamEEEvPbRT_i[_ZN3mcl3EcTINS_3FpTINS_2bn5local5FpTagELm384EEEE4loadIN6cybozu17MemoryInputStreamEEEvPbRT_i]+0xf3): undefined reference to `__memcpy_chk'
collect2: error: ld returned 1 exit status

A summary: a few glibc symbols like __memcpy_chk and __fprintf_chk cannot be found.

I tried adding glibc to alpine linux, but I think it didn't get picked up by the CGO build system.

Locally, on my dev machine with glibc, this all works. It would be great if we can make it work in lightweight environments like Alpine 👍

How to build bls to run on different kinds cpu?

I found that a built bls and mcl library sometimes panic on another computer, even they all are linux,amd64.

I do some research on this. I found that different cpu support for different Cpu::Type, and I found that xbyak do test these flags. I think maybe xbyak generate different codes because of different Cpu::Type.

So if I want build a library that run on different computers, may I should disable xbyak through MCL_USE_XBYAK=0 make, am I right?

If I disable xbyak, how much impact on performance? Is there a way to use xbyak in a general enough way?

Cmake instructions do not work

cd build
cmake ..
make
-- The CXX compiler identification is GNU 7.4.0
-- The ASM compiler identification is GNU
-- Found assembler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/bls/build
Scanning dependencies of target bls_c384
[  8%] Building CXX object CMakeFiles/bls_c384.dir/src/bls_c384.cpp.o
In file included from /tmp/bls/src/bls_c_impl.hpp:4:0,
                 from /tmp/bls/src/bls_c384.cpp:2:
/tmp/bls/include/bls/bls.h:10:10: fatal error: mcl/bn.h: No such file or directory
 #include <mcl/bn.h>
          ^~~~~~~~~~
compilation terminated.
CMakeFiles/bls_c384.dir/build.make:62: recipe for target 'CMakeFiles/bls_c384.dir/src/bls_c384.cpp.o' failed
make[2]: *** [CMakeFiles/bls_c384.dir/src/bls_c384.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/bls_c384.dir/all' failed
make[1]: *** [CMakeFiles/bls_c384.dir/all] Error 2
Makefile:129: recipe for target 'all' failed
make: *** [all] Error 2

Build bls in MSYS2 / mingw64

Hi Herumi,

I tried to build bls under MSYS2 / MinGW64, but I couldn't build. I got many errors like that: include/mcl/fp.hpp:330: undefined reference to mcl::fp::copyAndMask(unsigned long long*, void const*, unsigned long long, mcl::fp::Op const&, mcl::fp::MaskMode)' `

I used: make MCL_USE_LLVM=0 INTEL=0 MCL_USE_GMP=1 MCL_USE_OPENSSL=0

I read this article, and it is possible to build bls in MSYS2: #7

Could you help me?

Thanks in advance.

Is bls thread-safe?

Is bls thread-safe to use same curve to sign or verify concurrently?
Is bls thread-safe to use different curve to sign or verify concurrently?

Trusted setup required for threshold signatures?

As far as I can tell, currently the only way to create threshold keys is to call set(const SecretKeyVec& msk, const Id& id) of SecretKey class which requires all partial secret keys to be passed in as argument. Is it possible to use this library to create threshold keys in a way that no one participating in threshold setup knows all initial secret keys (msk above)?

fatal error: gmpxx.h: No such file or directory

To make lib/libbls.a and test, the following problems:

~/blswork/bls$ make test UNIT=4
g++ -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -m64 -I include -I test -I ../xbyak -I ../cybozulib/include -fomit-frame-pointer -DNDEBUG -Ofast -march=native  -fPIC -std=c++11 -I../mcl/include -D"MCLBN_FP_UNIT_SIZE=4" -c src/bls.cpp -o obj/bls.o -MMD -MP -MF obj/bls.d
In file included from ../mcl/include/mcl/op.hpp:9:0,
                 from ../mcl/include/mcl/fp.hpp:29,
                 from ../mcl/include/mcl/fp_tower.hpp:9,
                 from ../mcl/include/mcl/bn.hpp:9,
                 from ../mcl/include/mcl/bn256.hpp:10,
                 from src/bls.cpp:12:
../mcl/include/mcl/gmp_util.hpp:31:19: fatal error: gmpxx.h: No such file or directory
compilation terminated.
Makefile:68: recipe for target 'obj/bls.o' failed
make: *** [obj/bls.o] Error 1

My operating system is Ubuntu 16.04.4 LTS

K out of N

It's running fairly fine now including aggregation.
However, I could not find the function to check if k out n signed the aggregate.
(The blsAggregateSignature and blsFastAggregateVerify need exactly n)

golang code can not working.

make test_go failed !

root@7852eafa2090:~/work/bls# make run_go
make: *** No rule to make target 'run_go'.  Stop.
root@7852eafa2090:~/work/bls# vi Makefile
root@7852eafa2090:~/work/bls# make test_go
cd go/bls && env CGO_CFLAGS="-I../../include -I../../../mcl/include" CGO_LDFLAGS="-L../../lib -L../../../mcl/lib" LD_LIBRARY_PATH=../../lib go test .
--- FAIL: TestMain (0.00s)
	bls_test.go:341: GetMaxOpUnitSize() = 6
	bls_test.go:342: CurveFp254BNb
	bls_test.go:324: ERR Init curve=0
--- FAIL: TestBadPointOfG2 (0.00s)
	mcl_test.go:9: ERR Init curve=2
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x0]

runtime stack:
runtime.throw(0x5574c9, 0x2a)
	/opt/go/src/runtime/panic.go:596 +0x95
runtime.sigpanic()
	/opt/go/src/runtime/signal_unix.go:274 +0x2db

goroutine 7 [syscall, locked to thread]:
runtime.cgocall(0x507234, 0xc420027f48, 0x413228)
	/opt/go/src/runtime/cgocall.go:131 +0xe2 fp=0xc420027f18 sp=0xc420027ed8
_/root/work/bls/go/bls._Cfunc_mclBnGT_clear(0xc4200a8000)
	_/root/work/bls/go/bls/_test/_obj_test/_cgo_gotypes.go:911 +0x41 fp=0xc420027f48 sp=0xc420027f18
_/root/work/bls/go/bls.(*GT).Clear(0xc4200a8000)
	/root/work/bls/go/bls/mcl.go:420 +0x2b fp=0xc420027f60 sp=0xc420027f48
_/root/work/bls/go/bls.TestGT(0xc420060680)
	/root/work/bls/go/bls/mcl_test.go:21 +0x44 fp=0xc420027fa8 sp=0xc420027f60
testing.tRunner(0xc420060680, 0x558fb8)
	/opt/go/src/testing/testing.go:657 +0x96 fp=0xc420027fd0 sp=0xc420027fa8
runtime.goexit()
	/opt/go/src/runtime/asm_amd64.s:2197 +0x1 fp=0xc420027fd8 sp=0xc420027fd0
created by testing.(*T).Run
	/opt/go/src/testing/testing.go:697 +0x2ca

goroutine 1 [chan receive]:
testing.(*T).Run(0xc420060410, 0x54f931, 0x6, 0x558fb8, 0xc420049d00)
	/opt/go/src/testing/testing.go:698 +0x2f4
testing.runTests.func1(0xc420060410)
	/opt/go/src/testing/testing.go:882 +0x67
testing.tRunner(0xc420060410, 0xc420049de0)
	/opt/go/src/testing/testing.go:657 +0x96
testing.runTests(0xc42000cae0, 0x7e3040, 0x4, 0x4, 0xc420080fa0)
	/opt/go/src/testing/testing.go:888 +0x2c1
testing.(*M).Run(0xc420049f20, 0xc420049f20)
	/opt/go/src/testing/testing.go:822 +0xfc
main.main()
	_/root/work/bls/go/bls/_test/_testmain.go:72 +0xf7

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
	/opt/go/src/runtime/asm_amd64.s:2197 +0x1
FAIL	_/root/work/bls/go/bls	0.009s
Makefile:78: recipe for target 'test_go' failed
make: *** [test_go] Error 1

blsSecretKeySetByCSPRNG(&sec) not loading

Hi,

I included the bls and mcl library in my project

#include <iostream>
#include <mcl/bn_c384_256.h>
#include <bls.h>
#include <mcl/bn.h>
#include <mcl/curve_type.h>

using namespace std;

int main()
{
    cout << "Hello, World!" << endl;

    blsInit(MCL_BLS12_381, MCLBN_COMPILED_TIME_VAR);

    blsSetETHmode(BLS_ETH_MODE_LATEST);

    blsSecretKey sec;
    blsPublicKey pub;

    // init SecretKey sec by random number
    cout << blsSecretKeySetByCSPRNG(&sec) << endl;
    // get PublicKey pub from SecretKey sec
    blsGetPublicKey(&pub, &sec);

    blsSignature sig;
    char msg[] = "hello";
    const size_t msgSize = strlen(msg);

    blsSign(&sig, &sec, msg, msgSize);
    
    // return 1 if it is valid else 0
    cout <<  blsVerify(&sig, &pub, msg, msgSize) << endl;
    return 0;
}

And tried to execute the examples, however, the program stops at blsSecretKeySetByCSPRNG
(Doesn't return any value and doesn't continue executing afterwards either)

[Harmony] BLS incompatibility issue after fork update

@herumi
first of all, thank you for your contribution to this library. like many other projects, Harmony has been utilizing your library for block signing using bls. I am a developer at harmony and I have a question regarding upgrading to the latest bls standard. we originally used BLS_SWAP_G=1 with G1 public keys and G2 signatures with default generators (base points) as shown below:

x = 1490485673189267324327220854985940498515857427639219520252677586669310050426096250529683483057578053845695977302605
y = 1405772507307650904885814159424737301884803741041201599376687588686566229941847930862592328097124042659031385407926

the latest updates to your bls and mcl libraries needed us to change to BLS_ETH flag, however all our previous secret keys now are not compatible. possibly due to the changed generators (base points), as per eth2 bls standards:

x = 3685416753713387016781088315183077757961620795782546409894578378688607592378376318836054947676345821548104185464507
y = 1339506544944476473020471379941921221584933875938349620426543736416511423956333506472724655353366534992391756441569

my questions are:

  • is there a way for us to automatically become compatible without having to redo all the secret keys & corresponding public keys (based on different base point) or it is just not possible?
  • what are the configurations in the updated bls & mcl corresponding to the original setup of ours?

looking forward to your reply. thanks

make failing test

building the repo "bls" I the make-process yields the following build-error. It seems the test fails while reading the key-file sample/secretkey.txt

make[1]: Leaving directory '/home/frehberg/src/proj-dfinity/bls_work/mcl'
g++ -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -m64 -I include -I test -I ../xbyak -I ../cybozulib/include  -fomit-frame-pointer -DNDEBUG -Ofast -march=native -fPIC -std=c++11 -I../mcl/include -D"MCLBN_FP_UNIT_SIZE=6" -c sample/bls_smpl.cpp -o obj/bls_smpl.o -MMD -MP -MF obj/bls_smpl.d
g++ obj/bls_smpl.o -o bin/bls_smpl.exe lib/libbls.a lib/libbls384.a -lmcl -L../mcl/lib -lrt -lgmp -lgmpxx -lcrypto -m64  -lpthread
python bls_smpl.py
make sample/secretkey and sample/publickey files
sign message `hello bls threshold signature` by id=0
ERR can't load:sample/secretkey.txt
Traceback (most recent call last):
  File "bls_smpl.py", line 40, in <module>
    main()
  File "bls_smpl.py", line 29, in main
    sign(m)
  File "bls_smpl.py", line 9, in sign
    subprocess.check_call([EXE, "sign", "-m", m, "-id", str(i)])
  File "/usr/lib/python2.7/subprocess.py", line 186, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['bin/bls_smpl.exe', 'sign', '-m', 'hello bls threshold signature', '-id', '0']' returned non-zero exit status 1
Makefile:27: recipe for target 'sample_test' failed
make: *** [sample_test] Error 1

My installation steps are as follows:

I cloned the following repos into a work-directory, and installed gmp dev-lib

sudo apt-get install libgmp3-dev
git clone git://github.com/herumi/xbyak.git
git clone git://github.com/herumi/cybozulib.git
git clone git://github.com/herumi/mcl.git
git clone git://github.com/herumi/bls.git

cd bls ; make

How to get public key?

I am trying to retrieve public key using this code:

blsGetPublicKey(&pub, &sec);
char *address = new char[100];
blsPublicKeyGetHexStr(address, 100, &pub);
__android_log_write(ANDROID_LOG_ERROR, "test", address);

It works but returns corrupted string:
1 15a11bcb263b9dff6e3f4a171f60f38351b115e155b5ce223fdc2b441259b77d1e3706491a10bc84f7e7dbf10380f3ee

It should be:
b5a11bcb263b9dff6e3f4a171f60f38351b115e155b5ce223fdc2b441259b77d1e3706491a10bc84f7e7dbf10380f3ee.

As you see here is 1 1 instead of b in beginning. Why? Is it bug? Or I am doing something wrong?

Hello herumi, I have a question about Secret Sharing API

In this part, it's said that f(x) = msk[0] + msk[1] x + ... + msk[k-1] x^{k-1}, where msk[0] is the original secret key s. Does it mean that every member of the group is able to generate the final signature sH(m) without collecting signature of other members?

Feature suggestion: support for using go crypto/rand PRNG

It looks like the library is using /dev/urandom as a PRNG on linux platforms.
Allow go clients to provide the go crypto/rand generator for the library as a configuration option so there's more control over the PRNG used. See: https://golang.org/pkg/crypto/rand/ . The library currently support providing a c PRNG function. One way to implement this feature is to wrap crypto/rand in a compatible c function and provide it to the library.

BN256 - Could not determine Kind of name for C.blsHashToSignaure

TAGS USED: bn256

BUILD: SUCCESS
works => (commit = github.com/herumi/bls v0.0.0-20190523064038-b1733a744a2e

BUILD: FAILURE
fails => (commit = github.com/herumi/bls v0.0.0-20190607023536-90ce041aecd9)

ERROR MESSAGE:

github.com/herumi/bls/ffi/go/bls

/Users/sachin/gopath/pkg/mod/github.com/herumi/[email protected]/ffi/go/bls/bls.go:554:9: could not determine kind of name for C.blsHashToSignature

directly compile to wasm target

Generating WASM binary, avoid the intermediate step using JavaScript. Using the following makefile, the C/C++ code can be compiled to WASM directly, without this indirection via Javascript

EMSDK_HOME=/home/frehberg/tools/emsdk-portable
BINARYEN_HOME=$(EMSDK_HOME)/clang/e1.37.16_64bit/binaryen

SHELL=/bin/bash

WASM_FILE=bls.wasm
WAST_FILE=bls.wast

EMCC_OPT=-I./include -I./src -I../cybozulib/include -I../mcl/include -I./
EMCC_OPT+=-v -O3 -DNDEBUG -DMCLBN_FP_UNIT_SIZE=6 -DMCL_MAX_BIT_SIZE=384 -Os
EMCC_OPT+=-s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0 -s NO_EXIT_RUNTIME=1  -s ONLY_MY_CODE=1 -s WASM=1 -s SIDE_MODULE=1

$(WASM_FILE):
	. $(EMSDK_HOME)/emsdk_env.sh; $(EMSDK_HOME)/emscripten/1.37.16/emcc  src/bls_c.cpp ../mcl/src/fp.cpp  $(EMCC_OPT)  -o $(WASM_FILE)

$(WAST_FILE): $(WASM_FILE)
	. $(EMSDK_HOME)/emsdk_env.sh; $(BINARYEN_HOME)/bin/wasm-dis $(WASM_FILE) >> $(WAST_FILE)

the resulting code will depend on the following C++ symbols from C++-std-lib

 (import "env" "memoryBase" (global $import$0 i32))
 (import "env" "tableBase" (global $import$1 i32))
 (import "env" "setTempRet0" (func $import$2 (param i32)))
 (import "env" "getTempRet0" (func $import$3 (result i32)))
 (import "env" "invoke_iiii" (func $import$4 (param i32 i32 i32 i32) (result i32)))
 (import "env" "invoke_iiiii" (func $import$5 (param i32 i32 i32 i32 i32) (result i32)))
 (import "env" "invoke_viiiii" (func $import$6 (param i32 i32 i32 i32 i32 i32)))
 (import "env" "invoke_vi" (func $import$7 (param i32 i32)))
 (import "env" "invoke_vii" (func $import$8 (param i32 i32 i32)))
 (import "env" "invoke_iiiiiii" (func $import$9 (param i32 i32 i32 i32 i32 i32 i32) (result i32)))
 (import "env" "invoke_ii" (func $import$10 (param i32 i32) (result i32)))
 (import "env" "invoke_viii" (func $import$11 (param i32 i32 i32 i32)))
 (import "env" "invoke_v" (func $import$12 (param i32)))
 (import "env" "invoke_iii" (func $import$13 (param i32 i32 i32) (result i32)))
 (import "env" "invoke_iiiiii" (func $import$14 (param i32 i32 i32 i32 i32 i32) (result i32)))
 (import "env" "invoke_viiii" (func $import$15 (param i32 i32 i32 i32 i32)))
 (import "env" "_strlen" (func $import$16 (param i32) (result i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcj" (func $import$17 (param i32 i32 i32)))
 (import "env" "_fread" (func $import$18 (param i32 i32 i32 i32) (result i32)))
 (import "env" "_bitshift64Lshr" (func $import$19 (param i32 i32 i32) (result i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_" (func $import$20 (param i32 i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEaSEc" (func $import$21 (param i32 i32) (result i32)))
 (import "env" "_memcpy" (func $import$22 (param i32 i32 i32) (result i32)))
 (import "env" "___cxa_begin_catch" (func $import$23 (param i32) (result i32)))
 (import "env" "__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEED2Ev" (func $import$24 (param i32 i32)))
 (import "env" "__ZSt9terminatev" (func $import$25))
 (import "env" "__ZdlPv" (func $import$26 (param i32)))
 (import "env" "__ZNSt9exceptionD2Ev" (func $import$27 (param i32)))
 (import "env" "__ZNSt9bad_allocC1Ev" (func $import$28 (param i32)))
 (import "env" "___cxa_guard_acquire" (func $import$29 (param i32) (result i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEaSERKS5_" (func $import$30 (param i32 i32) (result i32)))
 (import "env" "___cxa_free_exception" (func $import$31 (param i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev" (func $import$32 (param i32)))
 (import "env" "___cxa_guard_release" (func $import$33 (param i32)))
 (import "env" "__ZNKSt3__220__vector_base_commonILb1EE20__throw_length_errorEv" (func $import$34 (param i32)))
 (import "env" "___resumeException" (func $import$35 (param i32)))
 (import "env" "___cxa_call_unexpected" (func $import$36 (param i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEjc" (func $import$37 (param i32 i32 i32)))
 (import "env" "_printf" (func $import$38 (param i32 i32) (result i32)))
 (import "env" "__Znwj" (func $import$39 (param i32) (result i32)))
 (import "env" "_fprintf" (func $import$40 (param i32 i32 i32) (result i32)))
 (import "env" "___cxa_guard_abort" (func $import$41 (param i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEC1ERKS5_jjRKS4_" (func $import$42 (param i32 i32 i32 i32 i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKc" (func $import$43 (param i32 i32) (result i32)))
 (import "env" "___cxa_allocate_exception" (func $import$44 (param i32) (result i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6appendEPKcj" (func $import$45 (param i32 i32 i32) (result i32)))
 (import "env" "_memset" (func $import$46 (param i32 i32 i32) (result i32)))
 (import "env" "_snprintf" (func $import$47 (param i32 i32 i32 i32) (result i32)))
 (import "env" "___cxa_end_catch" (func $import$48))
 (import "env" "__ZNSt3__213basic_ostreamIcNS_11char_traitsIcEEE5writeEPKci" (func $import$49 (param i32 i32 i32) (result i32)))
 (import "env" "_i64Subtract" (func $import$50 (param i32 i32 i32 i32) (result i32)))
 (import "env" "__ZNSt3__215basic_streambufIcNS_11char_traitsIcEEED2Ev" (func $import$51 (param i32)))
 (import "env" "__ZNSt3__29basic_iosIcNS_11char_traitsIcEEED2Ev" (func $import$52 (param i32)))
 (import "env" "_fclose" (func $import$53 (param i32) (result i32)))
 (import "env" "_strtoul" (func $import$54 (param i32 i32 i32) (result i32)))
 (import "env" "_fopen" (func $import$55 (param i32 i32) (result i32)))
 (import "env" "___udivdi3" (func $import$56 (param i32 i32 i32 i32) (result i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9push_backEc" (func $import$57 (param i32 i32)))
 (import "env" "___cxa_find_matching_catch_2" (func $import$58 (result i32)))
 (import "env" "___cxa_find_matching_catch_3" (func $import$59 (param i32) (result i32)))
 (import "env" "_llvm_eh_typeid_for" (func $import$60 (param i32) (result i32)))
 (import "env" "___muldi3" (func $import$61 (param i32 i32 i32 i32) (result i32)))
 (import "env" "_bitshift64Shl" (func $import$62 (param i32 i32 i32) (result i32)))
 (import "env" "___uremdi3" (func $import$63 (param i32 i32 i32 i32) (result i32)))
 (import "env" "_i64Add" (func $import$64 (param i32 i32 i32 i32) (result i32)))
 (import "env" "__ZNKSt3__221__basic_string_commonILb1EE20__throw_length_errorEv" (func $import$65 (param i32)))
 (import "env" "___errno_location" (func $import$66 (result i32)))
 (import "env" "_strcmp" (func $import$67 (param i32 i32) (result i32)))
 (import "env" "___cxa_throw" (func $import$68 (param i32 i32 i32)))
 (import "env" "_memmove" (func $import$69 (param i32 i32 i32) (result i32)))
 (import "env" "__ZNSt3__212basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6resizeEjc" (func $import$70 (param i32 i32 i32)))
 (import "env" "g$__ZNSt3__25ctypeIcE2idE" (func $import$71 (result i32)))
 (import "env" "g$__ZTINSt3__213basic_ostreamIcNS_11char_traitsIcEEEE" (func $import$72 (result i32)))
 (import "env" "g$__ZTINSt3__215basic_streambufIcNS_11char_traitsIcEEEE" (func $import$73 (result i32)))
 (import "env" "g$__ZTISt9bad_alloc" (func $import$74 (result i32)))
 (import "env" "g$__ZTISt9exception" (func $import$75 (result i32)))
 (import "env" "g$__ZTVN10__cxxabiv120__si_class_type_infoE" (func $import$76 (result i32)))
 (import "env" "g$__ZTVSt9exception" (func $import$77 (result i32)))
 (import "env" "g$_stderr" (func $import$78 (result i32)))
 (import "env" "memory" (memory $0 256))
 (import "env" "table" (table 0 anyfunc))

Status of blsSetETHmode

I have a question about the blsSetETHmode function. The name suggests that it has an impact when the BLS_ETH=1 mode is activated, however, the function sets the g_irtfHashAndMap boolean to true which is only used in the toG function, but when BLS_ETH is not defined. Is it possible to clarify the purpose of the function?

Testing: Unexpected signal during runtime execution

I am configuring and setting up the 0chain SDK, by installing BLS and MCL Dependencies. Upon using 'make install' I get the following error.

Please help me mitigate this.

Error:

(SeqRead) buf=000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
(rand.Reader) buf=6c3724fc88dd295f7146eb3f526b93cb18aa043b939803c15c616af6af914113
(default) buf=ce1960f68878a9d3909a5c884fc0a7d2f72fcaccd128b31ffe4109b2603d5b15
fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0x7fff727ea476]

runtime stack:
runtime.throw(0x4186159, 0x2a)
	/usr/local/Cellar/go/1.13.3/libexec/src/runtime/panic.go:774 +0x72
runtime.sigpanic()
	/usr/local/Cellar/go/1.13.3/libexec/src/runtime/signal_unix.go:378 +0x47c

goroutine 20 [syscall]:
runtime.cgocall(0x41259f0, 0xc000045e00, 0x1)
	/usr/local/Cellar/go/1.13.3/libexec/src/runtime/cgocall.go:128 +0x5b fp=0xc000045dd0 sp=0xc000045d98 pc=0x40056bb
github.com/0chain/gosdk/_herumi/bls/ffi/go/bls._Cfunc_blsGetPublicKey(0xc0000ca0c0, 0xc0000c6200)
	_cgo_gotypes.go:189 +0x41 fp=0xc000045e00 sp=0xc000045dd0 pc=0x411fb21
github.com/0chain/gosdk/_herumi/bls/ffi/go/bls.(*SecretKey).GetPublicKey(...)
	/Users/jenilthakker/go/github.com/0chain/gosdk/_herumi/bls/ffi/go/bls/bls.go:505
github.com/0chain/gosdk/_herumi/bls/ffi/go/bls.testPre(0xc0000c0100)
	/Users/jenilthakker/go/github.com/0chain/gosdk/_herumi/bls/ffi/go/bls/bls_test.go:54 +0x664 fp=0xc000045ed0 sp=0xc000045e00 pc=0x4119b74
github.com/0chain/gosdk/_herumi/bls/ffi/go/bls.test(0xc0000c0100, 0x0)
	/Users/jenilthakker/go/github.com/0chain/gosdk/_herumi/bls/ffi/go/bls/bls_test.go:493 +0x116 fp=0xc000045f20 sp=0xc000045ed0 pc=0x411e2e6
github.com/0chain/gosdk/_herumi/bls/ffi/go/bls.TestMain(0xc0000c0100)
	/Users/jenilthakker/go/github.com/0chain/gosdk/_herumi/bls/ffi/go/bls/bls_test.go:512 +0xee fp=0xc000045f70 sp=0xc000045f20 pc=0x411e4ae
testing.tRunner(0xc0000c0100, 0x41880b0)
	/usr/local/Cellar/go/1.13.3/libexec/src/testing/testing.go:909 +0xc9 fp=0xc000045fd0 sp=0xc000045f70 pc=0x40c2bc9
runtime.goexit()
	/usr/local/Cellar/go/1.13.3/libexec/src/runtime/asm_amd64.s:1357 +0x1 fp=0xc000045fd8 sp=0xc000045fd0 pc=0x405c5d1
created by testing.(*T).Run
	/usr/local/Cellar/go/1.13.3/libexec/src/testing/testing.go:960 +0x350

goroutine 1 [chan receive]:
testing.(*T).Run(0xc0000c0100, 0x417ea19, 0x8, 0x41880b0, 0x40736f6)
	/usr/local/Cellar/go/1.13.3/libexec/src/testing/testing.go:961 +0x377
testing.runTests.func1(0xc0000c0000)
	/usr/local/Cellar/go/1.13.3/libexec/src/testing/testing.go:1202 +0x78
testing.tRunner(0xc0000c0000, 0xc000044dc0)
	/usr/local/Cellar/go/1.13.3/libexec/src/testing/testing.go:909 +0xc9
testing.runTests(0xc00009e060, 0x428c2b0, 0x1, 0x1, 0x0)
	/usr/local/Cellar/go/1.13.3/libexec/src/testing/testing.go:1200 +0x2a7
testing.(*M).Run(0xc0000ba000, 0x0)
	/usr/local/Cellar/go/1.13.3/libexec/src/testing/testing.go:1117 +0x176
main.main()
	_testmain.go:68 +0x135
FAIL	github.com/0chain/gosdk/_herumi/bls/ffi/go/bls	1.398s
FAIL
make[1]: *** [test_go256] Error 1
make: *** [test-herumi] Error 2

SetLittleEndian vs SetLittleEndianMod

Thanks for your amazing library.

May I know what exactly SetLittleEndianMod is doing? A secret key is 32 bytes and SetLittleEndian just simply put any 32 bytes as secret key. right?
But SetLittleEndianMod is doing some kind of bitwise operations. What is the different between these two methods?
Is it safe to use 256-bits bip-39 seed as an input and generate unique secret key?

Incorrect DST in blsGetPop and blsVerifyPop

In §4.2.3 of BLS Signatures, the DST for the hash to elliptic curve function called in PopProve is BLS_POP_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_. However, in the implementation of blsGetPop, the DST being used is the one of blsSign, which is BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_, since the underlying function to be called is void msgToG2(G2& out, const void *msg, size_t msgSize) const, for which the DST is set to BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_.

If this is correct, the same remark is also applicable to blsVerifyPop. It would be possible to continue to factorize code between blsSign and blsGetPop on one hand, and blsVerify and blsVerifyPop on the other hand, but it must exclude the call to msgToG2 with the enforced DST.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.