aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-08-12 17:12:29 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-08-12 17:12:29 +0800
commitaa867dd6770e7956ff08bff55639a4f4d1d74910 (patch)
tree68c1a0ecc93b9235a4e57eae30b5e665ff799b7d
parent14eef5d9971e76c177a339f94de553a0501a1b71 (diff)
downloaddexon-bls-aa867dd6770e7956ff08bff55639a4f4d1d74910.tar
dexon-bls-aa867dd6770e7956ff08bff55639a4f4d1d74910.tar.gz
dexon-bls-aa867dd6770e7956ff08bff55639a4f4d1d74910.tar.bz2
dexon-bls-aa867dd6770e7956ff08bff55639a4f4d1d74910.tar.lz
dexon-bls-aa867dd6770e7956ff08bff55639a4f4d1d74910.tar.xz
dexon-bls-aa867dd6770e7956ff08bff55639a4f4d1d74910.tar.zst
dexon-bls-aa867dd6770e7956ff08bff55639a4f4d1d74910.zip
test_go runs on Linux/OSX
-rw-r--r--Makefile14
-rw-r--r--go/bls/bls_test.go1
-rw-r--r--go/bls/mcl_test.go132
3 files changed, 10 insertions, 137 deletions
diff --git a/Makefile b/Makefile
index c0378f4..f798e71 100644
--- a/Makefile
+++ b/Makefile
@@ -43,14 +43,18 @@ $(MCL_LIB):
##################################################################
BLS384_LIB=$(LIB_DIR)/libbls384.a
-BLS384_SLIB=$(LIB_DIR)/libbls384$(SHARE_BASENAME_SUF).$(LIB_SUF)
+BLS384_SNAME=bls384$(SHARE_BASENAME_SUF)
+BLS384_SLIB=$(LIB_DIR)/lib$(BLS384_SNAME).$(LIB_SUF)
lib: $(BLS_LIB) $(BLS384_SLIB)
$(BLS384_LIB): $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o
$(AR) $@ $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o
+ifeq ($(OS),mac)
+ MAC_LDFLAGS+=-lgmpxx -lgmp -lcrypto -lstdc++
+endif
$(BLS384_SLIB): $(OBJ_DIR)/bls_c384.o $(MCL_LIB)
- $(PRE)$(CXX) -shared -o $@ $(OBJ_DIR)/bls_c384.o $(MCL_LIB)
+ $(PRE)$(CXX) -shared -o $@ $(OBJ_DIR)/bls_c384.o $(MCL_LIB) $(MAC_LDFLAGS)
VPATH=test sample src
@@ -74,9 +78,11 @@ test: $(TEST_EXE)
@sh -ec 'for i in $(TEST_EXE); do $$i|grep "ctest:name"; done' > result.txt
@grep -v "ng=0, exception=0" result.txt; if [ $$? -eq 1 ]; then echo "all unit tests succeed"; else exit 1; fi
+ifeq ($(OS),mac)
+ MAC_GO_LDFLAGS="-ldflags=-s"
+endif
test_go: go/bls/bls.go go/bls/bls_test.go $(BLS384_SLIB)
- cd go/bls && env CGO_CFLAGS="-I../../include -I../../../mcl/include" CGO_LDFLAGS="-L../../lib -L../../../mcl/lib" LD_LIBRARY_PATH=../../lib go test .
-# cd go/bls && go test -tags $(GO_TAG) -v .
+ cd go/bls && ln -sf ../../lib . && env LD_RUN_PATH="../../lib" CGO_CFLAGS="-I../../include -I../../../mcl/include" CGO_LDFLAGS="-L../../lib -L../../../mcl/lib" go test $(MAC_GO_LDFLAGS) .
clean:
$(RM) $(BLS_LIB) $(OBJ_DIR)/*.d $(OBJ_DIR)/*.o $(EXE_DIR)/*.exe $(GEN_EXE) $(ASM_SRC) $(ASM_OBJ) $(LIB_OBJ) $(LLVM_SRC) $(BLS384_SLIB)
diff --git a/go/bls/bls_test.go b/go/bls/bls_test.go
index 998dd1f..5d5d432 100644
--- a/go/bls/bls_test.go
+++ b/go/bls/bls_test.go
@@ -325,7 +325,6 @@ func test(t *testing.T, c int) {
}
unitN = GetOpUnitSize()
t.Logf("unitN=%d\n", unitN)
- testPairing(t)
testPre(t)
testRecoverSecretKey(t)
testAdd(t)
diff --git a/go/bls/mcl_test.go b/go/bls/mcl_test.go
deleted file mode 100644
index 4a7f031..0000000
--- a/go/bls/mcl_test.go
+++ /dev/null
@@ -1,132 +0,0 @@
-package bls
-
-import "testing"
-import "fmt"
-
-func TestBadPointOfG2(t *testing.T) {
- err := Init(CurveFp382_2)
- if err != nil {
- t.Fatal(err)
- }
- var Q G2
- // this value is not in G2 so should return an error
- err = Q.SetString("1 18d3d8c085a5a5e7553c3a4eb628e88b8465bf4de2612e35a0a4eb018fb0c82e9698896031e62fd7633ffd824a859474 1dc6edfcf33e29575d4791faed8e7203832217423bf7f7fbf1f6b36625b12e7132c15fbc15562ce93362a322fb83dd0d 65836963b1f7b6959030ddfa15ab38ce056097e91dedffd996c1808624fa7e2644a77be606290aa555cda8481cfb3cb 1b77b708d3d4f65aeedf54b58393463a42f0dc5856baadb5ce608036baeca398c5d9e6b169473a8838098fd72fd28b50", 16)
- if err == nil {
- t.Error(err)
- }
-}
-
-func TestGT(t *testing.T) {
- var x GT
- x.Clear()
- if !x.IsZero() {
- t.Errorf("not zero")
- }
- x.SetInt64(1)
- if !x.IsOne() {
- t.Errorf("not one")
- }
-}
-
-func testNegAdd(t *testing.T) {
- var x Fr
- var P1, P2, P3 G1
- var Q1, Q2, Q3 G2
- err := P1.HashAndMapTo([]byte("this"))
- if err != nil {
- t.Error(err)
- }
- err = Q1.HashAndMapTo([]byte("this"))
- if err != nil {
- t.Error(err)
- }
- fmt.Printf("P1=%s\n", P1.GetString(16))
- fmt.Printf("Q1=%s\n", Q1.GetString(16))
- G1Neg(&P2, &P1)
- G2Neg(&Q2, &Q1)
- fmt.Printf("P2=%s\n", P2.GetString(16))
- fmt.Printf("Q2=%s\n", Q2.GetString(16))
-
- x.SetInt64(-1)
- G1Mul(&P3, &P1, &x)
- G2Mul(&Q3, &Q1, &x)
- if !P2.IsEqual(&P3) {
- t.Errorf("P2 != P3 %s\n", P3.GetString(16))
- }
- if !Q2.IsEqual(&Q3) {
- t.Errorf("Q2 != Q3 %s\n", Q3.GetString(16))
- }
-
- G1Add(&P2, &P2, &P1)
- G2Add(&Q2, &Q2, &Q1)
- if !P2.IsZero() {
- t.Errorf("P2 is not zero %s\n", P2.GetString(16))
- }
- if !Q2.IsZero() {
- t.Errorf("Q2 is not zero %s\n", Q2.GetString(16))
- }
-}
-
-func testPairing(t *testing.T) {
- var a, b, ab Fr
- err := a.SetString("123", 10)
- if err != nil {
- t.Error(err)
- return
- }
- err = b.SetString("456", 10)
- if err != nil {
- t.Error(err)
- return
- }
- FrMul(&ab, &a, &b)
- var P, aP G1
- var Q, bQ G2
- err = P.HashAndMapTo([]byte("this"))
- if err != nil {
- t.Error(err)
- return
- }
- fmt.Printf("P=%s\n", P.GetString(16))
- G1Mul(&aP, &P, &a)
- fmt.Printf("aP=%s\n", aP.GetString(16))
- err = Q.HashAndMapTo([]byte("that"))
- if err != nil {
- t.Error(err)
- return
- }
- fmt.Printf("Q=%s\n", Q.GetString(16))
- G2Mul(&bQ, &Q, &b)
- fmt.Printf("bQ=%s\n", bQ.GetString(16))
- var e1, e2 GT
- Pairing(&e1, &P, &Q)
- fmt.Printf("e1=%s\n", e1.GetString(16))
- Pairing(&e2, &aP, &bQ)
- fmt.Printf("e2=%s\n", e1.GetString(16))
- GTPow(&e1, &e1, &ab)
- fmt.Printf("e1=%s\n", e1.GetString(16))
- if !e1.IsEqual(&e2) {
- t.Errorf("not equal pairing\n%s\n%s", e1.GetString(16), e2.GetString(16))
- }
-}
-
-func testMcl(t *testing.T, c int) {
- err := Init(c)
- if err != nil {
- t.Fatal(err)
- }
- testNegAdd(t)
- testPairing(t)
-}
-
-func TestMclMain(t *testing.T) {
- t.Logf("GetMaxOpUnitSize() = %d\n", GetMaxOpUnitSize())
- t.Log("CurveFp254BNb")
- testMcl(t, CurveFp254BNb)
- if GetMaxOpUnitSize() == 6 {
- t.Log("CurveFp382_1")
- testMcl(t, CurveFp382_1)
- t.Log("CurveFp382_2")
- testMcl(t, CurveFp382_2)
- }
-}