Skip to content

Commit

Permalink
-tags options is necessary fo cgo
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Dec 5, 2018
1 parent afbcbea commit f63e122
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 9 deletions.
13 changes: 11 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,17 @@ ifeq ($(OS),mac)
MAC_GO_LDFLAGS="-ldflags=-s"
endif
# PATH is for mingw, LD_RUN_PATH is for linux, DYLD_LIBRARY_PATH is for mac
test_go: ffi/go/bls/bls.go ffi/go/bls/bls_test.go $(BLS384_SLIB)
cd ffi/go/bls && env PATH=$$PATH:../../../lib LD_RUN_PATH="../../../lib" DYLD_LIBRARY_PATH="../../../lib" go test $(MAC_GO_LDFLAGS) .
test_go256: ffi/go/bls/bls.go ffi/go/bls/bls_test.go $(BLS256_SLIB)
cd ffi/go/bls && env PATH=$$PATH:../../../lib LD_RUN_PATH="../../../lib" DYLD_LIBRARY_PATH="../../../lib" go test $(MAC_GO_LDFLAGS) -tags bn256 .
test_go384: ffi/go/bls/bls.go ffi/go/bls/bls_test.go $(BLS384_SLIB)
cd ffi/go/bls && env PATH=$$PATH:../../../lib LD_RUN_PATH="../../../lib" DYLD_LIBRARY_PATH="../../../lib" go test $(MAC_GO_LDFLAGS) -tags bn384 .
test_go384_256: ffi/go/bls/bls.go ffi/go/bls/bls_test.go $(BLS384_256_SLIB)
cd ffi/go/bls && env PATH=$$PATH:../../../lib LD_RUN_PATH="../../../lib" DYLD_LIBRARY_PATH="../../../lib" go test $(MAC_GO_LDFLAGS) -tags bn384_256 .

test_go:
$(MAKE) test_go256
$(MAKE) test_go384
$(MAKE) test_go384_256

EMCC_OPT=-I./include -I./src -I../mcl/include -I./ -Wall -Wextra
EMCC_OPT+=-O3 -DNDEBUG
Expand Down
10 changes: 7 additions & 3 deletions ffi/go/bls/bls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package bls

/*
#cgo CFLAGS:-I../../../include -I../../../../mcl/include/
#cgo LDFLAGS:-L../../../lib
#cgo CFLAGS:-DMCLBN_FP_UNIT_SIZE=6
#cgo LDFLAGS:-lbls384_dy -lcrypto -lgmp -lgmpxx -lstdc++
#cgo bn256 CFLAGS:-DMCLBN_FP_UNIT_SIZE=4
#cgo bn256 LDFLAGS:-lbls256_dy
#cgo bn384 CFLAGS:-DMCLBN_FP_UNIT_SIZE=6
#cgo bn384 LDFLAGS:-lbls384_dy
#cgo bn384_256 CFLAGS:-DMCLBN_FP_UNIT_SIZE=6 -DMCLBN_FR_UNIT_SIZE=4
#cgo bn384_256 LDFLAGS:-lbls384_256_dy
#cgo LDFLAGS:-L../../../lib -lcrypto -lgmp -lgmpxx -lstdc++
#include <bls/bls.h>
*/
import "C"
Expand Down
6 changes: 4 additions & 2 deletions ffi/go/bls/bls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,8 +380,10 @@ func TestMain(t *testing.T) {
t.Log("CurveFp254BNb")
test(t, CurveFp254BNb)
if GetMaxOpUnitSize() == 6 {
t.Log("CurveFp382_1")
test(t, CurveFp382_1)
if GetFrUnitSize() == 6 {
t.Log("CurveFp382_1")
test(t, CurveFp382_1)
}
t.Log("BLS12_381")
test(t, BLS12_381)
}
Expand Down
15 changes: 14 additions & 1 deletion ffi/go/bls/mcl.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package bls

/*
#cgo CFLAGS:-DMCLBN_FP_UNIT_SIZE=6
#cgo bn256 CFLAGS:-DMCLBN_FP_UNIT_SIZE=4
#cgo bn384 CFLAGS:-DMCLBN_FP_UNIT_SIZE=6
#cgo bn384_256 CFLAGS:-DMCLBN_FP_UNIT_SIZE=6 -DMCLBN_FR_UNIT_SIZE=4
#include <mcl/bn.h>
*/
import "C"
Expand All @@ -23,6 +25,17 @@ const BLS12_381 = C.MCL_BLS12_381
// IoSerializeHexStr
const IoSerializeHexStr = C.MCLBN_IO_SERIALIZE_HEX_STR

// GetFrUnitSize() --
func GetFrUnitSize() int {
return int(C.MCLBN_FR_UNIT_SIZE)
}

// GetFpUnitSize() --
// same as GetMaxOpUnitSize()
func GetFpUnitSize() int {
return int(C.MCLBN_FP_UNIT_SIZE)
}

// GetMaxOpUnitSize --
func GetMaxOpUnitSize() int {
return int(C.MCLBN_FP_UNIT_SIZE)
Expand Down
16 changes: 15 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@ git clone git://github.com/herumi/bls.git
git clone git://github.com/herumi/cybozulib_ext ; for only Windows
```

# **REMARK** libbls.a for C++ interface(bls/bls.hpp) is removed
# News
* -tags options is necessary for golang binding
* -tags bn256
* -tags bn384\_256
* -tags bn384 ; previous version
* Support swap of G1 and G2
* `make BLS_SWAP_G=1` then G1 is assigned to PublicKey and G2 is assigned to Signature.
* golang binding does not support this feature yet.
* Build option without GMP
* `make MCL_USE_GMP=0`
* Build option to specify `mcl` directory
* `make MCL_DIR=<mcl directory>`

* (old) libbls.a for C++ interface(bls/bls.hpp) is removed
Link `lib/libbls256.a` or `lib/libbls384.a` to use `bls/bls.hpp` according to MCLBN_FP_UNIT_SIZE = 4 or 6.

# Build and test for Linux
Expand Down Expand Up @@ -47,6 +60,7 @@ bin\bls_c384_test.exe
# Library
* libbls256.a/libbls256_dy.so ; for BN254 compiled with MCLBN_FP_UNIT_SIZE=4
* libbls384.a/libbls384_dy.so ; for BN254/BN381_1/BLS12_381 compiled with MCLBN_FP_UNIT_SIZE=6
* libbls384_256.a/libbls384_256_dy.so ; for BN254/BLS12_381 compiled with MCLBN_FP_UNIT_SIZE=6 and MCLBN_FR_UNIT_SIZE=4

See `mcl/include/curve_type.h` for curve parameter

Expand Down

0 comments on commit f63e122

Please sign in to comment.