提交 ad78db4d 编写于 作者: F Felix Lange

crypto: fix Sha3Hash and add a test for it

上级 8ce6a364
......@@ -42,7 +42,7 @@ func Sha3Hash(data ...[]byte) (h common.Hash) {
for _, b := range data {
d.Write(b)
}
d.Sum(h[:])
d.Sum(h[:0])
return h
}
......
......@@ -7,8 +7,8 @@ import (
"testing"
"time"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
)
// These tests are sanity checks.
......@@ -21,6 +21,12 @@ func TestSha3(t *testing.T) {
checkhash(t, "Sha3-256", func(in []byte) []byte { return Sha3(in) }, msg, exp)
}
func TestSha3Hash(t *testing.T) {
msg := []byte("abc")
exp, _ := hex.DecodeString("4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45")
checkhash(t, "Sha3-256-array", func(in []byte) []byte { h := Sha3Hash(in); return h[:] }, msg, exp)
}
func TestSha256(t *testing.T) {
msg := []byte("abc")
exp, _ := hex.DecodeString("ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册