diff --git a/crypto/bls/go.mod b/crypto/bls/go.mod new file mode 100644 index 000000000..45667a011 --- /dev/null +++ b/crypto/bls/go.mod @@ -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 +) diff --git a/crypto/bls/simple_sign_test.go b/crypto/bls/simple_sign_test.go new file mode 100644 index 000000000..11c026579 --- /dev/null +++ b/crypto/bls/simple_sign_test.go @@ -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 +}