RSA (Textbook Construction)
- •
What it is
- •
RSA is a public-key cryptosystem built on modular exponentiation. Key generation picks two large primes , forms the modulus , computes Euler's totient , and picks a public exponent coprime to (commonly 65537) with a matching private exponent . Encryption is ; decryption is — these invert each other precisely because , so by Euler's theorem . Signing reverses the roles: the signer computes using their own private key, and anyone can verify by checking using the signer's public key — proving the signer (and only the signer) produced , without needing to keep secret.
- •
- •
When to apply
- •
The starting point for reasoning about any RSA challenge — every attack in this domain (weak parameters, small exponents, shared moduli, leaked private data) is a deviation from this baseline that breaks one of its security assumptions.
- •
- •
Symbols and assumptions
- •
are distinct primes; ; . Public exponent is coprime to ; private exponent satisfies . Message representative: .
- •
- •
Math — step by step
- •
- Choose , so for an integer . Encrypt and decrypt .
- •
- For a unit , Euler’s theorem gives . For arbitrary , prove the equality separately modulo and : if is zero the claim is immediate; otherwise Fermat applies. CRT then gives equality modulo .
- •
- Factoring exposes and hence . These equations describe textbook RSA; secure encryption additionally needs an appropriate randomized encoding such as OAEP.
- •
- •
- •
Common pitfalls worth recognizing on sight
- •
: encryption is the identity function, — no decryption needed.
- •
is prime, not a semiprime: directly, no factoring needed.
- •
- •
Small (e.g. 3) without proper padding — see Low-Exponent Cube-Root Attack (Unpadded RSA) and Hastad's Broadcast Attack.
- •
- •
Python
- •
from Crypto.Util.number import inverse, bytes_to_long, long_to_bytes N = p * q phi = (p - 1) * (q - 1) d = inverse(e, phi) c = pow(bytes_to_long(message), e, N) m = long_to_bytes(pow(c, d, N))
- •
- •
- •
Cards
- •
What relationship between e, d, and φ(N) makes RSA encryption and decryption invert each other?
- •
ed ≡ 1 (mod φ(N)), so by Euler's theorem m^(ed) ≡ m (mod N).
- •
- •
How does RSA signing differ from RSA encryption in terms of which key is used?
- •
Signing uses the signer's own private key on the message (or its hash); encryption uses the recipient's public key.
- •
- •
Linked references 19
- Batch GCD Attack (Shared RSA Prime Across Keys)
- Boneh-Durfee Attack (Lattice Attack on Small RSA Private Exponent)
- Complex Multiplication (CM) Prime Factorization Backdoor
- Coppersmith's Method for Stereotyped-Partially-Known Messages
- cryptohack
- Duplicate Signature Key Selection (DSKS) Attack
- Fermat's Factorization Method (Close Primes)
- Franklin-Reiter Related Message Attack
- Hastad's Broadcast Attack
- Integer Factorization via ECM - Sage's factor()
- Low-Exponent Cube-Root Attack (Unpadded RSA)
- Partial-Match RSA Verification Exploit (Suffix Forgery via Small Modulus)
- ROCA Vulnerability (Infineon RSA Key Generation Weakness)
- RSA Blinding Attack (Signature Malleability)
- RSA Factorization from Known (N, e, d)
- RSA Padding Schemes (PKCS-1 v1.5 vs OAEP vs Unpadded)
- RSA Sign = Decrypt When Keys Are Shared (Unrestricted Signing Oracle)
- RSA with p = q (Repeated Prime Factor)
- Wiener's Attack (Continued Fractions, Small Private Exponent)