crypto: remove HashData utility

This commit is contained in:
Piotr Mikołajczyk 2025-11-18 11:27:02 +01:00
parent b406245737
commit 455331758d
No known key found for this signature in database
GPG key ID: 2E4C2AAD5E71D22D
2 changed files with 1 additions and 29 deletions

View file

@ -67,14 +67,6 @@ type KeccakState interface {
Read([]byte) (int, error) 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 // CreateAddress creates an ethereum address given the bytes and the nonce
func CreateAddress(b common.Address, nonce uint64) common.Address { func CreateAddress(b common.Address, nonce uint64) common.Address {
data, _ := rlp.EncodeToBytes([]interface{}{b, nonce}) data, _ := rlp.EncodeToBytes([]interface{}{b, nonce})

View file

@ -45,8 +45,7 @@ func TestKeccak256Hash(t *testing.T) {
func TestKeccak256Hasher(t *testing.T) { func TestKeccak256Hasher(t *testing.T) {
msg := []byte("abc") msg := []byte("abc")
exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45") exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
hasher := NewKeccakState() checkhash(t, "Sha3-256-array", func(in []byte) []byte { h := Keccak256Hash(in); return h[:] }, msg, exp)
checkhash(t, "Sha3-256-array", func(in []byte) []byte { h := HashData(hasher, in); return h[:] }, msg, exp)
} }
func TestToECDSAErrors(t *testing.T) { func TestToECDSAErrors(t *testing.T) {
@ -314,22 +313,3 @@ func BenchmarkKeccak256Hash(b *testing.B) {
Keccak256Hash(input[:]) 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[:])
}
}