





























Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!






























How to use this document Read in order. Part A orients you, Part B teaches the concepts in the order the professor taught them (five modules, each ending with a recap), Part C consolidates, Part D is for revision and self-testing. First pass: read the Key idea box and the figure of each concept, then the text. Second pass: do the Quick review (Section 9) without looking, then check the Answers. Source discipline. Normal text is what the professor said. "(slide)" marks slide-only content. Coloured boxes mark everything else:
Prerequisite What it is Why this lecture needs it
Security properties (Lecture 1)
Confidentiality, integrity (modification, deletion, replay).
Encryption gives confidentiality only; ECB swaps and stream-byte deletion are integrity attacks.
Passive vs active attacker, MITM (Lecture
Passive reads; active also modifies, deletes, inserts.
Swap and deletion attacks assume an active attacker in the middle.
Types of cryptanalytic attack (added context)
Ciphertext-only; known-plaintext (attacker knows some (P, C) pairs); chosen-plaintext (attacker gets chosen P encrypted).
Meet-in-the-middle and the ECB dictionary attack are known-plaintext attacks.
Hardware vs software cost (added context)
CPUs have native XOR/add/shift; arbitrary bit permutations have no instruction.
The professor's point that DES is "hardware-oriented"; ChaCha20's rotate.
Part B — Key concepts, fully explained
Module 1 — Foundations
3.1 The basic cryptographic model
Key idea Encryption transforms a plaintext P into an unreadable ciphertext C under key-1; decryption inverts it under the related key-2. The algorithms alone are not enough: the keys are the "special ingredient".
plaintext P (in clear) encryption^
ciphertext C (unreadable) decryption^
plaintext P (in clear)
key-1 key-
sender same content, transformed receiver (network, disk, cloud …)
key-1 and key-2 are related
Figure 2. The generic model of cryptography (slide 2).
Professor's example Sender and receiver can be the same person : you encrypt your backup before copying it to Dropbox. "Do I trust Dropbox? No, of course." You encrypt, upload, and later download and decrypt.
3.2 Kerckhoffs' principle
Key idea If the keys are secret, handled by trusted systems and long enough, the algorithm does not need to be secret — and it should be public so it can be analysed.
1 keys are kept secret
2 keys managed only by trusted systems
3 keys are of adequate length
the algorithm can and SHOULD be public widely analysed → weaknesses found
the hypotheses are what people forget Figure 3. Kerckhoffs' principle: three hypotheses, one conclusion (slide 4).
Professor's example Bug bounties. A student asked in the break whether bug bounties are silly, since you give your system to attackers. The answer: someone already knows how the system is made, so it is better to make it public, let everyone study it, and pay whoever finds a problem.
Added context Auguste Kerckhoffs, La cryptographie militaire (1883) (slide 4). The transcript's "Kirchhoff" is Kerckhoffs. For binary keys the lock analogy becomes about 2N^ trials for an N-bit key (slide 39).
Common mistake Quoting "algorithms should be public" without the three conditions. The principle says nothing about security if keys are short, leaked, or handled on compromised machines.
Module recap
Module 2 — Building blocks and classic algorithms
3.5 Why so many algorithms? DES vs AES
Key idea There are hundreds of symmetric algorithms because platforms differ and countries do not trust each other's designs. DES is obsolete; "if you have just to remember one algorithm, remember AES."
Algorithm Key (bits) Block (bits) Note (slide 7)
DES 56 64 obsolete
3-DES (2 keys) 112 64 56…112-bit strength
3-DES (3 keys) 168 64 112-bit strength
IDEA 128 64 famous for PGP
RC2 8–1024 64 usually 64-bit key
Blowfish 32–448 64 usually 128-bit key
CAST 40–128 64 usually 128-bit key
RC5 0–2048 1–
AES 128 / 192 / 256 128 state of the art
Unclear "If you find any system using DES nowadays, you need to put it on purpose to just f*** you" — the rest of the sentence is garbled. Likely meaning: DES must not be used; if you find it, it is a problem to report or replace.
3.6 Key length and block size
Added context The 56-bit key is too short today: DES was publicly brute-forced in 1998 (EFF "Deep Crack") in a few days. That, not a structural flaw, is the main reason it is obsolete.
3.9 Triple DES (3DES)
Key idea 3DES applies DES three times in EDE mode, so that with all keys equal it is single DES. It is three times slower and never gives the full security of three keys.
K₁ K₂ K₃ (2-key: K₁)
middle step uses the decryption routine with a DIFFERENT key → just another transformation K₁ = K₂ = K₃ ⇒ first two steps cancel ⇒ single DES (backward compatible)
Figure 5. Triple DES in EDE mode (slide 10).
standard FIPS 46/3 and ANSI X9.52 (slide)
Variant Key material Equivalent strength
2-key 3DES 112 bits 56 bits if the attacker has 2^59 bytes of memory; otherwise 112 bits
3-key 3DES 168 bits 112 bits — "at most the equivalent of two keys"
Unclear For 3-key 3DES the transcript says "only 120"; slide 10 says 112 bits , which is almost certainly what he meant.
Added context Why 112 for 3 keys: meet-in-the-middle (next section) also applies. Split the three stages into " stage" (tabulate, 2^56 ) and "2 stages" (brute-force two keys, 2^112 ). The cost is dominated by 2^112. The professor called the memory-based attacks on 2-key 3DES "mathematical attacks" without detailing them.
3.10 Double DES and the meet-in-the-middle attack
Key idea Double encryption doubles the time but adds only one bit of strength: a known-plaintext attack breaks it in about 2N+1^ operations. "Never do the double version."
P enc(K₁, ·) M enc(K₂, ·) C
the "middle"
step 1: for every key Kᵢ (2ᴺ keys) Xᵢ = enc(Kᵢ, P) store all 2ᴺ results in a table
step 2: for every key Kⱼ (2ᴺ keys) Yⱼ = dec(Kⱼ, C) look each one up in the table
step 3: find Xᵢ = Yⱼ ⇒ candidate (K₁, K₂) = (Kᵢ, Kⱼ) step 4: discard false positives with another (P, C) cost ≈ 2ᴺ + 2ᴺ = 2ᴺ⁺¹ (instead of 2²ᴺ)
Figure 6. Meet-in-the-middle attack on Double DES (slides 11–12).
the encryption of P under the right K₁ equals the decryption of C under the right K₂
Added context The slide text reads "2N+1": that is the exponent N+1 flattened by text extraction. The price of the attack is memory : a table of 2N^ entries (2^56 for DES). Why false positives: there are 2^112 key pairs but only 2^64 block values, so ≈ 2^48 wrong pairs match one (P, C); a second pair eliminates almost all of them. DES was shown not to be a group (1992), which is why Double DES gains at least one bit rather than zero.
Module recap
Module 3 — Applying a block cipher: modes, IV, padding, CTS
3.12 Encryption modes: overview
Key idea A block cipher only handles 8 or 16 bytes. The mode says how it is applied to real data — and a specification without the mode is incomplete.
Data larger than one block Data smaller than one block
ECB (Electronic Code Book) CBC (Cipher Block Chaining)
Padding CFB, OFB — very old, not used any more (professor) CTR (Counter mode)
Exam signal If asked how you encrypted data, "I used AES" is wrong/incomplete: AES is good, but you encrypted a terabyte — in which way did you apply it? Always add the mode, e.g. AES-CBC. The complete format is in §3.17.
3.13 ECB (Electronic Code Book)
Key idea ECB encrypts every block independently with the same key. Simple and fast, but "a completely wrong solution" for more than one block: identical blocks give identical ciphertext and blocks can be swapped.
enc(K, ·)
enc(K, ·)
enc(K, ·)
enc(K, ·)
Figure 7. ECB encryption: each block independently, same key (slide 17).
Pₙ, Cₙ = n-th plaintext / ciphertext block · a transmission error damages one block only (slide 18)
3.14 CBC (Cipher Block Chaining) and the IV
Key idea CBC XORs each plaintext block with the previous ciphertext block before encrypting, so the output depends on position. The first block is XORed with a random, never-repeated, non-secret IV.
= C₀
enc(K, ·)
enc(K, ·)
enc(K, ·)
enc(K, ·)
C₁ feeds block 2
Figure 9. CBC encryption (slide 19).
dec(K, ·)
dec(K, ·)
dec(K, ·)
dec(K, ·)
Figure 10. CBC decryption (slide 20).
decrypting Cₙ gives Pₙ ⊕ Cₙ₋₁; XOR is its own inverse, so XOR with Cₙ₋₁ again gives Pₙ
Added context Modern analysis also requires CBC IVs to be unpredictable (the BEAST attack on TLS 1.0 exploited predictable IVs). "Random and never repeated" satisfies both requirements.
Common mistake
3.15 Padding
Key idea When the last block is incomplete, fill it. The padding scheme lets the receiver remove it; with explicit-length padding you always pad — up to a full extra block when the data fits exactly.
← one 8-byte block (5 data bytes + 3 padding bytes) →
0x80 + null bytes D^ D^ D^ D^ D^80 00
null bytes, last = L (Schneier) D^ D^ D^ D^ D^00 00
all bytes = L (SSL/TLS) D^ D^ D^ D^ D^03 03
random, last = L (SSH2) D^ D^ D^ D^ D^05 F2^03
progressive (IPsec/ESP) D^ D^ D^ D^ D^01 02
all bytes = L−1 D^ D^ D^ D^ D^02 02
data is exact multiple (TLS style) D^ D^ D^ D^ D^ D^ D^ D^08 08 08 08 08 08 08 a whole extra block of padding
padding length byte L data
Figure 11. Padding schemes with an 8-byte block, 5 data bytes and 3 padding bytes (slides 22–23), and the exact-multiple case.
3.16 Ciphertext stealing (CTS)
Key idea CTS uses part of the previous ciphertext block as padding and swaps the last two blocks, so |ciphertext| = |plaintext| — essential for in-place storage encryption.
Pₙ₋₁ (full block) Pₙ (fragment) missing
enc(K, ·)
head tail (^) ← X = enc(K, Pₙ₋₁), split
Pₙ tail
tail used as padding enc(K, ·)
Cₙ₋₁ = enc(K, Pₙ‖tail) Cₙ* = head
position n−1 position n (partial)
blocks swapped: |C| = |P|, no padding
Figure 12. Ciphertext stealing with ECB (slide 26). The crossing arrows show the swap of the last two blocks.
fragment padded with zeros
Cₙ₋₂
enc(K, ·)
Eₙ₋₁ =^ head^ tail
Eₙ₋₁ (whole block) enc(K, ·)
Eₙ (tail hidden inside!)
Cₙ₋₁ = Eₙ Cₙ = head
position n−1 position n (partial)
(Pₙ‖0…0) ⊕ (head‖tail) = (Pₙ ⊕ head) ‖ tail XOR with 0 leaves tail intact
Figure 13. Ciphertext stealing with CBC (slide 27): the tail is hidden inside Eₙ thanks to the zero padding.
Exercise set by the professor "As an exercise, I suggest that you try to do also the decryption with a similar schema", and "try to write by yourself the schema for the encryption." "Think carefully because this is not trivial, it's a trick." Try it before reading the solutions below.
Added context Solution — ECB-CTS decryption: (1) dec(K, Cₙ₋₁) = Pₙ ‖ tail: the first m bytes are Pₙ, keep the tail. (2) Rebuild X = Cₙ* ‖ tail. (3) Pₙ₋₁ = dec(K, X). Solution — CBC-CTS decryption: (1) D = dec(K, Cₙ₋₁) = (Pₙ ⊕ head) ‖ tail. (2) head = the received final fragment, so Pₙ = first m bytes of D ⊕ head; the last bytes of D are the tail. (3) Rebuild Eₙ₋₁ = head ‖ tail; Pₙ₋₁ = dec(K, Eₙ₋₁) ⊕ Cₙ₋₂. CTS needs at least one full block before the fragment; it cannot handle data shorter than one block.
3.17 Complete specification of a symmetric encryption