mirror of
https://github.com/golang/go.git
synced 2026-06-27 03:11:23 +00:00
crypto/sha3: ensure unwrapped *sha3.Digest are usable
Updates #75154 Change-Id: I57508b1360702d66a89d44b5bd2728decd075305 Reviewed-on: https://go-review.googlesource.com/c/go/+/747160 Reviewed-by: Filippo Valsorda <filippo@golang.org> Reviewed-by: David Chase <drchase@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
79b47a7566
commit
76c2c9b32a
2 changed files with 23 additions and 2 deletions
|
|
@ -7,9 +7,11 @@ package hmac
|
|||
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,24 @@ func TestNoClone(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
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) { New(tc.fn, []byte("key")) })
|
||||
}
|
||||
}
|
||||
|
||||
func TestNonUniqueHash(t *testing.T) {
|
||||
if boring.Enabled {
|
||||
t.Skip("hash.Hash provided by boringcrypto are not comparable")
|
||||
|
|
|
|||
|
|
@ -103,8 +103,9 @@ type SHA3 struct {
|
|||
}
|
||||
|
||||
//go:linkname fips140hash_sha3Unwrap crypto/internal/fips140hash.sha3Unwrap
|
||||
func fips140hash_sha3Unwrap(sha3 *SHA3) *sha3.Digest {
|
||||
return &sha3.s
|
||||
func fips140hash_sha3Unwrap(s *SHA3) *sha3.Digest {
|
||||
s.init()
|
||||
return &s.s
|
||||
}
|
||||
|
||||
// New224 creates a new SHA3-224 hash.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue