Top Banner
Lecture 10 1
23

Crypto Lecture 10

Dec 11, 2015

Download

Documents

Jaher Wasim

encryption
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Crypto Lecture 10

Lecture 10

1

Page 2: Crypto Lecture 10

RSA algorithm

The most important public-key

cryptosystem is the RSA cryptosystem.

Invented in 1978 by Rivest, Shamir,

Adleman.

2

Page 3: Crypto Lecture 10

RSA algorithm (cont.)

Key Generation:

Step 1:

Pick a modulus n.

This is generally done as follows:

Pick two prime numbers p and q.

n = pq.

3

Page 4: Crypto Lecture 10

RSA algorithm (cont.)

Step 2:

Determine m = φ(n). (Euler’s

Totient function)

If n = pq (from Step 1).

m = (p-1)(q-1)

4

Page 5: Crypto Lecture 10

RSA algorithm (cont.)

Step 3:

Pick a value of e that is

relatively prime / co-prime to m.

Relatively prime / co-prime:

Two numbers are said relatively

prime when there only common divisor is

one.

5

Page 6: Crypto Lecture 10

RSA algorithm (cont.)

Example 1:

Check whether 10 and 9 is relatively

prime.

Solution:

Factors of 10 are 1, 2, 5, 10.

Factors of 9 are 1, 3, 9.

GCD (10 , 9) = 1

So 10 and 9 are relatively prime.

6

Page 7: Crypto Lecture 10

RSA algorithm (cont.)

Example 2:

Check 6 and 23 relatively prime or not

Solution:

Given numbers are 6 and 23

factors of 6 are 1, 2, 3, 6.

23 is a prime number.

GCD (6 , 23) = 1

So 6 and 23 is relatively prime.

7

Page 8: Crypto Lecture 10

RSA algorithm (cont.)

Example 3:

Check for relatively prime 21 and 14

Solution:

Given numbers are 21 and 14

factors of 21 is 1, 3, 7, 21

factors of 14 is 1, 2,7, 14

GCD (21,14) = 7

So 21 and 14 are not relatively prime

8

Page 9: Crypto Lecture 10

RSA algorithm (cont.)

Example 4:

Check whether 7 and 13 is relatively prime

Solution:

Given numbers are 7 and 13

7 is a prime number

13 is also a prime number

So GCD (7,13)=1

So 7 and 13 are relatively prime

9

Page 10: Crypto Lecture 10

RSA algorithm (cont.)

Step 4:

Determine the value d, which is

the modulo-m inverse of e.

Note that d will only exist if e and m are

relatively prime.

ed mod φ(n) = 1

ed = 1 mod φ(n)

d = e-1 mod φ(n)

10

Page 11: Crypto Lecture 10

RSA algorithm (cont.)

How to find a modular inverse:

A naive method of finding a modular inverse for A (mod C) is:

step 1. Calculate A * B mod C for B values 0 through C-1

step 2. The modular inverse of A mod C is the B value that makes

A * B mod C = 1

11

Page 12: Crypto Lecture 10

RSA algorithm (cont.)

• Example: A=3 C=7

Step 1. Calculate A * B mod C for B values 0 through C-1

• 3 * 0 ≡ 0 (mod 7)

• 3 * 1 ≡ 3 (mod 7)

• 3 * 2 ≡ 6 (mod 7)

• 3 * 3 ≡ 9 ≡ 2 (mod 7)

• 3 * 4 ≡ 12 ≡ 5 (mod 7)

• 3 * 5 ≡ 15 (mod 7) ≡ 1 (mod 7) <------ FOUND INVERSE!

• 3 * 6 ≡ 18 (mod 7) ≡ 4 (mod 7)

12

Page 13: Crypto Lecture 10

RSA algorithm (cont.)

Step 5:

Publish the pair (e, n) as the

Public Encryption Key.

Step 6:

Keep secret the pair (d, n) as the

Private Decryption Key.

13

Page 14: Crypto Lecture 10

RSA algorithm (cont.)

Encryption algorithm:

C = Pe mod n [ PU = (e, n)]

Decryption algorithm:

P = Cd mod n [ PR = (d, n)]

14

Page 15: Crypto Lecture 10

Example of RSA

Section1.

Generating Public and Private

Keys

1.1) pick two prime numbers, we'll pick

p = 3 and q = 11

1.2) calculate n = p * q = 3 * 11 = 33

15

Page 16: Crypto Lecture 10

Example of RSA (cont.)

1.3) calculate m = ( p - 1 ) * ( q - 1 )

= ( 3 - 1 ) * ( 11 - 1 ) = 20

1.4) choose a prime number e, such that e

is co-prime to m, i.e, m is not divisible by

e.

We have several choices for e: 7, 11, 13,

17, 19 (we cannot use 5, because 20 is

divisible by 5). Let's pick e = 7.

16

Page 17: Crypto Lecture 10

Example of RSA (cont.)

1.5) So, the numbers n = 33 and e = 7

become the public key.

PU = (e, n) = (7, 33)

1.6) To calculate the value of d, we need the

equation

ed mod φ(n) = 1

ed mod m = 1

7 * d mod 20 = 1

17

Page 18: Crypto Lecture 10

Example of RSA (cont.)

( 7 * d ) / 20 = ? with the remainder of 1.

we can easily conclude that 21 / 20 gives

"something" with the remainder of 1.

So, 7 * d = 21, and d = 3. This is our

private key.

PR = (d, n) = (3, 33)

18

Page 19: Crypto Lecture 10

Example of RSA (cont.)

Section 2.

Encrypting the message

Suppose the value of Plaintext message is,

P=14

Encryption algorithm:

C = Pe mod n [ PU = (e, n)]

= 147 mod 33 [ PU = (7, 33)]

= 105413504 mod 33

19

Page 20: Crypto Lecture 10

Example of RSA (cont.)

Easy way to find small mod value:

105413504 / 33 = 3194348.606

3194348 * 33 = 10541348

C = 105413504 - 10541348 = 20

So, our Encrypted message is C = 20.

20

Page 21: Crypto Lecture 10

Calculating Large mod value

2^90 mod 13 = (2^50 * 2^40) mod 13

= (2^50 mod 13 * 2^40 mod 13) mod 13 = ((2^30 * 2^20) mod 13 * 2^40 mod 13) mod 13 = (((2^30 mod 13) * (2^20 mod 13)) mod 13 * 2^40 mod 13) mod 13 = ((12 * 9) mod 13 * 2^40 mod 13) mod 13 = ((12 * 9) mod 13 * (2^20 * 2^20) mod 13) mod 13 = ((12 * 9) mod 13 * ((2^20 mod 13) * (2^20 mod 13)) mod 13) mod 13 = ((12 * 9) mod 13 * (9 * 9) mod 13) mod 13

= ( 4 * 3 ) mod 13 = 12 mod 13

2^90 mod 13 = 12

21

Page 22: Crypto Lecture 10

Example of RSA (cont.)

Section 3.

Decrypting the Message

We got the value of Ciphertext is, C = 20

Decryption algorithm:

P = Cd mod n [ PR = (d, n)]

= 203 mod 33 [ PR = (3, 33)]

= 8000 mod 33

22

Page 23: Crypto Lecture 10

Example of RSA (cont.)

So to calculate this remainder, we do:

8000 / 33 = 242.424242...

242 * 33 = 7986

P = 8000 - 7986

= 14

which is exactly the Plain text message.

23