{"record":{"id":"773c541695698d4c","repo":"golang/go","slug":"crypto-rsa-use-of-hash-functions-other-than-sha-2","errorCode":null,"errorMessage":"crypto/rsa: use of hash functions other than SHA-2 or SHA-3 is not allowed in FIPS 140-only mode","messagePattern":"crypto/rsa: use of hash functions other than SHA-2 or SHA-3 is not allowed in FIPS 140-only mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/rsa/fips.go","lineNumber":94,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\treturn boring.SignRSAPSS(bkey, hash, digest, opts.saltLength())\n\t}\n\tif priv.N.BitLen() >= 1024 {\n\t\tboring.UnreachableExceptTests()\n\t}\n\n\tif !hash.Available() {\n\t\treturn nil, errors.New(\"crypto/rsa: requested hash function unavailable: \" + hash.String())\n\t}\n\th := fips140hash.Unwrap(hash.New())\n\n\tif err := checkFIPS140OnlyPrivateKey(priv); err != nil {\n\t\treturn nil, err\n\t}\n\tif fips140only.Enforced() && !fips140only.ApprovedHash(h) {\n\t\treturn nil, errors.New(\"crypto/rsa: use of hash functions other than SHA-2 or SHA-3 is not allowed in FIPS 140-only mode\")\n\t}\n\tif fips140only.Enforced() && !fips140only.ApprovedRandomReader(random) {\n\t\treturn nil, errors.New(\"crypto/rsa: only crypto/rand.Reader is allowed in FIPS 140-only mode\")\n\t}\n\n\tk, err := fipsPrivateKey(priv)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tsaltLength := opts.saltLength()\n\tif fips140only.Enforced() && saltLength > h.Size() {\n\t\treturn nil, errors.New(\"crypto/rsa: use of PSS salt longer than the hash is not allowed in FIPS 140-only mode\")\n\t}\n\tswitch saltLength {\n\tcase PSSSaltLengthAuto:\n\t\tsaltLength, err = rsa.PSSMaxSaltLength(k.PublicKey(), h)\n\t\tif err != nil {","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/rsa/fips.go#L76-L112","documentation":"Returned during RSA PSS signing in FIPS 140-only mode when the hash used for signing is not an approved SHA-2 or SHA-3 variant. FIPS-approved RSA PSS requires SHA-2/SHA-3; hashes like SHA-1 are rejected. The check (fips140only.ApprovedHash) runs after the availability check and after private-key FIPS validation.","triggerScenarios":"Calling rsa.SignPSS with crypto.SHA1 (or another non-approved hash) in a FIPS-only build. Using a SignerOpts that resolves to SHA-1.","commonSituations":"Legacy protocols that mandate SHA-1 with RSA (e.g., old TLS cipher suites, legacy cert signatures) migrated into FIPS mode. Interop with systems that only support SHA-1.","solutions":["Switch to SHA-256 or stronger: use crypto.SHA256 with rsa.SignPSS.","Update peer systems/certificates to SHA-2 signatures.","If SHA-1 is unavoidable, run outside FIPS-only mode and document the compliance gap."],"exampleFix":"// before (FIPS-only build)\nsig, err := rsa.SignPSS(rand.Reader, priv, crypto.SHA1, digest, opts) // error\n\n// after\nsig, err := rsa.SignPSS(rand.Reader, priv, crypto.SHA256, digest, opts)","handlingStrategy":"validation","validationCode":"if fips140only.Enforced() && !fips140only.ApprovedHash(h) {\n    h = crypto.SHA256 // fall back to approved hash\n}\nreturn rsa.SignPSS(rand.Reader, priv, h, digest, opts)","typeGuard":"func isApprovedHash(h hash.Hash) bool { return fips140only.ApprovedHash(h) }","tryCatchPattern":"sig, err := rsa.SignPSS(rand.Reader, priv, hash, digest, opts)\nif err != nil && strings.Contains(err.Error(), \"other than SHA-2 or SHA-3\") {\n    sig, err = rsa.SignPSS(rand.Reader, priv, crypto.SHA256, digest, opts)\n}\nreturn sig, err","preventionTips":["Mandate SHA-256+ for all RSA signing in new code.","Upgrade peer systems and certificates away from SHA-1.","Centralize hash selection in a config layer that rejects non-approved hashes in FIPS builds."],"tags":["cryptography","go","rsa","pss","fips140","hash-function","compliance"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}