Cryptographic primitives
Three tools do almost all of it: one key, two keys, or no key
Symmetric encryption uses one key, asymmetric encryption a key pair, and a hash no key at all.
Cryptography looks like a jungle of acronyms. Underneath are three tools. Symmetric encryption: one secret key locks the data, and the same key unlocks it. Fast, and used for nearly all data. Asymmetric encryption: a pair of keys. What the public key locks, only the private key opens. And hashing, which uses no key at all. Any input becomes a fixed-size fingerprint, and there is no way back. Everything else in this lesson, and in the next, is these three, combined.
Symmetric encryption
Each extra key bit doubles the work: 56 bits fell, 128 never will
AES uses 128, 192 or 256-bit keys. DES, with 56 bits, was broken by brute force in 1998.
How strong is a symmetric key? Imagine a machine trying a billion billion keys every second, far beyond anything that exists. DES, the standard of the 1970s, used fifty-six bits. Our machine tries them all in under a tenth of a second. In 1999, real hardware did it in twenty-two hours. AES with a hundred and twenty-eight bits: ten thousand billion years. Almost a thousand times the age of the universe. AES-256: a number with fifty-one zeros. Every extra bit doubles the work. Nobody breaks AES by guessing. They steal the key instead.
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.
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.
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
With symmetric keys alone, n people need n(n−1)/2 keys. Public-key cryptography needs one pair each.
Symmetric encryption has one big problem: both sides need the same key, before they can talk securely. Six people who all want private conversations need fifteen keys, one for every pair, each delivered in secret. A hundred people need four thousand nine hundred and fifty. A thousand people need nearly half a million. That is the key distribution problem, and for most of history it limited secret communication to armies and governments. Public-key cryptography solved it: each person needs one key pair, and the public half can be printed on a website.
Asymmetric encryption
Anyone can lock with a public key; only the private key opens it
RSA and elliptic-curve cryptography use key pairs. A 256-bit ECC key matches a 3072-bit RSA key.
Public-key cryptography works like a padlock you can hand out freely. Asha creates a key pair. She publishes the public key for anyone, and keeps the private key to herself. Ben wants to send her a secret. He locks it with her public key. Now nobody, not even Ben, can open it. Only Asha’s private key can. Keys must be longer than symmetric keys for the same strength. To match AES-128, RSA needs three thousand and seventy-two bits; elliptic curves need two hundred and fifty-six. That is why modern systems prefer elliptic curves.
Asymmetric encryption · Going deeper
Two strangers agree a secret over an open line without sending it
Diffie-Hellman key exchange (today ECDHE) derives a shared secret that never crosses the network.
Here is something that sounds impossible. Two people agree on a secret, while an eavesdropper hears every word. Small numbers make it visible. They publicly agree on a prime, twenty-three, and a base, five. Asha picks a secret number, six, and sends five to the power six, modulo twenty-three: eight. Ben picks fifteen and sends nineteen. The eavesdropper sees twenty-three, five, eight and nineteen. Asha raises nineteen to her secret six; Ben raises eight to his fifteen. Both get two. The eavesdropper cannot, without one of the secrets. With numbers hundreds of digits long, nobody can.
Hashing
Change one character, and about half the fingerprint changes
A hash such as SHA-256 is fixed-size, one-way and collision-resistant. Any change gives a different digest.
Hashing is the third tool. Here is a real SHA-256 digest of the message: pay Sam a hundred dollars. Sixty-four hexadecimal characters, two hundred and fifty-six bits. Change one character, a hundred to nine hundred, and the digest is completely different: about half of all the bits flip. The same input always gives the same digest. The output is always the same size. You cannot work backwards from it. And nobody can find two inputs that share one. That makes hashes the tool for integrity: compare digests, and any change is obvious.
Digital signatures
Signed with a private key, checked with the public one
A digital signature gives integrity, authenticity and non-repudiation.
Combine hashing with a key pair, and you get a digital signature. Asha hashes the contract, and transforms the digest with her private key. That is her signature. She sends it with the contract. Ben hashes the contract himself. He uses Asha’s public key on the signature to recover the digest she signed. If the two match, the contract is exactly what she signed. Not one byte has changed. And because only Asha holds her private key, only she could have made it. She cannot later deny it.
Hybrid encryption
Real systems combine all three tools, each for what it does best
Hybrid encryption: a public key protects a random session key; AES encrypts the data; hashes and signatures check it.
In practice the tools work as a team. Suppose you send a two gigabyte file. Encrypting it with public-key cryptography would be painfully slow. So you generate a random AES key, and encrypt the file with that, fast. Then you encrypt only the small AES key with the recipient’s public key. Send both together: a digital envelope. The recipient unlocks the key with their private key, then the file. Each need has its tool: AES for secrecy, key exchange for sharing keys, hashes for integrity, signatures for proof of origin, slow hashes for passwords.
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.
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. 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.
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
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
NIST’s post-quantum standards ML-KEM, ML-DSA and SLH-DSA replace RSA and ECC, deprecated after 2030.
One future threat already has a deadline. A large enough quantum computer would break RSA and elliptic curves, the basis of almost every key exchange and signature today. NIST began a public competition in 2016. In 2022 it chose the winners. In 2024 it published the first standards, for key exchange and for signatures. In 2025 it added a backup. And in October 2026 it set the dates. After 2030, RSA and elliptic curves are deprecated. After 2035, they are not allowed at all. AES-256 survives. The worry is data recorded today and decrypted once the machines arrive.
Lesson complete
You finished “Cryptography”
Nicely done.