From 006ebf50dff0f49deb712b8c2b1c78468ed117ee Mon Sep 17 00:00:00 2001 From: Daniel Cason Date: Tue, 19 Apr 2022 14:38:48 +0200 Subject: [PATCH] BLS: simple sign and verify using blst library --- crypto/bls/simple_sign_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/crypto/bls/simple_sign_test.go b/crypto/bls/simple_sign_test.go index 11c026579..b604cb90e 100644 --- a/crypto/bls/simple_sign_test.go +++ b/crypto/bls/simple_sign_test.go @@ -3,6 +3,7 @@ package bls import ( "testing" + "github.com/tendermint/tendermint/crypto/bls/blst" "github.com/tendermint/tendermint/crypto/ed25519" ) @@ -26,6 +27,26 @@ func TestEd25519SignVerify(t *testing.T) { } } +func TestBlstSignVerify(t *testing.T) { + m := []byte("a test message to be signed") + privKey := blst.GenPrivKey() + pubKey := privKey.PubKey() + + sig, err := privKey.Sign(m) + if err != nil { + t.Error("Unexpected nil signature or error", m, sig, err) + } + if !pubKey.VerifySignature(m, sig) { + t.Error("Failed to verify signature produced by the key", m, sig) + } + if pubKey.VerifySignature(scrambleBytes(m), sig) { + t.Error("Unexpected to verify scrambled message", scrambleBytes(m), sig) + } + if pubKey.VerifySignature(m, scrambleBytes(sig)) { + t.Error("Unexpected to verify scrambled signature", m, scrambleBytes(sig)) + } +} + // Scrambles a byte array, currently just flipping a bit. // TODO: implement a more complex scrambling method. func scrambleBytes(b []byte) []byte {