From 20d898063b3185f9538045df92759818e371cd79 Mon Sep 17 00:00:00 2001 From: MITSUNARI Shigeo Date: Wed, 7 Jun 2017 01:14:54 +0900 Subject: test is ok --- Makefile | 4 ++-- go/bls/bls_test.go | 31 +++++++++++++++++++++---------- go/bls/mcl.go | 24 ++++++++++++------------ 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 019602c..37bec74 100644 --- a/Makefile +++ b/Makefile @@ -46,9 +46,9 @@ lib: $(BLS_LIB) $(BLS384_SLIB) $(BLS384_LIB): $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o $(AR) $@ $(LIB_OBJ) $(OBJ_DIR)/bls_c384.o -$(BLS384_SLIB): $(BLS384_LIB) $(BN384_LIB) +$(BLS384_SLIB): $(OBJ_DIR)/bls_c384.o $(MCL_LIB) # $(PRE)$(CXX) -shared -o $@ -Wl,--whole-archive $(BLS384_LIB) $(BN384_LIB) $(MCL_LIB) -Wl,--no-whole-archive - $(PRE)$(CXX) -shared -o $@ -Wl,--whole-archive $(BLS384_LIB) -Wl,--no-whole-archive + $(PRE)$(CXX) -shared -o $@ $(OBJ_DIR)/bls_c384.o $(MCL_LIB) VPATH=test sample src diff --git a/go/bls/bls_test.go b/go/bls/bls_test.go index 84e5344..b88867c 100644 --- a/go/bls/bls_test.go +++ b/go/bls/bls_test.go @@ -2,30 +2,41 @@ package bls import "testing" import "strconv" +import "fmt" var unitN = 0 // Tests (for Benchmarks see below) func testPairing(t *testing.T) { - return -// err := Init(CurveFp254BNb) -// if err != nil { -// t.Error(err) -// } var a, b, ab Fr - a.SetString("12345678901", 10) - b.SetString("abcdef0abcd", 16) + a.SetString("123", 10) + b.SetString("456", 10) FrMul(&ab, &a, &b) var P, aP G1 var Q, bQ G2 - P.HashAndMapTo([]byte("this")) + err := P.HashAndMapTo([]byte("this")) + if err != nil { + t.Error(err) + return + } + fmt.Printf("P=%s\n", P.GetString(16)) G1Mul(&aP, &P, &a) - Q.HashAndMapTo([]byte("that")) + 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) - GTPow(&e2, &e2, &ab) + 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)) } diff --git a/go/bls/mcl.go b/go/bls/mcl.go index d523308..d0deae4 100644 --- a/go/bls/mcl.go +++ b/go/bls/mcl.go @@ -103,7 +103,7 @@ func (x *Fr) SetHashOf(buf []byte) bool { // GetString -- func (x *Fr) GetString(base int) string { - buf := make([]byte, 1024) + buf := make([]byte, 2048) // #nosec n := C.mclBnFr_getStr((*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)), x.getPointer(), C.int(base)) if n == 0 { @@ -114,7 +114,7 @@ func (x *Fr) GetString(base int) string { // Serialize -- func (x *Fr) Serialize() []byte { - buf := make([]byte, 1024) + buf := make([]byte, 2048) // #nosec n := C.mclBnFr_serialize(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), x.getPointer()) if n == 0 { @@ -214,7 +214,7 @@ func (x *G1) HashAndMapTo(buf []byte) error { // GetString -- func (x *G1) GetString(base int) string { - buf := make([]byte, 1024) + buf := make([]byte, 2048) // #nosec n := C.mclBnG1_getStr((*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)), x.getPointer(), C.int(base)) if n == 0 { @@ -225,7 +225,7 @@ func (x *G1) GetString(base int) string { // Serialize -- func (x *G1) Serialize() []byte { - buf := make([]byte, 1024) + buf := make([]byte, 2048) // #nosec n := C.mclBnG1_serialize(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), x.getPointer()) if n == 0 { @@ -262,7 +262,7 @@ func G1Mul(out *G1, x *G1, y *Fr) { //////////////////////////////////////////// // G2 -- type G2 struct { - v C.mclBnG1 + v C.mclBnG2 } // getPointer -- @@ -320,7 +320,7 @@ func (x *G2) HashAndMapTo(buf []byte) error { // GetString -- func (x *G2) GetString(base int) string { - buf := make([]byte, 1024) + buf := make([]byte, 2048) // #nosec n := C.mclBnG2_getStr((*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)), x.getPointer(), C.int(base)) if n == 0 { @@ -331,7 +331,7 @@ func (x *G2) GetString(base int) string { // Serialize -- func (x *G2) Serialize() []byte { - buf := make([]byte, 1024) + buf := make([]byte, 2048) // #nosec n := C.mclBnG2_serialize(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), x.getPointer()) if n == 0 { @@ -421,7 +421,7 @@ func (x *GT) IsOne(rhs *GT) bool { // GetString -- func (x *GT) GetString(base int) string { - buf := make([]byte, 1024) + buf := make([]byte, 2048) // #nosec n := C.mclBnGT_getStr((*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)), x.getPointer(), C.int(base)) if n == 0 { @@ -432,7 +432,7 @@ func (x *GT) GetString(base int) string { // Serialize -- func (x *GT) Serialize() []byte { - buf := make([]byte, 1024) + buf := make([]byte, 2048) // #nosec n := C.mclBnGT_serialize(unsafe.Pointer(&buf[0]), C.size_t(len(buf)), x.getPointer()) if n == 0 { @@ -483,13 +483,13 @@ func Pairing(out *GT, x *G1, y *G2) { } // FinalExp -- -func FinalExp(out *GT, x *G1, y *G2) { - C.mclBn_pairing(out.getPointer(), x.getPointer(), y.getPointer()) +func FinalExp(out *GT, x *GT) { + C.mclBn_finalExp(out.getPointer(), x.getPointer()) } // MillerLoop -- func MillerLoop(out *GT, x *G1, y *G2) { - C.mclBn_pairing(out.getPointer(), x.getPointer(), y.getPointer()) + C.mclBn_millerLoop(out.getPointer(), x.getPointer(), y.getPointer()) } // GetUint64NumToPrecompute -- -- cgit v1.2.3