diff --git a/src/crypto/hmac/hmac_test.go b/src/crypto/hmac/hmac_test.go
index 4046a95..d595205 100644
--- a/src/crypto/hmac/hmac_test.go
+++ b/src/crypto/hmac/hmac_test.go
@@ -7,9 +7,11 @@
import (
"crypto/internal/boring"
"crypto/internal/cryptotest"
+ "crypto/internal/fips140hash"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
+ "crypto/sha3"
"crypto/sha512"
"errors"
"fmt"
@@ -596,6 +598,34 @@
}
}
+func TestSHA3Hash(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ fn func() hash.Hash
+ }{
+ {
+ "sha3 zero init hash",
+ func() hash.Hash { return justHash{&sha3.SHA3{}} },
+ },
+ {
+ "sha3 zero init hash by linkname",
+ func() hash.Hash { return justHash{fips140hash.Unwrap(&sha3.SHA3{})} },
+ },
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ h := New(tc.fn, []byte("key"))
+ if _, ok := h.(hash.Cloner); !ok {
+ t.Skip("no Cloner support")
+ }
+ h.Write([]byte("test"))
+ _, err := h.(hash.Cloner).Clone()
+ if !errors.Is(err, errors.ErrUnsupported) {
+ t.Errorf("Clone() = %v, want ErrUnsupported", err)
+ }
+ })
+ }
+}
+
func TestNonUniqueHash(t *testing.T) {
if boring.Enabled {
t.Skip("hash.Hash provided by boringcrypto are not comparable")
diff --git a/src/crypto/sha3/sha3.go b/src/crypto/sha3/sha3.go
index 48c67e9..4711f18 100644
--- a/src/crypto/sha3/sha3.go
+++ b/src/crypto/sha3/sha3.go
@@ -104,6 +104,7 @@
//go:linkname fips140hash_sha3Unwrap crypto/internal/fips140hash.sha3Unwrap
func fips140hash_sha3Unwrap(sha3 *SHA3) *sha3.Digest {
+ sha3.init()
return &sha3.s
}