You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
729 B

  1. package ed25519_test
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. "github.com/stretchr/testify/require"
  6. "github.com/tendermint/tendermint/crypto"
  7. "github.com/tendermint/tendermint/crypto/ed25519"
  8. )
  9. func TestSignAndValidateEd25519(t *testing.T) {
  10. privKey := ed25519.GenPrivKey()
  11. pubKey := privKey.PubKey()
  12. msg := crypto.CRandBytes(128)
  13. sig, err := privKey.Sign(msg)
  14. require.Nil(t, err)
  15. // Test the signature
  16. assert.True(t, pubKey.VerifyBytes(msg, sig))
  17. // Mutate the signature, just one bit.
  18. // TODO: Replace this with a much better fuzzer, tendermint/ed25519/issues/10
  19. sigEd := sig.(ed25519.SignatureEd25519)
  20. sigEd[7] ^= byte(0x01)
  21. sig = sigEd
  22. assert.False(t, pubKey.VerifyBytes(msg, sig))
  23. }