Crypto Basics
Crypto Basics
1
Information Security
• Computer security
• Protect system resources
• Protect data (dynamic/stored)
• Network security
• Protect network resources
• Protect exchanged data
Security = confidentiality + integrity + availability +
authenticity
2
Network Security Services
• Authentication
• validate authenticity claims (identity/data)
• Authorization
• Enforce selective access (information/resources)
• Confidentiality
• Prevent disclosure of data (entire message/selected
fields/traffic characteristics)
• Integrity
• Prevent tampering of data (entire message/selected fields)
• Non-repudiation
• Proof of origin, proof of delivery
CIA
3
Topics of Discussion
• Conventional Cryptography
• DES
• 2DES, 3DES
• AES
• Stream Ciphers
• Sychronous
• Asynchronous
• A5
• RC4
• Public-key cryptography
• Diffie-Hellman
• RSA
• ECC
• Key distribution
4
Topics (Cont’d)
• Data Protection
• Hash functions
• Mac functions
• Digital Signatures
• Cryptanalysis
• Linear
• Differential
• Side-Channel Attacks
5
Terminology
• Cryptology The art and science of making and
breaking “secret codes”
• Cryptography making “secret codes”
• Cryptanalysis breaking “secret codes”
• Crypto all of the above (and more)
6
Crypto
• Basis assumption
• The system is completely known to the attacker
• Only the key is secret
• Also known as Kerckhoffs Principle
• Crypto algorithms are not secret
• Why do we make this assumption?
• Experience has shown that secret algorithms are weak
when exposed
• Secret algorithms never remain secret
• Better to find weaknesses beforehand
7
Early Crypto Algorithms
• Caesar Cipher
• Mixed Alphabet
• Playfair Cipher
• One-time Pad
• Code book
8
One-time Pad Encryption
e=000 h=001 i=010 k=011 l=100 r=101 s=110 t=111
h e i l h i t l e r
Plaintext:
001 000 010 100 001 010 111 100 000 101
Key:
111 101 110 101 111 100 000 101 110 000
Ciphertext: 110 101 100 001 110 110 111 001 110 101
s r l h s s t h s r
9
One-time Pad Decryption
s r l h s s t h s r
110 101 100 001 110 110 111 001 110 101
111 101 110 101 111 100 000 101 110 000
001 000 010 100 001 010 111 100 000 101
h e i l h i t l e r
10
Post-WWII History
11
Claude Shannon
12
Cryptanalysis
• Ciphertext only
• Known plaintext
• Chosen plaintext
• “Lunchtime attack”
• Protocols might encrypt chosen text
• Adaptively chosen plaintext
• Related key
• Forward search (public key crypto only)
• Etc., etc.
13
Modern Symmetric
Encryption Standards
DES, AES
14
Block Cipher
• Plaintext and ciphertext consists of fixed sized blocks
• Ciphertext obtained from plaintext by iterating a
round function
• Input to round function consists of key and the output
of previous round
• Usually implemented in software
15
Data Encryption Standard
16
DES Numerology
17
Security of DES
18
Triple DES
• 3DES with 3 keys
19
Block Cipher Modes
20
Modes of Operation
• Block ciphers encrypt fixed size blocks
• Need ways to encrypt arbitrary amount of information
• Four were defined for DES in ANSI standard ANSI
X3.106-1983 Modes of Use
• Electronic Code Book (ECB)
• Cipher Block Chaining (CBC)
• Cipher Feed Back (CFB)
• Output Feed Back (OFB)
• Counter Mode (CTR)
21
Advanced Encryption Standard
AES
22
Origins of AES
23
Origins of AES (Cont’d)
• In 1997, NIST issued a CFP for AES
• security strength >= 3DES
• improved efficiency
• must be a symmetric block cipher (128-bit)
• key lengths of 128, 192, and 256 bits
24
The AES Cipher
25
Key/Block Size
Number of rounds 10 12 14
26
Modern Stream Ciphers
27
Block vs. Stream
• Block ciphers
• Process plaintext in relatively large blocks
• The same function is used to encrypt successive blocks
• Memory-less
• Stream ciphers
• Process plaintext in small blocks
• Encryption function may vary as plaintext is processed
• Have memory
• Sometimes called state ciphers since encryption
depends on not only the key and plaintext, but also on
the current state.
28
Pseudo Random Generators
• Compromise to computationally secure
• Instead of random, use pseudo random sequence based
on a short key
• the generated stream must be:
• statistically random (knowing part of seq not enough)
– PRG may be controlled without using data:
• Counter mode
– PRG may be controlled by data:
•
Cipher feedback mode
29
Synchronous Stream Ciphers
• Keystream generated independently of plaintext and of ciphertext
si mi si ci
si+1 si+1
f f
zi zi
k g h ci k g h-1
30
Self-synchronizing Ciphers
• Key-stream generated as a function of the key and a
fixed number of previous ciphertext digits
…
mi
zi
k g h ci
31
Linear Feedback Shift Registers
• LFSRS
• Well-suited to hardware implementation
• Can produce sequences of large period
• Can produce sequences with good statistical properties
c1 c2 Cl
32
A5 Algorithm
33
A5/1
Y y0 y1 y2 y3 y4 y5 y6 y7 y8 y9 y10 y11 y12 y13 y14 y15 y16 y17 y18 y19 y20 y21
Z z0 z1 z2 z3 z4 z5 z6 z7 z8 z9 z10 z11 z12 z13 z14 z15 z16 z17 z18 z19 z20 z21 z22
• Each value is a single bit
• Key is used as initial fill of registers
• Each register steps or not, based on (x8, y10, z10)
• Keystream bit is XOR of right bits of registers
34
RC4
• Proprietary cipher owned by RSA
• Variable key size, byte-oriented stream cipher
• Widely used (web SSL/TLS, wireless WEP)
• Key forms random permutation of all 8-bit values
• Uses that permutation to scramble input info
processed one byte at a time
35
RC4 Key Schedule
• Starts with an array S of numbers: 0..255
• S forms internal state of the cipher
• given a key k of length l bytes
for i = 0 to 255 do
S[i] = i
j = 0
for i = 0 to 255 do
j = (j + S[i] + k[i mod l]) (mod 256)
swap (S[i], S[j])
36
Stream Generation
• Encryption continues shuffling array values
i = j = 0
for each message byte Mi
i = (i + 1) (mod 256)
j = (j + S[i]) (mod 256)
swap(S[i], S[j])
t = (S[i] + S[j]) (mod 256)
Ci = Mi XOR S[t]
37
WEP Encryption
• Key length = 40. IV length = 24
Message CRC
XOR
Keystream = RC(IV,k)
IV Cipher Text
38
Public-Key Cryptography
Asymmetric Encryption
39
Public-Key Cryptography
• Involves the use of two keys:
• A public-key, which may be known by anybody, and can be
used to encrypt messages, and verify signatures
• A private-key, known only to the recipient, used to decrypt
messages, and sign (create) signatures
• Asymmetric, parties are not equal
• Clever application of number theory
• Single most significant advance in the 3000 year history of
cryptography
40
Basic Principle
41
Merkle's Puzzles
• One of the first public-key systems to be described
• Idea
• A selects 1 million keys and 1 million puzzles to encode with them
• Sends to B, 1 million encoded puzzles
• B selects a random puzzle and brute force it to get the key (takes
almost 2 minutes)
• Encrypt a string with the key and send to A
• A encrypts the string with million keys to find which key B selected
• What is the complexity for the eavesdropper?
42
Diffie-Hellman Key Exchange
• Public information:
p is a prime number
g is a generating element of Zp
• Alice’s
• Private Key : a
• Public Key : ga mod p
• Bob’s
• Private Key : b
• Public Key : gb mod p
43
DH Key Exchange
• Key Exchange:
• Alice obtains gb and computes
(gb)a = gab mod p = ks
• Bob obtains ga and computes
(ga)b = gab mod p = ks
Alice and Bob have agreed upon key ks
• The well-known man-in-the-middle attack exploits the lack of
authentication
44
RSA Scheme
• Best known and widely regarded as most practical public-key scheme
• Proposed by Rivest, Shamir & Adleman (RSA) in 1977
• Based on exponentiation in a finite (Galois) field over integers modulo
a prime
• Security relies on the difficulty of calculating factors of large numbers
45
RSA Setup
46
RSA
47
Simple RSA Example
• Example of RSA
• Select “large” primes p = 11, q = 3
• Then N = pq = 33 and (p1)(q1) = 20
• Choose e = 3 (relatively prime to 20)
• Find d such that ed = 1 mod 20, we find that d = 7
works
• Public key: (N, e) = (33, 3)
• Private key: d = 7
• Suppose message M = 8
• Ciphertext C is computed as
C = Me mod N = 83 = 512 = 17 mod 33
• Decrypt C to recover the message M by
M = Cd mod N = 177 = 410,338,673
= 12,434,505 33 + 8 = 8 mod 33
48
Security of RSA
• Brute force
• Trying all possible private keys
• Mathematical attacks
• Equivalent to factoring product of two primes
• Timing attacks
• Based on the running time of the decryption algorithm
• Cube-root attack
• Blinding attack
49
Elliptic Curve Crypto (ECC)
• “Elliptic curve” is not a cryptosystem
• Elliptic curves are a different way to do the math in public key system
• Elliptic curve versions of DH, RSA, etc.
• Elliptic curves may be more efficient
• Fewer bits needed for same security
• But the operations are more complex
50
Key Distribution
51
Where to Put Encryption
• Link encryption vs. end-to-end
• Both techniques hide user data (payload)
• Link encryption
• Hides address information
• Buffers clear data in each node
• E-T-E encryption
• Leaves addresses in the clear
• No need to buffer decrypted payload
• Use both techniques?
52
Key Distribution
• Most important component in secure transmission.
• Options: (between A and B).
• A selects a key and physically delivers it to B.
• A trusted third party key distribution center (KDC) selects
a key and physically delivers it to A and B.
• If A and B already have have a viable key, it can be used
to distribute a new key.
• If A and B have a secure link to KDC, can receive the key
through that channel.
53
Public-Key Authority
Public-key (4) Request|T2
authority
(5) EKd_auth[Ke_a|Request|T2]
(1) Request|T1
(2) EKd_auth[Ke_b|Request|T1]
A (6) EKe_a[N1|N2]
B
(7) EKe_b[N2]
54
Exchange of Public-key Certificates
Certificate
Authority Ke_b
(1) CA
A (2) CB
B
55
Distribution With Confidentiality and Authentication
(1) EKu_b[N1|IDA]
(4) EKu_b[EKr_a[Ks]]
56
Message Authentication
MAC and Hash
57
Message Authentication
Requirements
• Masquerade
• Content modification
• Insertion, deletion, transposition, modification of message contents
• Sequence modification
• Insertion, deletion, reordering of sequenced messages
• Timing modification
• Delay, replay
• Repudiation
• Denial of message transmission or receipt
58
Authentication Functions
• Message encryption
• Ciphertext itself serves as authenticator
• Hash function
• Public function maps message into fixed length value
• Message authentication code
• Public function combines message and secret key into fixed length
value
59
Message Authentication Code (MAC)
• Cryptographic checksum
• Mixes message with (shared) secret key to produce a fixed size block
• Assurances:
• Message has not been altered
• Message is from alleged sender
• Message sequence is unaltered (requires internal sequencing)
• MAC algorithm need not be reversible
60
Why Use MACs?
• Why not just use encryption?
• Clear-text stays clear
• MAC might be cheaper
• Broadcast
• Authentication of executables
• Architectural flexibility
• Separation of authentication check from message use
• Prolong the period of protection
61
One-way Hash Functions
• Converts a variable size message M into fixed size hash code H(M)
• Can be used with encryption for authentication
• E(M || H)
• M || E(H)
• M || signed H
• E( M || signed H ) gives confidentiality
• M || H( M || K )
• E( M || H( M || K ) )
62
Hash Function Requirements
• H can be applied to any size data block
• H produces fixed length output
• H is fast
• H is one-way, i.e., given h, it is computationally
infeasible to find any x s.t. h = H(x)
63
Hash Requirements (cont’d)
64
Birthday Attack
65
Crypto-Hashes
66
Popular Algorithms
67
HMD5 = 4-round compression function message
length
Message 100…0
L X 512 bits
512 bits
69
SHA-1 vs. MD5
70
HMAC
71
Algorithm (cont’d)
72
Advanced Cryptanalysis
• Modern cryptanalysis
• Differential cryptanalysis
• Linear cryptanalysis
• Side channel attack on RSA
• Hellman’s TMTO attack on DES
73
Side Channel Attacks
74
Side Channels
75
ACCESS CONTROL
Suku Nair
76
Access Control
• Two parts to access control
• Authentication: Who goes there?
• Determine whether access is allowed
• Authenticate human to machine
• Authenticate machine to machine
• Authorization: Are you allowed to do that?
• Once you have access, what can you do?
• Enforces limits on actions
• Note: Access control often used as synonym for authorization
78
Something You Know
• Passwords
• Lots of things act as passwords!
• PIN
• Social security number
• Mother’s maiden name
• Date of birth
• Name of your pet, etc.
79
Trouble with Passwords
80
Why Passwords?
• Why is “something you know” more popular than
“something you have” and “something you are”?
• Cost: passwords are free
• Convenience: easier for SA to reset password than to
issue new smartcard
81
Keys vs Passwords
82
Attacks on Passwords
• Attacker could…
• Target one particular account
• Target any account on system
• Target any account on any system
• Common attack path
• Outsider normal user administrator
• May only require one weak password!
83
Password Retry
• Suppose system locks after 3 bad passwords. How
long should it lock?
• 5 seconds
• 5 minutes
• Until SA restores service
• What are pros and cons of each?
84
Password File
85
Dictionary Attack
86
Password File
87
Password Cracking: Complexity
• Assumptions
• Pwds are 8 chars, 128 choices per character
• Then 1288 = 256 possible passwords
• There is a password file with 210 pwds
• Attacker has dictionary of 220 common pwds
• Probability of 1/4 that a pwd is in dictionary
• Work is measured by number of hashes
88
Password Cracking (cont’d)
• Attack 1 password without dictionary
• Must try 256/2 = 255 on average
• Just like exhaustive key search
• Attack 1 password with dictionary
• Expected work is about
1/4 (219) + 3/4 (255) = 254.6
• But in practice, try all in dictionary and quit if not found work is at
most 220 and probability of success is 1/4
89
Password Cracking
90
Password Cracking
91
Other Password Issues
92
Passwords
93
Password Cracking Tools
94