Skip to content
Closed
5 changes: 2 additions & 3 deletions common/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import (
"fmt"
"math/big"

"golang.org/x/crypto/sha3"

"github.com/erigontech/erigon/common/crypto/keccak"
"github.com/erigontech/erigon/common/hexutil"
"github.com/erigontech/erigon/common/length"
)
Expand Down Expand Up @@ -77,7 +76,7 @@ func (a *Address) checksumHex() []byte {
buf := a.hex()

// compute checksum
sha := sha3.NewLegacyKeccak256()
sha := keccak.NewLegacyKeccak256()
//nolint:errcheck
sha.Write(buf[2:])
hash := sha.Sum(nil)
Expand Down
6 changes: 3 additions & 3 deletions common/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import (
"sync"

"github.com/holiman/uint256"
"golang.org/x/crypto/sha3"

"github.com/erigontech/erigon/common"
"github.com/erigontech/erigon/common/crypto/keccak"
"github.com/erigontech/erigon/common/hexutil"
"github.com/erigontech/erigon/common/math"
)
Expand Down Expand Up @@ -111,7 +111,7 @@ func Keccak256Hash(data ...[]byte) (h common.Hash) {

// Keccak512 calculates and returns the Keccak512 hash of the input data.
func Keccak512(data ...[]byte) []byte {
d := sha3.NewLegacyKeccak512()
d := keccak.NewLegacyKeccak512()
for _, b := range data {
d.Write(b)
}
Expand Down Expand Up @@ -325,7 +325,7 @@ func PubkeyToAddress(p ecdsa.PublicKey) common.Address {
// hasherPool holds LegacyKeccak hashers.
var hasherPool = sync.Pool{
New: func() any {
return sha3.NewLegacyKeccak256()
return keccak.NewLegacyKeccak256()
},
}

Expand Down
27 changes: 27 additions & 0 deletions common/crypto/keccak/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Copyright 2009 The Go Authors.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google LLC nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
6 changes: 6 additions & 0 deletions common/crypto/keccak/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This is a vendored and modified copy of golang.org/x/crypto/sha3, with an assembly
implementation of keccak256. We wish to retain the assembly implementation,
which was removed in v0.44.0.

Ethereum uses a 'legacy' variant of Keccak, which was defined before it became SHA3. As
such, we cannot use the standard library crypto/sha3 package.
44 changes: 44 additions & 0 deletions common/crypto/keccak/hashes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright 2014 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package keccak

// This file provides functions for creating instances of the SHA-3
// and SHAKE hash functions, as well as utility functions for hashing
// bytes.

import (
"hash"
)

const (
dsbyteSHA3 = 0b00000110
dsbyteKeccak = 0b00000001
dsbyteShake = 0b00011111
dsbyteCShake = 0b00000100

// rateK[c] is the rate in bytes for Keccak[c] where c is the capacity in
// bits. Given the sponge size is 1600 bits, the rate is 1600 - c bits.
rateK256 = (1600 - 256) / 8
rateK448 = (1600 - 448) / 8
rateK512 = (1600 - 512) / 8
rateK768 = (1600 - 768) / 8
rateK1024 = (1600 - 1024) / 8
)

// NewLegacyKeccak256 creates a new Keccak-256 hash.
//
// Only use this function if you require compatibility with an existing cryptosystem
// that uses non-standard padding. All other users should use New256 instead.
func NewLegacyKeccak256() hash.Hash {
return &state{rate: rateK512, outputLen: 32, dsbyte: dsbyteKeccak}
}

// NewLegacyKeccak512 creates a new Keccak-512 hash.
//
// Only use this function if you require compatibility with an existing cryptosystem
// that uses non-standard padding. All other users should use New512 instead.
func NewLegacyKeccak512() hash.Hash {
return &state{rate: rateK1024, outputLen: 64, dsbyte: dsbyteKeccak}
}
Loading
Loading