RSA Algorithm
Introduction
The RSA cryptosystem, named after its inventors Rivest, Shamir, and Adleman, is one of the first practical public-key encryption systems. Its security rests on the computational difficulty of factoring large integers—a problem that has resisted efficient solution for centuries.
In RSA, the encryption key can be made public without compromising security, because decryption requires knowledge of the prime factorization of a large number. This asymmetry between easy multiplication and hard factorization is the mathematical foundation of the system.
Understanding RSA requires familiarity with modular arithmetic, Euler's theorem, and the Chinese Remainder Theorem. These number-theoretic tools combine elegantly to create a practical and secure encryption method.
Mathematical Prerequisites
Euler's Totient Function
Euler's totient function counts the integers from to that are coprime to For a prime
For the product of two distinct primes
Euler's Theorem
Euler's theorem generalizes Fermat's Little Theorem. If then:
This theorem is the key to RSA: it allows us to compute inverses of exponents modulo
Key Generation
RSA key generation proceeds as follows:
Choose two large distinct prime numbers and In practice, these are typically bits or larger each.
Compute the modulus This will be part of both public and private keys.
Compute Euler's totient:
Choose a public exponent such that and Common choices are or .
Compute the private exponent as the modular inverse of modulo
The public key is and the private key is The primes and must be kept secret and can be discarded after computing .
Encryption and Decryption
Encryption
To encrypt a message (represented as an integer with ), compute the ciphertext:
This operation uses only the public key. Anyone can encrypt messages to the key owner.
Decryption
To decrypt the ciphertext compute:
This requires the private key. Only the key owner can decrypt.
Correctness Proof
We must verify that decryption recovers the original message:
Substituting
Since we can write for some integer Thus:
If Euler's theorem gives so:
The case when (i.e., is divisible by or can be handled separately using the Chinese Remainder Theorem, confirming that decryption works for all valid messages.
Security of RSA
The security of RSA relies on the difficulty of the integer factorization problem. Given finding and is believed to be computationally infeasible for sufficiently large primes.
If an attacker could factor they could compute and then find from The best known classical algorithms for factoring have sub-exponential but super-polynomial complexity.
The number field sieve, the fastest known classical algorithm, factors an bit integer in approximately:
For 2048-bit keys, this is astronomically large. However, Shor's quantum algorithm can factor in polynomial time, making RSA vulnerable to future quantum computers.
Efficient Computation
Modular Exponentiation
Computing directly is infeasible for large exponents. Instead, we use repeated squaring (binary exponentiation). Express in binary and compute successive squares modulo .
This reduces the number of multiplications from to making encryption and decryption practical.
Chinese Remainder Theorem Optimization
Decryption can be accelerated using the Chinese Remainder Theorem. Since we compute:
Then combine using CRT. Since computations modulo and involve numbers half the size, this is about times faster than direct computation modulo .
Digital Signatures
RSA can also create digital signatures. To sign a message the signer computes:
Anyone can verify the signature using the public key:
Only the private key holder can produce valid signatures, but anyone can verify them. In practice, we sign a hash of the message rather than the message itself.
Summary
RSA is a public-key cryptosystem based on the difficulty of factoring large integers. Key generation involves choosing primes computing and then finding and with
Encryption computes decryption computes Euler's theorem guarantees correctness. RSA also enables digital signatures by reversing the roles of and .