Index

Cryptography Foundations

100%Open SVG ↗
CRYPTOGRAPHY FOUNDATIONSApplied Security · 02 — the primitives behind auth, TLS & signing: encrypt, hash, MAC, sign, exchangecrypto is a TOOLKIT that delivers the CIA goals (l.01): encryption→confidentiality, hashing/MAC→integrity, signatures→authenticity+non-repudiation. rule zero: NEVER roll your own — use vetted libraries. this names the primitives behind the whisper-code (Networking l.07).1 · ENCRYPTION — symmetric vs asymmetricSYMMETRIC: ONE shared key encrypts AND decrypts. FAST — used for all bulk data. (AES, the standard.)AliceBobsame keythe catch — KEY DISTRIBUTION: how do both sides get the shared key without ever meeting? →ASYMMETRIC (public-key): a KEY PAIR. encrypt with the PUBLIC key → only the PRIVATE key decrypts.PUBLIC key — share freely (the open padlock).PRIVATE key — keep secret (the only key that opens it).anyone can lock a message to you with your public padlock; only YOU can open it. (RSA, ECC.)solves key distribution — but SLOW, so it's used to exchange a symmetric key, not to encrypt bulk data.THE HYBRID (this is TLS): asymmetric to verify identity + agree a key → then symmetric (AES) for speed.never use ECB mode (identical blocks → identical ciphertext, patterns LEAK — 'the ECB penguin'). useAUTHENTICATED encryption (AES-GCM): confidentiality AND integrity in one primitive.2 · HASHING & HMAC — integritya CRYPTOGRAPHIC HASH: any input → fixed-size DIGEST. deterministic, ONE-WAY (can't reverse),collision-resistant, AVALANCHE (1 bit in → totally different out). (SHA-256.)'hello' → 2cf24dba5fb0a30e...'hellp' → 9c1185a5c5e9fc54... (one letter → nothing alike)it's NOT encryption — no key, nothing to decrypt. uses: file integrity, fingerprints, content-addressing (git commit = a hash!), dedup, proof-of-work, and password storage (+ salt, l.03).(vs the DSA hash table, l.03: crypto hashes ADD one-way + collision-resistance; DSA hashes just want spread.)HMAC — hash + a SECRET KEY:a bare hash proves integrity only if you trust the hash. HMAC(key, msg) proves the message wasn'ttampered AND came from someone holding the shared key.= integrity + authenticity, with a SYMMETRIC secret. used in JWTs (HS256), API request signing, TLS.the limit: both sides share the secret, so EITHER could have produced it → no non-repudiation. for that →you need a key PAIR: digital signatures (panel 3).3 · DIGITAL SIGNATURES & KEY EXCHANGE (Diffie-Hellman)SIGNATURE: sign with your PRIVATE key, anyone verifies with your PUBLIC key. the reverse of encryption.messagehashsign(privkey)= signatureverify(pubkey)= valid? ✓proves it came from YOU (only you hold the private key), wasn't altered, and you CAN'T DENY it (non-repudiation).vs HMAC: HMAC = shared secret (both can forge); a SIGNATURE = key pair (only the holder signs). → TLS certs,code signing, JWT (RS256), blockchain. a Certificate Authority SIGNS a server's cert — that's the trust chain.DIFFIE-HELLMAN — agree a shared secret over a PUBLIC channel, never sending it:like mixing paint: each side keeps a PRIVATE colour, swaps a PUBLIC mix; both combine to the SAME secretcolour that an eavesdropper (who saw only the public mixes) can't reproduce. this is how TLS makes itssession key — EPHEMERAL DH per connection gives FORWARD SECRECY (a stolen key can't decrypt past traffic).4 · WHICH PRIMITIVE? & the rulesGOAL PRIMITIVEkeep it secret ENCRYPTION (AES symmetric / RSA-ECC asymmetric)detect tampering HASH (SHA-256)tamper-proof + from-this-key HMAC (shared secret)prove author + non-repudiation SIGNATURE (private/public key pair)agree a key over open wire DIFFIE-HELLMAN key exchangeTLS IN ONE LINE: verify the cert (signature) + DH to agree a key → then AES-GCM for the fast bulk stream.THE RULES (violate these and the math won't save you):· don't roll your own crypto — use libsodium / the platform's vetted library.· use AUTHENTICATED encryption (AES-GCM), never plain ECB.· keys must be RANDOM, protected (KMS/HSM), and ROTATED.· algorithms EXPIRE — MD5 & SHA-1 are broken; don't use them.crypto is rarely broken by math — it's broken by MISUSE (bad keys, wrong mode, reused nonce). use the boring, vetted path.JARGON, DECODEDsymmetric encryption = one shared key (AES, fast, bulk) · asymmetric / public-key = a key pair (RSA/ECC, slow, key exchange) · key distribution = the problem asymmetric solves · ECB penguin = why block mode matterscryptographic hash = one-way fixed digest (SHA-256; deterministic, collision-resistant, avalanche) · digest = the hash output · HMAC = hash + secret key (integrity + authenticity) · nonce = a number used oncedigital signature = sign(private) / verify(public) → authenticity + non-repudiation · certificate = a public key signed by a CA · Diffie-Hellman = shared secret over a public channel · forward secrecy = past traffic stays safe if a key leaksAES-GCM = authenticated encryption (confidentiality + integrity) · RSA / ECC = asymmetric algorithms · KMS/HSM = key storage · 'don't roll your own crypto' = use vetted libraries; misuse, not math, is the usual break

Lessons that use this board

CRYPTOGRAPHY FOUNDATIONS Applied Security · 02 — the primitives behind auth, TLS & signing: encrypt, hash, MAC, sign, exchange crypto is a TOOLKIT that delivers the CIA goals (l.01): encryption→confidentiality, hashing/MAC→integrity, signatures→authenticity+non-repudiation. rule zero: NEVER roll your own — use vetted libraries. this names the primitives behind the whisper-code (Networking l.07). 1 · ENCRYPTION — symmetric vs asymmetric SYMMETRIC: ONE shared key encrypts AND decrypts. FAST — used for all bulk data. (AES, the standard.) Alice Bob same key the catch — KEY DISTRIBUTION: how do both sides get the shared key without ever meeting? → ASYMMETRIC (public-key): a KEY PAIR. encrypt with the PUBLIC key → only the PRIVATE key decrypts. PUBLIC key — share freely (the open padlock). PRIVATE key — keep secret (the only key that opens it). anyone can lock a message to you with your public padlock; only YOU can open it. (RSA, ECC.) solves key distribution — but SLOW, so it's used to exchange a symmetric key, not to encrypt bulk data. THE HYBRID (this is TLS): asymmetric to verify identity + agree a key → then symmetric (AES) for speed. never use ECB mode (identical blocks → identical ciphertext, patterns LEAK — 'the ECB penguin'). use AUTHENTICATED encryption (AES-GCM): confidentiality AND integrity in one primitive. 2 · HASHING & HMAC — integrity a CRYPTOGRAPHIC HASH: any input → fixed-size DIGEST. deterministic, ONE-WAY (can't reverse), collision-resistant, AVALANCHE (1 bit in → totally different out). (SHA-256.) 'hello' → 2cf24dba5fb0a30e... 'hellp' → 9c1185a5c5e9fc54... (one letter → nothing alike) it's NOT encryption — no key, nothing to decrypt. uses: file integrity, fingerprints, content- addressing (git commit = a hash!), dedup, proof-of-work, and password storage (+ salt, l.03). (vs the DSA hash table, l.03: crypto hashes ADD one-way + collision-resistance; DSA hashes just want spread.) HMAC — hash + a SECRET KEY: a bare hash proves integrity only if you trust the hash. HMAC(key, msg) proves the message wasn't tampered AND came from someone holding the shared key. = integrity + authenticity, with a SYMMETRIC secret. used in JWTs (HS256), API request signing, TLS. the limit: both sides share the secret, so EITHER could have produced it → no non-repudiation. for that → you need a key PAIR: digital signatures (panel 3). 3 · DIGITAL SIGNATURES & KEY EXCHANGE (Diffie-Hellman) SIGNATURE: sign with your PRIVATE key, anyone verifies with your PUBLIC key. the reverse of encryption. message hash sign(privkey) = signature verify(pubkey) = valid? ✓ proves it came from YOU (only you hold the private key), wasn't altered, and you CAN'T DENY it (non-repudiation). vs HMAC: HMAC = shared secret (both can forge); a SIGNATURE = key pair (only the holder signs). → TLS certs, code signing, JWT (RS256), blockchain. a Certificate Authority SIGNS a server's cert — that's the trust chain. DIFFIE-HELLMAN — agree a shared secret over a PUBLIC channel, never sending it: like mixing paint: each side keeps a PRIVATE colour, swaps a PUBLIC mix; both combine to the SAME secret colour that an eavesdropper (who saw only the public mixes) can't reproduce. this is how TLS makes its session key — EPHEMERAL DH per connection gives FORWARD SECRECY (a stolen key can't decrypt past traffic). 4 · WHICH PRIMITIVE? & the rules GOAL PRIMITIVE keep it secret ENCRYPTION (AES symmetric / RSA-ECC asymmetric) detect tampering HASH (SHA-256) tamper-proof + from-this-key HMAC (shared secret) prove author + non-repudiation SIGNATURE (private/public key pair) agree a key over open wire DIFFIE-HELLMAN key exchange TLS IN ONE LINE: verify the cert (signature) + DH to agree a key → then AES-GCM for the fast bulk stream. THE RULES (violate these and the math won't save you): · don't roll your own crypto — use libsodium / the platform's vetted library. · use AUTHENTICATED encryption (AES-GCM), never plain ECB. · keys must be RANDOM, protected (KMS/HSM), and ROTATED. · algorithms EXPIRE — MD5 & SHA-1 are broken; don't use them. crypto is rarely broken by math — it's broken by MISUSE (bad keys, wrong mode, reused nonce). use the boring, vetted path. JARGON, DECODED symmetric encryption = one shared key (AES, fast, bulk) · asymmetric / public-key = a key pair (RSA/ECC, slow, key exchange) · key distribution = the problem asymmetric solves · ECB penguin = why block mode matters cryptographic hash = one-way fixed digest (SHA-256; deterministic, collision-resistant, avalanche) · digest = the hash output · HMAC = hash + secret key (integrity + authenticity) · nonce = a number used once digital signature = sign(private) / verify(public) → authenticity + non-repudiation · certificate = a public key signed by a CA · Diffie-Hellman = shared secret over a public channel · forward secrecy = past traffic stays safe if a key leaks AES-GCM = authenticated encryption (confidentiality + integrity) · RSA / ECC = asymmetric algorithms · KMS/HSM = key storage · 'don't roll your own crypto' = use vetted libraries; misuse, not math, is the usual break

Saved in this browser only.

← The Security MindsetAuthentication →