mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-21 10:41:18 +00:00
The privkey.Generate method here was a custom-made method for deriving a private key from another private key. This function is currently not used anywhere in our codebase, and has not been reviewed enough that it would be secure to use. This removes that method. We should adopt the official ed25519 HD derivation once that has been standardized, in order to fulfill this need. closes #2000
32 lines
729 B
Go
32 lines
729 B
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.VerifyBytes(msg, sig))
|
|
|
|
// Mutate the signature, just one bit.
|
|
// TODO: Replace this with a much better fuzzer, tendermint/ed25519/issues/10
|
|
sigEd := sig.(ed25519.SignatureEd25519)
|
|
sigEd[7] ^= byte(0x01)
|
|
sig = sigEd
|
|
|
|
assert.False(t, pubKey.VerifyBytes(msg, sig))
|
|
}
|