{"record":{"id":"e4969646153f9275","repo":"golang/go","slug":"crypto-des-use-of-des-is-not-allowed-in-fips-140","errorCode":null,"errorMessage":"crypto/des: use of DES is not allowed in FIPS 140-only mode","messagePattern":"crypto/des: use of DES is not allowed in FIPS 140-only mode","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/crypto/des/cipher.go","lineNumber":33,"sourceCode":"\n// The DES block size in bytes.\nconst BlockSize = 8\n\ntype KeySizeError int\n\nfunc (k KeySizeError) Error() string {\n\treturn \"crypto/des: invalid key size \" + strconv.Itoa(int(k))\n}\n\n// desCipher is an instance of DES encryption.\ntype desCipher struct {\n\tsubkeys [16]uint64\n}\n\n// NewCipher creates and returns a new [cipher.Block].\nfunc NewCipher(key []byte) (cipher.Block, error) {\n\tif fips140only.Enforced() {\n\t\treturn nil, errors.New(\"crypto/des: use of DES is not allowed in FIPS 140-only mode\")\n\t}\n\n\tif len(key) != 8 {\n\t\treturn nil, KeySizeError(len(key))\n\t}\n\n\tc := new(desCipher)\n\tc.generateSubkeys(key)\n\treturn c, nil\n}\n\nfunc (c *desCipher) BlockSize() int { return BlockSize }\n\nfunc (c *desCipher) Encrypt(dst, src []byte) {\n\tif len(src) < BlockSize {\n\t\tpanic(\"crypto/des: input not full block\")\n\t}\n\tif len(dst) < BlockSize {","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/crypto/des/cipher.go#L15-L51","documentation":"In FIPS 140-only mode (fips140only.Enforced() == true), the des package refuses to construct a DES cipher because DES is not a FIPS-approved algorithm (its 56-bit key is insecure). The check runs before any key-length validation, so it short-circuits regardless of the key supplied.","triggerScenarios":"Calling des.NewCipher(key) in a binary built/run with FIPS 140-only enforcement enabled (e.g. a fips140-enabled Go toolchain build).","commonSituations":"Moving a legacy DES-based application into a FIPS-regulated deployment; building with FIPS toolchain settings without auditing crypto usage; compliance environments (government, finance, healthcare) that mandate FIPS-only.","solutions":["Replace DES with AES: aes.NewCipher with a 16/24/32-byte key.","If FIPS-only mode is not actually required for this binary, rebuild without FIPS 140-only enforcement.","For legacy DES-encrypted data, decrypt it in a non-FIPS build and re-encrypt with AES before operating under FIPS mode."],"exampleFix":"// before\nblock, err := des.NewCipher(key)\n// after\nblock, err := aes.NewCipher(key) // 16, 24, or 32 byte key","handlingStrategy":"validation","validationCode":"// Detect FIPS-only mode up front and refuse DES with a clear message:\nfunc newBlock(key []byte) (cipher.Block, error) {\n    // des.NewCipher already enforces this; gate your config instead.\n    if fipsEnabled() {\n        return nil, errors.New(\"DES is unavailable in FIPS-only mode; configure AES\")\n    }\n    return des.NewCipher(key)\n}","typeGuard":null,"tryCatchPattern":"block, err := des.NewCipher(key)\nif err != nil {\n    if strings.Contains(err.Error(), \"FIPS 140-only mode\") {\n        // Switch to AES or disable FIPS-only mode.\n    }\n    return err\n}","preventionTips":["Audit all crypto usage before enabling FIPS 140-only mode.","Prefer AES everywhere; reserve DES only for legacy-data migration outside FIPS mode.","Make the FIPS mode of the build explicit in deployment docs and CI."],"tags":["crypto","des","fips","compliance","go","security"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}