Docsity

Computer Networks First Chapter, Schemi e mappe concettuali di Computer Graphics

Toggle sidebar
bg1
INFORMATION SYSTEMS SECURITY · LECTURE 2 · 28 SEPTEMBER 2026
Symmetric cryptography
from Kerckhoffs to ChaCha20
Study document reconstructed from the spoken lecture of Prof. Antonio Lioy (Politecnico di Torino)
and the 02_crypto slides (roughly slides 1–48).
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:
•Key idea: the one-sentence takeaway of a concept (summary of lecture content).
•Professor's example: an example or analogy given in the lecture.
•Added context: background, derivations or corrections that did NOT come from the professor.
•Exam signal / Exercise: things the professor said matter for the exam, or set as work.
•Unclear: passages where the transcript is uncertain.
•Common mistake: errors students typically make (added context).
"(inferred)" marks reconstructions not directly supported by the transcript.
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25

Anteprima parziale del testo

Scarica Computer Networks First Chapter e più Schemi e mappe concettuali in PDF di Computer Graphics solo su Docsity!

INFORMATION SYSTEMS SECURITY · LECTURE 2 · 28 SEPTEMBER 2026

Symmetric cryptography

from Kerckhoffs to ChaCha

Study document reconstructed from the spoken lecture of Prof. Antonio Lioy (Politecnico di Torino)

and the 02_crypto slides (roughly slides 1–48).

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:

  • Key idea : the one-sentence takeaway of a concept (summary of lecture content).
  • Professor's example : an example or analogy given in the lecture.
  • Added context : background, derivations or corrections that did NOT come from the professor.
  • Exam signal / Exercise : things the professor said matter for the exam, or set as work.
  • Unclear : passages where the transcript is uncertain.
  • Common mistake : errors students typically make (added context). "(inferred)" marks reconstructions not directly supported by the transcript.

Contents

  • Part A — Orientation
    • 1 Lecture overview
    • 2 What you need to know first
  • Part B — Key concepts, fully explained
    • Module 1 — Foundations
    • Module 2 — Building blocks and classic algorithms
    • Module 3 — Applying a block cipher: modes, IV, padding, CTS
    • Module 4 — Counter mode and stream ciphers
    • Module 5 — AES and the key-distribution problem
  • Part C — Consolidation
    • 4 Beyond the slides
    • 5 Key terms
    • 6 Connections
    • 7 Exam and assignment signals
    • 8 Unclear points
  • Part D — Revision
    • Revision sheet
    • 9 Quick review

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

Goal: understand what encryption is, why algorithms should be public, and the one problem

symmetric cryptography leaves open.

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).

  • The professor opened with Julius Caesar 's cipher, used to send messages to his commanders.
  • Encrypted means unreadable: "you can read the bits, but you don't understand them."
  • Each algorithm is a generic transformation modified by a key , which is just a string of bits.

Key-2 is a sort of "antidote" to key-1: if one is used to encrypt, the other must be used to

decrypt.

  • Terminology (Part 2): plaintext or cleartext, written P — "text" is generic, it can be an image, a

program, anything; ciphertext, written C. Because a crypt is where the dead are buried, some

people are offended by "encrypt": the neutral terms are encipher / decipher.

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).

The professor stressed that "people give the principle and they forget the hypotheses." Each one:

1. Keys are kept secret. A key written on a sticker on the back of a laptop gives no security.

"Don't laugh. It happens."

2. Keys are managed only by trusted systems. If you decrypt on a laptop you don't trust,

malware may steal the key as you enter it. The system must be malware-free.

3. Keys are of adequate length. Bike-lock analogy: one ring needs at most 10 tries, two rings

100, three rings 1000. The longer the key, the stronger the security in general.

Conclusion: the algorithms can be made public, and according to Kerckhoffs they must be, so that

they are widely analysed and their weaknesses identified. If you keep an algorithm secret, someone

still knows it — whoever designed or implemented it, other people in your company — so it must be

intrinsically strong anyway.

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

  • Model: P → enc(key-1) → C → dec(key-2) → P; sender and receiver may be the same person.
  • Kerckhoffs: three hypotheses (secret keys, trusted systems, adequate length) ⇒ public algorithms.
  • Security through obscurity is bad.
  • Symmetric: one shared K, fast, for bulk data; open problem = key distribution.

Module 2 — Building blocks and classic algorithms

Goal: know the classic symmetric algorithms, the XOR operation they all rely on, and the attack that

explains why we use Triple DES but never Double DES.

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."

1. Different platforms: algorithms are designed to suit particular CPUs and operating systems.

2. Mutual distrust: should a Russian use a US algorithm, or a European a Chinese one?

Governments and companies develop their own so they can say "this is mine, no one can have

put a backdoor inside."

DES was used for many, many years and is obsolete today. AES is, at least for the Western world,

the best algorithm we have for encryption.

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

  • Key length: "the bigger the key, the better the security", given a well-designed algorithm. Brute

force needs about 2N^ trials (slide 39).

  • Block size: block ciphers are designed by mathematicians to process a fixed, small block —

64 bits (8 bytes) for DES, 128 bits for AES. Real data is much bigger (1 MB, 1 TB) or smaller (

byte), so we must "tweak" how the algorithm is applied. This is the job of the encryption modes

(Module 3).

  • The professor's stance: "I don't care [about the internals of] the algorithm. I trust the

mathematicians." The course focuses on how to use algorithms correctly.

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.

P E D E C

C′ C″

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).

  • A temporary solution after DES became too weak, before AES; it costs three DES operations (≈

3× slower).

  • The middle step calls the decryption routine, but with K₂ ≠ K₁ it does not recover the plaintext —

it is just another transformation.

  • Why EDE: we need to implement both DES and 3DES. Implement only 3DES; setting K₁ = K₂ =

K₃ gives single DES "in the same time".

2 keys: C′ = enc(K₁, P) C″ = dec(K₂, C′) C = enc(K₁, C″)

3 keys: C′ = enc(K₁, P) C″ = dec(K₂, C′) C = enc(K₃, C″)

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."

The question: 3DES is slow; is DES applied twice (two keys) not stronger than DES? The answer is

no. With two N-bit keys you would expect 2N bits of strength; you get N + 1. If the base algorithm

were a mathematical group , you would not gain even that bit, because some K₃ would exist with

enc(K₂, enc(K₁, P)) = enc(K₃, P).

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 attack, step by step (the professor's derivation)

Hypotheses: N-bit keys; the attacker knows a pair (P, C) with C = enc(K₂, enc(K₁, P)).

Observation: split the two operations with an intermediate value M:

M = enc(K₁, P) and C = enc(K₂, M)

the encryption of P under the right K₁ equals the decryption of C under the right K₂

1. For all 2N^ keys Kᵢ (00…0, 00…1, …) compute Xᵢ = enc(Kᵢ, P) and store them.

2. For all 2N^ keys Kⱼ compute Yⱼ = dec(Kⱼ, C).

3. Search the pairs with Xᵢ = Yⱼ: they give candidate keys (K₁, K₂) = (Kᵢ, Kⱼ).

4. There may be false positives : try more candidates, or discard them using other (P, C) pairs.

Cost: 2 N^ + 2N^ = 2N+1^ operations instead of 22N. "The computation time doubles, but the effective

key length increases by just one bit."

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

  • Many algorithms exist (platforms, distrust); remember AES ; DES is obsolete.
  • XOR: balanced, self-inverse, fast.
  • DES: 56 secret + 8 parity bits; permutations make it hardware-oriented; judge efficiency by elementary operations.
  • 3DES = EDE (compatible with DES); 2-key: 56 (with 2⁵⁹ B memory) / 112; 3-key: 112.
  • Double DES: meet-in-the-middle, 2N+1^ ⇒ never use double encryption.
  • RC2 published, RC4 leaked (ARCFOUR), insecure, banned by RFC 7465.

Module 3 — Applying a block cipher: modes, IV, padding, CTS

Goal: know how to encrypt data that is larger or smaller than one block, why ECB is wrong, why CBC

needs an IV, how padding and ciphertext stealing work, and how to specify an encryption

completely.

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.

P₁

enc(K, ·)

C₁

P₂

enc(K, ·)

C₂

P₃

enc(K, ·)

C₃

P₄

enc(K, ·)

C₄

Figure 7. ECB encryption: each block independently, same key (slide 17).

Cₙ = enc(K, Pₙ) Pₙ = enc−1(K, Cₙ)

Pₙ, Cₙ = n-th plaintext / ciphertext block · a transmission error damages one block only (slide 18)

Weakness 1 — swap attack

An active attacker swaps ciphertext blocks 3 and 4 in transit. Decryption works, but the plaintext is

reordered: "I don't know what I'm doing, but probably I will change the meaning" — and nothing

detects it.

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.

IV

= C₀

P₁

enc(K, ·)

C₁

P₂

enc(K, ·)

C₂

P₃

enc(K, ·)

C₃

P₄

enc(K, ·)

C₄

C₁ feeds block 2

Figure 9. CBC encryption (slide 19).

Cₙ = enc(K, Pₙ ⊕ Cₙ₋₁) with C₀ = IV

The chaining links all operations together, so swapped blocks no longer decrypt correctly. It does

not fix the first block — "the most vulnerable, because it's the one containing the application

header" — hence the IV.

IV

C₁

dec(K, ·)

P₁

C₂

dec(K, ·)

P₂

C₃

dec(K, ·)

P₃

C₄

dec(K, ·)

P₄

Figure 10. CBC decryption (slide 20).

Pₙ = enc−1(K, Cₙ) ⊕ Cₙ₋₁

decrypting Cₙ gives Pₙ ⊕ Cₙ₋₁; XOR is its own inverse, so XOR with Cₙ₋₁ again gives Pₙ

  • For the first block, XOR with the IV: the receiver must know the key and the IV.
  • One transmission error damages the decryption of two blocks (slide 20; not discussed in the

transcript).

Rules for the IV

  • Random and never repeated. Reusing an IV would let the attacker precompute for, say, a

Word header combined with that IV — the dictionary attack returns.

  • Not secret. A student objected: "if I know the IV, I can combine it with Word and perform the

attack." The answer: the attack needs precomputation taking a year or two. You read the IV

and start computing; at most you decrypt that one message, because the next has a different IV

— and most likely a different key by then. "By using a random IV, you make the precomputation

impossible."

  • For very strong security you can encrypt the IV — with ECB , because the IV is one block —

using the same key. The destination decrypts it and uses it for CBC.

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

  • Treating the IV as a second key: it is a public, per-message value.
  • Thinking CBC gives integrity: a modification produces garbage, not an alarm (integrity comes later with MACs).

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.

Typical case: you split data into blocks for CBC, and the last piece is not a full block. The right

technique is padding ("filling"). Problems: (1) performance — more data to transmit or store; (2)

which values to add; (3) how the receiver distinguishes padding from real data.

← 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.

  • Null bytes only if the length is known or derivable (e.g. a C string, ending with a null).

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.

Why: with padding the encrypted file becomes bigger than the original; to encrypt a whole disk "it

will need another disk". CTS is useful when we cannot increase the size of the data (in-place

storage). The price: the operation on the last blocks is more complex, a slight increase in time.

CTS with ECB — the simplest case

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.

1. Encrypt the last complete block: X = enc(K, Pₙ₋₁).

2. Split X into a head (same size as the fragment) and a tail (same size as the missing part).

3. The head is transmitted as the last, partial block Cₙ*.

4. The tail is appended to the fragment: Pₙ ‖ tail is a full block; encrypt it and put it in position n−1.

The tail is encrypted twice, "but not explicitly": once as part of the previous block, once as padding

for the last. The receiver knows how much is missing (e.g. 2 bytes), so it knows the tail size.

CTS with CBC

Pₙ₋₁ Pₙ 0…

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.

1. Proceed normally: Eₙ₋₁ = enc(K, Pₙ₋₁ ⊕ Cₙ₋₂).

2. Pad the fragment with zeros and XOR with Eₙ₋₁; encrypt: Eₙ = enc(K, (Pₙ ‖ 0…0) ⊕ Eₙ₋₁).

3. Transmit Eₙ in position n−1, and only the head of Eₙ₋₁ in position n.

"Where is the tail gone?" — "The trick is in the XOR": the tail part was XORed with zero, "and data

XORed with zero is the data", so decrypting Eₙ gives back the tail.

(Pₙ ‖ 0…0) ⊕ (head ‖ tail) = (Pₙ ⊕ head) ‖ tail

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

ALGORITHM – KEY SIZE – MODE – CTS e.g. AES-256-CBC-CTS

  • Key size when the algorithm allows several (AES: 128/192/256); omit it for fixed-key algorithms.