From a4e08a695200506ad2328ab4755cefad5674364a Mon Sep 17 00:00:00 2001 From: Paladz Date: Thu, 21 Feb 2019 14:20:13 +0800 Subject: [PATCH] small change (#1580) --- config/config.go | 12 ++++++++---- crypto/ed25519/ed25519.go | 5 +++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 2e2990f6..18b9a503 100644 --- a/config/config.go +++ b/config/config.go @@ -9,7 +9,8 @@ import ( "runtime" log "github.com/sirupsen/logrus" - "github.com/tendermint/go-crypto" + + "github.com/bytom/crypto/ed25519" ) var ( @@ -60,7 +61,7 @@ func (cfg *Config) NodeKey() (string, error) { } keyFile := rootify(cfg.P2P.NodeKeyFile, cfg.BaseConfig.RootDir) - buf := make([]byte, len(crypto.PrivKeyEd25519{})*2) + buf := make([]byte, ed25519.PrivateKeySize*2) fd, err := os.Open(keyFile) defer fd.Close() if err == nil { @@ -70,11 +71,14 @@ func (cfg *Config) NodeKey() (string, error) { } log.WithField("err", err).Warning("key file access failed") - privKey := crypto.GenPrivKeyEd25519() - if err = ioutil.WriteFile(keyFile, []byte(privKey.String()), 0600); err != nil { + _, privKey, err := ed25519.GenerateKey(nil) + if err != nil { return "", err } + if err = ioutil.WriteFile(keyFile, []byte(privKey.String()), 0600); err != nil { + return "", err + } return privKey.String(), nil } diff --git a/crypto/ed25519/ed25519.go b/crypto/ed25519/ed25519.go index 8d03d9d7..01047cfa 100644 --- a/crypto/ed25519/ed25519.go +++ b/crypto/ed25519/ed25519.go @@ -13,6 +13,7 @@ import ( cryptorand "crypto/rand" "crypto/sha512" "crypto/subtle" + "encoding/hex" "errors" "io" "strconv" @@ -42,6 +43,10 @@ func (priv PrivateKey) Public() crypto.PublicKey { return PublicKey(publicKey) } +func (priv PrivateKey) String() string { + return hex.EncodeToString(priv) +} + // Sign signs the given message with priv. // Ed25519 performs two passes over messages to be signed and therefore cannot // handle pre-hashed messages. Thus opts.HashFunc() must return zero to -- 2.11.0