Skip to content

Commit 545a5d0

Browse files
gzliudanJukLee0ira
authored andcommitted
crypto: improve trie updates (ethereum#21047)
1 parent fd38373 commit 545a5d0

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

crypto/crypto.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func HashData(kh KeccakState, data []byte) (h common.Hash) {
7575
// Keccak256 calculates and returns the Keccak256 hash of the input data.
7676
func Keccak256(data ...[]byte) []byte {
7777
b := make([]byte, 32)
78-
d := sha3.NewLegacyKeccak256().(KeccakState)
78+
d := NewKeccakState()
7979
for _, b := range data {
8080
d.Write(b)
8181
}
@@ -86,7 +86,7 @@ func Keccak256(data ...[]byte) []byte {
8686
// Keccak256Hash calculates and returns the Keccak256 hash of the input data,
8787
// converting it to an internal Hash data structure.
8888
func Keccak256Hash(data ...[]byte) (h common.Hash) {
89-
d := sha3.NewLegacyKeccak256().(KeccakState)
89+
d := NewKeccakState()
9090
for _, b := range data {
9191
d.Write(b)
9292
}

crypto/crypto_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ func TestKeccak256Hash(t *testing.T) {
4141
checkhash(t, "Sha3-256-array", func(in []byte) []byte { h := Keccak256Hash(in); return h[:] }, msg, exp)
4242
}
4343

44+
func TestKeccak256Hasher(t *testing.T) {
45+
msg := []byte("abc")
46+
exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
47+
hasher := NewKeccakState()
48+
checkhash(t, "Sha3-256-array", func(in []byte) []byte { h := HashData(hasher, in); return h[:] }, msg, exp)
49+
}
50+
4451
func TestToECDSAErrors(t *testing.T) {
4552
if _, err := HexToECDSA("0000000000000000000000000000000000000000000000000000000000000000"); err == nil {
4653
t.Fatal("HexToECDSA should've returned error")

0 commit comments

Comments
 (0)