Notes
Where it breaks
Think of it in two layers. The algorithm was designed and attacked by experts for decades. The usage was written last week, under a deadline. The mode, the nonce, where the key comes from, where it is stored, whether verification happens, how errors are handled and where random numbers come from: each of those can undo everything. OWASP lists this as cryptographic failures, near the top of its list of web application risks.
- the algorithm: designed and attacked by experts for decades
- the usage: written by you, last week, under deadline
- mode, nonce, key source, key storage, verification, error handling, randomness
- each one can undo everything
- OWASP: Cryptographic Failures
1. Rolling your own
Mistake one is inventing your own. A custom cipher that XORs data with a key. Base sixty four called encryption. A home-made protocol that uses correct parts in the wrong order. A custom password hash. Anyone can design a scheme that they themselves cannot break; that proves nothing. Use a high-level library such as libsodium or Tink, where the safe choices are made for you, and standard protocols such as TLS.
- custom ciphers: XOR with a key, shifted alphabets
- "encrypting" with Base64
- your own protocol built from correct parts in the wrong order
- your own password hash
- instead: a high-level library (libsodium, Tink, the platform crypto API) and standard protocols (TLS)
2. Weak randomness
Mistake two is weak randomness. Ordinary random functions are built for simulations, not security, and are fully predictable. We seeded Python's random with a timestamp and generated a one hundred and twenty eight bit value. Seeding again with the same time gave exactly the same value. A token generated that way can be guessed by trying every second of the day. For keys, tokens, salts and nonces, always use the secure source: the secrets module, or the operating system.
random.seed(1700000000) random.getrandbits(128) # 0x6b4b2d0c310f9fcb... random.seed(1700000000) random.getrandbits(128) # 0x6b4b2d0c310f9fcb... identical secrets.token_hex(16) # 3db14d09825e03f0a193c25bffc3a97a # unpredictable, from the OS
3. Reused nonce
Mistake three: a reused nonce. We encrypted two messages with AES in GCM mode, the same key and a fixed nonce of zeros. Combining the two ciphertexts with XOR gave exactly the XOR of the two plaintexts. Knowing the first message, we recovered the second in full, without the key. In GCM, nonce reuse also lets an attacker forge authentication tags. Generate a fresh random nonce every time, or let the library do it.
n = b"\x00" * 12 # fixed c1 = AESGCM(k).encrypt(n, p1, None) c2 = AESGCM(k).encrypt(n, p2, None) xor(c1, c2) == xor(p1, p2) # True # knowing p1, recover p2: # b"transfer 9999 to mallo" # no key needed. Forging tags # becomes possible as well
4. Key handling
Mistake four is key handling, the most common of all. Keys hard-coded in source, or inside a mobile app where anyone can extract them. Default keys from a tutorial left in production. A password used directly as a key instead of passing it through a key derivation function. The same key in development, test and production. Keys pasted into logs, tickets and chat. The fixes: a key management service or secrets manager, secret scanning, and rotation.
- hard-coded in source, or in a mobile app binary
- default or example keys left in production
- a password used directly as the key (use a KDF)
- the same key in dev, test and production
- keys in logs, tickets, chat
- fix: KMS or secrets manager, scanning, rotation
5. No authentication
Mistake five: encryption without authentication. ECB shows patterns. CBC or counter mode without a MAC lets an attacker flip bits in the ciphertext and change the decrypted result in a controlled way. If the server also reveals whether padding was valid, the attacker can decrypt data byte by byte, the padding oracle attack. Encrypted cookies get edited to change a role. The fix is simple: only use authenticated modes, GCM or ChaCha twenty with Poly thirteen oh five.
- ECB: patterns visible
- CBC or CTR with no MAC: attacker flips bits and changes the plaintext
- padding oracle: error differences let an attacker decrypt without the key
- encrypted cookies edited to change role or user id
- fix: AEAD only (GCM, ChaCha20-Poly1305)
6. Skipped verification
Mistake six: skipped verification. Each of these lines turns off certificate checking in a different language, usually added to make a test pass and never removed. With it, the connection is still encrypted, to anyone who cares to intercept it. The same pattern appears with tokens: decoding a JWT without verifying its signature, or accepting the algorithm none. Search your codebase for these strings. It takes one minute, and it often finds something.
requests.get(url, verify=False) curl -k / --insecure InsecureSkipVerify: true NODE_TLS_REJECT_UNAUTHORIZED=0 rejectUnauthorized: false TrustAllCerts, ALLOW_ALL_HOSTNAME jwt.decode(t, verify=False) "alg": "none" accepted # also: a failed check that is # logged and then ignored
7. Weak algorithms
Mistake seven: weak algorithms that linger. MD five and SHA one for signatures or integrity. DES, triple DES, RC four. RSA keys under two thousand and forty eight bits. Old SSL and TLS versions. Fast hashes for passwords. Tokens with too little randomness. Most of these survive in configuration files and legacy code nobody wants to touch. Keep an inventory of which cryptography is used where; you will need it again for the post-quantum migration.
- MD5, SHA-1: signatures, integrity, certificates
- DES, 3DES, RC4, Blowfish
- RSA under 2048 bits; RSA PKCS#1 v1.5 encryption
- SSLv3, TLS 1.0, TLS 1.1
- fast hashes for passwords
- short keys or tokens (under 128 bits of randomness)
- keep an inventory: what crypto is used where
8. Side channels
Mistake eight: side channels. Comparing a MAC or a token with a normal equals leaks through timing how many bytes were right. Returning different errors for bad padding and bad MAC tells an attacker which step failed. Secrets and decrypted data end up in logs and stack traces. Compressing data before encrypting it leaks content through length. The fixes: constant-time comparison, one generic error for any decryption failure, and care with logs.
- comparing MACs or tokens with == (timing)
- different errors for "bad padding" and "bad MAC"
- secrets and plaintext in logs and stack traces
- keys left in memory dumps
- compression before encryption (length leaks content)
- fix: constant-time compare, one generic error
Find them
The good news is that most of these can be found automatically. Static analysis rules in Semgrep, CodeQL and Bandit flag ECB mode, MD five, disabled verification and insecure random. Secret scanners find hard-coded keys. TLS scanners report old versions and weak ciphers. Dependency checks cover the crypto libraries themselves. And one review rule: any code that calls a low-level primitive directly gets a second reviewer who knows this checklist.
- SAST rules: Semgrep, CodeQL, Bandit flag ECB, MD5, verify=False, random
- secret scanning: gitleaks, TruffleHog
- TLS scans: testssl.sh, sslyze
- dependency checks for the crypto libraries themselves
- review rule: any direct use of a primitive needs a second pair of eyes
The safe defaults
Here is the page to keep. Encrypt with AES two fifty six in GCM mode or ChaCha twenty Poly thirteen oh five. Hash with SHA two fifty six. Authenticate with HMAC. Store passwords with Argon two i d or bcrypt. Sign with E D two five five one nine or ECDSA. Exchange keys with X two five five one nine. Transport over TLS 1.3. Take randomness from the operating system. Keep keys in a key service, versioned and rotated. And use a high-level, vetted library.
- encrypt: AES-256-GCM or ChaCha20-Poly1305
- hash: SHA-256
- MAC: HMAC-SHA-256
- passwords: Argon2id, bcrypt
- sign: Ed25519, ECDSA P-256
- key exchange: X25519
- transport: TLS 1.3
- random: the OS secure source
- keys: KMS, versioned, rotated
- library: high-level, vetted
Say it like this
In the interview: I look for custom cryptography, ECB or unauthenticated modes, fixed or reused nonces, insecure random number generators, hard-coded keys, MD five or SHA one, fast hashes for passwords, disabled certificate or signature verification, and comparisons that are not constant-time. Then I ask where the keys live and how they rotate. Most of this I automate with static analysis and secret scanning, and I steer teams to high-level libraries.
- "Custom crypto, ECB or unauthenticated modes, fixed
- or reused nonces, insecure
- random, hard-coded keys, MD5 or SHA-1, fast password
- hashes, disabled certificate
- or signature checks, and non-constant-time compares.
- Then: where do keys live?"