crypto-what-it-solves-threat-models-randomness-hashes-and-macs
Use before choosing any primitive: what cryptography does and does not solve and the problems people wrongly expect it to fix, threat models and what you are actually defending against, randomness and why CSPRNG choice and seeding is a common silent failure, hash functions and their security properties, and MACs and authentication. Includes the router for the whole cryptography reference.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 5
- Forks
- 3
01 前言 Front Matter
- name
- crypto-what-it-solves-threat-models-randomness-hashes-and-macs
- description
- Use before choosing any primitive: what cryptography does and does not solve and the problems people wrongly expect it to fix, threat models and what you are actually defending against, randomness and why CSPRNG choice and seeding is a common silent failure, hash functions and their security properties, and MACs and authentication. Includes the router for the whole cryptography reference.
03 SKILL.md 正文
Cryptography: What Cryptography Does and Doesn't Solve, Threat Models, Randomness, Hash Functions, and MACs
Part 1 of 6 of the Cryptography and Encryption reference (plugin
cryptography-and-encryption), covering §0–§5. Sibling skills:crypto-symmetric-aead-public-key-and-signatures(§6–§10),crypto-passwords-tls-pki-messaging-and-disk-encryption(§11–§16),crypto-implementation-failures-key-management-and-agility(§17–§19),crypto-advanced-constructions-blockchain-and-policy(§20–§22),crypto-reference(§23–§28). Section numbers are shared across the set; a reference written as §N →skillpoints into that sibling skill.Currency: The primitives are stable. Two migrations are actively underway. See §23 →
crypto-referencefor post-quantum cryptography, and TLS certificate lifetimes.
⚠️ Cryptography is the part of security that mostly WORKS. The primitives are rarely broken; the systems built from them fail constantly (§17 →
crypto-implementation-failures-key-management-and-agility). ⚠️ Almost every real-world break is a key management failure, an implementation bug, a protocol composition error, or a human process — not a cryptanalytic result.⚠️ THE RULE THAT MATTERS MOST: don't build it yourself. ⚠️ Use a vetted, well-maintained library at the highest level of abstraction that solves your problem. This document is for UNDERSTANDING what those libraries do and evaluating designs — not a recipe for implementing primitives.
Complements an electromagnetism reference (the physical layer), and security-focused material on threat modelling and application security.
⚠️ GOTCHA boxes mark the failure modes that have caused real breaches.
The three ideas that organize this document:
- ⚠️ ENCRYPTION WITHOUT AUTHENTICATION IS BROKEN (§7 →
crypto-symmetric-aead-public-key-and-signatures). Confidentiality alone is almost never what you want, and unauthenticated ciphertext is malleable. Use AEAD.- ⚠️ KEY MANAGEMENT IS THE HARD PART (§18 →
crypto-implementation-failures-key-management-and-agility). The algorithm choice is usually easy and usually not where you lose. Where keys live, who can reach them, and how they rotate is where systems actually fail.- ⚠️ AGILITY IS A DESIGN REQUIREMENT (§19 →
crypto-implementation-failures-key-management-and-agility, §23 →crypto-reference). Every algorithm eventually weakens. Systems that hardcoded their primitives are the ones in pain right now.
§0. Routing
| You want... | Go to |
|---|---|
| ⚠️ What crypto does and doesn't solve | §1 |
| Threat models | §2 |
| ⚠️ Randomness | §3 |
| Hash functions | §4 |
| MACs | §5 |
| Symmetric ciphers and modes | §6 → crypto-symmetric-aead-public-key-and-signatures |
| ⚠️ AEAD | §7 → crypto-symmetric-aead-public-key-and-signatures |
| Public key | §8 → crypto-symmetric-aead-public-key-and-signatures |
| Key exchange and forward secrecy | §9 → crypto-symmetric-aead-public-key-and-signatures |
| Signatures | §10 → crypto-symmetric-aead-public-key-and-signatures |
| ⚠️ Password storage | §11 → crypto-passwords-tls-pki-messaging-and-disk-encryption |
| TLS | §12 → crypto-passwords-tls-pki-messaging-and-disk-encryption |
| PKI and certificates | §13 → crypto-passwords-tls-pki-messaging-and-disk-encryption |
| End-to-end messaging | §14 → crypto-passwords-tls-pki-messaging-and-disk-encryption |
| Disk and file encryption | §15 → crypto-passwords-tls-pki-messaging-and-disk-encryption |
| Other protocols | §16 → crypto-passwords-tls-pki-messaging-and-disk-encryption |
| ⚠️ Implementation failures | §17 → crypto-implementation-failures-key-management-and-agility |
| ⚠️ Key management | §18 → crypto-implementation-failures-key-management-and-agility |
| Crypto agility | §19 → crypto-implementation-failures-key-management-and-agility |
| Advanced constructions | §20 → crypto-advanced-constructions-blockchain-and-policy |
| Blockchain crypto | §21 → crypto-advanced-constructions-blockchain-and-policy |
| Law and policy | §22 → crypto-advanced-constructions-blockchain-and-policy |
| What's live | §23 → crypto-reference |
| Misconceptions, numbers | §24–§25 → crypto-reference |
| Books, quick ref, method | §26–§28 → crypto-reference |
§1. ⚠️ What Cryptography Does and Doesn't Solve
⚠️ THE FOUR GOALS
⚠️ CONFIDENTIALITY nobody else can read it
⚠️ INTEGRITY it hasn't been altered
⚠️ AUTHENTICITY it's from who you think
⚠️ NON-REPUDIATION they can't later deny sending it
⚠️ These are DIFFERENT and require DIFFERENT mechanisms.
⚠️ Confusing them is the root of many design errors
⚠️ WHAT CRYPTO CANNOT DO
⚠️ Protect against a compromised ENDPOINT. ⚠️ If the attacker is
on the device, encryption in transit is irrelevant
⚠️ Hide METADATA — ⚠️ who talked to whom, when, how often and how
much. ⚠️ Metadata is frequently more revealing than content
⚠️ Fix a bad trust model. ⚠️ Encryption to the wrong party is
perfectly secure and completely useless
⚠️ Solve authorization, availability, or insider abuse
⚠️ Compensate for users who will click through any warning
⚠️ GOTCHA — "don't roll your own crypto" is often misunderstood as being about ALGORITHMS. It's mostly about PROTOCOLS AND IMPLEMENTATIONS. ⚠️ Nobody sensible designs a new block cipher; plenty of teams compose existing primitives into a novel protocol, and that is where the failures come from. ⚠️ The practical version: use libsodium/NaCl, Tink, the platform's crypto API, or an equivalent — at the highest level that solves your problem. ⚠️ If your code contains a mode of operation, an IV, or a padding decision, you are already lower-level than you probably need to be.
§2. Threat Models
⚠️ KERCKHOFFS'S PRINCIPLE: ⚠️ the system should be secure even if everything about it except the key is public knowledge. ⚠️ "Security through obscurity" fails because obscurity is not a secret you can rotate.
⚠️ ADVERSARY MODELS, in ascending strength
PASSIVE / eavesdropper · ⚠️ ACTIVE / can modify, inject, replay ·
⚠️ CHOSEN-PLAINTEXT and CHOSEN-CIPHERTEXT · ⚠️ ADAPTIVE ·
⚠️ PHYSICAL ACCESS (side channels, §17) · ⚠️ INSIDER
⚠️ THE QUESTIONS THAT DEFINE A DESIGN
⚠️ Who is the adversary and what can they DO?
⚠️ What must stay secret, and FOR HOW LONG? (§23.1)
⚠️ What is the trusted computing base?
⚠️ What happens when a key is compromised? (§9, §18)
⚠️ Security proofs are conditional: ⚠️ "provably secure" means "reduces to a problem we believe is hard, in a stated model, assuming the implementation is correct." ⚠️ All three qualifiers have failed in practice.
PART I — PRIMITIVES
§3. ⚠️ Randomness
⚠️ The most under-appreciated failure point, and it breaks everything above it silently. Bad randomness produces output that LOOKS fine.
⚠️ USE THE OPERATING SYSTEM CSPRNG. Always.
⚠️ /dev/urandom, getrandom(), BCryptGenRandom, SecRandomCopyBytes
⚠️ NEVER a language's default rand()/Math.random() — those are
statistical PRNGs, deliberately fast and entirely predictable
⚠️ WHERE IT HAS GONE WRONG IN REALITY
⚠️ Insufficient entropy at BOOT on embedded devices and VMs —
⚠️ producing duplicate keys across many devices
⚠️ VM cloning replaying the same RNG state
⚠️ A distribution patch that reduced the effective keyspace
of every key generated for years
⚠️ Deterministic nonce generation from a predictable counter (§17)
⚠️ THE /dev/random vs /dev/urandom DEBATE IS SETTLED on modern
systems: ⚠️ once seeded, urandom is fine and blocking is not a
security benefit
§4. Hash Functions
⚠️ Properties: ⚠️ preimage resistance, second preimage resistance, and COLLISION resistance — and collision resistance is the weakest of the three and the first to fall.
⚠️ STATUS
⚠️ MD5 BROKEN. Collisions are trivial. ⚠️ Not for anything security-related
⚠️ SHA-1 BROKEN for collisions (chosen-prefix collisions demonstrated).
⚠️ Deprecated everywhere that matters
⚠️ SHA-2 (SHA-256/384/512) ⚠️ the current workhorse. Fine
⚠️ SHA-3 / Keccak different internal structure (sponge) — ⚠️ a
structural hedge rather than a replacement
⚠️ BLAKE2/BLAKE3 fast, secure, good choices
⚠️ LENGTH EXTENSION ⚠️ SHA-2 (Merkle-Damgård) is vulnerable: knowing
H(m) lets you compute H(m ‖ padding ‖ extra) without knowing m.
⚠️ THIS IS WHY H(key ‖ message) IS NOT A MAC (§5)
⚠️ SHA-3 and BLAKE are not vulnerable
⚠️ GOTCHA — collision resistance matters when an ATTACKER CONTROLS BOTH INPUTS (certificates, signed documents, code signing). ⚠️ It matters much less for HMAC or for a random-input use. ⚠️ This is why SHA-1 was catastrophic for certificates and merely undesirable inside HMAC — but migrate anyway, because arguing about it costs more than replacing it. ⚠️ Do NOT use general-purpose hashes for passwords (§11 →
crypto-passwords-tls-pki-messaging-and-disk-encryption) — ⚠️ their speed is the problem.
§5. MACs
⚠️ A MAC provides integrity and authenticity with a SHARED key.
⚠️ HMAC is the standard construction and is specifically designed to resist §4's length
extension. ⚠️ Poly1305 and KMAC are also good.
⚠️ CRITICAL PROPERTIES:
⚠️ verify in CONSTANT TIME (§17 → crypto-implementation-failures-key-management-and-agility) — a naive byte-by-byte comparison leaks the correct
value through timing, one byte at a time; and use a SEPARATE key from encryption, or
better, use AEAD (§7 → crypto-symmetric-aead-public-key-and-signatures) which handles it.
⚠️ A MAC is NOT a signature — ⚠️ both parties hold the same key, so a MAC cannot prove
to a third party who created it. No non-repudiation (§1).
04 同仓库更多 Skills
white-paper-writing
Use when writing white papers, technical reports, policy documents, thought leadership pieces, or any long-form authoritative document. Triggers on requests to write, structure, outline, or review white papers, technical reports, position papers, policy briefs, or evidence-driven arguments. Also use for B2B content marketing strategy, technical documentation requiring authority, academic-style reports, or any document that must educate while persuading. Use when someone asks "how should I structure this" for a long-form document.
prose-technical-mechanics
Use when editing or writing prose at a technical/mechanical level: choosing between Anglo-Saxon and Latinate diction, placing information in topic vs stress positions, writing periodic vs cumulative sentences, handling sentence rhythm, punctuation as logic, transitions, paragraph structure, or phonesthetics. Use when someone wants to understand WHY prose works or doesn't, not just surface-level style advice. Triggers on word choice, sentence structure, emphasis, rhythm, diction, or any deep writing mechanics question.
prose-mechanics
Use when writing, editing, or analyzing prose style; when trying to avoid generic AI-sounding writing; when applying specific prose styles such as journalistic, academic, narrative, KJV biblical, Hemingway plain, Latinate/Jamesian, Orwellian, Augustan, Victorian, Early Modern (Bacon, Browne, Milton), or free indirect discourse; or when coaching someone on writing voice and mechanics. Triggers on any request to improve, analyze, or write in a specific prose style, to fix "AI-sounding" writing, to make prose more vivid or concrete, to vary sentence rhythm, or to understand how a particular writer achieves their effects.
narrative-structure
Use when structuring stories, pitches, presentations, white papers, or any persuasive narrative; analyzing the hero's journey in fiction or non-fiction; applying StoryBrand for business communication; designing narrative arcs for thought leadership; or understanding Vogler, Snyder, Propp, or Campbell frameworks. Triggers on any narrative structure, storytelling, pitch structure, StoryBrand, hero's journey, three-act structure, Freytag, Save the Cat, narrative arc, or "how should I structure this story/pitch/presentation" request.
legal-brief-writing
Use when writing legal briefs, motions, or any court filing; when analyzing judicial cognition and persuasion; when applying elite brief-writing techniques from Roberts, Clement, Kagan, Garner; or when structuring legal arguments for maximum persuasion. Also use for autistic/neurodivergent advocates who need to understand how their natural communication style maps to elite legal advocacy. Triggers on any legal writing, brief drafting, motion preparation, or legal argument structuring request.
journal-publishability-criteria
Use whenever a research paper, article or preprint is being written, revised, reviewed or published, and specifically before every publication of docs/paper.md. Covers what legitimate journals actually gate on, in order of gating — the editor's desk screen (scope, novelty, package problems), what reviewers judge (methodological soundness, claims the evidence can carry, statistical and qualitative reporting), EQUATOR reporting guidelines, the ICMJE authorship criteria, COPE's view of text recycling, the near-universal generative-AI policy (no AI author, disclosure, author responsibility), TOP 2025 transparency standards, how to verify a journal is legitimate, submitting without an institution, and a pre-submission checklist. Triggers on requests to evaluate, review, prepare or submit a paper, to judge publishability, to write a declarations or data-availability section, to disclose AI use, or to check a journal.