{"record":{"id":"c0ee4cf0041cdbdc","repo":"golang/go","slug":"rsa-requested-hash-function-unavailable-mgfhash","errorCode":null,"errorMessage":"rsa: requested hash function unavailable: {mgfHash}","messagePattern":"rsa: requested hash function unavailable: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/rsa/rsa.go","lineNumber":183,"sourceCode":"\n\treturn SignPKCS1v15(rand, priv, opts.HashFunc(), digest)\n}\n\n// Decrypt decrypts ciphertext with priv. If opts is nil or of type\n// *[PKCS1v15DecryptOptions] then PKCS #1 v1.5 decryption is performed. Otherwise\n// opts must have type *[OAEPOptions] and OAEP decryption is done.\nfunc (priv *PrivateKey) Decrypt(rand io.Reader, ciphertext []byte, opts crypto.DecrypterOpts) (plaintext []byte, err error) {\n\tif opts == nil {\n\t\treturn DecryptPKCS1v15(rand, priv, ciphertext)\n\t}\n\n\tswitch opts := opts.(type) {\n\tcase *OAEPOptions:\n\t\tif !opts.Hash.Available() {\n\t\t\treturn nil, errors.New(\"rsa: requested hash function unavailable: \" + opts.Hash.String())\n\t\t}\n\t\tif opts.MGFHash != 0 && !opts.MGFHash.Available() {\n\t\t\treturn nil, errors.New(\"rsa: requested hash function unavailable: \" + opts.MGFHash.String())\n\t\t}\n\t\tif opts.MGFHash == 0 {\n\t\t\treturn decryptOAEP(opts.Hash.New(), opts.Hash.New(), priv, ciphertext, opts.Label)\n\t\t} else {\n\t\t\treturn decryptOAEP(opts.Hash.New(), opts.MGFHash.New(), priv, ciphertext, opts.Label)\n\t\t}\n\n\tcase *PKCS1v15DecryptOptions:\n\t\tif l := opts.SessionKeyLen; l > 0 {\n\t\t\tplaintext = make([]byte, l)\n\t\t\tif _, err := io.ReadFull(rand, plaintext); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif err := DecryptPKCS1v15SessionKey(rand, priv, ciphertext, plaintext); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\treturn plaintext, nil\n\t\t} else {","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/rsa/rsa.go#L165-L201","documentation":"Returned by PrivateKey.Decrypt when opts is *rsa.OAEPOptions, opts.MGFHash is non-zero, and opts.MGFHash.Available() is false. Same root cause as error 503 but for the mask-generation function hash: the package that implements opts.MGFHash is not linked into the binary, so MGF1 cannot be constructed. Note that if MGFHash == 0 the code silently reuses opts.Hash, so this error fires only when MGFHash is explicitly set.","triggerScenarios":"Construct &rsa.OAEPOptions{Hash: crypto.SHA256, MGFHash: crypto.SHA384} without importing crypto/sha512 (which provides SHA384); set MGFHash to a hash identifier obtained from a JOSE/JWT header whose algorithm is not compiled in.","commonSituations":"Multi-hash OAEP profiles (e.g. some Smartcard / PIV / Federal PKI deployments use SHA-256 message + SHA-512 MGF); algorithm agility where the MGF hash comes from configuration.","solutions":["Blank-import the package that backs MGFHash (e.g. import _ \"crypto/sha512\" for SHA-384/512).","Omit MGFHash (leave it zero) so Decrypt reuses opts.Hash — only do this when protocol allows a single hash.","Validate opts.MGFHash.Available() before calling Decrypt and fail with a domain-specific error."],"exampleFix":"// before\nopts := &rsa.OAEPOptions{Hash: crypto.SHA256, MGFHash: crypto.SHA384}\npt, err := priv.Decrypt(rand.Reader, ct, opts) // err: requested hash function unavailable\n\n// after\nimport _ \"crypto/sha512\" // provides SHA-384 / SHA-512","handlingStrategy":"validation","validationCode":"opts := &rsa.OAEPOptions{Hash: crypto.SHA256, MGFHash: crypto.SHA384}\nif opts.MGFHash != 0 && !opts.MGFHash.Available() {\n    return errors.New(\"MGF hash \" + opts.MGFHash.String() + \" not linked\")\n}\nreturn priv.Decrypt(rand.Reader, ct, opts)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer a single hash for OAEP and MGF (omit MGFHash) unless a profile mandates otherwise.","Keep a list of which hash packages are blank-imported in main and re-check after dependency changes.","Add Available() checks in shared OAEP wrappers."],"tags":["rsa","oaep","hash","mgf","linking","crypto"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}