{"record":{"id":"93779d9f9c6b131c","repo":"golang/go","slug":"crypto-sha1-use-of-sha-1-is-not-allowed-in-fips-1","errorCode":null,"errorMessage":"crypto/sha1: use of SHA-1 is not allowed in FIPS 140-only mode","messagePattern":"crypto/sha1: use of SHA-1 is not allowed in FIPS 140-only mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/sha1/sha1.go","lineNumber":130,"sourceCode":"// also implements [encoding.BinaryMarshaler], [encoding.BinaryAppender] and\n// [encoding.BinaryUnmarshaler] to marshal and unmarshal the internal\n// state of the hash.\nfunc New() hash.Hash {\n\tif boring.Enabled {\n\t\treturn boring.NewSHA1()\n\t}\n\td := new(digest)\n\td.Reset()\n\treturn d\n}\n\nfunc (d *digest) Size() int { return Size }\n\nfunc (d *digest) BlockSize() int { return BlockSize }\n\nfunc (d *digest) Write(p []byte) (nn int, err error) {\n\tif fips140only.Enforced() {\n\t\treturn 0, errors.New(\"crypto/sha1: use of SHA-1 is not allowed in FIPS 140-only mode\")\n\t}\n\tboring.Unreachable()\n\tnn = len(p)\n\td.len += uint64(nn)\n\tif d.nx > 0 {\n\t\tn := copy(d.x[d.nx:], p)\n\t\td.nx += n\n\t\tif d.nx == chunk {\n\t\t\tblock(d, d.x[:])\n\t\t\td.nx = 0\n\t\t}\n\t\tp = p[n:]\n\t}\n\tif len(p) >= chunk {\n\t\tn := len(p) &^ (chunk - 1)\n\t\tblock(d, p[:n])\n\t\tp = p[n:]\n\t}","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/sha1/sha1.go#L112-L148","documentation":"Thrown by sha1.digest.Write when fips140only.Enforced() is true. In FIPS 140-only mode (GOFIPS=1 or equivalent), SHA-1 is not an approved algorithm for new hashing, so Write refuses to ingest data. The error appears at Write time, not at digest construction.","triggerScenarios":"Calling Write on a sha1 (or crypto/sha1-backed) hash while the process runs in FIPS-only mode. Triggered by TLS/X.509/JWT code paths that select SHA-1, or direct sha1.Sum/Write usage under GOFIPS=1.","commonSituations":"Enabling GOFIPS=1 (or building with GOEXPERIMENT=boringcrypto FIPS) on a system that still has SHA-1 dependencies; legacy protocols (old TLS 1.0/1.1, HMAC-SHA1 in some APIs) selected by config; migration to FIPS mode exposing a leftover SHA-1 caller.","solutions":["Switch the calling code to SHA-256 (crypto/sha256) or another FIPS-approved hash.","If SHA-1 is unavoidable and approved for your context, run without FIPS-only mode (do not set GOFIPS=1).","Audit HMAC/signature configuration to ensure SHA-256/384/512 are selected.","For TLS, disable TLS 1.0/1.1 and SHA-1 cipher suites on both client and server."],"exampleFix":"// before\nimport \"crypto/sha1\"\nh := sha1.New()\nh.Write(data) // fails under GOFIPS=1\nsum := h.Sum(nil)\n\n// after\nimport \"crypto/sha256\"\nh := sha256.New()\nh.Write(data)\nsum := h.Sum(nil)","handlingStrategy":"fallback","validationCode":"// Detect FIPS-only mode at startup and select an approved hash.\nfunc pickHash() crypto.Hash {\n    if fips140only.Enforced() {\n        return crypto.SHA256 // SHA-1 not allowed\n    }\n    return crypto.SHA1 // legacy path, if required\n}\n\n// Then use h := pickHash().New() instead of sha1.New() unconditionally.","typeGuard":null,"tryCatchPattern":"// Wrap SHA-1 writes so a FIPS rejection is observable and recoverable.\nfunc writeHash(h hash.Hash, data []byte) error {\n    if _, err := h.Write(data); err != nil {\n        if strings.Contains(err.Error(), \"FIPS 140-only mode\") {\n            // switch to SHA-256 and retry\n            h2 := sha256.New()\n            h2.Write(data)\n            return nil\n        }\n        return err\n    }\n    return nil\n}","preventionTips":["Default to SHA-256 everywhere to be FIPS-safe.","Run CI with GOFIPS=1 to surface SHA-1 usage before deployment.","Audit TLS/X.509/HMAC configs to ensure SHA-1 is not selected.","Document any place SHA-1 is intentionally retained and flag it during FIPS rollout."],"tags":["crypto","sha1","fips","compliance","go"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}