Prime Checking, RSA




CS255

Chris Pollett

Apr 13, 2015

Outline

Modular Exponentiation

Modular-Exponentiation(a, b, n)
1 d=1, k = length of b //k is high order bit
2 for i = k down to 0:
3     d = ( d * d ) mod n
4     if b_i = 1:
5          d = (d * a) mod n
6 return d

Public Key Cryptosystems

RSA

Correctness of RSA

Theorem. The RSA functions `P` and `S` on the last slides define inverse transformations.

Proof. `P(S(M)) = S(P(M))= M^(ed) mod n`. Since `e` and `d` are multiplicative inverses modulo `phi(n) = (p-1)(q-1)`, `ed = 1+k(p-1)(q-1)` for some `k`. If `M equiv 0 mod n`, then `M^(ed) equiv 0 mod n` so we are done. If `M` is not congruent to `0 mod p`, we have
`M^(ed) equiv M(M^(p-1))^(k(q-1)) mod p`
`equiv M(1)^(k(q-1)) mod p`
`equiv M mod p`
and a similar result holds `mod q`. By the Chinese Remainder Theorem, this implies `M^(ed) equiv M (mod n)`.

Quiz

Which of the following is true?

  1. For any finite group `(S, o+)` and any `a in S`, `o\r\d(a) = |langle a rangle|/2`.
  2. The equation `ax equiv b (mod n)` either has `d` distinct solutions modulo `n`, where `d = gcd(a,n)`, or it has no solutions.
  3. Given any `b,a in ZZ_n^star`, the equation `b^x equiv a mod n` has a solution `x`, where `0 le x < n`.

Testing for Primes

Miller Rabin Primality Testing

Miller Rabin continued

Miller-Rabin(n, s)
1 for j = 1 to s
2    a = Random(1, n - 1)
3    if Witness(a, n):
4        return "Composite"
5 return "Prime"

Error Rate

Theorem. If `n` is composite, then the number of witnesses to compositeness is at least `(n-1)/2`.

Proof. We show the number of non-witnesses is at most `(n-1)/2`. First, any non-witness must be in `ZZ_n^(star)` as it must satisfy `a^(n-1) equiv 1 mod n`, i.e., `a cdot a^(n-2) equiv 1 mod n`; thus, it has an inverse. So we know `gcd(a,n) | 1` and hence `gcd(a, n) = 1`. Next we show that all non-witnesses are contained in a proper subgroup of `ZZ_n^(star)`. This implies the Theorem. There two cases to consider:

  1. There is an `x` such that `x^(n-1) ne 1 mod n`. Then we show all the `b` such that `b^(n-1) equiv 1 mod n` form a group and we're done.
  2. The number `n` is Carmichael number, so `x^(n-1) equiv 1 mod n` for all `x in ZZ_n^(star)`. We'll describe this case next day.