aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2017-04-09 19:26:11 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2017-04-09 19:26:11 +0800
commit51e69f9763a8d7da268c6ebcb6e9678b0dcdfd91 (patch)
tree25033efe1c81b3288b7e4a5263199fc2ba6b3255
parent076cb73f57616c4ddc01db19c6c0487cd886d6a8 (diff)
downloaddexon-bls-51e69f9763a8d7da268c6ebcb6e9678b0dcdfd91.tar
dexon-bls-51e69f9763a8d7da268c6ebcb6e9678b0dcdfd91.tar.gz
dexon-bls-51e69f9763a8d7da268c6ebcb6e9678b0dcdfd91.tar.bz2
dexon-bls-51e69f9763a8d7da268c6ebcb6e9678b0dcdfd91.tar.lz
dexon-bls-51e69f9763a8d7da268c6ebcb6e9678b0dcdfd91.tar.xz
dexon-bls-51e69f9763a8d7da268c6ebcb6e9678b0dcdfd91.tar.zst
dexon-bls-51e69f9763a8d7da268c6ebcb6e9678b0dcdfd91.zip
add SetData/GetData/IsSame to bls.cgo
-rw-r--r--go/blscgo/bls.go81
-rw-r--r--go/main_test.go26
2 files changed, 107 insertions, 0 deletions
diff --git a/go/blscgo/bls.go b/go/blscgo/bls.go
index 5873f38..10892f9 100644
--- a/go/blscgo/bls.go
+++ b/go/blscgo/bls.go
@@ -106,6 +106,33 @@ func (sec *SecretKey) SetStr(s string) error {
return nil
}
+// SetData --
+func (sec *SecretKey) SetData(s string) error {
+ buf := []byte(s)
+ // #nosec
+ err := C.blsSecretKeySetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
+ if err > 0 {
+ return fmt.Errorf("bad string:%s", s)
+ }
+ return nil
+}
+
+// GetData --
+func (sec *SecretKey) GetData() string {
+ fpSize := GetOpUnitSize() * 8
+ buf := make([]byte, fpSize)
+ n := C.blsSecretKeyGetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
+ if n == 0 {
+ panic("implementation err. size of buf is small")
+ }
+ return string(buf[:n])
+}
+
+// IsSame --
+func (lhs *SecretKey) IsSame(rhs *SecretKey) bool {
+ return C.blsSecretKeyIsSame(lhs.getPointer(), rhs.getPointer()) == 1
+}
+
// SetArray --
func (sec *SecretKey) SetArray(v []uint64) {
expect := GetOpUnitSize()
@@ -196,6 +223,33 @@ func (pub *PublicKey) SetStr(s string) error {
return nil
}
+// SetData --
+func (sec *PublicKey) SetData(s string) error {
+ buf := []byte(s)
+ // #nosec
+ err := C.blsPublicKeySetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
+ if err > 0 {
+ return fmt.Errorf("bad string:%s", s)
+ }
+ return nil
+}
+
+// GetData --
+func (sec *PublicKey) GetData() string {
+ fpSize := GetOpUnitSize() * 8
+ buf := make([]byte, fpSize*2)
+ n := C.blsPublicKeyGetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
+ if n == 0 {
+ panic("implementation err. size of buf is small")
+ }
+ return string(buf[:n])
+}
+
+// IsSame --
+func (lhs *PublicKey) IsSame(rhs *PublicKey) bool {
+ return C.blsPublicKeyIsSame(lhs.getPointer(), rhs.getPointer()) == 1
+}
+
// Add --
func (pub *PublicKey) Add(rhs *PublicKey) {
C.blsPublicKeyAdd(pub.getPointer(), rhs.getPointer())
@@ -244,6 +298,33 @@ func (sign *Sign) SetStr(s string) error {
return nil
}
+// SetData --
+func (sec *Sign) SetData(s string) error {
+ buf := []byte(s)
+ // #nosec
+ err := C.blsSignSetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
+ if err > 0 {
+ return fmt.Errorf("bad string:%s", s)
+ }
+ return nil
+}
+
+// GetData --
+func (sec *Sign) GetData() string {
+ fpSize := GetOpUnitSize() * 8
+ buf := make([]byte, fpSize)
+ n := C.blsSignGetData(sec.getPointer(), (*C.char)(unsafe.Pointer(&buf[0])), C.size_t(len(buf)))
+ if n == 0 {
+ panic("implementation err. size of buf is small")
+ }
+ return string(buf[:n])
+}
+
+// IsSame --
+func (lhs *Sign) IsSame(rhs *Sign) bool {
+ return C.blsSignIsSame(lhs.getPointer(), rhs.getPointer()) == 1
+}
+
// GetPublicKey --
func (sec *SecretKey) GetPublicKey() (pub *PublicKey) {
pub = new(PublicKey)
diff --git a/go/main_test.go b/go/main_test.go
index a103ba2..b5069c3 100644
--- a/go/main_test.go
+++ b/go/main_test.go
@@ -126,6 +126,31 @@ func testPop(t *testing.T) {
}
}
+func testData(t *testing.T) {
+ var sec1, sec2 blscgo.SecretKey
+ sec1.Init()
+ s := sec1.GetData()
+ sec2.SetData(s)
+ if !sec1.IsSame(&sec2) {
+ t.Fatal("SecretKey not same")
+ }
+ pub1 := sec1.GetPublicKey()
+ s = pub1.GetData()
+ var pub2 blscgo.PublicKey
+ pub2.SetData(s)
+ if !pub1.IsSame(&pub2) {
+ t.Fatal("PublicKey not same")
+ }
+ m := "doremi"
+ sign1 := sec1.Sign(m)
+ s = sign1.GetData()
+ var sign2 blscgo.Sign
+ sign2.SetData(s)
+ if !sign1.IsSame(&sign2) {
+ t.Fatal("Sign not same")
+ }
+}
+
func test(t *testing.T, cp int) {
blscgo.Init(cp)
unitN = blscgo.GetOpUnitSize()
@@ -164,6 +189,7 @@ func test(t *testing.T, cp int) {
testAdd(t)
testSign(t)
testPop(t)
+ testData(t)
// put memory status
/*