CS 683 - Security and Privacy Fall 2019
Instructor: Karim Eldefrawy
University of San Francisco
http://www.cs.usfca.edu/~keldefrawy/teaching /fall2019/cs683/cs683_main.htm
1
CS 683 - Security and Privacy Fall 2019 Instructor: Karim Eldefrawy - - PowerPoint PPT Presentation
CS 683 - Security and Privacy Fall 2019 Instructor: Karim Eldefrawy University of San Francisco http://www.cs.usfca.edu/~keldefrawy/teaching /fall2019/cs683/cs683_main.htm 1 Lecture 7 Public Key Cryptography (Diffie-Hellman and RSA) 2
Instructor: Karim Eldefrawy
University of San Francisco
http://www.cs.usfca.edu/~keldefrawy/teaching /fall2019/cs683/cs683_main.htm
1
2
Adleman)
– Encryption: with public key; – Decryption: with private key – Digital Signatures: Signing by private key; Verification by public key. i.e., “encrypt” message digest/hash -- h(m) -- with private key
3
Public Key Cryptography
Public Key Cryptography
4
plaintext message, m ciphertext encryption algorithm decryption algorithm
Bob’s public key
plaintext message PK (m)
B
PK
B
Bob’s private key
SK
B
m = SK (PK (m))
B B
5
Key Pre-distribution: Diffie-Hellman
“New Directions in Cryptography” 1976 * p
System wide parameters : p large prime, a generator in Z − − − Alice's secret: v, public: mod Bob's secret: w, public: mod
v a w b
y a p y a p = =
Alice has: mod Bob has: mod ( ) mod ( ) mod
w b v a v ab b w ba a
y a p y a p K y p K y p = = = = =
6
Public Key Pre-distribution: Diffie-Hellman
Secure communication with Kab
Alice computes Kab Bob computes Kab = Kba Eve knows: p, a, ya and yb
7
Public Key Pre-distribution: Diffie-Hellman
*
Diffie Hellman Problem: : mod mod : mod Discrete Log Problem: : mod :
p v w a b vw v a
p large prime, a generator in Z Given y a p and y a p FIND a p Given y a p FIND v − − − = = =
8
Public Key Pre-distribution: Diffie-Hellman
Decision DH Problem: mod , mod : mod
v w a b vw ab
p large prime, a generator Given : y a p y a p Distinguish K a p from a random number! − − = = =
9
Eve is passive …
p a y
v a
mod =
Secure communication with Kab Choose random v
p a y
w b
mod =
Choose random w, Compute
p y K
w a ba
mod ) ( =
Compute
( ) mod
v ab b
K y p =
10
The Man-in-the-Middle (MitM) Attack
(assume Eve is an active adversary!)
p a y
v a
mod =
Secure communication with Kab Choose random v
p a y
w b
mod =
Choose random w, Compute
p y K
w a ba
mod ) ( =
Compute
( ) mod
v ab b
K y p =
11
Let n = pq where p,q − large primes e,d ∈R Zn and ed ≡ 1 mod Φ(n) where : Φ(n) = (p −1)(q −1) = pq − p − q −1 Secrets : p,q,d Publics : n,e Encryption : message = m < n E(x) = y = me mod n Decryption : ciphertext = y D( y) = x' = yd mod n
12
Why does it all work?
*
13
How does it all work?
Example: p=17 q=13 n=221 (p-1)(q-1)=192=34*2 pick e=5, d=77 Can we pick 16? 9? 27? 185? x=5, E(x)=3125 mod 221 = 31 D(y)=3177= 6.83676142775442000196395599558e+114 mod 221 = 5 Example: p=5 q=7 n=35 (p-1)(q-1)=24=3*23 pick e=11, d=11 x=2, E(x)=2048 mod 35 =18=y y=18, D(y)=6.426841007923e+13 mod 35 = 2
14
Why is it Secure?
Why: n has unique factors p, q Given p and q, computing (p-1)(q-1) is easy: Use extended Euclidian! Conjecture: breaking RSA is polynomially equivalent to factoring n. Recall that n is very, very large!
) ( 1 n mod ed Φ ≡
15
16
} } n; temp% m temp { e[i] if n % temp temp temp* { i i 1 l i for 1 temp n sizeof l = = = = − − >= − = = = − − − − − − − − − − − − ; * ) ( ; ; ) ; ; ( ; ); ( n mod m compute : goal
e
From left to right in e
17
: C - RSA ciphertext mod( 1) mod( 1) compute: mod mod and solve: mod mod
p q
p q d p d q p q
Let d d p d d q M C p M C q M M p M M q = − = − = = = = ) mod( )] mod ( ) mod ( [
1 1
pq q p p M p q q M M
q p − −
+ =
18
– Alice has (e’,d’,n) and Bob – (e”,d”,n) – Alice wants to compute d” (Bob’s private key) – She knows that: e’ * d’= 1 mod phi(n) – So: e’ * d’ = k * phi(n) + 1 and: e’ * d’ - 1 = k * phi(n) – Alice just needs to compute inverse of e” mod X
– Is it possible that e” has no inverse mod X?
– For all decryption purposes, d”’ is EQUIVALENT to d” – Suppose Eve encrypted for Bob: C = (m)e” mod n – Alice computes: Cd”’ mod n = me”d”’ mod n = (m) k’ * k * phi(n) + 1 mod n = m
19
20
El Gamal PK Cryptosystem (83)
m p mb b c k m' p k compute p k compute : Decryption c} {k, ciphertext p mb p my c : compute p b k compute Z r random generate Encryption x : secrets y b p publics Z Z C Z P p b y residue public y exponent private x generator element, primitive base, b prime large p
xr rx x x x xr r r p p p p x
= = = = = = = ∈ × = = ≡ − − − −
− − − −
mod ) ( . 3 mod ) ( . 2 mod . 1 . 4 mod mod . 3 mod : . 2 . 1 : , , : mod ;
1 1 1 * * *
21
11mod13 24 12 * 2 12 mod13 1 12 12 mod13 9 10 : Decryption {10,2} ciphertext 2 mod13 10 5 * 11 c 10 mod13 10 2 k 10 r 11 m : Encryption 5 mod13 9 2 y 9 x 2 b 13 p ≡ = = − = = = = = = = = = = = = =
22
I did not have intimate relations with that woman,…,
If you like your current health insurance plan, you can keep it!
23
A signature scheme: (P,A,K,Sign,Verify) P - plaintext (msgs) A - signatures K - keys Sign - signing function: (P*K)->A Verify - verification function: (P*A*K) à {0,1}
Usually message hash
24
??? ) ( : ) , ( :
Verificati : ) ( : Signing , : , , : mod 1 and mod and primes (large) two are q p where pq n Let
1 * ) ( e d n
y m m y Verify y signature n mod m y m Sign m message e n Publics d q p Secrets 1) 1)(q (p (n) Φ(n) ed Φ(n) d e Z e = = = =
F º = Î ¹ =
Use the fact that, in RSA, encryption reverses “decryption”
25
26
m xb m xb r xk r m r xb c k m c k r p p p p x
b b b b k y that notice p b p k y Verifying c} {k, e signatur p r xk m c : compute p b k compute Z r random generate Signing x : secrets y b p publics Z Z A Z P p b y residue public y exponent private x generator base, b prime large p
r r r
= = = = = − − = = ∈ × = = ≡ − − − −
− + − − − ) / / ( 1 1 * * *
) ( : ??? mod mod : . 4 1 mod ) ( . 3 mod : . 2 . 1 : , , : mod ;
27
El Gamal PK Cryptosystem
m p mb b c k m' p k compute p k compute : Decryption c} {k, ciphertext p mb p my c : compute p b k compute Z r random generate Encryption x : secrets y b p publics Z Z C Z P p b y residue public y exponent private x generator element, primitive base, b prime large p
xr rx x x x xr r r p p p p x
= = = = = = = ∈ × = = ≡ − − − −
− − − −
mod ) ( . 3 mod ) ( . 2 mod . 1 . 4 mod mod . 3 mod : . 2 . 1 : , , : mod ;
1 1 1 * * * *
m xb m xb r xk r m r xb c k m c k r p p p p x
b b b b k y that notice p b p k y Verifying c} {k, e signatur p r xk m c : compute p b k compute Z r random generate Signing x : secrets y b p publics Z Z A Z P p b y residue public y exponent private x generator base, b prime large p
r r r
= = = = = − − = = ∈ × = = ≡ − − − −
− + − − − ) / / ( 1 1 * * * *
) ( : ??? mod mod : . 4 1 mod ) ( . 3 mod : . 2 . 1 : , , : mod ;
El Gamal Signature Scheme
28
El Gamal Signature Scheme (contd) The good:
The bad:
29
The Digital Signature Standard (DSS)
30
DSS (contd)
??? mod mod : . 4 1 mod ) ( . 3 mod : . 2 . 1 : , , : , mod ;
1 1 * * * *
p b p k y Verifying c} {k, e signatur p r xk m c : compute p b k compute Z r random generate Signing x : ets y secr b p publics Z Z A Z P p b y residue public y exponent private x generator base, b prime large p
m c k r p p p p x
= = − − = = ∈ × = = ≡ − − − −
− −
p − 512 − bit prime q − 160 − bit prime, (p − 1)%q = 0 b − base, bq ≡1mod p (b = δ ( p−1)/q) x − private exponent y − public residue; y ≡ bx mod p P = Z p
*, A = Zq × Zq
publics : p, q, b, y secrets : x Signing :
q−1
Verifying : (bmc−1k kc−1 mod p)mod q = bk mod p ??? notice that : bmc−1ykc−1 = bmr/(m+xbr )(bx )(brr/(m+xbr ) = b(mr+xbrr)/(m+xbr ) = br
31
IDENTIFICATION
party: “prover” (who claims to be, say, Alice) convinces the other party: “verifier” (Bob) that she is indeed Alice
digital signatures
verify them
32
Point B Point A: entry Locked door
Claims to have the key
V cannot follow P into the cave
Claustrophobic and afraid of the dark
33
:
The Protocol
1) V asks someone he trusts to check that the door is locked on both sides. 2) P goes into the maze past point B (heading either right or left) 3) V looks into the cave (while standing at point A) 4) V randomly picks right or left 5) V shouts (very loudly!) for P to come out from the picked direction 6) If P doesn’t come out from the picked direction, V knows that P is a liar and protocol terminates REPEAT (2)-(6) n TIMES Point B Point A
34
(factorization is secret).
used by everyone, as long as nobody knows its
factorization after computing n.
35
1 < S < n (to serve as the key) such that gcd(S,n) = 1
key.
knows the secret S corresponding to the public key (I,n),
– i.e., to prove that he knows a square root of I mod n, without revealing S
36
Fiat-Shamir Prover (Alice) Verifier (Bob) n, I, S n
pick random R; set x=R2 mod n
I, x query = 0 1 R R * S mod n
Check that: R2 = x mod n (RS)2 = xI mod n
37
V wants to authenticate identity of P, who claims to have a public key I. Thus, V asks P to convince him that P knows the secret key S corresponding to I . 1. P chooses at random 1 < R < n and computes: X = R2 mod n 2. P sends X to V 3. V randomly requests from P one of two things (0 or 1):
(a) R
(b) RS mod n
4. P sends requested information
38
a) R2 ?= X (mod n)
b) (R*S)2 ?= X*I (mod n)
not know S
times, and, if each one succeeds, V concludes that P is the claimed party.
39
n, I (doesn’t know S) n
pick random R; set x=R2 mod n
I, x query = 0 R
Check that: R2 = x mod n
40
n, I (doesn’t know S) n
pick random R; set x=R2*I mod n
I, x=R2*I query = 1 R*I mod n (Instead of: R*S mod n)
Check that: (R*I)2 = x*I mod n
41
CLAIM: Protocol does not reveal ANY information about S or Protocol is ZERO-KNOWLEDGE Proof: We show that no information on S is revealed:
– RS mod n is random, since R is random and gcd(S, n) = 1. – If adversary can compute any information on S from
I, n, X and RS mod n
he can also compute the same information on S from I and n, since he can choose a random T = R’S mod n and compute:
X’ = T2I-1 = (R’)2S2I-1 = (R’)2
42
Clearly, if P knows S, then V is convinced of his identity. If P does not know S, he can either:
1. know R, but not RS mod n. Since he is choosing R, he cannot multiply it by the unknown value S
2. choose RS mod n, and thus can answer the second question: RS mod n. But, in this case, he cannot answer the
first question R, since he needs to divide by the unknown S.
43
he can compute S as the ratio between the two answers.
which question that V will ask, he cannot foresee the required choice. He can succeed in guessing V’s question with probability 1/2 for each question.
1,000,000,000 for t=20)