RSA
RSA is a public-key encryption system based on the idea that two prime numbers are computationally easy to multiply together but very difficult to factor back into the original primes. Named after its three creators from MIT: Ronald Rivest, Adi Shamir, and Leonard Adleman.
In RSA and other public-key systems, there is a public key, which can encrypt messages and is freely available, and a private key, which can decrypt messages and is kept secret. We can use the keys to encrypt messages (using the recipient's public key so only they can decrypt) and digital signatures (using the sender's private key to prove authenticity).
However, RSA is a slow algorithm typically not used for directly encrypting user data; more often, it's used for transmitting shared keys for symmetric key cryptography (like AES), which is much faster for bulk encryption.
Algorithm
To create a private and public key, we use the following steps:
- Select two large prime numbers, and . (In practice, each should be hundreds or thousands of bits long—commonly 2048 bits or more—to ensure security.)
- Calculate (the modulus).
- Calculate Euler's Totient Function:
- Choose a public key that is relatively prime to . Two numbers are relatively prime when their greatest common divisor (GCD) is 1. (A common choice is , a Fermat Prime. It has only two 1’s in its binary representation, greatly reducing exponentiation time.)
- Compute the private key where:
and are public key components, represented as .
, , and are the private key components, although and are typically discarded, and it's represented as .
Encryption and Decryption
Given and , we can encrypt messages: . Given , we can decrypt messages: .
Example
For a simple example (using small numbers for clarity):
- Choose primes and
- Calculate
- Calculate
- Choose (relatively prime to 3120)
- Calculate (since )
Public key:
Private key:
To encrypt message : To decrypt ciphertext :
Security Considerations
- If the value of is not large enough, an attacker could factorise it, effectively allowing them to solve for .
- Modern RSA implementations use secure padding schemes (like PKCS#1 OAEP) to protect against various attacks, including chosen-ciphertext attacks.
- Key sizes of at least 2048 bits are recommended for security through 2030.
- Side-channel attacks can leak information about private keys during implementation, requiring additional countermeasures.
RSA's security relies on the computational difficulty of the factoring problem, but quantum computers running Shor's algorithm could break RSA encryption, driving research into post-quantum cryptography alternatives.