Presentation 05
RSA · Diffie-Hellman
Key Exchange · Number Theory · Integer Factorization · Discrete Logarithm
Padding Schemes · PKI · Forward Secrecy · Quantum Threats
→ / ← navigate Esc overview F fullscreen ?print-pdf export
For N parties to communicate pairwise with symmetric keys, each pair needs a unique shared secret:
N(N−1) / 2 keys required
10 users → 45 keys 1,000 users → 499,500 keys 1M users → ~5 × 1011 keys
Key distribution requires a pre-existing secure channel — a chicken-and-egg problem.
Physical couriers, diplomatic bags, or pre-shared keys simply do not scale to the internet.
1974 Merkle's Puzzles
Ralph Merkle proposed sending N puzzles, each requiring O(N) work to solve. The intended recipient solves one; an eavesdropper must solve all N → O(N2) quadratic gap.
First published concept of public-key agreement, though only quadratic security.
1976 Diffie & Hellman
"New Directions in Cryptography" — introduced the concept of public-key cryptography and the DH key exchange protocol.
1977 RSA
Rivest, Shamir, Adleman — first practical public-key encryption and signature scheme.
Diffie & Hellman, "New Directions in Cryptography" IEEE IT (1976) · Merkle, "Secure Communications Over Insecure Channels" CACM (1978)
a ≡ b (mod n) means n divides (a − b)
Modular arithmetic forms a ring Z/nZ with addition and multiplication.
The set of integers coprime to n forms the multiplicative group (Z/nZ)* of order φ(n).
Euler's Totient Function φ(n)
Counts integers in [1, n] coprime to n.
φ(p) = p − 1 (p prime)
φ(pq) = (p−1)(q−1) (p,q distinct primes)
φ(pk) = pk − pk−1
Fermat's Little Theorem
If p is prime and gcd(a, p) = 1:
ap−1 ≡ 1 (mod p)
Euler's Theorem (generalization)
If gcd(a, n) = 1:
aφ(n) ≡ 1 (mod n)
This is the mathematical foundation of RSA.
Chinese Remainder Theorem (CRT)
If gcd(m, n) = 1, then for any a, b there exists a unique x (mod mn) such that:
x ≡ a (mod m) x ≡ b (mod n)
CRT enables a 4× speedup in RSA private key operations.
Hardy & Wright, "An Introduction to the Theory of Numbers" · Shoup, "A Computational Introduction to Number Theory and Algebra"
Prime Number Theorem: density of primes near N is ~1/ln(N)
For a 1024-bit prime: ~1 in 710 random odd numbers is prime.
Generation: pick random odd n, test primality, increment by 2, repeat.
Miller-Rabin Primality Test
Probabilistic test based on Fermat's Little Theorem:
Write n−1 = 2s · d (d odd). For random witness a:
ad ≡ 1 (mod n) OR
a2rd ≡ −1 (mod n) for some 0 ≤ r < s
Error probability: ≤ 4−t for t rounds.
64 rounds → error < 2−128
SAFE PRIME
p is a safe prime if p = 2q + 1 where q is also prime (a Sophie Germain prime).
Ensures (Z/pZ)* has a large prime-order subgroup → resists Pohlig-Hellman attack on DH.
STRONG PRIME
p is strong if: p − 1 has a large prime factor r, p + 1 has a large prime factor, and r − 1 has a large prime factor.
Historically required for RSA to resist Pollard's p−1 method, but modern key sizes make this less critical.
Industrial-Strength Generation
FIPS 186-5 specifies provable (Shawe-Taylor) and probable (Miller-Rabin) prime generation methods with required error bounds for each RSA key size.
FIPS 186-5, "Digital Signature Standard" (2023) · Menezes, Oorschot & Vanstone, "Handbook of Applied Cryptography" ch. 4
The original 1976 protocol for establishing a shared secret over an insecure channel.
SETUP Agree on public parameters: prime p and generator g of (Z/pZ)*
ALICE Choose secret a ∈ [2, p−2]
Compute and send A = ga mod p
BOB Choose secret b ∈ [2, p−2]
Compute and send B = gb mod p
SHARED SECRET
Alice computes: K = Ba mod p = gab mod p
Bob computes: K = Ab mod p = gab mod p
Alice Bob
secret a secret b
————————————————————
A = ga mod p ———→
←——— B = gb mod p
————————————————————
K = gab mod p
Key insight: An eavesdropper sees p, g, ga mod p, and gb mod p but cannot efficiently compute gab mod p. This is the Computational Diffie-Hellman (CDH) assumption.
Warning: Vanilla DH is vulnerable to man-in-the-middle attacks — no authentication of A or B. Must be combined with signatures or certificates.
Diffie & Hellman, "New Directions in Cryptography" IEEE Trans. Information Theory (1976)
Given g, p, h = gx mod p, find x.
No polynomial-time algorithm is known for general groups. Security of DH, ElGamal, and DSA rests on DLP hardness.
CDH (Computational DH): Given ga, gb, compute gab
DDH (Decisional DH): Distinguish (ga, gb, gab) from (ga, gb, gc)
DLP ≥ CDH ≥ DDH (in terms of hardness)
| Algorithm | Complexity | Notes |
|---|---|---|
| Brute force | O(p) | Trivial |
| Baby-step Giant-step | O(√p) | Shanks, 1971 |
| Pollard's rho | O(√p) | Parallelizable |
| Pohlig-Hellman | O(√q) | q = largest prime factor of group order |
| Index calculus | Lp[1/2, c] | Sub-exponential; Z/pZ* only |
| Number field sieve | Lp[1/3, 1.923] | Best known for large p |
Lp[α, c] = exp(c · (ln p)α · (ln ln p)1−α)
Sub-exponential but super-polynomial for α ∈ (0,1).
Menezes, Oorschot & Vanstone, "Handbook of Applied Cryptography" ch. 3 · Joux & Lercier, "Discrete Logarithms in GF(p)" (2006)
RFC 3526 MODP groups (2003)
Standardized groups: 1536, 2048, 3072, 4096, 6144, 8192-bit primes. All are safe primes (p = 2q+1).
RFC 7919 Negotiated FFDHE (2016)
TLS extension for negotiating named DH groups. Prevents downgrade to weak custom groups.
Groups: ffdhe2048, ffdhe3072, ffdhe4096, ffdhe6144, ffdhe8192.
Generator Selection
Use generator g of a prime-order subgroup of order q where p = 2q+1. Typically g = 2 for safe primes.
Prevents small subgroup attacks.
Static DH
Long-term DH key pair. Same shared secret for repeated exchanges with same party.
No forward secrecy: compromise of long-term key reveals all past sessions.
Ephemeral DH (DHE)
Fresh random exponent per session. Shared secret is unique each time.
Provides forward secrecy: compromise of long-term signing key does NOT reveal past session keys.
FFDHE in TLS 1.3
TLS 1.3 supports FFDHE key exchange alongside ECDHE. Only named groups allowed (no custom parameters). All key exchanges are ephemeral — forward secrecy is mandatory.
RFC 3526 (2003) · RFC 7919 (2016) · RFC 8446, TLS 1.3 (2018)
STEP 1 Choose two large distinct primes p and q
Each ~n/2 bits for an n-bit RSA modulus. |p − q| should not be too small.
STEP 2 Compute n = p · q
n is the RSA modulus (public). Its bit length defines the key size (2048, 3072, 4096, ...).
STEP 3 Compute φ(n) = (p−1)(q−1)
Alternatively use Carmichael's function: λ(n) = lcm(p−1, q−1). Smaller exponents, same correctness.
STEP 4 Choose e such that 1 < e < φ(n) and gcd(e, φ(n)) = 1
Standard choice: e = 65537 = 216 + 1 (Fermat prime F4)
Only two 1-bits → fast modular exponentiation (17 squarings + 1 multiply).
STEP 5 Compute d = e−1 mod φ(n)
Via the Extended Euclidean Algorithm. d is the private exponent.
Public Key: (n, e)
Published openly. Anyone can encrypt messages or verify signatures.
Private Key: d
Kept secret. Used to decrypt or sign.
In practice, store (p, q, d, dp, dq, qinv) for CRT optimization.
Security basis: Given n, it is computationally infeasible to factor n into p · q. Without factoring, computing φ(n) or d from (n, e) alone is believed equally hard.
p = 61, q = 53 → n = 3233
φ(n) = 60 × 52 = 3120
e = 17 → d = 2753
17 × 2753 = 46801 = 15 × 3120 + 1 ✓
Rivest, Shamir & Adleman, "A Method for Obtaining Digital Signatures..." CACM (1978) · PKCS #1 v2.2, RFC 8017
Encrypt (with public key):
c = me mod n
Message m must satisfy 0 ≤ m < n.
Decrypt (with private key):
m = cd mod n
By Euler's theorem: med ≡ m1 + kφ(n) ≡ m · (mφ(n))k ≡ m · 1k ≡ m (mod n)
This holds whenever gcd(m, n) = 1. For m = 0 or m divisible by p or q, correctness follows from CRT.
Deterministic: Same plaintext always produces same ciphertext. Attacker can build a dictionary.
Malleable: Given Enc(m1) and Enc(m2), attacker can compute Enc(m1 · m2) without decrypting:
m1e · m2e = (m1m2)e mod n
No semantic security: Attacker can test whether a ciphertext corresponds to a guessed plaintext by re-encrypting the guess.
Real-world RSA always uses a padding scheme (OAEP for encryption, PSS for signatures) to achieve IND-CCA2 security.
Sign (with private key):
s = md mod n
Only the holder of d can produce s.
Verify (with public key):
m' = se mod n
Accept if m' equals the original message (or its hash).
Never sign the raw message directly.
1. Compute h = Hash(message)
2. Sign the hash: s = hd mod n
Reasons: hash has fixed size (fits in one RSA block), prevents existential forgery on raw RSA.
Unforgeability: Without d, an attacker cannot produce a valid signature on a new message (under the RSA assumption).
Non-repudiation: Only the private key holder could have signed. Unlike MACs, a third party can verify without the signing key.
Existential forgery: Choose arbitrary s, compute m = se mod n. This (m, s) is a valid pair!
Blinding attack: Get victim to sign m' = m · re, then s/r is signature on m.
Both attacks are prevented by hash-then-sign + proper padding (PSS).
RSA-PSS (Probabilistic Signature Scheme): randomized padding that achieves EUF-CMA security in the random oracle model.
Bellare & Rogaway, "The Exact Security of Digital Signatures" (EUROCRYPT 1996) · PKCS #1 v2.2, RFC 8017
PKCS#1 v1.5 (1993)
Format: 0x00 || 0x02 || [random padding] || 0x00 || [message]
Bleichenbacher's attack (1998): adaptive chosen-ciphertext attack. ~1 million queries to decrypt by exploiting padding validity oracle.
ROBOT attack (2017) showed this was still exploitable in practice across major TLS implementations.
RSA-OAEP (1994/2001)
Optimal Asymmetric Encryption Padding (Bellare & Rogaway)
Two-round Feistel structure using hash functions G and H:
s = m ⊕ G(r), t = r ⊕ H(s)
Encrypt: c = (s || t)e mod n
Provably IND-CCA2 secure in the random oracle model.
PKCS#1 v1.5 Signatures
Format: 0x00 || 0x01 || [0xFF padding] || 0x00 || [DigestInfo]
Bleichenbacher (2006) / BERserk: parsing vulnerabilities in implementations that don't check padding strictly. Allowed signature forgery.
Still widely used (TLS 1.2 and earlier) but being phased out.
RSA-PSS (1996/2003)
Probabilistic Signature Scheme
Randomized via a salt value. Uses MGF (mask generation function) based on hash.
Provably EUF-CMA secure in the random oracle model.
Mandatory in TLS 1.3 for RSA signatures.
Recommendation: Use OAEP for encryption and PSS for signatures. Avoid PKCS#1 v1.5 in new designs.
Bleichenbacher, "Chosen Ciphertext Attacks Against Protocols Based on RSA..." (CRYPTO 1998) · Bellare & Rogaway (EUROCRYPT 1994)
| Algorithm | Complexity | Era |
|---|---|---|
| Trial division | O(√n) | Ancient |
| Pollard's p−1 | O(B · log n) | 1974 |
| Pollard's rho | O(n1/4) | 1975 |
| Quadratic sieve | Ln[1/2, 1] | 1981 |
| Elliptic curve method | Lp[1/2, √2] | 1987 |
| GNFS | Ln[1/3, 1.902] | 1993 |
GNFS (General Number Field Sieve) is the fastest known algorithm for factoring general integers > ~100 digits.
RSA-768 (768-bit, 232 digits) — factored 2009
~2,000 CPU-years equivalent. Lenstra et al.
RSA-250 (829-bit, 250 digits) — factored 2020
~2,700 CPU-years. Boudot, Gaudry, Guillevic, Heninger, Thomé, Zimmermann.
RSA-1024 is within reach of nation-state adversaries (estimated ~108 CPU-years with current methods).
Current Recommendations:
2048-bit — minimum for current use (NIST SP 800-57)
3072-bit — recommended for protection beyond 2030
4096-bit — conservative choice / high-value assets
Lenstra et al., "Factorization of a 768-Bit RSA Modulus" (CRYPTO 2010) · NIST SP 800-57 Part 1 Rev. 5 (2020)
Square-and-Multiply
Compute me mod n by scanning bits of e:
result = 1
for bit in e (MSB to LSB):
result = result2 mod n
if bit == 1: result = result · m mod n
For a k-bit exponent: k squarings + ~k/2 multiplies on average.
Montgomery Multiplication
Replaces expensive division (mod n) with shifts and additions by working in Montgomery form: ˜a = a · R mod n, where R = 2k.
MontMul(˜a, ˜b) = ˜a · ˜b · R−1 mod n
Reduction uses only additions and right-shifts — no trial division.
The standard method in all serious RSA implementations.
Instead of computing m = cd mod n directly:
mp = cd mod (p−1) mod p
mq = cd mod (q−1) mod q
m = CRT(mp, mq)
~4× speedup: two half-size exponentiations are 4× faster than one full-size.
This is why PKCS#8 RSA private keys store p, q, dp, dq, qinv.
Multi-Prime RSA
Use n = p1 · p2 · ... · pr (r ≥ 3 primes).
CRT gives r2× speedup for r primes.
3 primes: ~9× faster than single modular exponentiation.
Caution: each prime is smaller → easier to factor individually. Need larger n to compensate.
Montgomery, "Modular Multiplication Without Trial Division" Mathematics of Computation (1985) · PKCS #1 v2.2, RFC 8017
| RSA bits | Symmetric equiv. | ECC equiv. (bits) | Sign/s (SW) | Verify/s (SW) | Pub key size | Status |
|---|---|---|---|---|---|---|
| 1024 | ~80-bit | 160 | ~5,500 | ~160,000 | 128 B | BROKEN |
| 2048 | ~112-bit | 224 | ~800 | ~28,000 | 256 B | MINIMUM |
| 3072 | ~128-bit | 256 | ~270 | ~13,000 | 384 B | RECOMMENDED |
| 4096 | ~140-bit | ~384 | ~120 | ~7,500 | 512 B | CONSERVATIVE |
| 7680 | ~192-bit | 384 | ~18 | ~2,200 | 960 B | NICHE |
| 15360 | ~256-bit | 521 | ~2 | ~350 | 1920 B | THEORETICAL |
Benchmarks: OpenSSL 3.x on Intel i7 @ 3.6 GHz, single-core. Sign uses CRT; verify uses e = 65537.
Key observation: RSA signing throughput drops dramatically with key size (O(k3) for k-bit modulus), while ECC P-256 achieves 128-bit security with ~40,000 sign/s and 256-bit keys. This is the driving force behind the migration to ECC.
NIST SP 800-57 Part 1 Rev. 5 (2020) · OpenSSL speed benchmarks · Barker, "Recommendation for Key Management"
Choose prime p, generator g of (Z/pZ)*.
Choose secret x ∈ [1, p−2].
Compute h = gx mod p.
Public key: (p, g, h) Private key: x
To encrypt message m ∈ (Z/pZ)*:
Choose random k ∈ [1, p−2].
c1 = gk mod p
c2 = m · hk mod p
Ciphertext: (c1, c2)
Note: ciphertext is 2× the size of plaintext (message expansion).
Compute shared secret: s = c1x mod p
Recover message: m = c2 · s−1 mod p
Works because s = gkx = hk, so c2 · s−1 = m · hk · h−k = m.
ElGamal is essentially DH key exchange followed by one-time-pad encryption.
The ephemeral key k creates a DH shared secret hk = gxk which masks the message.
Security reduces to the DDH assumption (stronger than CDH).
Semantically secure (IND-CPA) due to randomization via k.
Homomorphic: Enc(m1) · Enc(m2) = Enc(m1 · m2)
Used in voting protocols, mix-nets, threshold cryptography.
ElGamal, "A Public Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms" IEEE IT (1985)
Speed: RSA-2048 encrypt is ~1,000× slower than AES-128-GCM per byte.
Message size: RSA can only encrypt messages < n (256 bytes for RSA-2048 minus padding overhead).
Expansion: ElGamal doubles ciphertext size.
KEM (Key Encapsulation Mechanism): Use public-key crypto to establish a shared symmetric key.
DEM (Data Encapsulation Mechanism): Use the symmetric key with a fast cipher (AES-GCM) for bulk data.
Clean separation with provable security composition.
1. Choose random r ∈ [0, n). Compute c = re mod n.
2. Derive symmetric key: K = KDF(r)
3. Encrypt data with AES-GCM using K.
4. Send (c, AES-GCM ciphertext).
Simpler and more efficient than RSA-OAEP for key transport. Standardized in ISO 18033-2.
Hybrid Public Key Encryption — modern framework combining:
KEM (DHKEM with X25519/P-256) + KDF (HKDF) + AEAD (AES-GCM/ChaCha20-Poly1305)
Used in: TLS Encrypted ClientHello (ECH), MLS messaging protocol, OHTTP.
In practice: Every TLS handshake, every PGP message, every Signal session uses hybrid encryption. Public-key crypto is the key exchange; symmetric crypto does the heavy lifting.
Cramer & Shoup, "Design and Analysis of Practical Public-Key Encryption Schemes Secure against Adaptive CCA" (2003) · RFC 9180 (2022)
WIENER (1990)
If d < n0.25/3, continued fraction expansion of e/n recovers d efficiently.
Exploits small private exponent.
Boneh-Durfee (1999) extended to d < n0.292 using lattice methods.
COPPERSMITH (1996)
Uses LLL lattice reduction to find small roots of polynomials mod n.
Applications: small e with small message padding, partial key exposure (knowing ~half of d suffices to recover the rest), stereotyped messages.
HÅSTAD BROADCAST
If same message m is encrypted with e = 3 to 3 different recipients (different ni), CRT + cube root recovers m.
Prevented by proper padding (OAEP).
TIMING (Kocher, 1996)
Square-and-multiply branches on key bits. Measuring execution time reveals the private exponent d.
Countermeasure: constant-time implementation, RSA blinding.
FAULT ON CRT-RSA
Boneh-DeMillo-Lipton (1997): A single fault during CRT computation leaks p or q.
If fault in mp but not mq: gcd(sfaultye − m, n) = q.
Devastating: one faulty signature breaks the key.
Countermeasure: verify signature before output.
COMMON MODULUS
If two users share the same n with different e1, e2 where gcd(e1, e2) = 1, an attacker with both ciphertexts can decrypt using the extended Euclidean algorithm.
Wiener (EUROCRYPT 1990) · Coppersmith (J. Cryptology 1997) · Boneh, DeMillo & Lipton (EUROCRYPT 1997) · Kocher (CRYPTO 1996)
MAN-IN-THE-MIDDLE
Mallory intercepts Alice's A and Bob's B, substitutes her own values. Establishes separate shared secrets with each party.
Vanilla DH provides NO authentication.
Fix: authenticate key exchange with digital signatures (STS protocol, TLS handshake).
SMALL SUBGROUP
If the group order has small prime factors, attacker sends elements of small subgroups. Victim's shared secret leaks information about the private exponent modulo small primes.
Fix: use safe primes (p = 2q+1) or validate received elements (check gq = 1 in prime-order subgroup).
LOGJAM (2015)
Precomputation attack on 512-bit DH (export-grade):
NFS precomputation for a fixed prime takes ~1 week. After that, individual DLPs take ~90 seconds.
A single 1024-bit prime used by most of the internet could be targeted by a nation-state with ~$100M in custom hardware (est.).
Fix: use ≥ 2048-bit groups, prefer ECDH.
PRECOMPUTATION DANGER
Many servers used the same DH primes (e.g., Apache's hardcoded 1024-bit prime). Precomputation against that prime breaks ALL connections using it.
Snowden documents suggest NSA may have performed such precomputation.
INVALID GROUP
Attacker sends a value from a different (weaker) group. If not validated, victim computes in the wrong group.
Fix: validate received public keys are in the expected group.
Adrian et al., "Imperfect Forward Secrecy: How Diffie-Hellman Fails in Practice" (CCS 2015) · RFC 2785, "Methods for Avoiding the Small-Subgroup Attacks"
A certificate binds a public key to an identity (domain name, organization), signed by a trusted Certificate Authority (CA).
Key fields: subject, issuer, validity period, public key, extensions (SAN, key usage), CA signature.
Certificate Chains
Root CA (self-signed, in trust store)
↓ signs
Intermediate CA
↓ signs
End-entity certificate (your server)
Root CAs are pre-installed in browsers/OSes (~150 trusted roots).
Revocation
CRL (Certificate Revocation List): CA publishes list of revoked serial numbers. Scalability issues.
OCSP (Online Certificate Status Protocol): Real-time check. Privacy concern (CA learns which sites you visit).
OCSP Stapling: Server fetches its own OCSP response and staples it to the TLS handshake.
HIERARCHICAL PKI
Used by TLS/SSL (WebPKI). Top-down trust from root CAs.
Scalable, well-understood, legally binding.
Single point of failure: compromised CA can issue rogue certificates (DigiNotar 2011, Symantec 2015).
WEB OF TRUST
Used by PGP/GPG. Decentralized: users sign each other's keys.
Trust is transitive and user-defined. No central authority.
Difficult to bootstrap, poor UX, key management burden on users.
CERTIFICATE TRANSPARENCY
Append-only public log of all issued certificates (RFC 6962).
Domain owners monitor logs to detect misissued certs.
Required by Chrome since 2018 for all new certificates.
RFC 5280 (X.509 v3) · RFC 6960 (OCSP) · RFC 6962 (Certificate Transparency)
| Security (bits) | RSA (bits) | ECC (bits) | Ratio |
|---|---|---|---|
| 80 | 1024 | 160 | 6.4× |
| 112 | 2048 | 224 | 9.1× |
| 128 | 3072 | 256 | 12× |
| 192 | 7680 | 384 | 20× |
| 256 | 15360 | 521 | 29.5× |
The ratio grows because RSA relies on sub-exponential factoring (L[1/3]) while ECC relies on exponential ECDLP (Pollard's rho: O(√n)).
| Operation | RSA-3072 | ECDSA P-256 |
|---|---|---|
| Key generation | ~150 ms | ~0.1 ms |
| Sign | ~3.7 ms | ~0.2 ms |
| Verify | ~0.08 ms | ~0.5 ms |
| Public key size | 384 B | 32 B |
| Signature size | 384 B | 64 B |
Industry migration: ECC dominates in TLS 1.3 (ECDHE + ECDSA). RSA still used for legacy compatibility, certificate signatures, and code signing. NIST recommends transitioning to ECC or PQC.
RSA advantage: Verification is extremely fast (e = 65537 has only 17 squarings). Ideal when verification is done far more often than signing (certificate validation, firmware signatures).
NIST SP 800-57 (2020) · eBACS benchmarking project · RFC 8446, TLS 1.3
Perfect Forward Secrecy (PFS): Compromise of long-term private keys does not compromise past session keys.
Even if an attacker records all ciphertext and later obtains the server's private key, they cannot decrypt historical traffic.
Without FS (RSA key transport): Server's RSA private key decrypts the pre-master secret from any recorded session.
Mass surveillance: "record now, decrypt later" is a realistic threat.
With FS: Each session uses unique ephemeral keys. Breaking one session does not help with any other.
DHE Ephemeral Diffie-Hellman
Fresh DH exponents per session. Long-term key only used for signing the ephemeral public values.
ECDHE Ephemeral Elliptic Curve DH
Same concept on elliptic curves. Faster, smaller keys.
The dominant key exchange in modern TLS.
TLS 1.3 Mandates Forward Secrecy
RSA key transport (non-FS) was removed entirely from TLS 1.3.
Only (EC)DHE key exchange is allowed.
Cipher suites: TLS_AES_128_GCM_SHA256, TLS_AES_256_GCM_SHA384, TLS_CHACHA20_POLY1305_SHA256.
Key deletion: Ephemeral secrets must be securely erased after key derivation. Memory zeroization and key lifetime management are critical for FS to hold.
RFC 8446 (TLS 1.3) · NIST SP 800-52 Rev. 2 (TLS Guidelines)
Factoring: Shor's algorithm factors n-bit integers in O(n3) quantum time using O(n) logical qubits.
RSA-2048 can be broken in hours on a sufficiently large fault-tolerant quantum computer.
Discrete Log: Shor also solves DLP in polynomial time.
Breaks DH, ECDH, ElGamal, DSA, and ECDSA.
RSA-2048: ~4,100 logical qubits
RSA-3072: ~6,200 logical qubits
ECC P-256: ~2,330 logical qubits
With current error rates, physical qubit overhead is ~1,000×–10,000×.
Recent work by Gidney & Ekerå (2021): RSA-2048 in ~8 hours with 20M physical qubits.
NIST PQC STANDARDS
ML-KEM (FIPS 203) — lattice-based KEM (ex-CRYSTALS-Kyber)
ML-DSA (FIPS 204) — lattice-based signatures (ex-CRYSTALS-Dilithium)
SLH-DSA (FIPS 205) — hash-based signatures (ex-SPHINCS+)
Finalized August 2024.
Harvest Now, Decrypt Later
Adversaries recording encrypted traffic today can decrypt it once quantum computers arrive. Long-lived secrets (government, healthcare, financial) are already at risk.
CNSA 2.0 Timeline (NSA)
2025: begin transition to PQC
2030: PQC for all new systems
2033: exclusive PQC for web browsers/servers
2035: exclusive PQC for all NSS
Shor, "Algorithms for Quantum Computation" (FOCS 1994) · Gidney & Ekerå, "How to Factor 2048-bit RSA..." (2021) · NIST FIPS 203/204/205 (2024)
Radix-2 Montgomery: Process one bit per clock cycle. Area-efficient but slow (k cycles for k-bit modulus).
High-Radix (2w): Process w bits per cycle. k/w cycles but needs w-bit multiplier. Common: w = 16 or 32.
Systolic Array: Pipeline multiple word-level multiplications. Throughput of one Montgomery multiplication per cycle after pipeline fills.
RSA-2048 on Virtex-7: ~0.3ms per modular exponentiation (CRT)
RSA-2048 on 28nm ASIC: ~0.05ms per operation
Throughput limited by modular exponentiation: O(k2) multiplications for k-bit modulus.
With CRT, two independent half-size exponentiations can run in parallel on dual Montgomery cores.
Combined CRT + dual-core: ~8× speedup over single full-width exponentiation.
RSA BLINDING
Before decryption: multiply c by re for random r.
After: divide result by r.
Attacker's timing/power observations are decorrelated from the actual c and d.
CONSTANT-TIME
Always perform both square and multiply (discard multiply result when bit = 0). No branching on secret bits.
Montgomery ladder: another constant-time approach for modular exponentiation.
Tenca & Koç, "A Scalable Architecture for Modular Multiplication" (IEEE Trans. Computers, 2003)
// Radix-2 Montgomery Modular Multiplier
// Computes: result = a * b * R^(-1) mod n, where R = 2^WIDTH
module montgomery_mul #(
parameter WIDTH = 2048
)(
input logic clk,
input logic rst_n,
input logic start,
input logic [WIDTH-1:0] a, // multiplicand (in Montgomery form)
input logic [WIDTH-1:0] b, // multiplier (in Montgomery form)
input logic [WIDTH-1:0] n, // modulus (odd)
output logic [WIDTH-1:0] result, // a * b * R^(-1) mod n
output logic done
);
logic [WIDTH:0] s; // partial sum (WIDTH+1 bits for overflow)
logic [$clog2(WIDTH)-1:0] i; // bit counter
logic running;
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
s <= '0;
i <= '0;
running <= 1'b0;
done <= 1'b0;
end else if (start) begin
s <= '0;
i <= '0;
running <= 1'b1;
done <= 1'b0;
end else if (running) begin
// Step 1: q_i = (s[0] + a[i]*b[0]) mod 2
logic q_i;
logic [WIDTH:0] s_next;
q_i = s[0] ^ (a[i] & b[0]);
// Step 2: s = (s + a[i]*b + q_i*n) >> 1
s_next = s + (a[i] ? {1'b0, b} : '0) + (q_i ? {1'b0, n} : '0);
s <= s_next >> 1;
if (i == WIDTH[$clog2(WIDTH)-1:0] - 1) begin
running <= 1'b0;
done <= 1'b1;
end
i <= i + 1;
end
end
// Final subtraction: if s >= n, result = s - n; else result = s
assign result = (s >= {1'b0, n}) ? s[WIDTH-1:0] - n : s[WIDTH-1:0];
endmodule
Montgomery, "Modular Multiplication Without Trial Division" Math. Comp. (1985) · Koç et al., "Analyzing and Comparing Montgomery Multiplication Algorithms" IEEE Micro (1996)
import random, math
def is_probable_prime(n, k=64):
"""Miller-Rabin primality test with k rounds."""
if n < 2: return False
if n < 4: return True
if n % 2 == 0: return False
# Write n-1 as 2^s * d
s, d = 0, n - 1
while d % 2 == 0:
s += 1; d //= 2
for _ in range(k):
a = random.randrange(2, n - 1)
x = pow(a, d, n)
if x == 1 or x == n - 1:
continue
for _ in range(s - 1):
x = pow(x, 2, n)
if x == n - 1: break
else:
return False # composite
return True # probably prime
def gen_prime(bits):
"""Generate a random probable prime of given bit length."""
while True:
p = random.getrandbits(bits) | (1 << (bits - 1)) | 1 # set MSB and LSB
if is_probable_prime(p):
return p
def extended_gcd(a, b):
if a == 0: return b, 0, 1
g, x1, y1 = extended_gcd(b % a, a)
return g, y1 - (b // a) * x1, x1
def mod_inverse(e, phi):
g, x, _ = extended_gcd(e % phi, phi)
assert g == 1, "Modular inverse does not exist"
return x % phi
def rsa_keygen(bits=2048):
p = gen_prime(bits // 2)
q = gen_prime(bits // 2)
n = p * q
phi = (p - 1) * (q - 1)
e = 65537
d = mod_inverse(e, phi)
return {'pub': (n, e), 'priv': (n, d), 'p': p, 'q': q}
def rsa_encrypt(m, pub):
n, e = pub
assert 0 <= m < n, "Message must be in [0, n)"
return pow(m, e, n)
def rsa_decrypt(c, priv):
n, d = priv
return pow(c, d, n)
# --- Demo with small primes ---
keys = rsa_keygen(bits=512) # small for demo only!
msg = 42
ct = rsa_encrypt(msg, keys['pub'])
pt = rsa_decrypt(ct, keys['priv'])
assert pt == msg, "Decryption failed!"
print(f"n = {keys['pub'][0]}")
print(f"e = {keys['pub'][1]}")
print(f"ct = {ct}")
print(f"pt = {pt} ✓")
Pick two primes and watch RSA key generation, encryption, and decryption step by step.
Input Primes:
Click "Compute" to see results...
First public-key protocol (1976). Establishes shared secret over insecure channel.
Security: Discrete Logarithm Problem
Best attack: L[1/3] (NFS)
Use ephemeral DH (DHE/ECDHE) for forward secrecy.
Minimum: 2048-bit MODP or 256-bit ECDH.
First practical PKE & signature (1977). Encrypt, sign, key transport.
Security: Integer Factorization Problem
Best attack: L[1/3] (GNFS)
Always use OAEP/PSS padding. Never textbook RSA.
Minimum: 2048-bit. Recommend: 3072-bit.
Shor's algorithm breaks both RSA and DH in polynomial time.
NIST PQC: ML-KEM, ML-DSA, SLH-DSA standardized (2024).
Harvest-now-decrypt-later is already a threat.
Begin migrating to hybrid classical+PQC now.
Foundational Papers
Diffie & Hellman, "New Directions in Cryptography" IEEE IT (1976)
Rivest, Shamir & Adleman, "A Method for Obtaining Digital Signatures and Public-Key Cryptosystems" CACM (1978)
ElGamal, "A Public Key Cryptosystem..." IEEE IT (1985)
Merkle, "Secure Communications Over Insecure Channels" CACM (1978)
Standards
PKCS #1 v2.2 / RFC 8017 — RSA Cryptography Specifications
NIST SP 800-57 — Recommendation for Key Management
FIPS 186-5 — Digital Signature Standard (2023)
RFC 3526 / 7919 — MODP DH Groups / Negotiated FFDHE
RFC 8446 — TLS 1.3
RFC 9180 — Hybrid Public Key Encryption (HPKE)
Attacks & Cryptanalysis
Bleichenbacher, "Chosen Ciphertext Attacks..." (CRYPTO 1998)
Wiener, "Cryptanalysis of Short RSA Secret Exponents" (EUROCRYPT 1990)
Coppersmith, "Small Solutions to Polynomial Equations..." J. Cryptology (1997)
Boneh, DeMillo & Lipton, "On the Importance of Checking..." (EUROCRYPT 1997)
Kocher, "Timing Attacks on... RSA, DSS..." (CRYPTO 1996)
Adrian et al., "Imperfect Forward Secrecy: How DH Fails in Practice" (CCS 2015)
Textbooks
Menezes, Oorschot & Vanstone, "Handbook of Applied Cryptography" (CRC, 1996)
Katz & Lindell, "Introduction to Modern Cryptography" (3rd ed., 2020)
Shoup, "A Computational Introduction to Number Theory and Algebra" (2008)
Boneh & Shoup, "A Graduate Course in Applied Cryptography" (2020)
Part of the Modern Cryptography Presentation Series