aboutsummaryrefslogtreecommitdiffstats
path: root/ffi/go/bls/bls_test.go
diff options
context:
space:
mode:
authorMITSUNARI Shigeo <herumi@nifty.com>2019-01-08 18:46:49 +0800
committerMITSUNARI Shigeo <herumi@nifty.com>2019-01-09 13:20:27 +0800
commitddd2989d3e681aed4c03c6223978d2d6d0cfe206 (patch)
treea4b26d2fba2b062daa2be824678923db878b4264 /ffi/go/bls/bls_test.go
parent25093f5bc029196b4fe8240355147680be7c3880 (diff)
downloaddexon-bls-ddd2989d3e681aed4c03c6223978d2d6d0cfe206.tar
dexon-bls-ddd2989d3e681aed4c03c6223978d2d6d0cfe206.tar.gz
dexon-bls-ddd2989d3e681aed4c03c6223978d2d6d0cfe206.tar.bz2
dexon-bls-ddd2989d3e681aed4c03c6223978d2d6d0cfe206.tar.lz
dexon-bls-ddd2989d3e681aed4c03c6223978d2d6d0cfe206.tar.xz
dexon-bls-ddd2989d3e681aed4c03c6223978d2d6d0cfe206.tar.zst
dexon-bls-ddd2989d3e681aed4c03c6223978d2d6d0cfe206.zip
add SignHash, VerifyHash to cgo
Diffstat (limited to 'ffi/go/bls/bls_test.go')
-rw-r--r--ffi/go/bls/bls_test.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/ffi/go/bls/bls_test.go b/ffi/go/bls/bls_test.go
index 7626156..72f1838 100644
--- a/ffi/go/bls/bls_test.go
+++ b/ffi/go/bls/bls_test.go
@@ -2,6 +2,8 @@ package bls
import "testing"
import "strconv"
+import "crypto/sha256"
+import "crypto/sha512"
var unitN = 0
@@ -392,6 +394,33 @@ func testAggregate2(t *testing.T) {
}
}
+func testHash(t *testing.T) {
+ var sec SecretKey
+ sec.SetByCSPRNG()
+ pub := sec.GetPublicKey()
+ m := "abc"
+ var h []byte
+ if GetOpUnitSize() == 4 {
+ d := sha256.Sum256([]byte(m))
+ h = d[:]
+ } else {
+ // use SHA512 if bitSize > 256
+ d := sha512.Sum512([]byte(m))
+ h = d[:]
+ }
+ sig1 := sec.Sign(m)
+ sig2 := sec.SignHash(h)
+ if !sig1.IsEqual(sig2) {
+ t.Errorf("SignHash")
+ }
+ if !sig1.Verify(pub, m) {
+ t.Errorf("sig1.Verify")
+ }
+ if !sig2.VerifyHash(pub, h) {
+ t.Errorf("sig2.VerifyHash")
+ }
+}
+
func test(t *testing.T, c int) {
err := Init(c)
if err != nil {
@@ -411,6 +440,7 @@ func test(t *testing.T, c int) {
testSerializeToHexStr(t)
testPairing(t)
testAggregate2(t)
+ testHash(t)
}
func TestMain(t *testing.T) {