diff --git a/crypto/crypto.go b/crypto/crypto.go index db6b6ee071..1d575326df 100644 --- a/crypto/crypto.go +++ b/crypto/crypto.go @@ -67,14 +67,6 @@ type KeccakState interface { Read([]byte) (int, error) } -// HashData hashes the provided data using the KeccakState and returns a 32 byte hash -func HashData(kh KeccakState, data []byte) (h common.Hash) { - kh.Reset() - kh.Write(data) - kh.Read(h[:]) - return h -} - // CreateAddress creates an ethereum address given the bytes and the nonce func CreateAddress(b common.Address, nonce uint64) common.Address { data, _ := rlp.EncodeToBytes([]interface{}{b, nonce}) diff --git a/crypto/crypto_test.go b/crypto/crypto_test.go index d803ab27c5..bed51d76ac 100644 --- a/crypto/crypto_test.go +++ b/crypto/crypto_test.go @@ -45,8 +45,7 @@ func TestKeccak256Hash(t *testing.T) { func TestKeccak256Hasher(t *testing.T) { msg := []byte("abc") exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45") - hasher := NewKeccakState() - checkhash(t, "Sha3-256-array", func(in []byte) []byte { h := HashData(hasher, in); return h[:] }, msg, exp) + checkhash(t, "Sha3-256-array", func(in []byte) []byte { h := Keccak256Hash(in); return h[:] }, msg, exp) } func TestToECDSAErrors(t *testing.T) { @@ -314,22 +313,3 @@ func BenchmarkKeccak256Hash(b *testing.B) { Keccak256Hash(input[:]) } } - -// goos: darwin -// goarch: arm64 -// pkg: github.com/ethereum/go-ethereum/crypto -// cpu: Apple M1 Pro -// BenchmarkHashData -// BenchmarkHashData-8 793386 1278 ns/op 32 B/op 1 allocs/op -func BenchmarkHashData(b *testing.B) { - var ( - input [512]byte - buffer = NewKeccakState() - ) - rand.Read(input[:]) - - b.ReportAllocs() - for b.Loop() { - HashData(buffer, input[:]) - } -}