Plaintext, Keys, Kerckhoffs and the Security Goals
A vendor's datasheet promises "proprietary military-grade encryption, algorithm kept secret for extra security". A reviewer should read that sentence as a warning. To see why, you need the vocabulary every later lesson uses, and one principle from 1883 that still decides which designs survive.
The words
| Term | Meaning |
|---|---|
| plaintext | the data you want to protect (any bytes, not only text) |
| ciphertext | the encrypted form; should reveal nothing about the plaintext except, usually, its length |
| key | the secret parameter; with it you decrypt, without it you should learn nothing |
| cipher | the pair of algorithms encrypt and decrypt |
| symmetric | the same key encrypts and decrypts (AES, ChaCha20) |
| asymmetric / public-key | a key pair: anyone can use the public key, only the owner holds the private key (RSA, elliptic curves) |
| nonce / IV | a per-message value, usually public, that makes two encryptions of the same plaintext differ; a nonce must never repeat under one key |
| key space | the set of possible keys; its size in bits is the upper bound on brute-force strength |
| primitive | one building block (a block cipher, a hash) as opposed to a protocol that combines several (TLS) |
Kerckhoffs's principle
Auguste Kerckhoffs wrote in 1883 that a military cipher "must not require secrecy, and it must be able to fall into the hands of the enemy without inconvenience". Today's form: a system must stay secure when everything about it except the key is public. Claude Shannon said the same more bluntly: assume "the enemy knows the system".
The reasons are practical:
- Algorithms leak. Firmware gets dumped, binaries get reverse-engineered, employees move on. A key can be changed in minutes, an algorithm baked into a million devices cannot.
- Public algorithms get reviewed. AES, SHA-3 and the post-quantum standards came out of open competitions in which the world's cryptanalysts attacked every candidate for years. A secret algorithm has been attacked only by its authors.
- History agrees. Secret designs such as the DVD's CSS, the GSM A5/1 and A5/2 ciphers and the MIFARE Classic's Crypto-1 were reverse-engineered and broken soon after they reached attackers' hands.
So the whole secret must be the key, which means the key must be large enough that trying every possibility is hopeless. The toy below shows the opposite case: a shift (Caesar) cipher, whose algorithm everyone knows and whose key space has 26 entries.
import string
A = string.ascii_uppercase
def shift(text, k):
return "".join(A[(A.index(c) + k) % 26] if c in A else c for c in text)
secret_key = 11
ct = shift("ATTACK AT DAWN", secret_key)
print("ciphertext:", ct)
# Kerckhoffs: the attacker knows the algorithm. With 26 keys, trying them all is instant.
for k in range(26):
guess = shift(ct, -k)
if "AT" in guess.split():
print(f"key {k:2}: {guess}")
for name, bits in [("shift cipher", 4.7), ("DES", 56), ("AES-128", 128), ("AES-256", 256)]:
seconds = 2 ** bits / 2 / 1e12 # half the keys at a trillion guesses per second
years = seconds / 3.156e7
print(f"{name:12} 2^{bits:<5} keys: {years:.1e} years on average")ciphertext: LEELNV LE OLHY
key 11: ATTACK AT DAWN
shift cipher 2^4.7 keys: 4.1e-19 years on average
DES 2^56 keys: 1.1e-03 years on average
AES-128 2^128 keys: 5.4e+18 years on average
AES-256 2^256 keys: 1.8e+57 years on average
The attacker recognised the right key because the plaintext has structure (English words), which is almost always true. At a trillion keys per second, a 56-bit DES key falls in about 0.0011 years, roughly ten hours, while a 128-bit AES key would take about 5 × 10^18 years. Key size is not everything (a design flaw can shortcut the search), but a small key space is fatal on its own.
The security goals
| Goal | Question it answers | Typical tool |
|---|---|---|
| confidentiality | can an outsider read it? | encryption (AES-GCM, ChaCha20-Poly1305) |
| integrity | was it changed? | MAC, AEAD tag, signature |
| authenticity | who sent it? | MAC (shared key), signature (public key) |
| non-repudiation | can the sender later deny it? | signatures only: a MAC key is shared, so either side could have made the tag |
| forward secrecy | does a key stolen tomorrow expose today's traffic? | ephemeral key exchange (X25519 in TLS 1.3) |
The goals are independent. Encryption alone does not give integrity: the one-time-pad lesson changes an amount in an encrypted bank transfer without knowing the key. A hash alone does not give authenticity: anyone can recompute it. Each lesson names the goal a primitive delivers and the ones it doesn't.
Attacker models
A claim like "secure" only means something against a stated attacker:
- ciphertext-only: sees ciphertexts (the eavesdropper on a Wi-Fi network);
- known-plaintext: also knows some plaintext–ciphertext pairs (file headers, protocol greetings, the "Hello" every message starts with);
- chosen-plaintext (CPA): can get chosen messages encrypted (any web app that encrypts what users submit);
- chosen-ciphertext (CCA): can submit ciphertexts and observe how the system reacts (any server that decrypts what it receives: the padding-oracle lesson is the classic case).
Modern ciphers are expected to resist the strongest of these, CCA, and authenticated encryption is the construction that gives it.
How weak designs are detected
- Secret or home-made algorithms: in code review, any cipher that is not a standard primitive from a maintained library (look for XOR loops, custom S-boxes, "scramble" functions); in procurement, datasheets that won't name algorithms.
- Small key spaces: keys derived from short PINs, timestamps or user names; 4-digit "encryption codes"; DES or 40-bit export ciphers in configuration.
- Missing goals: encryption with no tag or MAC; hashes used as signatures.
How it is fixed
- Use standard, publicly analysed algorithms through a well-maintained library (
cryptography, libsodium, the platform's TLS stack). Prefer high-level APIs (AESGCM,Fernet,nacl.secret.SecretBox) that make the dangerous choices for you. - Keys of at least 128 bits of security, from a CSPRNG or a proper KDF.
- Choose primitives by the goals you need, and write the goals down in the design document.
Pitfalls
- "Encrypted" in a requirements document without saying against whom and for which goals.
- Treating encoding (Base64, hex, URL-encoding) as encryption. It has no key.
- Calling a hash "encryption". Hashes are one-way and keyless; encryption is reversible with the key.
Practice
1. A smart-lock vendor says its protocol is safe because "the algorithm is confidential". What two questions do you ask?
What is the key, and how large is the key space? And has the algorithm been publicly analysed? If security depends on the algorithm staying secret, one firmware dump breaks every lock; Kerckhoffs's principle says only the key may be secret.
2. A webhook sender adds sha256(body) in a header. Which goal does this give, and against whom?
Only accidental-corruption detection. An attacker who changes the body recomputes the hash, so there is no integrity against an adversary and no authenticity. A MAC with a shared key (HMAC) or a signature is needed.
3. Which attacker model fits a login API that decrypts an encrypted cookie the client sends back?
Chosen-ciphertext: the client controls the ciphertext the server decrypts and can watch the responses.
Practice problems in 21 languages: Crack a Caesar Cipher, Decode a Vigenere Cipher.
Test yourself
What does Kerckhoffs's principle say?
- Algorithms should be secret
- A system should be secure even if everything except the key is public
- Keys should be short so they can be remembered
- Every message needs a new algorithm
Which goal can a MAC NOT provide that a signature can?
- Integrity
- Authenticity between two parties
- Non-repudiation
- Detecting tampering
At a trillion guesses per second, roughly how long does an average search of the 56-bit DES key space take?
- A few seconds
- About ten hours
- About a thousand years
- Longer than the age of the universe
A server decrypts tokens submitted by clients and returns different errors for different failures. Which attacker model must the design resist?
- Ciphertext-only
- Known-plaintext
- Chosen-ciphertext
- None, the server is internal