Skip to content

Commit 391d4cb

Browse files
authored
Merge pull request #18390 from realdave/remove-sha3-pkg
vendor, crypto, swarm: switch over to upstream sha3 package
2 parents 3f421ac + 8ec344b commit 391d4cb

File tree

99 files changed

+4505
-1017
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+4505
-1017
lines changed

cmd/swarm/access_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ import (
3333

3434
"github.com/ethereum/go-ethereum/crypto"
3535
"github.com/ethereum/go-ethereum/crypto/ecies"
36-
"github.com/ethereum/go-ethereum/crypto/sha3"
3736
"github.com/ethereum/go-ethereum/log"
3837
"github.com/ethereum/go-ethereum/swarm/api"
3938
swarmapi "github.com/ethereum/go-ethereum/swarm/api/client"
4039
"github.com/ethereum/go-ethereum/swarm/testutil"
40+
"golang.org/x/crypto/sha3"
4141
)
4242

4343
const (
@@ -598,7 +598,7 @@ func TestKeypairSanity(t *testing.T) {
598598
t.Fatal(err)
599599
}
600600

601-
hasher := sha3.NewKeccak256()
601+
hasher := sha3.NewLegacyKeccak256()
602602
hasher.Write(salt)
603603
shared, err := hex.DecodeString(sharedSecret)
604604
if err != nil {

common/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"strings"
2828

2929
"github.com/ethereum/go-ethereum/common/hexutil"
30-
"github.com/ethereum/go-ethereum/crypto/sha3"
30+
"golang.org/x/crypto/sha3"
3131
)
3232

3333
// Lengths of hashes and addresses in bytes.
@@ -196,7 +196,7 @@ func (a Address) Hash() Hash { return BytesToHash(a[:]) }
196196
// Hex returns an EIP55-compliant hex string representation of the address.
197197
func (a Address) Hex() string {
198198
unchecksummed := hex.EncodeToString(a[:])
199-
sha := sha3.NewKeccak256()
199+
sha := sha3.NewLegacyKeccak256()
200200
sha.Write([]byte(unchecksummed))
201201
hash := sha.Sum(nil)
202202

consensus/clique/clique.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ import (
3333
"github.com/ethereum/go-ethereum/core/state"
3434
"github.com/ethereum/go-ethereum/core/types"
3535
"github.com/ethereum/go-ethereum/crypto"
36-
"github.com/ethereum/go-ethereum/crypto/sha3"
3736
"github.com/ethereum/go-ethereum/ethdb"
3837
"github.com/ethereum/go-ethereum/log"
3938
"github.com/ethereum/go-ethereum/params"
4039
"github.com/ethereum/go-ethereum/rlp"
4140
"github.com/ethereum/go-ethereum/rpc"
4241
lru "github.com/hashicorp/golang-lru"
42+
"golang.org/x/crypto/sha3"
4343
)
4444

4545
const (
@@ -148,7 +148,7 @@ type SignerFn func(accounts.Account, []byte) ([]byte, error)
148148
// panics. This is done to avoid accidentally using both forms (signature present
149149
// or not), which could be abused to produce different hashes for the same header.
150150
func sigHash(header *types.Header) (hash common.Hash) {
151-
hasher := sha3.NewKeccak256()
151+
hasher := sha3.NewLegacyKeccak256()
152152

153153
rlp.Encode(hasher, []interface{}{
154154
header.ParentHash,

consensus/ethash/algorithm.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030
"github.com/ethereum/go-ethereum/common"
3131
"github.com/ethereum/go-ethereum/common/bitutil"
3232
"github.com/ethereum/go-ethereum/crypto"
33-
"github.com/ethereum/go-ethereum/crypto/sha3"
3433
"github.com/ethereum/go-ethereum/log"
34+
"golang.org/x/crypto/sha3"
3535
)
3636

3737
const (
@@ -123,7 +123,7 @@ func seedHash(block uint64) []byte {
123123
if block < epochLength {
124124
return seed
125125
}
126-
keccak256 := makeHasher(sha3.NewKeccak256())
126+
keccak256 := makeHasher(sha3.NewLegacyKeccak256())
127127
for i := 0; i < int(block/epochLength); i++ {
128128
keccak256(seed, seed)
129129
}
@@ -177,7 +177,7 @@ func generateCache(dest []uint32, epoch uint64, seed []byte) {
177177
}
178178
}()
179179
// Create a hasher to reuse between invocations
180-
keccak512 := makeHasher(sha3.NewKeccak512())
180+
keccak512 := makeHasher(sha3.NewLegacyKeccak512())
181181

182182
// Sequentially produce the initial dataset
183183
keccak512(cache, seed)
@@ -301,7 +301,7 @@ func generateDataset(dest []uint32, epoch uint64, cache []uint32) {
301301
defer pend.Done()
302302

303303
// Create a hasher to reuse between invocations
304-
keccak512 := makeHasher(sha3.NewKeccak512())
304+
keccak512 := makeHasher(sha3.NewLegacyKeccak512())
305305

306306
// Calculate the data segment this thread should generate
307307
batch := uint32((size + hashBytes*uint64(threads) - 1) / (hashBytes * uint64(threads)))
@@ -375,7 +375,7 @@ func hashimoto(hash []byte, nonce uint64, size uint64, lookup func(index uint32)
375375
// in-memory cache) in order to produce our final value for a particular header
376376
// hash and nonce.
377377
func hashimotoLight(size uint64, cache []uint32, hash []byte, nonce uint64) ([]byte, []byte) {
378-
keccak512 := makeHasher(sha3.NewKeccak512())
378+
keccak512 := makeHasher(sha3.NewLegacyKeccak512())
379379

380380
lookup := func(index uint32) []uint32 {
381381
rawData := generateDatasetItem(cache, index, keccak512)

consensus/ethash/consensus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ import (
3131
"github.com/ethereum/go-ethereum/consensus/misc"
3232
"github.com/ethereum/go-ethereum/core/state"
3333
"github.com/ethereum/go-ethereum/core/types"
34-
"github.com/ethereum/go-ethereum/crypto/sha3"
3534
"github.com/ethereum/go-ethereum/params"
3635
"github.com/ethereum/go-ethereum/rlp"
36+
"golang.org/x/crypto/sha3"
3737
)
3838

3939
// Ethash proof-of-work protocol constants.
@@ -575,7 +575,7 @@ func (ethash *Ethash) Finalize(chain consensus.ChainReader, header *types.Header
575575

576576
// SealHash returns the hash of a block prior to it being sealed.
577577
func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) {
578-
hasher := sha3.NewKeccak256()
578+
hasher := sha3.NewLegacyKeccak256()
579579

580580
rlp.Encode(hasher, []interface{}{
581581
header.ParentHash,

core/rawdb/accessors_chain_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import (
2323

2424
"github.com/ethereum/go-ethereum/common"
2525
"github.com/ethereum/go-ethereum/core/types"
26-
"github.com/ethereum/go-ethereum/crypto/sha3"
2726
"github.com/ethereum/go-ethereum/ethdb"
2827
"github.com/ethereum/go-ethereum/rlp"
28+
"golang.org/x/crypto/sha3"
2929
)
3030

3131
// Tests block header storage and retrieval operations.
@@ -47,7 +47,7 @@ func TestHeaderStorage(t *testing.T) {
4747
if entry := ReadHeaderRLP(db, header.Hash(), header.Number.Uint64()); entry == nil {
4848
t.Fatalf("Stored header RLP not found")
4949
} else {
50-
hasher := sha3.NewKeccak256()
50+
hasher := sha3.NewLegacyKeccak256()
5151
hasher.Write(entry)
5252

5353
if hash := common.BytesToHash(hasher.Sum(nil)); hash != header.Hash() {
@@ -68,7 +68,7 @@ func TestBodyStorage(t *testing.T) {
6868
// Create a test body to move around the database and make sure it's really new
6969
body := &types.Body{Uncles: []*types.Header{{Extra: []byte("test header")}}}
7070

71-
hasher := sha3.NewKeccak256()
71+
hasher := sha3.NewLegacyKeccak256()
7272
rlp.Encode(hasher, body)
7373
hash := common.BytesToHash(hasher.Sum(nil))
7474

@@ -85,7 +85,7 @@ func TestBodyStorage(t *testing.T) {
8585
if entry := ReadBodyRLP(db, hash, 0); entry == nil {
8686
t.Fatalf("Stored body RLP not found")
8787
} else {
88-
hasher := sha3.NewKeccak256()
88+
hasher := sha3.NewLegacyKeccak256()
8989
hasher.Write(entry)
9090

9191
if calc := common.BytesToHash(hasher.Sum(nil)); calc != hash {

core/types/block.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import (
2828

2929
"github.com/ethereum/go-ethereum/common"
3030
"github.com/ethereum/go-ethereum/common/hexutil"
31-
"github.com/ethereum/go-ethereum/crypto/sha3"
3231
"github.com/ethereum/go-ethereum/rlp"
32+
"golang.org/x/crypto/sha3"
3333
)
3434

3535
var (
@@ -109,7 +109,7 @@ func (h *Header) Size() common.StorageSize {
109109
}
110110

111111
func rlpHash(x interface{}) (h common.Hash) {
112-
hw := sha3.NewKeccak256()
112+
hw := sha3.NewLegacyKeccak256()
113113
rlp.Encode(hw, x)
114114
hw.Sum(h[:0])
115115
return h

core/vm/instructions.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"github.com/ethereum/go-ethereum/common"
2525
"github.com/ethereum/go-ethereum/common/math"
2626
"github.com/ethereum/go-ethereum/core/types"
27-
"github.com/ethereum/go-ethereum/crypto/sha3"
2827
"github.com/ethereum/go-ethereum/params"
28+
"golang.org/x/crypto/sha3"
2929
)
3030

3131
var (
@@ -387,7 +387,7 @@ func opSha3(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memory
387387
data := memory.Get(offset.Int64(), size.Int64())
388388

389389
if interpreter.hasher == nil {
390-
interpreter.hasher = sha3.NewKeccak256().(keccakState)
390+
interpreter.hasher = sha3.NewLegacyKeccak256().(keccakState)
391391
} else {
392392
interpreter.hasher.Reset()
393393
}

crypto/crypto.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ import (
3030

3131
"github.com/ethereum/go-ethereum/common"
3232
"github.com/ethereum/go-ethereum/common/math"
33-
"github.com/ethereum/go-ethereum/crypto/sha3"
3433
"github.com/ethereum/go-ethereum/rlp"
34+
"golang.org/x/crypto/sha3"
3535
)
3636

3737
var (
@@ -43,7 +43,7 @@ var errInvalidPubkey = errors.New("invalid secp256k1 public key")
4343

4444
// Keccak256 calculates and returns the Keccak256 hash of the input data.
4545
func Keccak256(data ...[]byte) []byte {
46-
d := sha3.NewKeccak256()
46+
d := sha3.NewLegacyKeccak256()
4747
for _, b := range data {
4848
d.Write(b)
4949
}
@@ -53,7 +53,7 @@ func Keccak256(data ...[]byte) []byte {
5353
// Keccak256Hash calculates and returns the Keccak256 hash of the input data,
5454
// converting it to an internal Hash data structure.
5555
func Keccak256Hash(data ...[]byte) (h common.Hash) {
56-
d := sha3.NewKeccak256()
56+
d := sha3.NewLegacyKeccak256()
5757
for _, b := range data {
5858
d.Write(b)
5959
}
@@ -63,7 +63,7 @@ func Keccak256Hash(data ...[]byte) (h common.Hash) {
6363

6464
// Keccak512 calculates and returns the Keccak512 hash of the input data.
6565
func Keccak512(data ...[]byte) []byte {
66-
d := sha3.NewKeccak512()
66+
d := sha3.NewLegacyKeccak512()
6767
for _, b := range data {
6868
d.Write(b)
6969
}

crypto/sha3/LICENSE

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)