11: Cryptography Fundamentals
Course: Networking - Security Advanced · Updated: October 2026 Literature: K&R chapter 8 (Security in Computer Networks): what is network security, principles of cryptography, message integrity and digital signatures Related lab: Lab: Network security (solution)
Learning objectives
After studying this article you can:
- name the properties of secure communication: confidentiality, integrity, authentication, availability (and non-repudiation)
- explain what an attacker can do (eavesdrop, modify, impersonate, hijack, deny service)
- explain symmetric-key cryptography (block ciphers, DES, AES) and Cipher-Block Chaining with an Initialisation Vector
- explain public-key cryptography and RSA, and why session keys are used
- explain cryptographic hash functions, MACs and digital signatures
- explain why MD5 and SHA-1 are broken, and what post-quantum cryptography is
1. What is network security?
The classic actors: Alice and Bob want to communicate securely. Trudy (the intruder) wants to interfere.
| Property | Meaning |
|---|---|
| Confidentiality | Only the sender and the intended receiver can understand the message → encryption |
| Message integrity | The receiver can detect whether the message was changed → hashes, MACs, signatures |
| End-point authentication | Sender and receiver can confirm each other's identity → see article 12 |
| Operational security / availability | Services stay available and protected against attacks → firewalls, IDS (see article 16) |
Together, confidentiality, integrity and availability are the CIA triad. Non-repudiation (the sender can't deny having sent something) is added through digital signatures.
What can Trudy do?
- eavesdrop: intercept messages
- insert messages into a connection
- impersonate: forge the source address or other fields
- hijack: take over a running connection by removing the sender or receiver and inserting herself
- denial of service: stop the service from being used by others
2. The language of cryptography
1 | |
- Kerckhoffs's principle: the algorithms are public. Only the key is secret.
- Types of attacks on an encryption scheme:
- Ciphertext-only: Trudy has only the ciphertext. Approaches: brute force (try all keys) or statistical analysis (letter frequencies).
- Known-plaintext: Trudy knows some plaintext/ciphertext pairs.
- Chosen-plaintext: Trudy can get chosen plaintexts encrypted.
3. Symmetric-key cryptography
Alice and Bob share the same secret key K_S.
3.1 Classical ciphers
- Caesar cipher: shift each letter k places. There are only 25 keys, so it is trivially broken.
- Monoalphabetic substitution: each letter is replaced by another letter. There are 26! (~10²⁶) keys, but it is broken easily by frequency analysis.
- Polyalphabetic (Vigenère): several substitution alphabets in turn.
3.2 Block ciphers
Modern symmetric ciphers are block ciphers. The message is processed in blocks of a fixed size (e.g. 128 bits), and each block is transformed by a complex mapping that depends on the key.
| Algorithm | Key | Block | Status (2026) |
|---|---|---|---|
| DES (1977) | 56 bits | 64 bits | Broken. Brute-forced in 22 hours in 1999 (EFF Deep Crack + distributed.net), and in minutes today. |
| 3DES | 112/168 bits | 64 bits | Deprecated, and disallowed by NIST since 2024 (the Sweet32 attack on 64-bit blocks) |
| AES (2001, FIPS 197) | 128 / 192 / 256 bits | 128 bits | The standard. With AES-128 it would take billions of years to try all keys. Hardware support (AES-NI) in all CPUs. |
| ChaCha20 | 256 bits | (stream cipher) | Modern alternative, fast on devices without AES hardware (phones, IoT). Used in TLS 1.3 and WireGuard. |
3.3 Cipher-Block Chaining (CBC) and the IV
Problem: if you encrypt each block separately (ECB mode), identical plaintext blocks give identical ciphertext blocks. Patterns stay visible. The famous example is the "ECB penguin" image, where the outline of the picture can still be seen after encryption.
Cipher-Block Chaining (CBC): before encryption, each plaintext block is XORed with the previous ciphertext block:
1 2 | |
- The Initialisation Vector (IV) is a random value for the first block. It is sent in the clear with the ciphertext. Because of the IV, the same message encrypted twice gives a different ciphertext.
- The IV doesn't have to be secret, but it must be unpredictable and must never be reused with the same key.
Modern practice (2026): CBC is now discouraged because of padding oracle attacks (POODLE, Lucky 13). Use AEAD modes (Authenticated Encryption with Associated Data), which encrypt and protect integrity at the same time:
- AES-GCM (Galois/Counter Mode)
- ChaCha20-Poly1305
In TLS 1.3, only AEAD ciphers are allowed. GCM also uses a unique nonce (similar to the IV), and reusing a nonce in GCM is catastrophic.
4. Public-key cryptography
Problem with symmetric keys: how do Alice and Bob agree on a shared key if they have never met? Diffie and Hellman (1976) and Rivest, Shamir and Adleman (1977) found a radically different approach:
- Each person has a key pair: a public key K⁺ (published) and a private key K⁻ (secret).
- What is encrypted with K⁺ can only be decrypted with K⁻:
K_B⁻( K_B⁺(m) ) = m - It must be practically impossible to work out the private key from the public key.
1 2 | |
4.1 RSA
- It is based on modular arithmetic with very large numbers. Its security rests on the fact that factoring the product of two large primes (n = p·q) is very hard.
- RSA also works "the other way round":
K_B⁺( K_B⁻(m) ) = m. This is the basis of digital signatures. - Key sizes (2026): at least 2048 bits, and 3072 bits for use beyond 2030. 1024-bit RSA is considered broken.
- Elliptic Curve Cryptography (ECC), e.g. X25519 (key exchange) and Ed25519 / ECDSA P-256 (signatures), gives the same security with much shorter keys (256 bits ≈ RSA-3072) and is faster. Most new systems use ECC.
4.2 Session keys
Public-key cryptography is slow. RSA is at least ~100–1000× slower than AES. So in practice systems use hybrid encryption:
- Alice chooses a random symmetric session key K_S.
- She encrypts K_S with Bob's public key and sends it to him.
- Bob decrypts K_S with his private key.
- From then on, both use K_S with AES for the actual data.
Modern refinement: TLS 1.3 no longer sends a session key encrypted with RSA. Both sides use (EC)Diffie-Hellman (ECDHE) to agree on a key. This gives forward secrecy: if the server's private key is stolen later, past sessions still can't be decrypted. See article 13.
5. Message integrity
5.1 Cryptographic hash functions
A hash function H(m) produces a fixed-size digest (a "fingerprint") of a message of any size. A cryptographic hash function must be:
- one-way: given h, it is infeasible to find m with H(m) = h
- collision-resistant: it is infeasible to find two different messages x ≠ y with H(x) = H(y)
The Internet checksum is a poor crypto hash. It is easy to create a different message with the same checksum (for example by swapping characters).
| Hash function | Digest | Status (2026) |
|---|---|---|
| MD5 (1992, RFC 1321) | 128 bits | Broken. Collisions can be produced in seconds. Abused by the Flame malware (2012) to forge a Microsoft certificate. |
| SHA-1 | 160 bits | Broken. SHAttered (Google/CWI Amsterdam, 2017) produced the first practical collision. NIST will withdraw it fully by 2030. |
| SHA-2 (SHA-256, SHA-384, SHA-512) | 256–512 bits | The standard (TLS certificates, Bitcoin, software signing) |
| SHA-3 (Keccak, 2015) | 224–512 bits | Standard, with a different internal design (a backup for SHA-2) |
| BLAKE2 / BLAKE3 | variable | Very fast, used in WireGuard and many applications |
Note: the 2018 course material still listed MD5 as "widely used". MD5 is no longer acceptable for any security purpose. It is only used as a non-security checksum to detect accidental errors.
Password storage needs slow hash functions with a salt: Argon2id, scrypt, bcrypt. Never store passwords with plain SHA-256 or MD5.
5.2 Message Authentication Code (MAC)
A hash alone doesn't prove who made the message, because Trudy can compute a new hash for her modified message. Solution: include a shared secret s:
1 | |
The standard construction is HMAC (RFC 2104), e.g. HMAC-SHA256. It is used in TLS, IPsec, SSH, OSPF authentication, JWT tokens and so on.
5.3 Digital signatures
A digital signature is like a handwritten signature, but verifiable and unforgeable:
- Bob computes the hash H(m) (hashing is fast and gives a fixed size).
- Bob signs the hash with his private key: K_B⁻(H(m)).
- Alice checks it with Bob's public key: does K_B⁺(signature) equal H(m)?
If so, then: - the message was signed by someone who has Bob's private key (authentication) - the message wasn't changed (integrity) - Bob can't deny signing it (non-repudiation)
Problem: how does Alice know that a public key really belongs to Bob? The answer is certificates and a Certificate Authority (CA). The CA signs the binding "this public key belongs to Bob". This is the Public Key Infrastructure (PKI), explained in article 13.
6. Post-quantum cryptography (PQC)
A large enough quantum computer could break RSA, Diffie-Hellman and ECC with Shor's algorithm. Symmetric algorithms (AES) and hashes are much less affected: Grover's algorithm only halves the effective key strength, so AES-256 stays secure.
"Harvest now, decrypt later": attackers (state actors in particular) record encrypted traffic today to decrypt it once quantum computers exist. Data that must stay secret for 10+ years is already at risk.
NIST's post-quantum standards (August 2024):
| Standard | Algorithm | Purpose |
|---|---|---|
| FIPS 203 | ML-KEM (formerly CRYSTALS-Kyber) | Key encapsulation (key exchange) |
| FIPS 204 | ML-DSA (formerly CRYSTALS-Dilithium) | Digital signatures |
| FIPS 205 | SLH-DSA (formerly SPHINCS+) | Hash-based signatures (conservative backup) |
| (2025 selection) | HQC | Backup KEM based on different mathematics |
| FIPS 206 (draft) | FN-DSA (Falcon) | Compact signatures |
Status in 2026: - Chrome, Firefox, Edge and Safari, together with Cloudflare, Google and others, already use hybrid key exchange X25519MLKEM768 in TLS by default. A large share of HTTPS traffic is already protected against "harvest now, decrypt later". - Signal (PQXDH, SPQR), Apple iMessage (PQ3) and OpenSSH (since version 9.0 with sntrup761, and since 10.0 with mlkem768x25519 as the default) use post-quantum key exchange. - NIST's timeline (IR 8547): RSA and ECC are deprecated from 2030 and disallowed from 2035. The EU has a coordinated roadmap with similar dates for critical infrastructure.
7. Summary
- Secure communication = confidentiality, integrity, authentication, availability.
- Symmetric (AES, ChaCha20) is fast but needs a shared key. Use AEAD modes (GCM, Poly1305). CBC needs a random IV.
- Public-key (RSA, ECC) solves key distribution, but it is slow, so it is used for session keys or key agreement (DH).
- Hashes (SHA-2/3), HMAC and digital signatures provide integrity and authentication. MD5 and SHA-1 are broken.
- The world is moving to post-quantum cryptography (ML-KEM, ML-DSA). It is already deployed in browsers and messaging apps.
References
Videos
- Jim Kurose: Principles of cryptography, message integrity (chapter 8 video lectures): https://gaia.cs.umass.edu/kurose_ross/lectures.php
- Computerphile: "Public Key Cryptography", "AES Explained", "SHA: Secure Hashing Algorithm", "Post-Quantum Cryptography": https://www.youtube.com/@Computerphile
- Dan Boneh: Cryptography I (Stanford, free on Coursera): https://www.coursera.org/learn/crypto
- Christof Paar: Introduction to Cryptography (Ruhr University Bochum, full lecture series on YouTube): https://www.youtube.com/results?search_query=Christof+Paar+Introduction+to+Cryptography
- 3Blue1Brown: "How secure is 256 bit security?": https://www.youtube.com/@3blue1brown
Articles and books
- Crypto 101 (free introductory book): https://www.crypto101.io/
- Serious Cryptography, 2nd ed. (J.-P. Aumasson, No Starch Press, 2024)
- The Joy of Cryptography (free online textbook): https://joyofcryptography.com/
- SHAttered, the first SHA-1 collision: https://shattered.io/
- NIST, Post-Quantum Cryptography: https://csrc.nist.gov/projects/post-quantum-cryptography
- Cloudflare blog, The state of the post-quantum Internet: https://blog.cloudflare.com/tag/post-quantum/
Standards
- FIPS 197: AES · FIPS 180-4: SHA-2 · FIPS 202: SHA-3
- FIPS 203/204/205: ML-KEM, ML-DSA, SLH-DSA
- RFC 2104: HMAC · RFC 8017: RSA (PKCS #1) · RFC 8439: ChaCha20-Poly1305
- NIST SP 800-131A: Transitioning the Use of Cryptographic Algorithms and Key Lengths
- NIST IR 8547: Transition to Post-Quantum Cryptography Standards
Tools
- CyberChef (GCHQ): encode, encrypt and hash in the browser: https://gchq.github.io/CyberChef/
- OpenSSL:
openssl enc -aes-256-gcm,openssl dgst -sha256,openssl genpkey - Cryptopals Crypto Challenges (break real crypto yourself): https://cryptopals.com/
Cyber Security
Why it matters
Cryptography is the foundation of almost every security measure: HTTPS, VPNs, Wi-Fi security, disk encryption, password storage, software updates, e-mail signing, payment cards, passports, DigiD, and cryptocurrency. When cryptography fails, everything built on it fails:
- Broken algorithms are still in use: MD5 and SHA-1 in legacy systems, DES/3DES in old payment terminals, RC4 in old Wi-Fi/TLS. Attackers look for them first.
- Implementation bugs are much more common than mathematical breaks: Heartbleed (OpenSSL, 2014), ROCA (weak RSA keys in smartcards and Estonian ID cards, 2017), and nonce reuse (Sony PS3's ECDSA private key was recovered in 2010).
- "Don't roll your own crypto": home-made encryption by developers is almost always breakable.
- Key management is the hardest part: keys in source code, in Git repositories or in config files, with no rotation. Leaked keys are one of the most common causes of cloud breaches.
- The quantum threat: the transition to PQC is a huge migration project, as big as Y2K. Organisations have to start now with a crypto inventory.
- Ransomware uses strong cryptography against victims. Without backups, encrypted data is lost.
How to make it safe
- Use standard, well-reviewed libraries: libsodium, OpenSSL/BoringSSL, the platform crypto APIs, or Python's
cryptographypackage. Never implement algorithms yourself. - Choose current algorithms: AES-256-GCM or ChaCha20-Poly1305, SHA-256 or better, Ed25519/ECDSA P-256 or RSA ≥ 3072, and for passwords Argon2id. Disable DES, 3DES, RC4, MD5 and SHA-1.
- Use authenticated encryption (AEAD). Never use ECB, and never reuse an IV or nonce with the same key.
- Manage keys properly: store them in a Key Management Service (KMS), a Hardware Security Module (HSM) or a secrets manager (HashiCorp Vault, Azure Key Vault, AWS KMS). Rotate keys, and use secret scanning in Git (e.g.
gitleaks, GitHub secret scanning). - Use good randomness: use a cryptographically secure random number generator (
secretsin Python,/dev/urandom). Never userandom. - Practise crypto-agility: design systems so algorithms can be replaced without a complete rebuild.
- Prepare for post-quantum: make an inventory of where cryptography is used (a Cryptographic Bill of Materials), prioritise data that must stay secret for a long time, and enable hybrid PQC key exchange (TLS, SSH, VPN) where it is available. The Dutch government and the AIVD have published a migration guide.
- Keep reliable backups (offline/immutable) against ransomware.
Extra references
- AIVD / CWI / TNO, The PQC Migration Handbook (Dutch government, 2nd edition 2024): https://www.aivd.nl/
- NCSC-NL, ICT-beveiligingsrichtlijnen voor Transport Layer Security (TLS) (current algorithm recommendations, also in English): https://www.ncsc.nl/
- BSI TR-02102 (German Federal Office for Information Security), Cryptographic Mechanisms: Recommendations and Key Lengths: https://www.bsi.bund.de/
- OWASP Cryptographic Storage Cheat Sheet and Password Storage Cheat Sheet: https://cheatsheetseries.owasp.org/
- Latacora, Cryptographic Right Answers (practical algorithm choices): https://www.latacora.com/blog/2018/04/03/cryptographic-right-answers/
- EU NIS Cooperation Group, Coordinated Implementation Roadmap for the transition to Post-Quantum Cryptography (2025): https://digital-strategy.ec.europa.eu/