Cryptographic primitives

Three tools do almost all of it: one key, two keys, or no key

Symmetricone shared keyplaintextsame keyciphertextsame key turns it backAES, ChaCha20Asymmetrica key pairplaintextpublic keyciphertextonly the private key opens itRSA, elliptic curvesHashno key at allany inputhash256-bit digestno way back, by designSHA-256, SHA-3Almost all of cryptography is built from three tools: one shared key, a pair of keys, or no key at all.Symmetric encryption is fast and protects data in bulk, but both sides need the same secret key. Asymmetricencryption solves sharing: anyone may use the public key, only its owner holds the private one. A hashencrypts nothing; it produces a fixed-size fingerprint used to detect any change.

Symmetric encryption uses one key, asymmetric encryption a key pair, and a hash no key at all.

Symmetric encryption

Each extra key bit doubles the work: 56 bits fell, 128 never will

Time to try every key at a billion billion keys a second (10¹⁸)DES56-bit key0.07 secondsbroken in 22 hours in 1999AES-128128-bit key1.1 × 10^13 yearsAES-256256-bit key3.7 × 10^51 yearsBar length is the number of bits; each extra bit doubles the work. The universe is about 1.4 × 10^10 years old.Each extra key bit doubles an attacker’s work: 56 bits fell in a day, 128 bits will never fall to guessing.AES (the Advanced Encryption Standard, 2001) uses keys of 128, 192 or 256 bits and is built into modern processors,encrypting gigabytes a second. It replaced DES, whose 56-bit key a purpose-built machine searched in 1998.Attacks on real systems go around the maths: stolen keys, weak passwords, bad implementations.

AES uses 128, 192 or 256-bit keys. DES, with 56 bits, was broken by brute force in 1998.

Modes and ciphers · Going deeper

Block and stream ciphers, ECB, GCM and authenticated encryption

Use authenticated encryption such as AES-GCM or ChaCha20-Poly1305. Never ECB.

Block and stream

AES is a block cipher: it encrypts 128 bits at a time. A mode of operation chains blocks together. ChaCha20 is a stream cipher, generating a keystream to combine with data; it is fast on phones without AES hardware.

Modes you will meet

  • ECB each block encrypted on its own; identical blocks give identical output, so patterns show through. Never use it.
  • CBC each block mixed with the previous one; common in older systems, needs a random IV and separate integrity protection.
  • CTR turns a block cipher into a stream; parallel and fast.
  • GCM counter mode plus an authentication tag: confidentiality and integrity in one step. The default in TLS 1.3.

Key terms

  • Initialisation vector (IV) or nonce a value that makes each encryption unique; never reuse one with the same key in GCM.
  • Key stretching deriving a strong key from a password with a slow function such as PBKDF2 or Argon2.
  • Obfuscation and steganography hiding data, or hiding that data exists (inside an image); not a substitute for encryption.

Key distribution

Shared keys must be delivered first, and their number explodes

6 people: 15 shared keysPeopleSymmetric keys: n(n−1)/2Key pairs: n1045101004,9501001,000499,5001,000Symmetric keys must be shared before they can be used, and the number of keys explodes with each person.Every pair of people needs its own secret key, delivered safely in advance: that is the key distribution problem.With public-key cryptography each person needs one key pair, and public keys can be published openly. Inpractice the two are combined: a public-key method agrees a fresh symmetric key, and AES does the bulk work.

With symmetric keys alone, n people need n(n−1)/2 keys. Public-key cryptography needs one pair each.

Asymmetric encryption

Anyone can lock with a public key; only the private key opens it

Ashapublishespublic keykeepsprivate keyBenlocks with Asha’sciphertextonly Asha’s private key opens itEqual strength (NIST SP 800-57)BitsSymmetricRSAECC1123TDEA2048224128AES-1283072256192AES-1927680384256AES-25615360512Anyone can lock a message with a public key; only the matching private key can open it.The keys are mathematically linked, but the private key cannot be worked out from the public one. RSA relies onthe difficulty of factoring huge numbers; elliptic-curve cryptography (ECC) gets the same strength from muchshorter keys, which is why phones and TLS prefer it. Asymmetric operations are slow, so they protect keys, not bulk data.

RSA and elliptic-curve cryptography use key pairs. A 256-bit ECC key matches a 3072-bit RSA key.

Asymmetric encryption · Going deeper

Two strangers agree a secret over an open line without sending it

Public: prime p = 23, base g = 5anyone may see theseAshasecret a = 6sends g^a mod p = 8Bensecret b = 15sends g^b mod p = 198 →← 19eavesdropper sees 23, 5, 8, 1919^6 mod 23 = 28^15 mod 23 = 2Diffie-Hellman lets two people agree a secret over an open line without ever sending it: both get 2.Each keeps a private number and sends only a value derived from it. Combining the other’s value with their ownsecret gives both sides the same result, which the eavesdropper cannot compute without a or b. Real systems usenumbers hundreds of digits long, or elliptic curves (ECDHE), and pick fresh secrets for every session.

Diffie-Hellman key exchange (today ECDHE) derives a shared secret that never crosses the network.

Hashing

Change one character, and about half the fingerprint changes

Pay Sam $10062f74f072d4cd47b09812e3b861c0241cace353192e2129de9ec6a8bb34ba459Pay Sam $9005ad0b1e3d6da83a2ac7124a05e5b96c1cf3012797a1dbea09da0f11b18e4811fone character changed: 133 of 256 output bits flipped (52%)Same input, same digestevery time, on every machineFixed size256 bits, for one word or a whole filmOne-wayno way to recover the inputCollision-resistantno two inputs found with one digestA hash is a fixed-size fingerprint: change one character and about half of the output changes.The digests above are real SHA-256 outputs. Hashes prove integrity: publish a file’s digest, and anyone can checktheir download matches. MD5 and SHA-1 are broken for this purpose, because collisions can be made deliberately.An HMAC mixes a secret key into the hash, so only someone with the key can produce a valid one.

A hash such as SHA-256 is fixed-size, one-way and collision-resistant. Any change gives a different digest.

Digital signatures

Signed with a private key, checked with the public one

Asha signsBen verifiesContracthashdigestprivate keySignaturesends the contract and the signature togetherContracthashdigest ASignaturepublic keydigest BA = B ?✓Integrity: not one byte changed✓Authenticity and non-repudiation: only Asha’s key made itA signature is made with a private key and checked with the public one: it proves who signed, and that nothing changed.Signing hashes the document and transforms the digest with the signer’s private key. Anyone holding the publickey can check it. Because only the signer has the private key, they cannot later deny signing (non-repudiation).Signatures protect software updates, certificates, emails (S/MIME) and every TLS connection.

A digital signature gives integrity, authenticity and non-repudiation.

Hybrid encryption

Real systems combine all three tools, each for what it does best

Large file2 GBAES-256, fastEncrypted fileRandom AES key32 bytesrecipient’s public keyWrapped keySent togethera digital envelopeNeedToolConfidentialityAES (symmetric)Sharing a keyECDHE or RSAIntegritySHA-256, HMACProof of origindigital signaturePasswordsslow salted hashReal systems use all three tools together, each for the job it does best.Asymmetric cryptography moves a small random key safely; symmetric cryptography encrypts the data quickly; hashesand signatures prove nothing changed and who sent it. Email encryption, disk encryption and TLS all follow thispattern. The weak point is rarely the algorithm: it is how keys are generated, stored and rotated.

Hybrid encryption: a public key protects a random session key; AES encrypts the data; hashes and signatures check it.

Key management · Going deeper · 1 of 2

Where keys live: HSM, TPM, KMS, secure enclaves and escrow

Keys are protected in HSMs, TPMs, cloud KMS and secure enclaves, and rotated on a schedule.

Hardware that protects keys

  • Hardware security module (HSM) a tamper-resistant device that generates and uses keys without ever exposing them; used by banks, CAs and cloud key services.
  • Trusted Platform Module (TPM) a chip in a computer that stores keys for disk encryption (BitLocker) and measures the boot process.
  • Secure enclave an isolated processor area in phones and laptops that holds biometric data and passkeys.
  • Key management service (KMS) a cloud service that holds master keys in HSMs and logs every use (AWS KMS, Azure Key Vault, Google Cloud KMS).

The key life cycle

Generatewith a strong random source
Storein hardware or a vault
Rotateon a schedule and after any exposure
Destroywhen retired, so old data stays unreadable

Key escrow

A copy of a key held by a trusted third party so data can be recovered, for example disk-encryption recovery keys stored in the company directory. It helps recovery and creates a target, so access to escrowed keys is tightly controlled.

Hybrid encryption · Going deeper · 2 of 2

Quantum computers threaten public keys, so the switch has a deadline

2016202020242028203220362016NIST opens the competition2022four algorithms chosen2024FIPS 203, 204, 205 published2025HQC chosen as a backup2026IR 8547 final: dates set2030RSA and ECC deprecated2035RSA and ECC disallowedReplacements:ML-KEM (FIPS 203) for key exchange · ML-DSA (FIPS 204) and SLH-DSA (FIPS 205) for signatures · AES-256 staysA large quantum computer would break RSA and elliptic curves, so the move to new algorithms has a deadline.Shor’s algorithm factors and solves discrete logarithms efficiently on a quantum computer; symmetric ciphers onlylose half their bits of strength, so AES-256 remains safe. Attackers can record traffic today and decrypt it later(“harvest now, decrypt later”), which is why long-lived secrets are moving first. Browsers already use ML-KEM.

NIST’s post-quantum standards ML-KEM, ML-DSA and SLH-DSA replace RSA and ECC, deprecated after 2030.

Lesson complete

You finished “Cryptography”

Nicely done.

Open in a new tab