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 {