aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--accounts/keystore/keystore_passphrase.go17
-rw-r--r--build/ci.go3
-rwxr-xr-xbuild/clean_go_build_cache.sh11
-rw-r--r--cmd/geth/chaincmd.go3
-rw-r--r--cmd/geth/main.go3
-rw-r--r--cmd/utils/flags.go5
-rw-r--r--core/blockchain.go10
-rw-r--r--crypto/randentropy/rand_entropy.go42
-rw-r--r--crypto/secp256k1/curve.go43
-rw-r--r--crypto/secp256k1/secp256_test.go39
10 files changed, 95 insertions, 81 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
diff --git a/build/ci.go b/build/ci.go
index 7d22b5255..2aa85edb4 100644
--- a/build/ci.go
+++ b/build/ci.go
@@ -122,7 +122,8 @@ var (
// Note: wily is unsupported because it was officially deprecated on lanchpad.
// Note: yakkety is unsupported because it was officially deprecated on lanchpad.
// Note: zesty is unsupported because it was officially deprecated on lanchpad.
- debDistros = []string{"trusty", "xenial", "artful", "bionic"}
+ // Note: artful is unsupported because it was officially deprecated on lanchpad.
+ debDistros = []string{"trusty", "xenial", "bionic", "cosmic"}
)
var GOBIN, _ = filepath.Abs(filepath.Join("build", "bin"))
diff --git a/build/clean_go_build_cache.sh b/build/clean_go_build_cache.sh
index e6a523fb4..1666381d9 100755
--- a/build/clean_go_build_cache.sh
+++ b/build/clean_go_build_cache.sh
@@ -1,6 +1,15 @@
#!/bin/sh
-function version_gt() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"; }
+# Cleaning the Go cache only makes sense if we actually have Go installed... or
+# if Go is actually callable. This does not hold true during deb packaging, so
+# we need an explicit check to avoid build failures.
+if ! command -v go > /dev/null; then
+ exit
+fi
+
+version_gt() {
+ test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
+}
golang_version=$(go version |cut -d' ' -f3 |sed 's/go//')
diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go
index d3086921b..ff27a9dfb 100644
--- a/cmd/geth/chaincmd.go
+++ b/cmd/geth/chaincmd.go
@@ -94,7 +94,8 @@ processing will proceed even if an individual RLP-file import failure occurs.`,
Requires a first argument of the file to write to.
Optional second and third arguments control the first and
last block to write. In this mode, the file will be appended
-if already existing.`,
+if already existing. If the file ends with .gz, the output will
+be gzipped.`,
}
importPreimagesCommand = cli.Command{
Action: utils.MigrateFlags(importPreimages),
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index 1c618de35..77ef6afe2 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -251,6 +251,9 @@ func main() {
// It creates a default node based on the command line arguments and runs it in
// blocking mode, waiting for it to be shut down.
func geth(ctx *cli.Context) error {
+ if args := ctx.Args(); len(args) > 0 {
+ return fmt.Errorf("invalid command: %q", args[0])
+ }
node := makeFullNode(ctx)
startNode(ctx, node)
node.Wait()
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index fb1221365..27e56f109 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -644,8 +644,7 @@ func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
for _, url := range urls {
node, err := discover.ParseNode(url)
if err != nil {
- log.Error("Bootstrap URL invalid", "enode", url, "err", err)
- continue
+ log.Crit("Bootstrap URL invalid", "enode", url, "err", err)
}
cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
}
@@ -1199,7 +1198,7 @@ func RegisterShhService(stack *node.Node, cfg *whisper.Config) {
}
// RegisterEthStatsService configures the Ethereum Stats daemon and adds it to
-// th egiven node.
+// the given node.
func RegisterEthStatsService(stack *node.Node, url string) {
if err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
// Retrieve both eth and les services
diff --git a/core/blockchain.go b/core/blockchain.go
index 2f1e78423..7b7e4e79a 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -450,15 +450,19 @@ func (bc *BlockChain) ExportN(w io.Writer, first uint64, last uint64) error {
}
log.Info("Exporting batch of blocks", "count", last-first+1)
+ start, reported := time.Now(), time.Now()
for nr := first; nr <= last; nr++ {
block := bc.GetBlockByNumber(nr)
if block == nil {
return fmt.Errorf("export failed on #%d: not found", nr)
}
-
if err := block.EncodeRLP(w); err != nil {
return err
}
+ if time.Since(reported) >= statsReportLimit {
+ log.Info("Exporting blocks", "exported", block.NumberU64()-first, "elapsed", common.PrettyDuration(time.Since(start)))
+ reported = time.Now()
+ }
}
return nil
@@ -1203,8 +1207,8 @@ type insertStats struct {
startTime mclock.AbsTime
}
-// statsReportLimit is the time limit during import after which we always print
-// out progress. This avoids the user wondering what's going on.
+// statsReportLimit is the time limit during import and export after which we
+// always print out progress. This avoids the user wondering what's going on.
const statsReportLimit = 8 * time.Second
// report prints statistics if some number of blocks have been processed
diff --git a/crypto/randentropy/rand_entropy.go b/crypto/randentropy/rand_entropy.go
deleted file mode 100644
index 539d3ac89..000000000
--- a/crypto/randentropy/rand_entropy.go
+++ /dev/null
@@ -1,42 +0,0 @@
-// Copyright 2015 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-package randentropy
-
-import (
- crand "crypto/rand"
- "io"
-)
-
-var Reader io.Reader = &randEntropy{}
-
-type randEntropy struct {
-}
-
-func (*randEntropy) Read(bytes []byte) (n int, err error) {
- readBytes := GetEntropyCSPRNG(len(bytes))
- copy(bytes, readBytes)
- return len(bytes), nil
-}
-
-func GetEntropyCSPRNG(n int) []byte {
- mainBuff := make([]byte, n)
- _, err := io.ReadFull(crand.Reader, mainBuff)
- if err != nil {
- panic("reading from crypto/rand failed: " + err.Error())
- }
- return mainBuff
-}
diff --git a/crypto/secp256k1/curve.go b/crypto/secp256k1/curve.go
index 6fdf2be6a..56be235b3 100644
--- a/crypto/secp256k1/curve.go
+++ b/crypto/secp256k1/curve.go
@@ -1,5 +1,6 @@
// Copyright 2010 The Go Authors. All rights reserved.
// Copyright 2011 ThePiachu. All rights reserved.
+// Copyright 2015 Jeffrey Wilcke, Felix Lange, Gustav Simonsson. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
@@ -35,8 +36,6 @@ import (
"crypto/elliptic"
"math/big"
"unsafe"
-
- "github.com/ethereum/go-ethereum/common/math"
)
/*
@@ -45,6 +44,27 @@ extern int secp256k1_ext_scalar_mul(const secp256k1_context* ctx, const unsigned
*/
import "C"
+const (
+ // number of bits in a big.Word
+ wordBits = 32 << (uint64(^big.Word(0)) >> 63)
+ // number of bytes in a big.Word
+ wordBytes = wordBits / 8
+)
+
+// readBits encodes the absolute value of bigint as big-endian bytes. Callers
+// must ensure that buf has enough space. If buf is too short the result will
+// be incomplete.
+func readBits(bigint *big.Int, buf []byte) {
+ i := len(buf)
+ for _, d := range bigint.Bits() {
+ for j := 0; j < wordBytes && i > 0; j++ {
+ i--
+ buf[i] = byte(d)
+ d >>= 8
+ }
+ }
+}
+
// This code is from https://github.com/ThePiachu/GoBit and implements
// several Koblitz elliptic curves over prime fields.
//
@@ -231,8 +251,9 @@ func (BitCurve *BitCurve) ScalarMult(Bx, By *big.Int, scalar []byte) (*big.Int,
// Do the multiplication in C, updating point.
point := make([]byte, 64)
- math.ReadBits(Bx, point[:32])
- math.ReadBits(By, point[32:])
+ readBits(Bx, point[:32])
+ readBits(By, point[32:])
+
pointPtr := (*C.uchar)(unsafe.Pointer(&point[0]))
scalarPtr := (*C.uchar)(unsafe.Pointer(&scalar[0]))
res := C.secp256k1_ext_scalar_mul(context, pointPtr, scalarPtr)
@@ -264,8 +285,8 @@ func (BitCurve *BitCurve) Marshal(x, y *big.Int) []byte {
byteLen := (BitCurve.BitSize + 7) >> 3
ret := make([]byte, 1+2*byteLen)
ret[0] = 4 // uncompressed point flag
- math.ReadBits(x, ret[1:1+byteLen])
- math.ReadBits(y, ret[1+byteLen:])
+ readBits(x, ret[1:1+byteLen])
+ readBits(y, ret[1+byteLen:])
return ret
}
@@ -290,11 +311,11 @@ func init() {
// See SEC 2 section 2.7.1
// curve parameters taken from:
// http://www.secg.org/collateral/sec2_final.pdf
- theCurve.P = math.MustParseBig256("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F")
- theCurve.N = math.MustParseBig256("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")
- theCurve.B = math.MustParseBig256("0x0000000000000000000000000000000000000000000000000000000000000007")
- theCurve.Gx = math.MustParseBig256("0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798")
- theCurve.Gy = math.MustParseBig256("0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8")
+ theCurve.P, _ = new(big.Int).SetString("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F", 0)
+ theCurve.N, _ = new(big.Int).SetString("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141", 0)
+ theCurve.B, _ = new(big.Int).SetString("0x0000000000000000000000000000000000000000000000000000000000000007", 0)
+ theCurve.Gx, _ = new(big.Int).SetString("0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798", 0)
+ theCurve.Gy, _ = new(big.Int).SetString("0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", 0)
theCurve.BitSize = 256
}
diff --git a/crypto/secp256k1/secp256_test.go b/crypto/secp256k1/secp256_test.go
index 3bccddab8..ef2a3a379 100644
--- a/crypto/secp256k1/secp256_test.go
+++ b/crypto/secp256k1/secp256_test.go
@@ -10,10 +10,8 @@ import (
"crypto/elliptic"
"crypto/rand"
"encoding/hex"
+ "io"
"testing"
-
- "github.com/ethereum/go-ethereum/common/math"
- "github.com/ethereum/go-ethereum/crypto/randentropy"
)
const TestCount = 1000
@@ -24,11 +22,24 @@ func generateKeyPair() (pubkey, privkey []byte) {
panic(err)
}
pubkey = elliptic.Marshal(S256(), key.X, key.Y)
- return pubkey, math.PaddedBigBytes(key.D, 32)
+
+ privkey = make([]byte, 32)
+ blob := key.D.Bytes()
+ copy(privkey[32-len(blob):], blob)
+
+ return pubkey, privkey
+}
+
+func csprngEntropy(n int) []byte {
+ buf := make([]byte, n)
+ if _, err := io.ReadFull(rand.Reader, buf); err != nil {
+ panic("reading from crypto/rand failed: " + err.Error())
+ }
+ return buf
}
func randSig() []byte {
- sig := randentropy.GetEntropyCSPRNG(65)
+ sig := csprngEntropy(65)
sig[32] &= 0x70
sig[64] %= 4
return sig
@@ -51,7 +62,7 @@ func compactSigCheck(t *testing.T, sig []byte) {
func TestSignatureValidity(t *testing.T) {
pubkey, seckey := generateKeyPair()
- msg := randentropy.GetEntropyCSPRNG(32)
+ msg := csprngEntropy(32)
sig, err := Sign(msg, seckey)
if err != nil {
t.Errorf("signature error: %s", err)
@@ -74,7 +85,7 @@ func TestSignatureValidity(t *testing.T) {
func TestInvalidRecoveryID(t *testing.T) {
_, seckey := generateKeyPair()
- msg := randentropy.GetEntropyCSPRNG(32)
+ msg := csprngEntropy(32)
sig, _ := Sign(msg, seckey)
sig[64] = 99
_, err := RecoverPubkey(msg, sig)
@@ -85,7 +96,7 @@ func TestInvalidRecoveryID(t *testing.T) {
func TestSignAndRecover(t *testing.T) {
pubkey1, seckey := generateKeyPair()
- msg := randentropy.GetEntropyCSPRNG(32)
+ msg := csprngEntropy(32)
sig, err := Sign(msg, seckey)
if err != nil {
t.Errorf("signature error: %s", err)
@@ -136,7 +147,7 @@ func TestRandomMessagesWithRandomKeys(t *testing.T) {
func signAndRecoverWithRandomMessages(t *testing.T, keys func() ([]byte, []byte)) {
for i := 0; i < TestCount; i++ {
pubkey1, seckey := keys()
- msg := randentropy.GetEntropyCSPRNG(32)
+ msg := csprngEntropy(32)
sig, err := Sign(msg, seckey)
if err != nil {
t.Fatalf("signature error: %s", err)
@@ -164,7 +175,7 @@ func signAndRecoverWithRandomMessages(t *testing.T, keys func() ([]byte, []byte)
func TestRecoveryOfRandomSignature(t *testing.T) {
pubkey1, _ := generateKeyPair()
- msg := randentropy.GetEntropyCSPRNG(32)
+ msg := csprngEntropy(32)
for i := 0; i < TestCount; i++ {
// recovery can sometimes work, but if so should always give wrong pubkey
@@ -177,11 +188,11 @@ func TestRecoveryOfRandomSignature(t *testing.T) {
func TestRandomMessagesAgainstValidSig(t *testing.T) {
pubkey1, seckey := generateKeyPair()
- msg := randentropy.GetEntropyCSPRNG(32)
+ msg := csprngEntropy(32)
sig, _ := Sign(msg, seckey)
for i := 0; i < TestCount; i++ {
- msg = randentropy.GetEntropyCSPRNG(32)
+ msg = csprngEntropy(32)
pubkey2, _ := RecoverPubkey(msg, sig)
// recovery can sometimes work, but if so should always give wrong pubkey
if bytes.Equal(pubkey1, pubkey2) {
@@ -207,7 +218,7 @@ func TestRecoverSanity(t *testing.T) {
func BenchmarkSign(b *testing.B) {
_, seckey := generateKeyPair()
- msg := randentropy.GetEntropyCSPRNG(32)
+ msg := csprngEntropy(32)
b.ResetTimer()
for i := 0; i < b.N; i++ {
@@ -216,7 +227,7 @@ func BenchmarkSign(b *testing.B) {
}
func BenchmarkRecover(b *testing.B) {
- msg := randentropy.GetEntropyCSPRNG(32)
+ msg := csprngEntropy(32)
_, seckey := generateKeyPair()
sig, _ := Sign(msg, seckey)
b.ResetTimer()