mirror of
https://github.com/XTLS/REALITY.git
synced 2026-09-28 01:48:07 +03:00
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:
@@ -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)
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"crypto/rc4"
|
||||
"crypto/sha1"
|
||||
"crypto/sha256"
|
||||
_ "crypto/sha512" // for crypto.SHA384
|
||||
"fmt"
|
||||
"hash"
|
||||
"runtime"
|
||||
|
||||
Reference in New Issue
Block a user