From 4640e92af70810001ecb3228640ea45448879cd0 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Mon, 6 Jan 2025 21:12:03 +0100 Subject: [PATCH] crypto/rsa: apply fips140=only to opts.Hash in SignPSS Change-Id: I6a6a46569bd364b36f83b9aef640eca94e045173 Reviewed-on: https://go-review.googlesource.com/c/go/+/641315 Reviewed-by: Roland Shoemaker LUCI-TryBot-Result: Go LUCI Reviewed-by: Russ Cox Auto-Submit: Filippo Valsorda Reviewed-by: Daniel McCarney --- src/crypto/rsa/fips.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/crypto/rsa/fips.go b/src/crypto/rsa/fips.go index 24dfb38cf6..347775df16 100644 --- a/src/crypto/rsa/fips.go +++ b/src/crypto/rsa/fips.go @@ -67,6 +67,11 @@ func SignPSS(rand io.Reader, priv *PrivateKey, hash crypto.Hash, digest []byte, if err := checkFIPS140OnlyPrivateKey(priv); err != nil { return nil, err } + + if opts != nil && opts.Hash != 0 { + hash = opts.Hash + } + if fips140only.Enabled && !fips140only.ApprovedHash(hash.New()) { return nil, errors.New("crypto/rsa: use of hash functions other than SHA-2 or SHA-3 is not allowed in FIPS 140-only mode") } @@ -74,10 +79,6 @@ func SignPSS(rand io.Reader, priv *PrivateKey, hash crypto.Hash, digest []byte, return nil, errors.New("crypto/rsa: only crypto/rand.Reader is allowed in FIPS 140-only mode") } - if opts != nil && opts.Hash != 0 { - hash = opts.Hash - } - if boring.Enabled && rand == boring.RandReader { bkey, err := boringPrivateKey(priv) if err != nil { -- 2.48.1