golang/go · error
crypto/des: use of DES is not allowed in FIPS 140-only mode
Error message
crypto/des: use of DES is not allowed in FIPS 140-only mode
What it means
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.
Source
Thrown at src/crypto/des/cipher.go:33
// The DES block size in bytes.
const BlockSize = 8
type KeySizeError int
func (k KeySizeError) Error() string {
return "crypto/des: invalid key size " + strconv.Itoa(int(k))
}
// desCipher is an instance of DES encryption.
type desCipher struct {
subkeys [16]uint64
}
// NewCipher creates and returns a new [cipher.Block].
func NewCipher(key []byte) (cipher.Block, error) {
if fips140only.Enforced() {
return nil, errors.New("crypto/des: use of DES is not allowed in FIPS 140-only mode")
}
if len(key) != 8 {
return nil, KeySizeError(len(key))
}
c := new(desCipher)
c.generateSubkeys(key)
return c, nil
}
func (c *desCipher) BlockSize() int { return BlockSize }
func (c *desCipher) Encrypt(dst, src []byte) {
if len(src) < BlockSize {
panic("crypto/des: input not full block")
}
if len(dst) < BlockSize {View on GitHub (pinned to b6b368adc5)
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.
Example fix
// before block, err := des.NewCipher(key) // after block, err := aes.NewCipher(key) // 16, 24, or 32 byte key
Defensive patterns
Strategy: validation
Validate before calling
// Detect FIPS-only mode up front and refuse DES with a clear message:
func newBlock(key []byte) (cipher.Block, error) {
// des.NewCipher already enforces this; gate your config instead.
if fipsEnabled() {
return nil, errors.New("DES is unavailable in FIPS-only mode; configure AES")
}
return des.NewCipher(key)
} Try / catch
block, err := des.NewCipher(key)
if err != nil {
if strings.Contains(err.Error(), "FIPS 140-only mode") {
// Switch to AES or disable FIPS-only mode.
}
return err
} Prevention
- 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.
When it happens
Trigger: Calling des.NewCipher(key) in a binary built/run with FIPS 140-only enforcement enabled (e.g. a fips140-enabled Go toolchain build).
Common situations: 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.
Related errors
- crypto/des: use of TripleDES is not allowed in FIPS 140-only
- crypto/dsa: use of DSA is not allowed in FIPS 140-only mode
- crypto/ecdh: only crypto/rand.Reader is allowed in FIPS 140-
- crypto/ecdh: use of X25519 is not allowed in FIPS 140-only m
- crypto/ecdsa: use of custom curves is not allowed in FIPS 14
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/e4969646153f9275.
Report an issue: GitHub.