mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 12:46:44 +00:00
crypto: remove HashData utility
This commit is contained in:
parent
b406245737
commit
455331758d
2 changed files with 1 additions and 29 deletions
|
|
@ -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})
|
||||
|
|
|
|||
|
|
@ -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[:])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue