RSA - Primality Checking




CS255

Chris Pollett

Apr 15, 2019

Outline

Introduction

Square Roots

Theorem. If `p` is an odd prime, and `e ge 1`, then the equation `x^2 equiv 1 (mod p^e)` has only two solutions, `x = 1` and `x = -1`.

Proof. Let `n = p^e`. Theorem (#) implies `ZZ_n^star` has a generator `g`. So the above equation can be rewritten as `g^((i\n\d(x))2) equiv g^(i\n\d(1)) mod n`. Note `i\n\d(1) = 0`, so Theorem (##) implies this is equation is equivalent to `2 cdot i\n\d(x) equiv 0 mod phi(n)`, a modular linear equation we can solve. We know `phi(n) = p^e(1- 1/p) = (p-1)p^(e-1)`. If `d` is `gcd(2, phi(n))`, then `d=2` (as if `p` is odd, `2` divides `p-1`) and `d | 0`. So we know this equation has two solutions, which we can compute using our algorithm or by inspection as `1` and `-1`.

Corollary. If there exists a nontrivial square root of `1` modulo `n`, then `n` is composite.

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 statements is true?

  1. `ZZ_7^star` has a subgroup of size 4.
  2. `18x equiv 9 mod 81` has no solutions.
  3. There exists a number `a mod 105` such that `a equiv 2 mod 3`, `a equiv 4 mod 5`, `a equiv 6 mod 7`.

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"

Effeciently Computing Powers Mod n

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 in ZZ_n^(star)` such that `x^(n-1) ne 1 mod n`. In this case, we note all the `b` such that `b^(n-1) equiv 1 mod n` form a group. To see this note, `1` is in this group. As `b \cdot b^{n-2} equiv 1 mod n` and
    `(b^{n-2})^{n-1} equiv b^{(n-2)cdot(n-1)} equiv (b^{n-1})^{n-2} equiv 1^{n-2} equiv 1 mod n`.
    the inverse of `b`, `b^{-1} = b^{n-2}`, satisfies `(b^{-1})^{n-1} equiv 1 mod n`. Finally, given `b`, `c` satisfying the property,
    `(b \cdot c)^{n-1} equiv (b^{n-1}) (c^{n-1}) equiv 1 cdot 1 equiv 1 mod n`,
    So this set is a group. Since it does not contain `x`, it is a proper subgroup of `ZZ_n^(star)`.
  2. The number `n` is Carmichael number. In this case, `x^(n-1) equiv 1 mod n` for all `x in ZZ_n^(star)`. i.e, such that `gcd(x, n) = 1`. We show this case next.

Miller-Rabin Correctness -- The Carmichael Number Case

Miller-Rabin Correctness -- Finish The Carmichael Number Case