Named after Ronald Rivest, Adi Shamir, Leonard Adleman. A block cipher over used for both encryption and digital signatures.
Security rests on the integer factorization problem: given for 2 large equal-size primes, finding is computationally intractable. The interactive guide to RSA steps through key generation, encryption, and why factoring is hard.
Key Pair Generation
- Choose 2 large, distinct, equal-size primes , kept secret.
- Compute , public, its bit length is the RSA key length.
- Compute , kept secret.
- Choose with and , public.
- Compute , secret.
Public key: . Private key: . , , and must be destroyed after generation.
Primality Testing
and are found by drawing random odd integers of the target bit length and testing each for primality until one passes.
Trial division by the first few hundred small primes rejects most candidates in a few operations. Survivors go to the Miller-Rabin probabilistic test.
Miller-Rabin tests an odd . Write with odd. Pick a random base with . Then passes base iff or for some with .
A composite passes at most of the bases. Running independent random bases bounds the probability of accepting a composite by . around is standard.
Each base costs 1 modular exponentiation, bit operations with schoolbook multiplication. So a candidate is classified in time polynomial in the key length.
Encryption and Decryption
Encryption cost is a single exponentiation with a small exponent . Decryption cost is a single exponentiation with an exponent up to the full length of , far more expensive.
Hybrid Encryption
RSA is not used to encrypt large data directly, since modular exponentiation on large numbers is slow and the message must be smaller than . Instead:
- The sender picks a random symmetric session key and encrypts the file with a symmetric cipher such as AES under .
- The sender encrypts with the receiver’s RSA public key and sends both the encrypted file and the encrypted key.
- The receiver recovers with their RSA private key, then decrypts the file.
Key Length
RSA-1024 provides less than 112 bits of security strength. It is not acceptable for new encryption, key transport, or signature generation.
Use an RSA modulus of at least 2048 bits where RSA is required. The larger modulus increases the cost of modular exponentiation, so resource-constrained systems should use a standard modern protocol and an appropriate authenticated key-establishment algorithm rather than weakening RSA.
Correctness
Worked Examples
Given and base , determine whether Miller-Rabin identifies as composite.
Solution Reveal Hide
- , so , .
- , not and not .
- For , , not .
- No residue reached , so is a witness and is composite.
- .
Given , , and , generate an RSA key pair. Encrypt and decrypt .
Solution Reveal Hide
- .
- .
- , since .
- , since .
- Public key , private key .
- For , , and .