4a AsymmetricCrytosystem PDF
4a AsymmetricCrytosystem PDF
Introduction to Cryptography
Semester 2, 13/14
Asymmetric Cryptography
2 main characteristics:
o One key is used for encryption and a different key but related key is used for
decryption.
o Public key, KPu, a key that is known to everybody
o Private key, KPr, a key that is only known by the owner.
Example
Page 1 of 17
Semester 2, 13/14
f is easy to compute
f -1 is difficult to compute
f -1 becomes easy to compute if a trap door is known
Page 2 of 17
Semester 2, 13/14
Example
If n is large, n = p q is a one-way function.
Given p and q , it is always easy to calculate n; given n, it is very difficult to compute p and
q. This is the factorization problem.
If n is large, the function y = xk mod n is a trapdoor one-way function.
Given x, k, and n, it is easy to calculate y. Given y, k, and n, it is very difficult to calculate x.
This is the discrete logarithm problem. However, if we know the trapdoor, k such that k
k = 1 mod f(n), we can use x = yk mod n to find x.
Example of One Way Function
Factoring
Given x and y, computing n = x y is EASY.
However, given n, computing the factors x and y is HARD.
Discrete Logarithm
Given x, a, and p, computing y x a mod p is EASY.
However, given y, x, and p, computing a is HARD.
Discrete Square-root
Given x and n, computing a x2 mod n is EASY
However, given a and n, computing x is HARD
Example
For x = 6, a = 9, p = 11, we compute
y xa x((x 2 ) 2 ) 2 mod p
with 4 multiplications:
y = 6((62 )2 )2 = 6((36)2)2
= 6((3)2 )2 = 6(9)2
= 6(81) = 6(4)
= 24 = 2
However, finding an a such that
6a 2 mod 11 is hard
We need to try all possibilities (from 1 to p-1) to obtain such a.
Security of Public-Key Cryptography
Similar to symmetric key schemes brute force exhaustive search attack is always theoretically
possible but keys used are too large ( > 512 bits)
Keys used must be large enough to make brute force attack impractical, but small enough for
practical encryption/decryption.
o requires the use of very large numbers
But encryption process is slow compared to symmetric key schemes.
Page 3 of 17
Semester 2, 13/14
Page 4 of 17
Semester 2, 13/14
Authentication
Alice: chooses a random number, r
Alice B: E(KPuB, r) Bobs public key
Bob: r = D(KPrB, E(KPuB, r)) , his private key
Bob Alice: r
o Thus identify that the receiver is Bob.
Digital signature
How do Alice & Bob communicate in such a way that Alice can verify that Bob sent the
message Bob cannot deny that he sent the message?
Alice and Bob pick KPuA, KPrA, KPuB and KPrB
Publicize KPuA and KPuB
Bob Alice: E(KPuA, E(KPrB, P))
Alice: D(KPRA, E(KPuA, E(KPrB, P)) = E(KPrB, P)
Alice: D(KPuB, E(KPrB, P)) = P
Public-Key Cryptosystem: Secrecy and Authentication
Page 5 of 17
Semester 2, 13/14
Algorithm
RSA
Elliptic
Curve
DiffieHellman
DSS
Encryption/Decryption
Digital Signature
Key Exchange
Semester 2, 13/14
Working of RSA
One Way Function (OWF): multiplying two primes
If they are fairly small we can do this in our heads, on a piece of paper, or on a calculator.
As they get bigger and bigger it is fairly easy to write a computer program to compute the
product.
Multiplication runs in polynomial time.
Multiplication of two primes is easy.
However it is difficult to determine the prime factors of n if the n is large.
Example
To factor: Com
To factor
15
143
6887
31897
600 digit number
600 digit even number
Take two large primes, p and q (about 100 digits), and compute their product n = p q; n is
called the modulus.
note (n)=(p-1)(q-1) totient Euler function
Choose a number, e, less than n and relatively prime to (p-1) (q-1). (e, n) is the
encryption/public key
where 1 < e < (n), gcd (e, (n)) = 1
Find d, the multiplicative inverse of e such that d = e-1 mod [(p-1)(q-1)]. So (d, n) is the
decryption/private key
e. d 1 mod (n) and 0 d n
d e-1 mod (n)
Publish their public encryption key: KPU={e, n}
Keep private decryption key: KPR {d, n}
The factors p and q may be kept with the private key, or destroyed.
Page 7 of 17
Semester 2, 13/14
However if one could factor n into p and q, then one could obtain the private key d. Thus the
security of RSA is based on the assumption that factoring is difficult.
The discovery of an easy method of factoring would "break" RSA
The floor of
= 17.
Check 2, 3, 5, 7, 11, 13, and 17.
The numbers 2, 3, and 5 do not divide 301, but 7 does.
Therefore 301 is not a prime.
Page 8 of 17
Semester 2, 13/14
Eulers Phi-Function
Eulers phi-function, (n), sometimes referred as Eulers totient function, plays a very
important role in cryptography.
We can combine the above four rules to find the value of f(n).
For example, if n can be factored as n = p1e1 p2e2 pkek
then we combine the third and the fourth rule to find
Example
o What is the value of (13)?
Because 13 is a prime, (13) = (13 1) = 12.
o
Page 9 of 17
Semester 2, 13/14
Eulers Theorem
First Version:
af(n) 1 (mod n)
Second Version: a k f(n) + 1 a (mod n)
Example
o Find the result of 624 mod 35
We have 624 mod 35 = 6(35) mod 35 = 1.
Find the result of 2062 mod 77.
If we let k = 1 on the second version, we have
2062 mod 77 = (20 mod 77) (2077) + 1 mod 77) mod 77
= (20)(20) mod 77 = 15.
Multiplicative Inverses
o
a1 mod p = a p 2 mod p
Example:
The answers to multiplicative inverses modulo a prime can be found without using the
extended Euclidean algorithm:
Page 10 of 17
Semester 2, 13/14
Example 1
Key generation:
Given p = 5 and q = 3
Find n
n = p q = 5 3 = 15
Find (n)
(n) = (p-1)(q-1) = 4 2 = 8
Choose integer e,
Say e = 5
Find d
Example 2
Let p = 11, q = 13, so n = p * q = 143
(n) = (p-1)(q-1) = 10 * 12 = 120
Choose e relatively prime to (n), say e = 11
Now d = 11-1 mod 120 = 11
Page 11 of 17
Semester 2, 13/14
If plaintext m = 7,
c = me mod n = 711 mod 143 = 106
To decrypt, since c = 106
m = cd mod n = 10611 mod 143 = 7
What is kept secret: p, q and d
What are revealed: e, and n
Example 3
Encrypt RENAISSANCE using p = 53 and q = 61.
n = p * q = 3233
Say e = 71, then d = 791
(check the validity of e and d)
Break the message into blocks of 4 digits where A = 00, B = 01, , Z = 25 (in practice,
characters would be represented by their 8 bit ASCII codes)
Thus RE NA IS SA NC E = 1704 1300 0818 1800 1302 0426
The 1st block is encrypted as 170471 mod 3233 = 3106
Example 4
p = 61, q = 53, pq = 3233,
e = 17 (public exponent),
Page 12 of 17
Semester 2, 13/14
Example 5
Select primes p=11, q=3.
n = p q = 11 3 = 33
= (p-1)(q-1) = 10 2 = 20
Choose e = 3
Check gcd (e, p-1) = gcd (3, 10) = 1
Page 13 of 17
Semester 2, 13/14
0
0
1
1
2
8
3
27
4
31
5
26
6
18
7
13
8
17
9
3
10
10
11
11
12
12
13
19
14
5
15
9
16
4
m
c
17
29
18
24
19
28
20
14
21
21
22
22
23
23
24
30
25
16
26
20
27
15
28
7
29
2
30
6
31
25
32
32
Example 5
Suppose Ted wants to send the message NO to Jennifer.
Ted changes each character to a number (from 00 to 25), with each character coded as
two digits.
He then concatenates the two coded characters and gets a four-digit number. The
plaintext is 1314.
Page 14 of 17
Semester 2, 13/14
transmitting short secret key/value eg. credit card, key for use in symmetric E/D system
digital signature
authentication i.e. identifying an entity
certificate
Page 15 of 17
Semester 2, 13/14
Breaking RSA
The obvious way to do this attack is to factor the public modulus, n, into its two prime factors,
p and q. From p, q, and e, the attacker can easily get d.
The hard part is factoring n;
Security of RSA depends on factoring being difficult. In fact, the task of recovering the
private key is equivalent to the task of factoring the modulus.
It should be noted that hardware improvements alone will not weaken RSA, as long as
appropriate key lengths are used. In fact, hardware improvements should increase the
security of RSA.
Another way to break RSA is to find a technique to compute eth roots mod n.
Since c = me mod n , the eth root of c mod n is the message m.
This would allow someone to recover encrypted messages and forge signatures even
without knowing the private key.
No general methods are currently known that attempt to break RSA in this way. However,
in special cases where multiple related messages are encrypted with the same small
exponent, it may be possible to recover the messages.
These are no attack against the algorithm but instead the protocol.
Attacker sees a ciphertext and guesses that the message might be, for example, "Attack at
dawn," and encrypts this guess with the public key of the recipient and by comparison
with the actual ciphertext, the attacker knows whether or not the guess was correct.
Appending some random bits to the message can thwart this attack.
Page 16 of 17
Semester 2, 13/14
Example
Eve listen to Alices communication and manage to collect a ciphertext message, c,
encrypted with Alice public key. Eve wants to read the message i.e. m = cd.
To recover m, Eve choose a random #, r, such that r is less than n.
Then she get Alices public key, e and start computing
x = re mod n, y = xc mod n,
t = r-1 mod n
If x = re mod n, then r = xd mod n
Eve gets Alice to sign y with her private key, thereby decrypting y.
Alice send Eve u = yd mod n
Eve computes tu mod n = r-1 yd mod n = r-1 xd cd mod n = cd mod n = m
Page 17 of 17