Network Security
CS 6823 Lecture 5
Cryptography
Phillip Mak
[email protected]
Cryptography
Overview
Symmetric Key Cryptography
Public Key Cryptography
Message integrity and digital signatures
Cryptography basics
Cryptography is the process of converting plaintext into ciphertext.
Plaintext Readable text
Ciphertext Unreadable or encrypted text
Cryptography is used to hide information from unauthorized users
Decryption is the process of converting ciphertext back to plaintext
Cryptography requires at least two pieces of information
Encryption algorithm
Encryption key
3
History of Cryptography
Substitution Cipher
Replaces one letter with another letter based
on some key
Example: Julius Caesars Cipher
Key value of right shift 3
ABCDEFGHIJKLMNOPQRSTUVWXYZ
DEFGHIJKLMNOPQRSTUVWXYZABC
History of Cryptography (cont)
Cryptanalysis studies the process of
breaking encryption algorithms
When a new encryption algorithm is
developed; cryptanalysts study it and try to
break it.
This is an important part of the development
cycle of a new encryption algorithm
5
World War I
Zimmerman Telegram
Encrypted telegram from
foreign secretary of the
German empire to German
ambassador in Mexico
Intercepted and decrypted
by the British
Indicated that unrestricted
sub warfare would
commence. Proposed an
alliance with Mexico to
reclaim lost land to US.
Pivotal in US entering WWI
Courtesy: Wikipedia
6
World War II
Enigma
Used by the
Germans
Replaced letters as
they were typed
Substitutions were
computed using a
key and a set of
switches and rotors.
Cryptography Issues
Confidentiality: only sender, intended receiver should understand
message contents:
sender encrypts message
receiver decrypts message
Message Integrity: sender, receiver want to ensure message not
altered (in transit, or afterwards) without detection.
End-Point Authentication: send, receiver want to confirm identity of
each other.
Non-Repudiation: ensuring that the sender actually sent the
message
8
Friends and enemies: Alice, Bob, Eve
Well known in network security world
Bob, Alice want to communicate securely
Trudy (intruder) may intercept, delete, add to message
Who might Bob, Alice be?
...well, real-life Bobs and Alices!
Web browsers/server for electronic transactions
online banking client/server
DNS servers
routers exchanging routing table updates
10
The Language of Cryptography
m plaintext message
KA(m) is ciphertext, encrypted with key KA
m = KB(KA(m))
11
Simple Encryption Scheme
Substitution Cipher: substituting one thing for another
Mono-alphabetic cipher: substitute one letter for another
Plaintext: abcdefghijklmnopqrstuvwxyz
Ciphertext: mnbvcxzasdfghjklpoiuytrewq
Example:
Plaintext: bob. i love you. alice
ciphertext: nkn. s gktc wky. mgsbc
Key: The mapping from the set of 26 letters to the set of 26
letters
12
Poly-alphabetic Encryption: Vigenre
M
n monoalphabetic ciphers M , M , ...., M
1
M,
3
Cycling pattern:
e.g. n=4, M , M , M , M , M , M , M , M ,
1
For each new plaintext symbol, use subsequent
monoalphabetic pattern in a cyclic pattern.
dog: d from M , o from M , g from M
1
Key: the n ciphers and the cyclic pattern
Algorithm: Vigenre
Example:
Plaintext: NYU Row N/Column C -> P
Key: COMSEC Row Y/Column O -> M
Ciphertext: PMG Row U/Column M -> G
Figure: All possible shift ciphers
13
Vernam Perfect Substitution Cipher
If we use Vignere with keylength as long as the plaintext then
cryptanalysis will become very difficult.
If we change key every time we encrypt then cryptanalysts job
becomes even more difficult. One-time pad or Vernam Cipher.
How do we get such long keys?
A large book shared by transmitter and receiver.
Initial key followed by previous messages themselves!!
Random number sequence based on common shared and secret
seed.
Such a cipher is difficult to break but not very practical.
Also called a one time pad
14
Breaking an Encryption Scheme
Cipher-text only attack: Eve has ciphertext that she can
analyze.
Two approaches:
Search through all keys: must be able to differentiate resulting plaintext from
gibbersh
Statistical analysis
Known-plaintext attack: Eve has some plaintext
corresponding to some ciphertext.
E.g., in monoalphabetic cipher, trudy determines pairings for
a,l,i,c,e,b,o
Chosen-plaintext attack:
Eve can get the ciphertext from some chosen plaintext
15
Computational Effort Required
Time Number of primitive operations required.
Computational time required for the attack.
Some attacks become more feasible as
computing power becomes cheaper and faster.
Memory Amount of storage required to
complete the attack. This can be either hard
disk or memory.
Data Amount of captured data required to
complete the attack.
16
Rainbow Tables
Rainbow Table
Pre-computes commonly used passwords
Time/Memory Tradeoff
Used to recover the plaintext from a given HASH value.
Commonly used to attack HASHed password
Password & hash (MD5)
password
5f4dc
Each
user with the
password password will have the same hash
password
5f4dc
5f4dcc3b5aa765d61d8327deb882cf99
password
5f4dc
password123
482c8
Defense
p@ssword123
95463
Password
SALT
Hash (MD5)
Adding
a
SALT
to
each
password
p@$$word123
270db
password
3OjH1
e740b
SALT random number concatenated to
Password
gIW9E
9921a
the PASSWORD
to prevent
Password
1Hhw9
a4a16
Rainbow table attacks
password
pLRt8
C6d82
Since SALT is a random number the attacker
wouldlCwLI
have toec33b
compute
p@ssword123
a Rainbow table for each SALT value. Large
SALTEFxXk
value is952ba
critical
p@$$word123
17
Types of Cryptography
Crypto often uses keys:
Algorithm is typically known to everyone
Only keys are secret Kerckhoffs Principle Can be extended to
security systems design in general
Public Key Cryptography
Involves the use of two keys
Symmetric key cryptography
Involves the use of one key
Hash functions
Involves the use of no keys
Nothing secret: How can this be useful?
18
Shannon Characteristics of Good Ciphers
The amount of secrecy needed should determine the
amount of labor appropriate for encryption and
decryption.
The set of keys and enciphering algorithms should be
free from complexity.
The implementation of the process should be as simple
as possible.
Errors in ciphering should not propagate and cause
corruption of future information in the message.
The size of enciphered text should be no longer than
the text of the original message.
19
Confusion and Diffusion
Confusion: Changes in the key should
affect many parts in the ciphertext.
Diffusion: Changing one character in the
plaintext will result in multiple changes
throughout the ciphertext.
20
Symmetric Key Cryptography
21
Symmetric Key Cryptography
Symmetric Key crypto: Bob and Alice share
same symmetric key: Ks
22
Two Types of Symmetric Ciphers
Stream Ciphers
Encrypt one bit at a time
Block Ciphers
Break plaintext message into equal-size blocks
Encrypt each block as a unit
23
Stream Ciphers:
Combine each bit of keystream with bit of plaintext to get bit of
ciphertext
m(i) = ith bit of message
ks(i) = ith bit of keystream
c(i) = ith bit of ciphertext
c(i) = ks(i) m(i) ( = exclusive or)
m(i) = ks(i) c(i)
24
Problems With Stream Ciphers
Known plain-text attack
Theres often predictable
and repetitive data in
communication messages
attacker receives some
cipher text c and correctly
guesses corresponding
plaintext m
ks = m c
Attacker now observes c,
obtained with same
sequence ks
m = ks c
Even easier
Attacker obtains two
ciphertexts, c and c,
generating with same key
sequence
c c = m m
There are well known
methods for decrypting two
plaintexts given their XOR
Integrity problem too
suppose attacker knows c
and m (eg, plaintext
attack);
wants to change m to m
calculates c = c (m
m)
25
RC4 Stream Cipher
RC4 is a popular stream cipher
Extensively analyzed and considered good
Key can be from 1 to 256 bytes
Used in WEP for 802.11
Can be used in SSL
26
Block Ciphers
Message to be encrypted is processed in blocks of k
bits (e.g., 64-bit blocks).
1-to-1 mapping is used to map k-bit block of plaintext
to k-bit block of ciphertext
Example with k=3
inputoutput
000110
001111
010101
011100
inputoutput
100011
101010
110000
111001
What is the ciphertext for 010110001111 ?
27
Block Ciphers
How many possible mappings are there for k=3?
How many 3-bit inputs?
How many permutations of the 3-bit inputs?
Answer: 23! = 40,320 ; not very many!
In general, 2k! mappings; huge for k=64
Problem:
Table approach requires table with 264 entries, each entry with 64
bits
Table too big: instead use function that simulates a randomly
permuted table
28
Prototype Function
64-bit input
8bits
8bits
8bits
8bits
8bits
8bits
8bits
8bits
S1
S2
S3
S4
S5
S6
S7
S8
8 bits
8 bits
8 bits
8 bits
8 bits
8 bits
8 bits
8 bits
Substitution
table
64-bit intermediate
Loop for
n rounds
64-bit output
29
From
Kaufman
et al
Why Rounds in Prototype?
If only a single round, then one bit of input
affects at most 8 bits of output.
In 2nd round, the 8 affected bits get scattered
and inputted into multiple substitution boxes.
How many rounds?
How many times do you need to shuffle cards?
Becomes less efficient as n increases
30
Encrypting a Large Message
Why not just break message in 64-bit blocks, encrypt
each block separately?
If same block of plaintext appears twice, will give same
cyphertext.
How about:
Generate random 64-bit number r(i) for each plaintext
block m(i)
Calculate c(i) = KS( m(i) r(i) )
Transmit c(i), r(i), i=1,2,
At receiver: m(i) = KS(c(i)) r(i)
Problem: inefficient, need to send c(i) and r(i)
31
Cipher Block Chaining (CBC)
CBC generates its own random numbers
Have encryption of current block depend on result of previous
block
c(i) = KS( m(i) c(i-1) )
m(i) = KS( c(i)) c(i-1)
How do we encrypt first block?
Initialization vector (IV): random block = c(0)
IV does not have to be secret
Change IV for each message (or session)
Guarantees that even if the same message is sent repeatedly, the
ciphertext will be completely different each time
32
Cipher Block Chaining (CBC)
33
Symmetric Key Crypto: DES
DES: Data Encryption Standard
US encryption standard [NIST 1993]
56-bit symmetric key, 64-bit plaintext input
Block cipher with cipher block chaining
How secure is DES?
DES Challenge: 56-bit-key-encrypted phrase decrypted
(brute force) in less than a day
1998: EFFs $250k machine- 1,800 custom chips
No known good analytic attack making DES more secure:
3DES: encrypt/decrypt 3 times with 3 different keys
ciphertext = EK3(DK2(EK1(plaintext)))
34
Symmetric Key Crypto: DES
DES Operation:
initial permutation
16 identical rounds of function
application, each using different
48 bits of key
Final permutation
35
Advanced Encryption Standard
Newest (Nov. 2001) symmetric-key NIST standard, replacing
DES
Processes data in 128 bit blocks
128, 192, or 256 bit keys
Brute force decryption (try each key) takes 10 billion years for
AES
Based on the current fastest supercomputer 33.86 petaFLOPS (10 15
FLOPS)
Not adjusted for technological advancements
36
Public Key Cryptography
37
Public Key Cryptography
Issues Symmetric Key
Cryptography
Requires Sender and
Receiver know shared
key
Q: How do we agree
on the key in the first
place?
Secretly sharing keys
is extremely difficult
problem
Public Key
Cryptography
(Asymmetric)
radically different
approach [DiffieHellman76, RSA78]
sender, receiver do
not share secret key
public encryption key
known to all
private decryption key
known only to receiver
38
Public Key Cryptography
39
Public Key Encryption Algorithms:
Requirements:
need K and K such that:
-
- +
K (K (m)) = m
B B
+
Given public key K , it should be impossible to compute
private key K
B
RSA: Rivest, Shamir, Adelson algorithm
40
Prereq: Modular Arithmetic
x mod n = remainder of x when divide by n
Facts:
(a+b) mod n = [(a mod n) + (b mod n)] mod n
(a-b) mod n = [(a mod n) - (b mod n)] mod n
(a*b) mod n = [(a mod n) * (b mod n)] mod n
(a*b*c)mod n = [(a mod n)(b mod n)(c mod n)] mod n
Review worked examples:
https://www.khanacademy.org/math/appl
iedmath/cryptography/modarithmetic/a/fast
-modular-exponentiation
41
RSA: Getting Ready
A message is a bit pattern.
A bit pattern can be uniquely represented by an
integer number.
Thus encrypting a message is equivalent to
encrypting a number.
Example
m= 10010001 . This message is uniquely represented
by the decimal number 145.
To encrypt m, we encrypt the corresponding number,
which gives a new number (the ciphertext).
42
RSA: Creating Public/Private Keypair
1. Choose two large prime numbers p, q.
(e.g., 1024 bits each)
2. Compute n = pq, = (p-1)(q-1)
3. Choose e (with e< ) that has no common factors
with . (e, are relatively prime).
4. Choose d such that ed-1 is exactly divisible by .
(in other words: ed mod = 1 ; or d = e-1 mod )
KB
5. Public key is (n,e). Private key is (n,d).
-
KB
43
RSA: Encryption and Decryption
0. Given (n,e) and (n,d) as computed
above
1. To encrypt message m (<n),
compute
c = me mod
n
2. To decrypt received bit pattern, c,
computed
m = c mod
n
d
e
m = (m mod n)
mod n
44
RSA Example
Bob chooses p=5, q=7. Then n=35, =24.
e=5 (so e, relatively prime).
d=29 (so ed-1 exactly divisible by ).
Encrypting 8-bit messages.
encrypt:
decrypt:
bit pattern
e
m
0000lI00
12
248832
c
17
481968572106750915091411825223071697
e
c = m mod n
17
d
m = c mod n
12
45
RSA: Another Important Property
The following property will be very useful
later:
-
K (K (m))
B B
+ = m= K (K (m))
B B
use public key
first, followed
by private key
use private key
first, followed
by public key
Result is the same!
46
Why is RSA Secure?
Suppose you know Bobs public key (n,e). How hard
is it to determine d?
Essentially need to find factors of n without knowing
the two factors p and q.
Fact: factoring a big number is hard.
= (p-1)(q-1)
Hard to find p, q, when given n, e
Generating RSA Keys
Have to find big primes p and q
Approach: make good guess then apply testing rules
Typical key size is 2048-bits
47
Problems with RSA
Slow to generate keys e, d even by
todays CPU power
Does not have Perfect Forward
Security
But its free from licensing concerns
48
Session Keys
Exponentiation is computationally intensive
DES is at least 100 times faster than RSA
Session key, KS
Bob and Alice use RSA to exchange a symmetric
key KS
Once both have KS, they use symmetric key
cryptography
49
Diffie-Hellman
Allows two entities to agree on shared key.
But does not provide encryption
n is a large prime; g is a number less than n.
n and g are made public
a, g, n
a
A=g mod
n a
K=B mod
n
b
g, n, A
B
B=g mod
n
b
K=A mod
n
50
Diffie-Hellman (cont)
Alice and Bob agree to use a prime number n=23 and
base g=5.
Alice chooses a secret integer a=6, then sends Bob A =
ga mod n
A = 56 mod 23 = 8.
Bob chooses a secret integer b=15, then sends Alice B
= gb mod n
B = 515 mod 23 = 19.
Alice computes s = Ba mod n
196 mod 23 = 2.
Bob computes s = Ab mod n
815 mod 23 = 2.
51
Message Integrity and
Digital Signatures
52
Message Integrity
Allows communicating parties to verify that
received messages are authentic.
Content of message has not been altered
Source of message is who/what you think it is
Message has not been artificially delayed
(playback attack)
Sequence of messages is maintained
Lets first talk about message digests
53
Encryption vs. Hashing
PlainText
Encryption( )
Message
CipherText
o
r
Decryption( )
Encryption keeps
communications private
Encryption and decryption
can
use same or different keys
Achieved by various
algorithms,
e.g. DES, CAST
Need key management
Hash
Message Digest
Hash transforms message into
fixed-size string
One-way hash function
Strongly collision-free hash
Message digest can be viewed
as digital fingerprint
Used for message integrity
check and digital certificates
Hash is generally faster than
encryption
Message Digests
Function H( ) that takes as input
an arbitrary length message and
outputs a fixed-length string:
message signature
Note that H( ) is a many-to-1
function
Desirable properties:
H( ) is often called a hash
Easy to calculate
function
Irreversibility
Collision resistance:
Computationally difficult
to produce m and m
such that H(m) = H(m)
Seemingly random output
55
Hash Function Algorithms
MD5 hash function widely used (RFC 1321)
computes 128-bit message digest in 4-step
process.
SHA-1 is also used.
US standard [NIST, FIPS PUB 180-1]
160-bit message digest
kobrienlaptop:~kobrien$echo"test"|md5sum
d8e8fca2dc0f896fd7cb4cb0031ba249
kobrienlaptop:~kobrien$echo"test"|md5sum
d8e8fca2dc0f896fd7cb4cb0031ba249
kobrienlaptop:~kobrien$echo"test1"|md5sum
3e7705498e8be60520841409ebc69bc1
kobrienlaptop:~kobrien$echo"test1"|md5sum
3e7705498e8be60520841409ebc69bc1
56
Commonly Used Hash Functions
(MD5 and SHA)
Both MD5 and SHA are derived based on MD4
MD5 provides 128-bit output, SHA provide 160-bit output,
(only first 96 bits used in IPSec)
Both of MD5 and SHA are considered one-way strongly
collision-free hash functions
SHA is computationally slower than MD5, but more secure
MD5, SHA1 not collision resistant
Relevance to non-repudiation, commitment
So What Does This Mean?
SHA1 is still much safer than MD5
Best known attack has effort > 2^64
HMAC SHA1 (keyed SHA1) believed to be
unaffected by current attacks
Industry making a move towards SHA256
and other secure crypto methods
Actual transition will take place within
standard groups first
IETF and NIST among others addressing this issue
Birthday Attack
If 23 people are in the room, what is the
chance that they all have different birthdays?
365 364 363 362 361 360
343
x
x
x
x
x
x...
365 365 365 365 365 365
365
= 49%
So theres a 51% chance that two of them
have the same birthday
59
Birthday Attack (Cont)
If there are N possible hash values,
Youll find collisions when you have calculated
1.2 x sqrt(N) values
SHA-1 uses a 160-bit key
Theoretically, it would require 280
computations to break
SHA-1 has already been broken, because of
other weaknesses
60
Security Level of Crypto Algorithms
Security Level
Work Factor
Algorithms
Weak
O(240)
DES, MD5
Legacy
O(264)
RC4, SHA1
Minimum
O(280)
3DES, SEAL, SKIPJACK
Standard
O(2128)
AES-128, SHA-256
High
O(2192)
AES-192, SHA-384
Ultra
O(2256)
AES-256, SHA-512
Hash-Based Message Authentication Code (HMAC)
Authenticates sender
Verifies message integrity
No encryption!
Also called keyed hash
62
End Point Authentication
Want to be sure of the originator of the
message end-point authentication.
Assuming Alice and Bob have a shared
secret, will MAC provide message
authentication.
We do know that Alice created the message.
But did she send it?
63
Playback Attack
Bob cannot distinguish between the original
communication and the later playback
Problem is that the shared secret is used over and over
64
Defending Against Playback Attack: Nonce
1) Alice sends the message, I
am Alice, to Bob
2) Bob chooses a nonce, R,
and sends it to Alice
3) Alice encrypts the nonce
using Alice and Bob's
symmetric secret key, KA-B,
and sends the encrypted
nonce, KA-B (R) back to
Bob.
A nonce is a number that a protocol will only ever use
once-in-a-lifetime
65
Nonce (cont)
It is the fact that Alice knows KA-B and
uses it to encrypt a value that lets Bob
know that the message he receives was
generated by Alice.
The nonce is used to ensure that Alice is
"live." Bob decrypts the received
message. If the decrypted nonce equals
the nonce he sent Alice, then Alice is
authenticated.
66