crypto/sha3 was introduced in Go 1.24, which is now the minimum Go version of this module. Made the hashes go:fix inline wrappers, since the new types can be used as hash.Hash directly. The SHAKE instances need a wrapper for the methods we dropped from crypto.XOF, so no go:fix inline there. Kept the generic implementation for the legacy Keccak hashes we did not bring to the standard library. We need to keep them working, but they don't need to be fast. Fixes golang/go#73681 Updates golang/go#65269 Change-Id: I6a6a69648b6353b153c70a2cec84864e64dcd61b Reviewed-on: https://go-review.googlesource.com/c/crypto/+/710115 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Filippo Valsorda <filippo@golang.org> Reviewed-by: Daniel McCarney <daniel@binaryparadox.net> Reviewed-by: David Chase <drchase@google.com> Reviewed-by: Roland Shoemaker <roland@golang.org>
96 lines
2.5 KiB
Go
96 lines
2.5 KiB
Go
// Copyright 2014 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Package sha3 implements the SHA-3 hash algorithms and the SHAKE extendable
|
|
// output functions defined in FIPS 202.
|
|
//
|
|
// Most of this package is a wrapper around the crypto/sha3 package in the
|
|
// standard library. The only exception is the legacy Keccak hash functions.
|
|
package sha3
|
|
|
|
import (
|
|
"crypto/sha3"
|
|
"hash"
|
|
)
|
|
|
|
// New224 creates a new SHA3-224 hash.
|
|
// Its generic security strength is 224 bits against preimage attacks,
|
|
// and 112 bits against collision attacks.
|
|
//
|
|
// It is a wrapper for the [sha3.New224] function in the standard library.
|
|
//
|
|
//go:fix inline
|
|
func New224() hash.Hash {
|
|
return sha3.New224()
|
|
}
|
|
|
|
// New256 creates a new SHA3-256 hash.
|
|
// Its generic security strength is 256 bits against preimage attacks,
|
|
// and 128 bits against collision attacks.
|
|
//
|
|
// It is a wrapper for the [sha3.New256] function in the standard library.
|
|
//
|
|
//go:fix inline
|
|
func New256() hash.Hash {
|
|
return sha3.New256()
|
|
}
|
|
|
|
// New384 creates a new SHA3-384 hash.
|
|
// Its generic security strength is 384 bits against preimage attacks,
|
|
// and 192 bits against collision attacks.
|
|
//
|
|
// It is a wrapper for the [sha3.New384] function in the standard library.
|
|
//
|
|
//go:fix inline
|
|
func New384() hash.Hash {
|
|
return sha3.New384()
|
|
}
|
|
|
|
// New512 creates a new SHA3-512 hash.
|
|
// Its generic security strength is 512 bits against preimage attacks,
|
|
// and 256 bits against collision attacks.
|
|
//
|
|
// It is a wrapper for the [sha3.New512] function in the standard library.
|
|
//
|
|
//go:fix inline
|
|
func New512() hash.Hash {
|
|
return sha3.New512()
|
|
}
|
|
|
|
// Sum224 returns the SHA3-224 digest of the data.
|
|
//
|
|
// It is a wrapper for the [sha3.Sum224] function in the standard library.
|
|
//
|
|
//go:fix inline
|
|
func Sum224(data []byte) [28]byte {
|
|
return sha3.Sum224(data)
|
|
}
|
|
|
|
// Sum256 returns the SHA3-256 digest of the data.
|
|
//
|
|
// It is a wrapper for the [sha3.Sum256] function in the standard library.
|
|
//
|
|
//go:fix inline
|
|
func Sum256(data []byte) [32]byte {
|
|
return sha3.Sum256(data)
|
|
}
|
|
|
|
// Sum384 returns the SHA3-384 digest of the data.
|
|
//
|
|
// It is a wrapper for the [sha3.Sum384] function in the standard library.
|
|
//
|
|
//go:fix inline
|
|
func Sum384(data []byte) [48]byte {
|
|
return sha3.Sum384(data)
|
|
}
|
|
|
|
// Sum512 returns the SHA3-512 digest of the data.
|
|
//
|
|
// It is a wrapper for the [sha3.Sum512] function in the standard library.
|
|
//
|
|
//go:fix inline
|
|
func Sum512(data []byte) [64]byte {
|
|
return sha3.Sum512(data)
|
|
}
|