mirror of
https://github.com/tendermint/tendermint.git
synced 2026-02-03 18:42:14 +00:00
* crypto: Use curve25519-voi This switches the ed25519, sr25519 and merlin provider to curve25519-voi and additionally adopts ZIP-215 semantics for ed25519 verification. * crypto: Implement batch verification interface for ed25519 and sr25519 This commit adds the batch verification interface, but does not enable it for anything. * types: Use batch verification for verifying commits signatures
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package ed25519_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/tendermint/tendermint/crypto"
|
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
|
)
|
|
|
|
func TestSignAndValidateEd25519(t *testing.T) {
|
|
privKey := ed25519.GenPrivKey()
|
|
pubKey := privKey.PubKey()
|
|
|
|
msg := crypto.CRandBytes(128)
|
|
sig, err := privKey.Sign(msg)
|
|
require.Nil(t, err)
|
|
|
|
// Test the signature
|
|
assert.True(t, pubKey.VerifySignature(msg, sig))
|
|
|
|
// Mutate the signature, just one bit.
|
|
// TODO: Replace this with a much better fuzzer, tendermint/ed25519/issues/10
|
|
sig[7] ^= byte(0x01)
|
|
|
|
assert.False(t, pubKey.VerifySignature(msg, sig))
|
|
}
|
|
|
|
func TestBatchSafe(t *testing.T) {
|
|
v := ed25519.NewBatchVerifier()
|
|
|
|
for i := 0; i <= 38; i++ {
|
|
priv := ed25519.GenPrivKey()
|
|
pub := priv.PubKey()
|
|
|
|
var msg []byte
|
|
if i%2 == 0 {
|
|
msg = []byte("easter")
|
|
} else {
|
|
msg = []byte("egg")
|
|
}
|
|
|
|
sig, err := priv.Sign(msg)
|
|
require.NoError(t, err)
|
|
|
|
err = v.Add(pub, msg, sig)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
ok, _ := v.Verify()
|
|
require.True(t, ok)
|
|
}
|