crypto slides
crypto slides
Crypto intro
Jan 27, 2025
1
Logistics
2
Essential Cryptography
Symmetric Key Encryption
Stream and Block Ciphers
Message-Authentication Codes
Hash Functions
Key Establishment
Asymmetric (Public Key) Encryption
One-slide takeaway
4
Message
Eve
Alice Passive Eavesdropper Bob
Mallory
Man-in-the-Middle
Ingredients for a Secure Channel
6
Confidentiality Eve
Attacker can’t see the message
Symmetric Ciphers
Integrity
Mallor
Attacker can’t modify the message y
Message Authentication Codes (MACs)
Confidentiality - Symmetric Key Encryption
7
Encryption Decryption
plaintext ciphertext
plaintext
K encrypt(.) K decrypt(.)
ciphertext ciphertext
plaintext
Substitution cipher
8
K = A -> T
B -> X
C -> S
…
Z -> D
…
“AN”
…
J J MG U Q K G X C Q L T F
Weakness:
Assume “I” is the most common letter → “Q” is the most common in encrypted letters
→ The first letter of key is “Q” – “I” = “H”
One-Time Pads
11
First example of a
P1 P2 P3 P4
K1 K2 K3 K4
P1 K1 P2 K2 P3 K3 P4 K4
Pi K i Pi Ki
0 0 0
0 1 1
1 0 1
1 1 0
Problems with One-Time Pads
13
Improvement
Stream cipher
Stream cipher: making OTP practical
14
Key Message
N bits
(seed)
N << M
M bits
PRG must be unpredictable
15
GET
Weak PRG
17
C1 = M1 PRG(K)
C2 = M2 PRG(K)
C1 C2 = ?
Two-time pad vulnerability
19
C1 = M1 PRG(K)
C2 = M2 PRG(K)
C1 C2 = M1 M2
Two-time pad vulnerability
20
C1 = M1 PRG(K)
C2 = M2 PRG(K)
C1 C2 = M1 M2
K K1 K2 K3 K4 …
M1 M2 M3 M4
Block ciphers
25
n bits n bits
PT Block E, D CT Block
Key k bits
Canonical examples:
1. 3DES: n= 64 bits, k = 168 bits
2. AES: n=128 bits, k = 128, 192, 256 bits
ECB – Electronic Codebook Mode
26
P1 P2 P3 P4 …
EK EK EK EK
C1 C2 C3 C4 …
ECB – Electronic Codebook Mode
27
P1 P2 P3 P4 …
EK EK EK EK
C1 C2 C3 C4 …
Why not ECB?
28
P1 P2 P3 …
?
EK EK EK
C1 C2 C3 …
CBC: Cipher-Block Chaining Mode
30
P1 P2 P3 …
Random
“Initialization EK EK EK
Vector”
IV C1 C2 C3 …
CBC: Cipher-Block Chaining Mode
31
P1 P2 P3 …
Random
“Initialization EK EK EK
Vector”
IV C1 C2 C3 …
key k
key expansion
k1 k2 k3 kn
R(kn,.)
R(k1,.)
R(k2,.)
R(k3,.)
m c
AES: state-of-the-art (2000)
33
One block
AES: state-of-the-art (2000)
34
One block
How Safe is AES?
35
c=mk
Attacker can change the ciphertext by
cp
When decrypted,
(c p) k = ?
(c p) k = ((m k) p) k = m p
Assuming m has a single bit.
1 indicates attack
0 indicates retreat
Can always force the wrong decision (not knowing what m is)
Integrity
37
Example:
Protecting public binaries on disk
Protecting ads on web pages
Attack against integrity
38
m p <- D ( k) <- (m k) p
“From Eve”
k k
message m tag
Alice Bob
message m tag
Alice Bob
Ideal: Random
mapping from
any arbitrary-size input
to a fixed size output
Hash Function Requirements
43
First pre-image
Given h(x), find x
Second pre-image
Given m1, find m2 s.t. h(m1) = h(m2)
Collision
Given nothing, find any m1 != m2 s.t. h(m1) = h(m2)
Birthday Attack: 70% for 30 students
MD5 Hash Function
44
Designed in 1992 by
Ron Rivest
128-bit output
128-bit internal state
d131dd02c5e6eec4693d9a0698aff95c 2fcab58712467eab4004583eb8fb7f89
55ad340609f4b30283e488832571415a 085125e8f7cdc99fd91dbdf280373c5b
d8823e3156348f5bae6dacd436c919c6 dd53e2b487da03fd02396306d248cda0
e99f33420f577ee8ce54b67080a80d1e c69821bcb6a8839396f9652b6ff72a70
d131dd02c5e6eec4693d9a0698aff95c 2fcab50712467eab4004583eb8fb7f89
55ad340609f4b30283e4888325f1415a 085125e8f7cdc99fd91dbd7280373c5b
d8823e3156348f5bae6dacd436c919c6 dd53e23487da03fd02396306d248cda0
e99f33420f577ee8ce54b67080280d1e c69821bcb6a8839396f965ab6ff72a70
Block-Chaining Construction
Also known as Merkle-Damgaard hash
MAC = H (K||m1||..mn)
Encryption Decryption
plaintext ciphertext
plaintext
K encrypt(.) K decrypt(.)
ciphertext ciphertext
plaintext
Key establishment:
Chicken-and-egg problem
57
Eavesdropper??
Public Key Cryptography
58
Mallory
Chooses
random x gx
Chooses
random v gv
Chooses
random y
gy
Chooses
gw random w
Confidentiality
Integrity
Authentication
Public Key Cryptography
63
• Two keys
– Private key (sk) known only to individual
– Public key (pk) available to anyone
Alice Bob
Non-interactive:
Secure Email (PGP): Bob has Alice’s pub-key and sends
her an email
Encrypted File Systems
skA
write read
Alice
E(pkA, data)
Bob File
E(pkB, data)
Establishing a Shared Secret –
eavesdropping attacker only
Key exchange (e.g., in HTTPS)
Alice Bob
“Alice”, pk
choose random
x ∈ {0,1}128
Insecure Against Man-in-The-Middle
As described, the protocol is insecure against active attacks
“Alice”, pk
choose random
x ∈ {0,1}128
Signature: 39:10:83:2e:09:ef:ac:50:04:0a:fb:9a:f0:fa:14:58:ad:a0:81:b0:3d
7c:be:b1:82:19:b9:7c3:8:04:e9:1e5d:b5:80:af:d4:a0:81:b0:b0:68:5b:a4:a4
:ff:b5:8a:3a:a2:29:e2:6c:7c3:8:04:e9:1e5d:b5:7c3:8:04:e9:1e:5d:b5
Signatures on Certificates
73
Sigature = EncryptSK(SHA-1(certificate))
SHA-1(certificate) = DecryptPK(signature)
Certificate Chains
74
k = D(c, sk)
validate signature
choose random
pre-master key k c = E(k, pk)
k = D(c, sk)
real key = PRF(k, "master secret", ClientHello.random + ServerHello.random)
HMAC: HMAC-SHA256
Implementation: OpenSSL
Don’t Roll Your Own!!
80