RSA Mechanics
Key generation, encryption and the correctness proof, worked on small numbers — plus why textbook RSA is unusable, what padding actually does, and why new systems pick elliptic curves instead.
RSA (1977–78) was the first practical public-key cryptosystem and is still holding up a large share of the world's TLS certificates and code signatures. Its security rests on the presumed hardness of factoring a large semiprime. The mechanics fit on one page — which is why every course teaches it — but essentially every real-world RSA break has come not from factoring but from the gap between those clean equations and a safe implementation.
Why asymmetric crypto exists at all #
With symmetric ciphers, every pair of communicating parties needs its own shared key: users require keys, all distributed out of band, and one compromised machine exposes every conversation it participated in. Public-key crypto makes it linear — keys, one keypair per user, public halves published freely.
The trade is speed. RSA is orders of magnitude slower than AES, so nobody encrypts bulk data with it: you encrypt a random session key with the recipient's public key, ship that alongside the AES-encrypted payload, and that hybrid pattern is what TLS, PGP, S/MIME and age all do.
Key generation and the algorithm #
- Pick two large random primes of equal bit length. Compute .
- Compute .
- Choose a public exponent with .
- Compute with the extended Euclidean algorithm.
- Public key is ; private key is . Discard and — but never disclose them.
Correctness follows from Euler's theorem: since , write , so
Textbook RSA is broken — padding is not optional #
The bare equation fails as an encryption scheme on multiple counts:
- Deterministic. Same plaintext → same ciphertext. An attacker with a guessable message space (a yes/no vote, a credit card number, a session ID) just encrypts every candidate under the public key and matches. Semantic security requires randomness in every encryption.
- Malleable. — multiply a ciphertext by and the plaintext gets multiplied by , without the private key. This homomorphism is a feature in other contexts and a disaster here.
- Small message + small exponent. If (e.g. and a short message), no modular reduction happens and over the integers. Håstad's broadcast attack generalizes it: the same message sent to recipients under different moduli is recoverable by CRT.
The fixes are the padding schemes in RFC 8017:
| Scheme | Purpose | Status |
|---|---|---|
| PKCS #1 v1.5 encryption | randomized padding | legacy — Bleichenbacher-vulnerable (below) |
| OAEP | randomized, chosen-ciphertext-secure encryption | current for RSA encryption |
| PKCS #1 v1.5 signatures | deterministic signature padding | still widely deployed, acceptable when implemented carefully |
| PSS | randomized signature padding with a security proof | current preference |
Failure modes that aren't factoring #
Nobody has factored a 2048-bit RSA modulus. The public record of RSA compromise is almost entirely about implementation:
- Bad randomness in key generation. Heninger et al. (2012) scanned the internet and computed the private keys of 0.50% of TLS hosts — roughly 64,000 — because their moduli shared a prime factor with another host's. The cause was embedded devices generating keys at first boot from an unseeded entropy pool. Any two moduli sharing a factor are both broken by a single GCD, which costs nothing against a corpus you already have. This makes entropy a load-bearing dependency of RSA, not a detail.
- Side channels. Timing and power analysis of modular exponentiation, and the CRT fault attack — a single bit-flip during one CRT half lets reveal . Constant-time implementations and signature verification-after-signing are mandatory countermeasures.
- Shared or reused moduli, structurally weak primes from a flawed generator — ROCA (CVE-2017-15361, 2017), an Infineon key-generation defect that made 1024- and 2048-bit keys factorable from the public key alone, forcing Estonia to suspend and re-issue certificates for 760,000 national ID cards and affecting Infineon TPMs, Gemalto smartcards and YubiKeys besides.
Source claims audit #
Seeded from a university lab manual (RSA lab, following Applied Cryptography). Status of its load-bearing claims:
| Claim from source | Status | Notes |
|---|---|---|
| Key generation steps, , encrypt/decrypt equations, correctness derivation | current | Matches the original paper |
| Worked example and all six ciphertext blocks | current | Independently recomputed; all values confirmed |
| vs key-count argument for asymmetric crypto | current | Standard motivation, still the clearest one |
| Hybrid encryption: session key under RSA, bulk under a symmetric cipher | current | Exactly what TLS/PGP do |
| "Primes of 100–200 digits or more" | outdated | 100 decimal digits ≈ 332 bits — far too small. Today: 1024-bit primes for a 2048-bit modulus, minimum |
| "Asymmetric cryptography was proposed only about 20 years ago" | outdated | Dates the text to ~1997; Diffie–Hellman 1976, RSA 1977–78 |
| "Discard and " | needs nuance | Correct not to transmit them, but implementations retain them for CRT decryption — they must be protected, not literally destroyed |
| Message split into fixed blocks, zero-padded on the left | outdated / dangerous | This is textbook RSA. Real RSA encrypts one padded block (OAEP) — usually a symmetric key — never a raw block-chunked message |
| Source presents RSA with no padding at all | — | Added: determinism, malleability, Håstad, Bleichenbacher lineage |
| "Message can equally be encrypted with and decrypted with " | needs correction | Superficially true algebraically, but "encryption with the private key" is not signing — real signatures require PSS/PKCS#1 padding and hashing; see digital signatures |
Sources
- paperA Method for Obtaining Digital Signatures and Public-Key Cryptosystems (Rivest, Shamir, Adleman, 1978)
- docsRFC 8017 — PKCS #1 v2.2: RSA Cryptography Specifications
- paperChosen Ciphertext Attacks Against Protocols Based on RSA Encryption Standard PKCS #1 (Bleichenbacher, 1998)
- paperMining Your Ps and Qs: Widespread Weak Keys in Network Devices (Heninger et al., USENIX Security 2012)
- docsNIST SP 800-57 Part 1 Rev. 5 — Recommendation for Key Management
- paperThe Return of Coppersmith's Attack: Practical Factorization of Widely Used RSA Moduli (ROCA)
- paperEverlasting ROBOT: the Marvin Attack (Kario, 2023)