crypto: return an error if a hash function is not available

Calling New otherwise panics, which is unnecessary, especially in
crypto.SignMessage and especially if we add a new not-implemented hash
value for ML-DSA external Mu.

Change-Id: I9f8d29d01e126838d7d2585133e562536a6a6964
Reviewed-on: https://go-review.googlesource.com/c/go/+/745660
Reviewed-by: Roland Shoemaker <roland@golang.org>
Reviewed-by: Daniel McCarney <daniel@binaryparadox.net>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Filippo Valsorda <filippo@golang.org>
This commit is contained in:
yuhan6665
2026-09-08 21:45:43 -04:00
parent c2a3952d66
commit ac7d996924
2 changed files with 4 additions and 0 deletions
+3
View File
@@ -21,6 +21,9 @@ import (
// verifyHandshakeSignature verifies a signature against unhashed handshake contents.
func verifyHandshakeSignature(sigType uint8, pubkey crypto.PublicKey, hashFunc crypto.Hash, signed, sig []byte) error {
if hashFunc != directSigning {
if !hashFunc.Available() {
return fmt.Errorf("hash function unavailable: %v", hashFunc)
}
h := hashFunc.New()
h.Write(signed)
signed = h.Sum(nil)
+1
View File
@@ -13,6 +13,7 @@ import (
"crypto/rc4"
"crypto/sha1"
"crypto/sha256"
_ "crypto/sha512" // for crypto.SHA384
"fmt"
"hash"
"runtime"