Ma 479 / csse 479, Cryptography Handout to accompany rsa



Download 113.3 Kb.
Date01.02.2018
Size113.3 Kb.
#37598



MA 479 / CSSE 479, Cryptography
Handout to accompany RSA

Spring term, 2003-2004

This handout helps you understand RSA and some of its analysis. Questions are (generally) answered on succeeding pages. For maximum enjoyment, try to answer the questions as you see them.

Question 1: For any algorithm, what questions should any Computer Scientist ask?

Question 2: What is the RSA algorithm?

Question 3: From Question 1 and 2, what must we show about the RSA algorithm?


Answer 1: For any algorithm, what questions should any Computer Scientist ask?

1. What is the algorithm? 2. Is the algorithm correct? 3. How fast is the algorithm?



Answer 2: What is the RSA algorithm? See next page.

Answer 3: From Question 1 and 2, what must we show about the RSA algorithm?

  • What is the RSA algorithm? (See next page.)

  • Is RSA correct? (And first, what does it mean for RSA to be correct?)

    • Question 4: give details.

  • How fast is RSA? (And first, what are the parts of RSA and how fast is each part?)

    • Question 5: give details.

RSA cryptosystem:

  1. Generate keys.

    1. Select large primes p and q. [use Miller-Rabin probabilistic test]

    2. Compute:

  • n = pq

  • (n) = (p-1)(q-1)

    1. Select integer e such that: [use Extended Euclidean algorithm

  • gcd( e, (n) ) = 1 repeatedly until you find one]

  • 1 < e < (n)

    1. Compute d = e –1 mod (n) [comes for free from previous step]

Public key is (n, e). Private key is (p, q, n, d).

  1. Encrypt.

  • Plaintext P is a positive integer less than n.

  • Ciphertext C = Pe mod n. [use fast exponentiation]

  1. Decrypt.

  • P = Cd mod n


We must show the following:

  1. RSA is correct, i.e., [ (Pe) mod n ]d mod n = P.

    • Question 6: give the proof (see next page).

  1. One can generate keys quickly:

  • How to select large primes?

  • How to select e and d?

  1. One can encrypt and decrypt quickly:

  • How to avoid gargantuan numbers when exponentiating?

  • How to exponentiate fast?

  1. Attacks fail:

  • Exhaustive key search.

  • Factoring et al.

  • Timing (and other side channels).

Review: RSA is correct, i.e., [ (Pe) mod n ]d mod n = P.

  1. Definitions.

  • a mod n is the remainder (residue) when a is divided by n.

  • We say a b mod n if (a mod n) = (b mod n).
    We read this as a is congruent to b modulo n.

  • Zn is {0, 1, 2, ... n-1 }. Called the residues modulo n.

  • gcd( a, b ) is the greatest common divisor of a and b.

  • If gcd( x, y ) = 1, we say x and y are relatively prime.

  1. Modular arithmetic.

    1. Fact: +, , (but not ) work as usual in Zn.

  • (a + b) mod n = [ (a mod n) + (b mod n) ] mod n.

  • Ditto subtraction, multiplication (and hence exponentiation).

  • If (a + b)  (a + c) mod n then bc mod n.

    1. Fact: If a and n are relatively prime:

  • a has a unique inverse a-1 such that (aa-1) mod n = 1.

  • If (ab)  (ac) mod n then bc mod n.

  1. Fermat’s little theorem: For every prime p, we have .

  2. Euler’s totient function.

  • Definition: (n) is the number of positive integers less than n that are relatively prime to n.

  • Fact: for every prime p, we have (p) = p-1.

  • Fact: for n = pq where p and q are prime, we have (n) = (p-1)(q-1).

  1. Euler’s theorem: If a and n are relatively prime, then a(n) mod n = 1.

  • Corollary: Suppose n = pq where p and q are prime.
    Then for any positive integer m less than n, we have mk(n)+1 mod n = m.

  • Corollary: RSA is correct, i.e., ( (Pe) mod n )d mod n = P.



Question 7: How to encrypt and decrypt quickly without gargantuan numbers?

  • What are the two basic ideas?

  • What is an efficient implementation of those ideas? (See next page.)


To encrypt and decrypt quickly.

To compute ab mod n: Write b as bk bk1 bk2 ... b1 b0.

d := 1

for i := k downto 0



d := d * d mod n

if ( bi = 1 )

d := d * a mod n

return d


Example: use the following multiplication facts to compute 7560 mod 561 (by hand, using the above algorithm).

Hints: if you need something not in the table, you are off the track.


Also, 560 = 1 0 0 0 1 1 0 0 0 0

By the way, what would Fermat say the answer should be, if 561 were prime? It turns out that 561 is a Carmichael number (in fact, the smallest one), which are numbers that have the property that primes have in Fermat’s theorem, but are not themselves prime.




d

d2 mod 561

d 7 mod 561

1

1

7

7

49

49

49

157

343

157

526

538

526

103

316

103

511

160

160

355

559

355

361

241

241

298

4

298

166

403

166

67

40

67

1

469

Question 8: How to find large primes quickly?

  • Basic idea: a Monte Carlo algorithm (sometimes lies)?

  • What is such an algorithm?

    • How to show that it is fast?

    • How to show that it usually works?

  • Details!

Randomized Algorithms

Definitions.

  • A randomized algorithm is one which makes some random choices that may affect the correctness and/or running time

  • A Monte Carlo algorithm sometimes gives false negatives, but only a known percentage of the time.

  • A Las Vegas algorithm always tells the truth, but runs very slowly a known percentage of the time.

  • An Atlantic City algorithm sometimes gives false negatives and also sometimes gives false positives.

  • A Sherwood Forest algorithm makes a large number of random attempts at something in the hopes that one will work!


To select large primes quickly.

To generate a large prime:

  1. Pick a large odd integer.

  2. Test if it is prime.

  3. If prime, done.
    Otherwise, return to Step 1.

Facts:

  • Not known (yet) how to do Step 2 efficiently with certainty.

  • Can do Step 2 efficiently with high probability!

  • There are enough primes that this method stops soon (probably).

  • The Prime Number Theorem says that if P(n) denotes the number of primes less than n, then .

  • So if n is the biggest integer to be considered in Step 1, what is the expected number of trials (iterations of the loop) required to find a prime? __________

  • If n is 10100, then the expected number of trials is about ____________.

  • Is 10100 big enough? Too big?

Question 9: What do you need to implement the above?
Question 10: How could you show that the above is fast? What do you need to know?
Question 11 How could you show that the above is usually correct? What do you need to know?

To test whether an integer n is prime:

Miller-Rabin( n, s )

Repeat s times:

Pick a random integer a between 1 and n1.

If Witness( a, n ) (i.e., if a is a witness for the non-primality of n)

return not-prime (definitely!)

Return prime (almost surely!)



Facts:

  • The Witness function returns true if and only if a is a “witness” for the non-primality of n. See below.

  • For any odd non-prime n,
    there are at least 3(n1)/4 witnesses to its non-primality.

Question 12: How could you easily give evidence for this? Prove it?

  • If n is prime,
    then Miller-Rabin will definitely say prime. See below.

  • If n is not prime,
    then Miller-Rabin will erroneously say prime with probability less than (¼)s.

Question 13: Prove this.

  • The run-time for Witness is O( log3 n),
    so the run-time for Miller-Rabin is O(s log3 n).

Question 14: After you see Witness, prove this.
Question 15: Witness is very similar to an algorithm we have seen. Can you guess which one? Hint:

x2 mod p = 1

has only two solutions in Zp – namely, 1 and p1.



Witness( a, n ) [Same as fast exponentiation, but with highlighted lines added.]

Write n-1 as bk bk1 bk2 ... b1 b0.

d := 1

for i := k downto 0



oldD := d

d := d * d mod n



if d = 1 and oldD 1 and oldD n-1

return true (a is a witness to the non-primality of n)

if ( bi = 1 )

d := d * a mod n

if d 1

return true (a is a witness to the non-primality of n)

return false (a is not a witness, maybe n is prime)



Example:

Compute Witness( 7, 561) by hand, using the results from the example you did earlier of fast exponentiation.



Facts:

  • If p is an odd prime, then the equation

x2 mod p = 1

has only two solutions in Zp – namely, 1 and p1.



Question 16: Prove this.

  • If Witness returns true inside the loop,
    then oldD is a witness to the non-primality of n, by the previous fact.

  • If Witness completes the loop, then d equals an1 mod n (as in fast exponentiation).

  • If Witness completes the loop and returns true, then a is a witness to the non-primality of n, by the previous fact and Fermat’s theorem.

Question 17: Convince yourself of the truth of the last few statements.

To compute the greatest common divisor of b and c:

Euclid( b, c )
B := b

C := c


while C <> 0

R := B mod C



B := C

C := R


return B (B = gcd(a,b))
or:


Facts:

  • For any a, gcd(a, 0)=a.

  • For any x, gcd(b,c) = gcd(b-cx, c).

Question 18: Prove these facts.

Question 19: Use these facts to prove that the Euclidean Algorithm is correct.

  • The Euclidean Algorithm always stops.

Question 20: Why?

Question 21: Prove these.

Question 22: What does this make the running time of Euclid?

Download 113.3 Kb.

Share with your friends:




The database is protected by copyright ©ua.originaldll.com 2024
send message

    Main page