weak-cryptography
A cryptographic primitive that no longer protects what it is given.
- Group
- Code
- Runs
- Runs under ur scan:
ur scan --rule weak-cryptography - Level
- warning
- Reads
- Every file
- Fix
- None: the safe form depends on what the value is meant to be
Why
The program encrypts or hashes with a primitive that is broken or too weak for what it protects: DES, whose key is found by search, Triple DES, whose blocks repeat within a long message, RC4, whose keystream is biased, MD5 or SHA-1, whose collisions are found in practice, or an RSA key under 2048 bits, which can be factored. Encrypt with AES-GCM or ChaCha20-Poly1305, hash with SHA-256 or stronger, and make RSA keys of at least 2048 bits.
The fix, as Ur suggests it: use AES-GCM and SHA-256.
For agents
Never use DES, Triple DES, RC4, MD5, SHA-1, or RSA keys under 2048 bits; use AES-GCM or ChaCha20-Poly1305, SHA-256 or stronger, and RSA keys of 2048 bits or more.
Example
vault/cipher.gopackage vault
import "crypto/des"
func Cipher(key []byte) error {
_, err := des.NewCipher(key)
return err
}
$ ur scan --rule weak-cryptography
warning[weak-cryptography]: `des.NewCipher` uses DES, whose 56-bit key is found by search
--> ./vault/cipher.go:6:12 module's top level
= hint: use AES-GCM and SHA-256
= see: CWE-327: Use of a Broken or Risky Cryptographic Algorithm, MITRE (2024-11-19), https://cwe.mitre.org/data/definitions/327.html
scanned 1 file (no framework recognized)
weak-cryptography: 1 high, 0 medium
1 finding and 0 of medium confidence
Source
CWE-327: Use of a Broken or Risky Cryptographic Algorithm, MITRE (2024-11-19).