RSA involves a public key and a private key. The public key can be known to everyone and is used for encrypting messages. Messages encrypted with the public key can only be decrypted using the private key.
Operation
The RSA algorithm involves three steps: key generation, encryption and decryption.
Key generation
RSA involves a public key and a private key. The public key can be known to everyone and is used for encrypting messages. Messages encrypted with the public key can only be decrypted using the private key. The keys for the RSA algorithm are generated the following way:
- Choose two distinct prime numbers p and q.
- For security purposes, the integers p and q should be chosen uniformly at random and should be of similar bit-length. Prime integers can be efficiently found using a Primality test.
- Compute n = pq.
- n is used as the modulus for both the public and private keys
- Compute the totient: .
- Choose an integer e such that , and e and share no divisors other than 1 (i.e. e and are coprime).
- e is released as the public key exponent.
- Choosing e having a short addition chain results in more efficient encryption. Small public exponents (such as e=3) could potentially lead to greater security risks.
- Determine d (using modular arithmetic) which satisfies the congruence relation .
- Stated differently, ed − 1 can be evenly divided by the totient (p − 1)(q − 1).
- This is often computed using the Extended Euclidean Algorithm.
- d is kept as the private key exponent.
The public key consists of the modulus n and the public (or encryption) exponent e. The private key consists of the modulus n and the private (or decryption) exponent d which must be kept secret.
Notes on some variants:
- PKCS#1 v2.0 and PKCS#1 v2.1 specifies using , where lcm is the least common multiple instead of .
- For efficiency the following values may be precomputed and stored as part of the private key:
- p and q: the primes from the key generation,
- and ,
- .
Encryption
Alice transmits her public key (n,e) to Bob and keeps the private key secret. Bob then wishes to send message M to Alice.
He first turns M into an integer 0 < m < n by using an agreed-upon reversible protocol known as a padding scheme. He then computes the ciphertext c corresponding to:
This can be done quickly using the method of exponentiation by squaring. Bob then transmits c to Alice.
Decryption
Alice can recover m from c by using her private key exponent d by the following computation:
Given m, she can recover the original message M by reversing the padding scheme.
The above decryption procedure works because:
- .
Now, since ,
- .
The last congruence directly follows from Euler's theorem when m is relatively prime to n. Using the Chinese remainder theorem, it can be shown that the equations holds for all m.
This shows that we get the original message back:
Its a very popular algorithm and is widely used in variety of security applications. In this article you have explained all the aspects of it in simple way. I will suggest the link to this post to all my friends who are finding it difficult to understand.
ReplyDeleteelectronic signatures