BLS signatures: simple test unit for Ed25519 keys

This commit is contained in:
Daniel Cason
2022-04-19 14:28:20 +02:00
parent a1104b98d2
commit 0ad230b99e
2 changed files with 49 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
module github.com/tendermint/tendermint/crypto/bls
go 1.17
require github.com/tendermint/tendermint v0.35.4
require (
github.com/oasisprotocol/curve25519-voi v0.0.0-20210609091139-0a56a4bca00b // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
)
+37
View File
@@ -0,0 +1,37 @@
package bls
import (
"testing"
"github.com/tendermint/tendermint/crypto/ed25519"
)
func TestEd25519SignVerify(t *testing.T) {
m := []byte("a test message to be signed")
privKey := ed25519.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 {
bb := make([]byte, len(b))
copy(bb, b)
index := len(b) / 2
bb[index] ^= 1
return bb
}