aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/keystore
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-07-26 19:33:13 +0800
committerFelix Lange <fjl@users.noreply.github.com>2018-07-26 19:33:13 +0800
commitd9575e92fc6e52ba18267410fcd2426d5a148cbc (patch)
tree81e569ddd1d5404fc7ce94fd0ff6f91b78be6b35 /accounts/keystore
parent11a402f747956816bbf49e5f4b7fb5deeecd3017 (diff)
downloaddexon-d9575e92fc6e52ba18267410fcd2426d5a148cbc.tar.gz
dexon-d9575e92fc6e52ba18267410fcd2426d5a148cbc.tar.zst
dexon-d9575e92fc6e52ba18267410fcd2426d5a148cbc.zip
crypto/secp256k1: remove external LGPL dependencies (#17239)
Diffstat (limited to 'accounts/keystore')
-rw-r--r--accounts/keystore/keystore_passphrase.go17
1 files changed, 12 insertions, 5 deletions
diff --git a/accounts/keystore/keystore_passphrase.go b/accounts/keystore/keystore_passphrase.go
index da632fe34..59738abe1 100644
--- a/accounts/keystore/keystore_passphrase.go
+++ b/accounts/keystore/keystore_passphrase.go
@@ -28,18 +28,18 @@ package keystore
import (
"bytes"
"crypto/aes"
- crand "crypto/rand"
+ "crypto/rand"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
+ "io"
"io/ioutil"
"path/filepath"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/math"
"github.com/ethereum/go-ethereum/crypto"
- "github.com/ethereum/go-ethereum/crypto/randentropy"
"github.com/pborman/uuid"
"golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/scrypt"
@@ -93,7 +93,7 @@ func (ks keyStorePassphrase) GetKey(addr common.Address, filename, auth string)
// StoreKey generates a key, encrypts with 'auth' and stores in the given directory
func StoreKey(dir, auth string, scryptN, scryptP int) (common.Address, error) {
- _, a, err := storeNewKey(&keyStorePassphrase{dir, scryptN, scryptP}, crand.Reader, auth)
+ _, a, err := storeNewKey(&keyStorePassphrase{dir, scryptN, scryptP}, rand.Reader, auth)
return a.Address, err
}
@@ -116,7 +116,11 @@ func (ks keyStorePassphrase) JoinPath(filename string) string {
// blob that can be decrypted later on.
func EncryptKey(key *Key, auth string, scryptN, scryptP int) ([]byte, error) {
authArray := []byte(auth)
- salt := randentropy.GetEntropyCSPRNG(32)
+
+ salt := make([]byte, 32)
+ if _, err := io.ReadFull(rand.Reader, salt); err != nil {
+ panic("reading from crypto/rand failed: " + err.Error())
+ }
derivedKey, err := scrypt.Key(authArray, salt, scryptN, scryptR, scryptP, scryptDKLen)
if err != nil {
return nil, err
@@ -124,7 +128,10 @@ func EncryptKey(key *Key, auth string, scryptN, scryptP int) ([]byte, error) {
encryptKey := derivedKey[:16]
keyBytes := math.PaddedBigBytes(key.PrivateKey.D, 32)
- iv := randentropy.GetEntropyCSPRNG(aes.BlockSize) // 16
+ iv := make([]byte, aes.BlockSize) // 16
+ if _, err := io.ReadFull(rand.Reader, iv); err != nil {
+ panic("reading from crypto/rand failed: " + err.Error())
+ }
cipherText, err := aesCTRXOR(encryptKey, keyBytes, iv)
if err != nil {
return nil, err