mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-22 02:41:19 +00:00
crypto/ed25519: Remove privkey.Generate method (#2022)
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
This commit is contained in:
parent
e36ce6f893
commit
eb7dea1b0d
@ -98,27 +98,6 @@ func (privKey PrivKeyEd25519) ToCurve25519() *[PubKeyEd25519Size]byte {
|
||||
return keyCurve25519
|
||||
}
|
||||
|
||||
// Generate deterministically derives a new priv-key bytes from key.
|
||||
// The privkey is generated as Sha256(amino_encode({privkey, index}))
|
||||
// Note that we append the public key to the private key, the same way
|
||||
// that golang/x/crypto/ed25519 does. See
|
||||
// https://github.com/tendermint/ed25519/blob/master/ed25519.go#L39 for
|
||||
// further details.
|
||||
func (privKey PrivKeyEd25519) Generate(index int) PrivKeyEd25519 {
|
||||
bz := cdc.MustMarshalBinaryBare(struct {
|
||||
PrivKey [64]byte
|
||||
Index int
|
||||
}{privKey, index})
|
||||
newBytes := crypto.Sha256(bz)
|
||||
newKey := new([64]byte)
|
||||
copy(newKey[:32], newBytes)
|
||||
// ed25519.MakePublicKey(newKey) alters the last 32 bytes of newKey.
|
||||
// It places the pubkey in the last 32 bytes of newKey, and returns the
|
||||
// public key.
|
||||
ed25519.MakePublicKey(newKey)
|
||||
return PrivKeyEd25519(*newKey)
|
||||
}
|
||||
|
||||
// GenPrivKey generates a new ed25519 private key.
|
||||
// It uses OS randomness in conjunction with the current global random seed
|
||||
// in tendermint/libs/common to generate the private key.
|
||||
|
@ -9,16 +9,6 @@ import (
|
||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||
)
|
||||
|
||||
func TestGeneratePrivKey(t *testing.T) {
|
||||
testPriv := ed25519.GenPrivKey()
|
||||
testGenerate := testPriv.Generate(1)
|
||||
signBytes := []byte("something to sign")
|
||||
pub := testGenerate.PubKey()
|
||||
sig, err := testGenerate.Sign(signBytes)
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, pub.VerifyBytes(signBytes, sig))
|
||||
}
|
||||
|
||||
func TestSignAndValidateEd25519(t *testing.T) {
|
||||
|
||||
privKey := ed25519.GenPrivKey()
|
||||
|
Loading…
x
Reference in New Issue
Block a user