Number theory

Theory Of Numbers

Shop Books Developers Feedback
Home

RSA Encryption

Prequisites

Modulo P

The Set:
Z(p) = { 0 , 1 , 2 , 3 , 4 , . . . , p-1 }

Is called the set of integers modulo p (or mod p for short). It is a set that contains Integers from 0 up until p-1.
Example: Z10={0,1,2,3,4,5,6,7,8,9}

Multiplicative Inverse And The Greatest Common Divisor



A multiplicative inverse for x is a number that when multiplied by x, will equal 1. The multiplicative inverse of x is written as x-1 and is defined as so:

x . x-1 = 1

The greatest common divisor (gcd) between two numbers is the largest integer that will divide both numbers. For example, gcd(4,10)=2.

The interesting thing is that if two numbers have a gcd of 1, then the smaller of the two numbers has a multiplicative inverse in the modulo of the larger number.


Example: Lets work in the set Z9, then 4 Z9 and gcd(4 , 9) = 1. Therefore 4 has a multiplicative inverse (written 4-1) in mod 9, which is 7. And indeed, 4 . 7 = 28 = 1 mod 9. But not all numbers have inverses. For instance, 3 Z9 but 3-1 does not exist! This is because gcd(3 , 9)=3 ≠ 1.

Euler's Totient

Euler's Totient is the number of elements that have a multiplicative inverse in a set of modulo integers. The totient is denoted using the Greek symbol phi ϕ.the totient is just the count of the number of elements that have their gcd with the modulus equal to 1. This brings us to an important equation regarding the totient and prime numbers:


p P , ϕ(p) = (p-1)


EXAMPLE : ϕ(7) = |{0 , 1 , . . . , 6 }| = 6



R S A

With the above background, we have enough tools to describe RSA and show how it works. RSA is actually a set of two algorithms:

  1. Key Generation: A key generation algorithm.
  2. RSA Function Evaluation: A function F that takes as input a point x and a key k and produces either an encrypted result or plaintext, depending on the input and the key.

Key Generation

The key generation algorithm is the most complex part of RSA. The aim of the key generation algorithm is to generate both the public and the private RSA keys. Sounds simple enough! Unfortunately, weak key generation makes RSA very vulnerable to attack. So it has to be done correctly. Here is what has to happen in order to generate secure RSA keys

  1. Large Prime Number Generation: Two large prime numbers p and q need to be generated. These numbers are very large: At least 512 digits, but 1024 digits is considered safe.
  2. Modulus : From the two large numbers, a modulus n is generated by multiplying p and q.
  3. Totient : The totient of n,ϕ(n) is calculated. n = p * q
  4. Public Key (e) : A prime number is calculated from the range [ 3, ϕ(n) ) that has a greatest common divisor of 1 with ϕ(n).
  5. Private Key (d): Because the prime in step 4 has a gcd of 1 with ϕ(n), we are able to determine it's inverse with respect to modϕ(n).


R S A Function Evaluation

This is the process of transforming a plaintext message into ciphertext, or vice-versa. The RSA function, for message m and key k is evaluated as follows:
F(m,k) = mk mod (n)

Encryption : F(m,e) = me mod n = c (cipher) where m is the message , e is the public key and n is modulus

Decryption : F(c,d) = cd mod n = m the message

R S A Keygen










References

mitocw

MIT OpenCourseWare By Prof.Andrew Sutherland