{"record":{"id":"f5d9ae4026049835","repo":"golang/go","slug":"crypto-rc4-use-of-rc4-is-not-allowed-in-fips-140","errorCode":null,"errorMessage":"crypto/rc4: use of RC4 is not allowed in FIPS 140-only mode","messagePattern":"crypto/rc4: use of RC4 is not allowed in FIPS 140-only mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/rc4/rc4.go","lineNumber":35,"sourceCode":")\n\n// A Cipher is an instance of RC4 using a particular key.\ntype Cipher struct {\n\ts    [256]uint32\n\ti, j uint8\n}\n\ntype KeySizeError int\n\nfunc (k KeySizeError) Error() string {\n\treturn \"crypto/rc4: invalid key size \" + strconv.Itoa(int(k))\n}\n\n// NewCipher creates and returns a new [Cipher]. The key argument should be the\n// RC4 key, at least 1 byte and at most 256 bytes.\nfunc NewCipher(key []byte) (*Cipher, error) {\n\tif fips140only.Enforced() {\n\t\treturn nil, errors.New(\"crypto/rc4: use of RC4 is not allowed in FIPS 140-only mode\")\n\t}\n\tk := len(key)\n\tif k < 1 || k > 256 {\n\t\treturn nil, KeySizeError(k)\n\t}\n\tvar c Cipher\n\tfor i := 0; i < 256; i++ {\n\t\tc.s[i] = uint32(i)\n\t}\n\tvar j uint8 = 0\n\tfor i := 0; i < 256; i++ {\n\t\tj += uint8(c.s[i]) + key[i%k]\n\t\tc.s[i], c.s[j] = c.s[j], c.s[i]\n\t}\n\treturn &c, nil\n}\n\n// Reset zeros the key data and makes the [Cipher] unusable.","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/rc4/rc4.go#L17-L53","documentation":"Returned by rc4.NewCipher when FIPS 140-only mode is enforced. RC4 is a broken stream cipher disallowed by FIPS 140; the Go module blocks its instantiation in enforced builds as the very first check, before key-size validation. The guard mirrors the broader policy of excluding non-approved legacy algorithms.","triggerScenarios":"Calling rc4.NewCipher(key) in a binary built with FIPS 140-only enforcement. Importing a dependency that still uses RC4 (e.g., old TLS/legacy protocol code).","commonSituations":"Migrating a legacy application that uses RC4 for compatibility with old systems into a FIPS-only deployment. Third-party libraries with hardcoded RC4. Test code that exercises legacy cipher interop.","solutions":["Replace RC4 with an approved cipher: aes.NewCipher(key) or chacha20.","Run the legacy RC4 path in a non-FIPS build if backwards compatibility is mandatory.","Audit dependencies for crypto/rc4 imports and upgrade/remove them."],"exampleFix":"// before (FIPS-only build)\nc, err := rc4.NewCipher(key) // blocked\n\n// after\nc, err := aes.NewCipher(keyAES32)","handlingStrategy":"validation","validationCode":"if fips140only.Enforced() {\n    return nil, errors.New(\"RC4 blocked in FIPS mode; use AES\")\n}\nreturn rc4.NewCipher(key)","typeGuard":"func rc4Allowed() bool { return !fips140only.Enforced() }","tryCatchPattern":"c, err := rc4.NewCipher(key)\nif err != nil && strings.Contains(err.Error(), \"RC4 is not allowed in FIPS 140-only mode\") {\n    c, err = aes.NewCipher(keyAES32)\n}\nreturn c, err","preventionTips":["Replace all RC4 usage with AES or ChaCha20.","Scan dependencies for crypto/rc4 imports during FIPS migration.","Gate any legacy interop behind a non-FIPS build tag."],"tags":["cryptography","go","rc4","fips140","legacy-cipher","compliance"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}