RSA Background Theory and Algorithms: 1 Introductions
RSA Background Theory and Algorithms: 1 Introductions
(18)
That is, each element x
i
of R is a unique positive integer less than n with gcd (x
i
; n) = 1. Now multiply
each element by a, modulo n:
S =
(ax
1
modn) ; :::;
ax
(n)
modn
(19)
The set S is a permutation of R, by the following line of reasoning:
1. Because a is relatively prime to n and x
i
is relatively prime to n, a x
i
must also be relatively prime to
n. Thus, all member of S are integers that are less than n and relatively prime to n.
2. There are no duplicates in S. (similar to Theorem 7)
4
Therefore
(n)
Y
i=1
(ax
i
modn) =
(n)
Y
i=1
x
i
(n)
Y
i=1
(ax
i
) =
(n)
Y
i=1
x
i
(modn)
a
(n)
(n)
Y
i=1
(x
i
) =
(n)
Y
i=1
x
i
(modn)
a
(n)
= 1 (modn) (20)
However, if a and n are relatively prime then a
k
and n are relatively prime and we have
a
k
(n)
= 1 (modn) (21)
Alternatively we can state the result as
a
(n)+1
= a (modn) (22)
where a does not have to be relatively prime to n.
Notice that this is looks very similar to Theorem 7! As we will see, it also provides us with what we need
to build the RSA algorithm.
3 The RSA Algorithm
First we have a Plaintext block M < n; that is the block size b must satisfy b _ log
2
n. In practice, the block
size b is i bits, where 2
i
< n _ 2
i+1
. The cipher block C is given by
C = M
e
modn (23)
and decryption by
M = C
d
modn = (M
e
)
d
= M
ed
modn (24)
Both the sender and receiver must know n. The sender knows the value of e, and only the receiver knows
the value of d.
PU
key
= e; n (25)
PR
key
= d; n (26)
For this algorithm to be satisfactory for PKI we must meet the following requirements:
1. It is possible to nd values of e; d; n such that M
ed
modn = M for all M < n.
2. It is relatively easy to calculate M
e
modn and C
d
modn for all values of M < n.
3. It is infeasible to determine d given e and n.
Requirement (2) can be easily satised using ordinary arithmetic modulo n. (3) relies on the diculty
in factoring large primes as we will see. That leaves Relationship (1).
We need to nd a relationship of the form
M
ed
(modn) = M or M
ed
= M (modn) (27)
5
If
ed 1 = k (n) (28)
== ed = k(n) + 1 (29)
== ed = 1 (mod(n)) (30)
Then By Theorem 10 (see Equation 21)
M
ed1
= 1 (modn) (31)
is known to hold. The alternate form of Theorem 10 gives.
M
ed
= M (modn)
From Equation 30 we must have that e and d are inverses of each other modulo (n). That is,
ed = 1 mod(n) (32)
d = e
1
mod(n) (33)
This gives the method of calculating d or e. Also note that, according to the rules of modular arithmetic,
this is true only if d (and therefore e) is relatively prime to (n). Equivalently, gcd ((n) ; d) = 1. We can
check the gcd and nd the inverse using Euclids Extended algorithm.
Table 1 gives the values needed for the RSA scheme. Notice that (n) is never divulged in the public
or private keys. Generating a public key from the private (or vice versa) requires knowledge of (n). No
problem you say, Ill just factor n. But here is the rub: factoring large primes is dicult and thus requirement
(3) from above is met.
p; q, two prime numbers (private, chosen)
n = pq (public, calculated)
e, with gcd ((n) ; e) = 1; 1 < e < (n) (public, calculated)
d = e
1
(mod(n)) (private, calculated)
Table 1: RSA Values
This leads to the key generation algorithm given in Table 2.
Key Generation
Select p; q p; q both prime p ,= q
Calculate n = p q
Calculate (n) = (p 1) (q 1)
Select integer e gcd ((n) ; e) = 1; 1 < e < (n)
Calculate d d = e
1
mod((n))
Return Public Key PU
key
= e; n
Return Private Key PR
key
= d; n
Table 2: Key Generation Algorithm
Example 11 (Simple RSA) 1. Let p = 17 and q = 11.
2. Then n = 187
3. and (n) = 160.
4. Select e such that gcd (e; (n)) = 1 (relatively prime) and e < (n). Let e = 7.
5. Determine d = 23 using Euclids extended algorithm.
6
6. Return the public and private keys PU
key
= 7; 187 ; and PR
key
= 23; 187.
Suppose we have M = 88. Encrypting this with PU
key
and exploiting the properties of modular arithmetic
gives:
88
7
=
88
4
mod187
88
2
mod187
88
1
mod187
88
1
mod187 = 88
88
2
mod187 = 77
88
4
mod187 = 77
2
mod187 = 132
88
7
mod187 = 132 77 88 mod187 = 11
So C = 88
7
mod187 = 11.
4 Homework
1. Using the example above, decrypt C = 11.
2. Program the RSA algorithm in jave to generate key pairs and encrypt/decrypt 32-bit blocks of data.
7