rgoussu@goussu: ~/library/security
~/library/security cat cryptography-for-engineers.md

Cryptography for engineers

# What to use, not how to build it — the primitive families, the misuse traps, and the boring right answers.

Conceptsaved 2026-08-08 #cryptography#security#encryption#hashing

Overview

Engineering cryptography is a selection problem, not a construction problem: the primitives are solved, the libraries exist, and virtually every real-world crypto failure is misuse — wrong primitive, wrong mode, reused nonce, home-rolled protocol. The goal of this note is the map: which family solves which problem, and the short list of boring, correct answers to reach for.

Key points

  • Four primitive families, four jobs: symmetric encryption (confidentiality at speed — AES-GCM, ChaCha20-Poly1305), asymmetric encryption/key exchange (establishing secrets over hostile channels — ECDH/X25519, RSA-OAEP legacy), signatures (authenticity + integrity — Ed25519, ECDSA), hashing (fingerprints — SHA-256, BLAKE3; slow hashes — argon2id, bcrypt — exclusively for passwords).
  • AEAD or nothing: modern symmetric encryption is authenticated (GCM, Poly1305) — encryption without integrity (raw CBC) invites padding-oracle attacks. And nonce reuse is catastrophic in GCM — unique per key, always.
  • Hybrid by default: real systems use asymmetric crypto only to establish a symmetric key, then symmetric for the data — that's TLS, that's envelope encryption (KMS: data encrypted with a data key, data key encrypted with a master key).
  • MAC ≠ hash: integrity against an adversary needs a key (HMAC) — a plain hash can be recomputed by the attacker; and comparison of MACs/tokens must be constant-time.
  • Randomness is load-bearing: keys, nonces, tokens from the CSPRNG (/dev/urandom, SecureRandom) — never Math.random(), never timestamps.
  • The boring right answers: TLS for transport, libsodium/Tink-style misuse-resistant libraries over raw OpenSSL bindings, argon2id for passwords, Ed25519 for signing, AES-256-GCM for data at rest, KMS + envelope encryption in the cloud. If you're composing primitives by hand, stop — a protocol already exists.
  • Don't: invent protocols, use ECB (the penguin), use MD5/SHA-1 for anything security-relevant, encrypt passwords (hash them), confuse encoding (base64) with encryption.
  • To explore: key rotation & cryptoperiods, post-quantum migration (ML-KEM in TLS), hash length-extension (why HMAC, not hash(key||msg)), JWT signing pitfalls in practice.

Practice

  • CryptoHack (source) — gamified puzzles across the primitive families; builds intuition for misuse before you touch real code.
  • Cryptopals set 1–3 (exercise) — implement, then break, real crypto: XOR, AES modes, the padding oracle — the single best cure for "just use a library" being an empty slogan.
  • Stand up your own CA + mTLS (exercise) — see the primitives composed into the protocol you deploy: key exchange, signatures, and certificates working together.

Related