Browse Source

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
pull/2028/head
Dev Ojha 7 years ago
committed by Anton Kaliaev
parent
commit
eb7dea1b0d
2 changed files with 0 additions and 31 deletions
  1. +0
    -21
      crypto/ed25519/ed25519.go
  2. +0
    -10
      crypto/ed25519/ed25519_test.go

+ 0
- 21
crypto/ed25519/ed25519.go View File

@ -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.


+ 0
- 10
crypto/ed25519/ed25519_test.go View File

@ -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…
Cancel
Save