Crypto Summary
Crypto Summary
.y
. x’.
x’’ . y’
bit strings of any length n-bit strings
slide 7
Hashing vs. Encryption
◆ Hashing is one-way. There is no “uh-hashing”!
• A ciphertext can be decrypted with a decryption key…
hashes have no equivalent of “decryption”
◆ Hash(x) looks “random”, but can be compared
for equality with Hash(x’)
• Hash the same input twice → same hash value
• Encrypt the same input twice → different ciphertexts
◆ Cryptographic hashes are also known as
“cryptographic checksums” or “message
digests”
slide 8
Application: Password Hashing
◆ Instead of user password, store hash(password)
◆ When user enters a password, compute its hash
and compare with the entry in the password file
• System does not store actual passwords!
• Cannot go from hash to password!
◆ Why is hashing better than encryption here?
◆ Does hashing protect weak, easily guessable
passwords?
slide 9
Application: Software Integrity
VIRUS
badFile
goodFile
The Times
BigFirm™ hash(goodFile) User
slide 12
Overview of MD5
◆ Designed in 1991 by Ron Rivest
◆ Iterative design using compression function
M1 M2 M3 M4
IHV0
IHV4
slide 13
History of MD5 Collisions
◆ 2004: first collision attack
• The only difference between colliding messages is
128 random-looking bytes
◆ 2007: chosen-prefix collisions
• For any prefix, can find colliding messages that have
this prefix and differ up to 716 random-looking bytes
◆ 2008: rogue SSL certificates
• Talk about this in more detail when discussing PKI
◆ 2012: MD5 collisions used in cyberwarfare
• Flame malware uses an MD5 prefix collision to fake a
Microsoft digital code signature
slide 14
Basic Structure of SHA-1
Against padding attacks
A B C D E
5 bitwise
• B⊕C⊕D 60..79
+
left-rotate
Current message block mixed in
• For steps 0..15, W0..15=message block Wt
Multi-level shifting of message blocks
• For steps 16..79,
Wt=Wt-16⊕Wt-14⊕Wt-8⊕Wt-3 +
Special constant added
30 bitwise
left-rotate (same value in each 20-step round, Kt
4 different constants altogether)
+
A B C D E
slide 17
How Strong Is SHA-1?
◆ Every bit of output depends on every bit of input
• Very important property for collision-resistance
◆ Brute-force inversion requires 2160 ops, birthday
attack on collision resistance requires 280 ops
◆ Weaknesses discovered in 2005
• Collisions can be found in 263 ops
◆ Researchers at Google/CWI demonstrated first
collision attack in 2017
slide 18
NIST Competition
◆ A public competition to develop a new
cryptographic hash algorithm
• Organized by NIST (read: NSA)
◆ 64 entries into the competition (Oct 2008)
◆ 5 finalists in 3rd round (Dec 2010)
◆ Winner: Keccak (Oct 2012)
• standardized as SHA-3
slide 19
Integrity and Authentication
KEY MAC
(message authentication code) KEY
message, MAC(KEY,message)
?
message =
Alice Bob
Recomputes MAC and verifies whether it is
equal to the MAC attached to the message
slide 21
Structure of HMAC
magic value (flips half of key bits)
hash(key,hash(key,message))
slide 22
Overview of Symmetric Encryption
Basic Problem
-----
-----
-----
?
slide 26
One-Time Pad (Vernam Cipher)
-----
----- 10111101…
----- = 10111101…
⊕ 10001111… ⊕
= 00110010… 00110010… =
slide 29
No Integrity
0
-----
----- 10111101…
----- = 10111101… 0
⊕ 10001111… ⊕
= 00110010… 00110010… =
slide 30
Dangers of Reuse
----- P1
----- C1 00000000…
----- = 00000000…
⊕ 00110010… ⊕
= 00110010… 00110010… =
----- P2
----- C2
----- = 11111111…
⊕ 11001101…
= 00110010…
slide 32
Block Ciphers
◆ Operates on a single chunk (“block”) of plaintext
• For example, 64 bits for DES, 128 bits for AES
• Same key is reused for each block (can use short keys)
◆ Result should look like a random permutation
◆ Not impossible to break, just very expensive
• If there is no more efficient algorithm (unproven
assumption!), can only break the cipher by brute-force,
try-every-possible-key search
• Time and cost of breaking the cipher exceed the value
and/or useful lifetime of protected information
slide 33
Permutation
1 1
2 2
3 3
4 4
CODE becomes DCEO
slide 38
Basic Structure of Rijndael
128-bit plaintext 128-bit key
(arranged as 4x4 array of 8-bit bytes)
⊕
S shuffle the array (16x16 substitution table)
slide 40
ECB Mode
plaintext
ciphertext
slide 42
Adobe Passwords Stolen (2013)
◆ 153 million account passwords
• 56 million of them unique
◆ Encrypted using 3DES in ECB mode rather than
hashed
Password hints
slide 43
CBC Mode: Encryption
plaintext
Initialization
vector
(random) ⊕ key ⊕ key ⊕ key ⊕ key
block block block block
Sent with ciphertext cipher cipher cipher cipher
(preferably encrypted)
ciphertext
Initialization
vector ⊕ key ⊕ key ⊕ key ⊕ key
decrypt decrypt decrypt decrypt
ciphertext
slide 45
ECB vs. CBC
[Picture due to Bart Preneel]
Similar plaintext
blocks produce
similar ciphertext
blocks (not good!)
slide 46
Choosing the Initialization Vector
◆ Key used only once
• No IV needed (can use IV=0)
◆ Key used multiple times
• Best: fresh, random IV for every message
• Can also use unique IV (eg, counter), but then the first
step in CBC mode must be IV’ ← E(k, IV)
– Example: Windows BitLocker
– May not need to transmit IV with the ciphertext
◆ Multi-use key, unique messages
• Synthetic IV: IV ← F(k’, message)
– F is a cryptographically secure keyed pseudorandom function
slide 47
CBC and Electronic Voting
[Kohno, Stubblefield, Rubin, Wallach]
plaintext
Initialization
vector ⊕ key ⊕ key ⊕ key ⊕ key
(supposed to
be random)
DES DES DES DES
ciphertext
Found in the source code for Diebold voting machines:
DesCBCEncrypt((des_c_block*)tmp, (des_c_block*)record.m_Data,
totalSize, DESKEY, NULL, DES_ENCRYPT)
slide 48
CTR (Counter Mode)
plaintext
Random IV
IV
ciphertext
slide 50
How Can a Cipher Be Attacked?
◆ Attackers knows ciphertext and encryption algthm
• What else does the attacker know? Depends on the
application in which the cipher is used!
◆ Known-plaintext attack (stronger)
• Knows some plaintext-ciphertext pairs
◆ Chosen-plaintext attack (even stronger)
• Can obtain ciphertext for any plaintext of his choice
◆ Chosen-ciphertext attack (very strong)
• Can decrypt any ciphertext except the target
• Sometimes very realistic
slide 51
Known-Plaintext Attack
[From “The Art of Intrusion”]
cipher(key,PIN)
Crook #2 eavesdrops
Crook #1 changes on the wire and learns
his PIN to a number ciphertext corresponding
of his choice to chosen plaintext PIN
slide 54
The Chosen-Plaintext Game
◆ Attacker does not know the key
◆ He chooses as many plaintexts as he wants, and
receives the corresponding ciphertexts
◆ When ready, he picks two plaintexts M0 and M1
• He is even allowed to pick plaintexts for which he
previously learned ciphertexts!
◆ He receives either a ciphertext of M0, or a
ciphertext of M1
◆ He wins if he guesses correctly which one it is
slide 55
Meaning of “Leaks No Information”
◆ Idea: given a ciphertext, attacker should not be
able to learn even a single bit of useful
information about the plaintext
◆ Let Enc(M0,M1,b) be a “magic box” that returns
encrypted Mb 0 or 1
• Given two plaintexts, the box always returns the
ciphertext of the left plaintext or right plaintext
• Attacker can use this box to obtain the ciphertext of
any plaintext M by submitting M0=M1=M, or he can try
to learn even more by submitting M0≠M1
◆ Attacker’s goal is to learn just this one bit b
slide 56
Chosen-Plaintext Security
◆ Consider two experiments (A is the attacker)
Experiment 0 Experiment 1
A interacts with Enc(-,-,0) A interacts with Enc(-,-,1)
and outputs his guess of bit b and outputs his guess of bit b
• Identical except for the value of the secret bit
• b is attacker’s guess of the secret bit
◆ Attacker’s advantage is defined as
| Prob(A outputs 1 in Exp0) - Prob(A outputs 1 in Exp1)) |
◆ Encryption scheme is chosen-plaintext secure if
this advantage is negligible for any efficient A
slide 57
Simple Example
◆ Any deterministic, stateless symmetric encryption
scheme is insecure
• Attacker can easily distinguish encryptions of different
plaintexts from encryptions of identical plaintexts
• This includes ECB mode of common block ciphers!
Attacker A interacts with Enc(-,-,b)
Let X,Y be any two different plaintexts
C1 ← Enc(X,X,b); C2 ← Enc(X,Y,b);
If C1=C2 then b=0 else b=1
msg Decrypt
encrypt(msg), MAC(msg)
encrypt(msg2), MAC(msg2)
?
=
Alice Encrypt(K1,msg) Bob
Verify MAC
Overview of
Public-Key Cryptography
slide 60
Public-Key Cryptography
public key
Alice
Bob
Given: Everybody knows Bob’s public key
- How is this achieved in practice?
Only Bob knows the corresponding private key
Goals: 1. Alice wants to send a message that
only Bob can read
2. Bob wants to send a message that
only Bob could have written slide 61
Applications of Public-Key Crypto
◆ Encryption for confidentiality
• Anyone can encrypt a message
– With symmetric crypto, must know the secret key to encrypt
• Only someone who knows the private key can decrypt
• Secret keys are only stored in one place
◆ Digital signatures for authentication
• Only someone who knows the private key can sign
◆ Session key establishment
• Exchange messages to create a secret session key
• Then switch to symmetric cryptography (why?)
slide 62
Public-Key Encryption
◆ Key generation: computationally easy to generate
a pair (public key PK, private key SK)
◆ Encryption: given plaintext M and public key PK,
easy to compute ciphertext C=EPK(M)
◆ Decryption: given ciphertext C=EPK(M) and private
key SK, easy to compute plaintext M
• Infeasible to learn anything about M from C without SK
• Trapdoor function: Decrypt(SK,Encrypt(PK,M))=M
slide 63
Some Number Theory Facts
◆ Euler totient function ϕ(n) where n≥1 is the
number of integers in the [1,n] interval that are
relatively prime to n
• Two numbers are relatively prime if their
greatest common divisor (gcd) is 1
◆ Euler’s theorem:
if a∈Zn*, then aϕ(n) ≡ 1 mod n
◆ Special case: Fermat’s Little Theorem
if p is prime and gcd(a,p)=1, then ap-1 ≡ 1 mod p
slide 64
RSA Cryptosystem
◆ Key generation:
[Rivest, Shamir, Adleman 1977]
• Generate large primes p, q
– At least 2048 bits each… need primality testing!
• Compute n=pq
– Note that ϕ(n)=(p-1)(q-1)
• Choose small e, relatively prime to ϕ(n)
– Typically, e=3 (may be vulnerable) or e=216+1=65537 (why?)
• Compute unique d such that ed ≡ 1 mod ϕ(n)
• Public key = (e,n); private key = d
◆ Encryption of m: c = me mod n
◆ Decryption of c: cd mod n = (me)d mod n = m
slide 65
Why RSA Decryption Works
◆ e⋅d ≡ 1 mod ϕ(n)
◆ Thus e⋅d = 1+k⋅ϕ(n) = 1+k(p-1)(q-1) for some k
◆ If gcd(m,p)=1, then by Fermat’s Little Theorem,
mp-1 ≡ 1 mod p
◆ Raise both sides to the power k(q-1) and multiply
by m, obtaining m1+k(p-1)(q-1) ≡ m mod p
◆ Thus med ≡ m mod p
◆ By the same argument, med ≡ m mod q
◆ Since p and q are distinct primes and p⋅q=n,
med ≡ m mod n
slide 66
Why Is RSA Secure?
◆ RSA problem: given c, n=pq, and
e such that gcd(e,(p-1)(q-1))=1,
find m such that me=c mod n
• In other words, recover m from ciphertext c and public
key (n,e) by taking eth root of c modulo n
• There is no known efficient algorithm for doing this
◆ Factoring problem: given positive integer n, find
primes p1, …, pk such that n=p1e1p2e2…pkek
◆ If factoring is easy, then RSA problem is easy, but
may be possible to break RSA without factoring n
slide 67
“Textbook” RSA Is Bad Encryption
◆ Deterministic
• Attacker can guess plaintext, compute ciphertext, and
compare for equality
• If messages are from a small set (for example, yes/no),
can build a table of corresponding ciphertexts
◆ Can tamper with encrypted messages
• Take an encrypted auction bid c and submit
c(101/100)e mod n instead
◆ Does not provide semantic security (security
against chosen-plaintext attacks)
slide 68
Integrity in RSA Encryption
◆ “Textbook” RSA does not provide integrity
• Given encryptions of m1 and m2, attacker can create
encryption of m1⋅m2
– (m1e) ⋅ (m2e) mod n ≡ (m1⋅m2)e mod n
• Attacker can convert m into mk without decrypting
– (me)k mod n ≡ (mk)e mod n
◆ In practice, OAEP is used: instead of encrypting
M, encrypt M⊕G(r) ; r⊕H(M⊕G(r))
• r is random and fresh, G and H are hash functions
• Resulting encryption is plaintext-aware: infeasible to
compute a valid encryption without knowing plaintext
– … if hash functions are “good” and RSA problem is hard slide 69
Digital Signatures: Basic Idea
public key
Alice Bob
slide 71
Diffie-Hellman Protocol
◆ Alice and Bob never met and share no secrets
◆ Public info: p and g
• p is a large prime number, g is a generator of Zp*
– Zp*={1, 2 … p-1}; ∀a∈Zp* ∃i such that a=gi mod p
gy mod p
Alice Bob
slide 74
Advantages of Public-Key Crypto
◆ Confidentiality without shared secrets
• Very useful in open environments
• Can use this for key establishment, avoiding the
“chicken-or-egg” problem
– With symmetric crypto, two parties must share a secret before
they can exchange secret messages
◆ Authentication without shared secrets
◆ Encryption keys are public, but must be sure that
Alice’s public key is really her public key
• This is a hard problem… Often solved using public-key
certificates
slide 75
Disadvantages of Public-Key Crypto
◆ Calculations are 2-3 orders of magnitude slower
• Modular exponentiation is an expensive computation
• Typical usage: use public-key cryptography to establish
a shared secret, then switch to symmetric crypto
– SSL, IPsec, most other systems based on public crypto
◆ Keys are longer
• 2048 bits (RSA) rather than 128 bits (AES)
◆ Relies on unproven number-theoretic assumptions
• Factoring, RSA problem, discrete logarithm problem,
decisional Diffie-Hellman problem…
slide 76