- Number theory problems used in public key cryptography
- Need efficient ways of generating large prime numbers
- Definitions of hard computational problems are the base of crypto systems
Let p, q be relatively prime.
Let n=pq be the modulus.
Given integers c1 and c2 there exists a unique integer 0≤x<n such that:
xx≡c1(modp)≡c2(modq)
x≡pny1c1+qny2c2(modn)
Where:
y1≡(pn)−1(modp)≡q−1(modp)y2≡(qn)−1(modq)≡p−1(modq)
Condensed Equation:
x≡qc1(q−1(modp))+pc2(p−1(modq))(modpq)
Find x such that x≡5(mod6) and x≡33(mod35):
-
c1=5 and c2=33
-
p=6 and q=35 are relatively prime so CRT can be used
-
n=6⋅35=210
For y1:
6210y135y15y1y1≡1(mod6)≡1(mod6)≡1(mod6)≡5(mod6)
Make sure you replace q with qmodp (assuming q>p): otherwise instead of finding 5−1(mod6), you will find 6−1mod35.
For y2:
35210y16y1y1≡1(mod35)≡1(mod35)≡6(mod35)
x≡pny1c1+qny2c2(modn)≡(35⋅5⋅5)+(6⋅6⋅33)(mod210)≡173(mod210)
Find x such that x≡5(mod7) and x≡7(mod10)
gcd(7,10)=1; p and q are relatively prime. Hence, CRT applies.
Hence n=7⋅10=70
x≡10⋅y1⋅5+7⋅y2⋅7≡50y1+49y2(mod70)(mod70)
Where:
Hence:
x≡50y1+49y2≡50⋅5+49⋅3≡250+147≡40+7≡47(mod70)(mod70)(mod70)(mod70)(mod70)
Test:
-
47mod7=42+5=5 as required
-
47mod10=40+7=7 as required
Given the positive integer n, the Euler function ϕ(n) denotes the number of positive integers less than n and relatively prime to n.
e.g. ϕ(10)=4 as Z10∗={1,3,7,9}.
ϕ(p)=p−1 where p is prime.
ϕ(pq)=(p−1)(q−1) where p and q are distinct primes.
if n=p1e1…ptet where pi are distinct primes, then:
ϕ(n)=i=1∏tpiei−1(pi−1)
e.g. for 24=23⋅31, ϕ(24)=22(2−1)⋅30(3−1)=4⋅2=8
Let p be a prime; for any integer a such that 1<a≤p−1:
ap−1modp=1
More general case of Fermat’s theorem.
If gcd(a,n)=1 (i.e. a and n coprime) then:
aϕ(n)modn=1
Testing for primality by trial division not practical for large numbers.
There are many probabilistic methods, although these may fail in exceptional circumstances.
Agrawal, Saxena, Kayal 2002: polynomial time deterministic primality test, although still impractical.
Fermat’s little theorem: if p is prime, ap−1modp=1 for all a such that gcd(a,p)=1.
If an−1modn=1, n is NOT a prime.
The probability of failure can be reduced by repeating the test with different base values of a.
Given the number n to test for primality and k, the number of times to run the test:
- Pick a at random such that 1<a<n−1
- If an−1modn=1, return n as being composite. Otherwise, return probable prime
- The powers can be reduced using the following properties:
-
abmodn=(amodn)(bmodn)modn
-
(am)kmodn=(ammodn)kmodn
Some composite numbers such as 561 and 1105 are called Carmichael numbers; the Fermat primality test always returns these numbers as being probable primes.
Check if 517 is prime, running the test at most four times with values a=2,3,11,17.
n−1=517−1=516=43⋅3⋅22
Using a=2:
2516mod517=(243mod517)12mod517=(382)12mod517=((382)3mod517)4mod517=(28)4mod517=460=1
Hence it is composite, so we do not need to make further checks.
Most widely used test for generating large prime numbers. It is guaranteed to detect composite numbers of the test is run sufficiently many times.
Modular square root of 1: a number x such that x2modn=1. In other words, the root of the equation x2−1≡(x−1)(x+1)≡0(modn).
There are four square roots of 1 when n=pq (i.e. composite):
- Two are 1 and −1
- Two are called non-trivial square roots of 1
If x is a non-trivial square root of 1 then gcd(x−1,n) is a non-trivial factor of n. Hence, n must be composite.
Let n and u be odd and find v such that n−1=2vu. Then:
- Pick a at random such that 1<a<n−1
- Set b=aumodn
- If b=1, return probable prime
- For j=0 to v−1:
- If b=−1, return probable prime
- Else, set b=b2modn
- Return composite
If the test returns probable prime, n may be composite.
If n is composite then then test returns probable prime with at most a probability of 0.25.
As the algorithm is run k times, it outputs probable prime when n is composite with a probability of no more than 0.25k.
In practice, the error probability is smaller: when a is given the first seven primes, the smallest composite the algorithm returns as being a probable prime is 341,550,071,728,321
Given a random a such that 0<a<n−1, with n−1 being equal to 2vu.
Hence, b can be given the values {aumodn,a2umodn,…,a2vumodn}.
Each number on the sequence is the square of the previous number (modulo n).
If n is prime, a2vumodn=an−1=1 (Fermat’s theorem). Hence:
- Either aumodn=1 OR
- There is a square root of 1 somewhere in the sequence whose value is −1 (which is equal to n−1
If a non-trivial square root of 1 is found, n must be composite.
Let n=1729 (a Charmichael number)
n−1=1728=64×27=26×27. Hence, v=6, u=27.
- Choose a=2
-
b=227mod1729=645
-
b=1 so:
-
b=6452modn=1065
-
b=10652modn=1
-
b=12modn=1
-
…
- Hence, b=−1=n−1 will never occur
- Hence, n must be composite
NB: 1064 is a non-trivial square root of 1 modulo 1729: gcd(1729,1064)=133 is a factor of 1729.
Let n=17.
n−1=16=2vu.
16=25 and u must be odd. Hence, the only valid values are u=1 and v=5.
Let 1<a<n−1 be a prime. Pick a=3:
-
b=aumodn=31mod17=3
- This is not 1 so:
- Repeat up to v=5 times:
-
b=32mod17=9
-
b=92mod17=13
-
b=132mod17=16=−1
Hence, 17 is a probable prime. Repeat for other values of a until satisfied.
- Choose a random odd integer n of the same number of bits as the required prime
- Test if r is divisible by any of a small list of primes
- If not:
- Apply the Miller-Rabin test five random or fixed based values of a
- If r fails any test, set r=r+2 and return to step 2
This incremental method does not produce completely random primes. If this is an issue start from step 1 if r is found to be composite.
Two aspects:
- Algorithmic complexity: how long does it to take to run a particular algorithm
- Problem complexity: how long does it to take to run the best known algorithm for the given problem
Express this complexity using ‘big O’ notation; in terms of the space and time required to solve the problem for a given size.
Integer factorization: given an integer of m bits, find its prime factors.
Discrete logarithm problem (base 2): given a prime p of m bits and an integer 0<y<p, find x such that y=2xmodp
There are no known polynomial algorithms to solve the problems; the best known algorithms are sub-exponential.
Trial by division: exponential time algorithm
Some fast methods exist, although they only apply to integers with particular properties.
Bets known general method: number field sieve, a sub-exponential algorithm.
As n=pq, n is large even with small keys; brute force search of 128-bit AES keys takes roughly the same computational effort as factorization of a 3072-bit number with two factors of roughly equal size.
Given a prime p and generator g of Zp∗, the discrete logarithm is:
Given y∈Zp∗, find x such that y=gxmodp.
(i.e. find the power given the remainder)
This can be written as x=logg(y)(modp).
If p is large enough, the problem is hard. Given the same length, the security level is equal RSA (and hence should be at least 2048 bits).
Find x such that 2x=3mod5:
123:21mod5=2:22mod5=4mod5=4:23mod5=8mod5=3
Hence x=3.
Find the discrete logarithm of the number 4 with regard to base 2 for the modulus p=7.
i.e. solve 2x=4mod7.
12345:21:22≡2⋅2:23≡4⋅2≡8:24≡1⋅2:24≡2⋅2≡2≡4≡1≡2≡4(mod7)(mod7)(mod7)(mod7)(mod7)
There is a cycle with powers of 2 modulo 7 taking on the values 2,4,1. Hence, x=2.