Google search

Search IT Security Blog:


Saturday, October 10, 2009

RSA

In cryptography, RSA (which stands for Rivest, Shamir and Adleman who first publicly described it) is an algorithm for public-key cryptography. It is the first algorithm known to be suitable for signing as well as encryption, and one of the first great advances in public key cryptography. RSA is widely used in electronic commerce protocols, and is believed to be secure given sufficiently long keys and the use of up-to-date implementations.

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:

  1. 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.

  2. Compute n = pq.

    • n is used as the modulus for both the public and private keys

  3. Compute the totient: \varphi(n) = (p-1)(q-1)\,.

  4. Choose an integer e such that 1 < e < \varphi(n), and e and \varphi(n) share no divisors other than 1 (i.e. e and \varphi(n) 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.

  5. Determine d (using modular arithmetic) which satisfies the congruence relation d e \equiv  1\pmod{\varphi(n)}.

    • 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 \lambda(n) = {\rm lcm}(p-1, q-1) \,, where lcm is the least common multiple instead of \varphi(n) = (p-1)(q-1) \,.

  • 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,

    • d\mod (p - 1) and d\mod(q - 1),

    • q^{-1} \mod(p).

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:


 c \equiv m^e \pmod{n}.

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:

m \equiv c^d \pmod{n}.

Given m, she can recover the original message M by reversing the padding scheme.

The above decryption procedure works because:

c^d \equiv (m^e)^d \equiv m^{ed}\pmod{n}.

Now, since ed = 1 + k\varphi(n),

m^{ed} \equiv m^{1 + k\varphi(n)} \equiv m (m^{\varphi(n)})^{k} \equiv m \pmod{n}.

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:

c^d \equiv m \pmod{n}.

1 comment:

  1. 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.
    electronic signatures

    ReplyDelete