




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This document covers topics related to cryptography and primality testing. It includes RSA, attacks on plain RSA, discrete log/DDH, polynomial time algorithms, GCD, multiplicative inverse, power mod, uniform sampling, Chinese remainder theorem, Bertrand's postulate, Miller-Rabin test, and more. the probability of failure in generating random primes and the Miller-Rabin primality test. It can be useful as study notes, lecture notes, summary, or exam for a course on cryptography or number theory.
Typology: Study notes
1 / 102
This page cannot be seen from the preview
Don't miss anything!





























































































Spring 2021^1
Recap
RSA Key-Generation
KeyGeneration (1 n^ )
Step 1: Pick two random n-bit primes p and q Step 2: Let N=pq, 𝜙𝜙 𝑁𝑁 = (𝑝𝑝 − 1)(𝑞𝑞 − 1) Step 3: …
Question : How do we accomplish step one?
Bertrand’s Postulate
Theorem 8.32. For any n > 1 the fraction of n-bit integers that are prime is at least 1 ⁄3𝑛𝑛.
GenerateRandomPrime (1 n^ )
For i=1 to 3n 2 :
p’ {0,1}n- p 1 ‖𝑝𝑝𝑝 if isPrime(p) then return p
return fail
Can we do this in polynomial time?
isPrime(p): Miller-Rabin Test
Theory : Deterministic algorithm to test for primality.
Practice: Miller-Rabin Test (randomized algorithm)
The “Almost” Miller-Rabin Test
Input : Integer N and parameter 1t
Output : “prime” or “composite”
for i=1 to t:
a {1,…,N-1} if 𝑎𝑎 𝑁𝑁−1^ ≠ 1 mod N then return “composite”
Return “prime”
Claim: If N is prime then algorithm always outputs “prime”
Proof: For any a ∈ {1,…,N−1} we have 𝑎𝑎 𝑁𝑁−1^ = 𝑎𝑎 𝜙𝜙 𝑁𝑁^ = 1 𝑚𝑚𝑚𝑚𝑚𝑚 𝑁𝑁
𝜙𝜙 𝑁𝑁 = 𝑁𝑁 − 1 for primes N
Miller-Rabin Primality Test
Input : Integer N and parameter 1t
Output : “prime” or “composite”
If Even(N) or PerfectPower(N ) return “composite”
Else find 𝑢𝑢 (odd) and 𝑟𝑟 ≥ 1 s.t. N − 1 = 2𝑟𝑟^ 𝑢𝑢
for j=1 to t:
pick 𝑎𝑎 in [2,N-2] randomly if 𝑎𝑎 𝑢𝑢^ ≠ ±1 mod N and 𝑎𝑎 2
𝑖𝑖 (^) 𝑢𝑢 ≠ −1 mod N for all 1 ≤ 𝑖𝑖 ≤ 𝑟𝑟 − 1 return “composite”
Return “prime”
Miller-Rabin Primality Test
Input : Integer N and parameter 1 t
Output : “prime” or “composite”
If Even(N) or PerfectPower(N ) return “composite”
Else find 𝑢𝑢 (odd) and 𝑟𝑟 ≥ 1 s.t. N − 1 = 2𝑟𝑟^ 𝑢𝑢
for j=1 to t:
pick 𝑎𝑎 in [2,N-2] randomly if 𝑎𝑎 𝑢𝑢^ ≠ ±1 mod N and 𝑎𝑎 2
𝑖𝑖 (^) 𝑢𝑢 ≠ −1 mod N for all 1 ≤ 𝑖𝑖 ≤ 𝑟𝑟 − 1 return “composite”
Return “prime”
Lemma: If p is prime and 𝑥𝑥 2 = 1 mod p then 𝑥𝑥 = ±1 mod p
Miller-Rabin Primality Test
Input : Integer N and parameter 1t
Output : “prime” or “composite”
If Even(N) or PerfectPower(N ) return “composite”
Else find 𝑢𝑢 (odd) and 𝑟𝑟 ≥ 1 s.t. N − 1 = 2𝑟𝑟^ 𝑢𝑢
for j=1 to t:
pick 𝑎𝑎 in [2,N-2] randomly if 𝑎𝑎 𝑢𝑢^ ≠ ±1 mod N and 𝑎𝑎 2
𝑖𝑖 (^) 𝑢𝑢 ≠ −1 mod N for all 1 ≤ 𝑖𝑖 ≤ 𝑟𝑟 − 1 return “composite”
Return “prime”
If N is prime we won’t return composite 𝟎𝟎 = 𝑎𝑎 2
𝑟𝑟 (^) 𝑢𝑢 − 𝟏𝟏 = 𝑎𝑎 2
𝑟𝑟−1 (^) 𝑢𝑢 − 𝟏𝟏 𝑎𝑎 2
𝑟𝑟−1 (^) 𝑢𝑢
𝑟𝑟−2 (^) 𝑢𝑢 − 𝟏𝟏 𝑎𝑎 2
𝑟𝑟−2 (^) 𝑢𝑢
𝑟𝑟−1 (^) 𝑢𝑢
𝑎𝑎 2
𝑖𝑖 (^) 𝑢𝑢 − 𝟏𝟏 = 𝑎𝑎 2
𝑖𝑖−1 (^) 𝑢𝑢 − 𝟏𝟏 𝑎𝑎 2
𝑖𝑖−1 (^) 𝑢𝑢
Miller-Rabin Primality Test
Input : Integer N and parameter 1t
Output : “prime” or “composite”
If Even(N) or PerfectPower(N ) return “composite”
Else find 𝑢𝑢 (odd) and 𝑟𝑟 ≥ 1 s.t. N − 1 = 2𝑟𝑟^ 𝑢𝑢
for j=1 to t:
pick 𝑎𝑎 in [2,N-2] randomly if 𝑎𝑎 𝑢𝑢^ ≠ ±1 mod N and 𝑎𝑎 2
𝑖𝑖 (^) 𝑢𝑢 ≠ −1 mod N for all 1 ≤ 𝑖𝑖 ≤ 𝑟𝑟 − 1 return “composite”
Return “prime” 𝑎𝑎^2
𝑖𝑖 (^) 𝑢𝑢 − 𝟏𝟏 = 𝑎𝑎 2
𝑖𝑖−1 (^) 𝑢𝑢 − 𝟏𝟏 𝑎𝑎 2
𝑖𝑖−1 (^) 𝑢𝑢
If N is prime we won’t return composite
𝑟𝑟 (^) 𝑢𝑢 − 𝟏𝟏 = ⋯ = 𝑎𝑎 𝑢𝑢^ − 𝟏𝟏 � 𝒊𝒊=𝟎𝟎
𝒓𝒓−𝟏𝟏 𝑎𝑎 2
𝑖𝑖 (^) 𝑢𝑢
Miller-Rabin Primality Test
Input : Integer N and parameter 1t
Output : “prime” or “composite”
If Even(N) or PerfectPower(N ) return “composite”
Else find 𝑢𝑢 (odd) and 𝑟𝑟 ≥ 1 s.t. N − 1 = 2𝑟𝑟^ 𝑢𝑢
for j=1 to t:
if 𝑎𝑎 𝑢𝑢^ ≠ ±1 mod N and 𝑎𝑎 2
𝑖𝑖 (^) 𝑢𝑢 ≠ −1 mod N for all 1 ≤ 𝑖𝑖 ≤ 𝑟𝑟 − 1 return “composite”
Return “prime”
Claim: If N is composite then at most ¼ choices of random value a in [2,n-1] will pass the test
Miller-Rabin Primality Test
Input : Integer N and parameter 1t
Output : “prime” or “composite”
If Even(N) or PerfectPower(N ) return “composite”
Else find 𝑢𝑢 (odd) and 𝑟𝑟 ≥ 1 s.t. N − 1 = 2𝑟𝑟^ 𝑢𝑢
for j=1 to t:
if 𝑎𝑎 𝑢𝑢^ ≠ ±1 mod N and 𝑎𝑎 2
𝑖𝑖 (^) 𝑢𝑢 ≠ −1 mod N for all 1 ≤ 𝑖𝑖 ≤ 𝑟𝑟 − 1 return “composite”
Return “prime”
Claim: If N is composite then we return prime with probability at most 𝟒𝟒 −𝐭𝐭 Proof: (See textbook )
Back to RSA Key-Generation
KeyGeneration (1 n^ )
Step 1: Pick two random n-bit primes p and q Step 2: Let N=pq, 𝜙𝜙 𝑁𝑁 = (𝑝𝑝 − 1)(𝑞𝑞 − 1) Step 3: Pick e > 1 such that gcd(e, 𝜙𝜙 𝑁𝑁 )= Step 4: Set d=[e-1^ mod 𝜙𝜙 𝑁𝑁 ] (secret key) Return: N, e, d
Be Careful Where You Get Your “Random Bits!”
The Return of Coppersmith's Attack: Practical Factorization of Widely Used RSA Moduli (CCS 2017)^22