RSA Correctness
Statement
Let for distinct odd primes and . Define . Choose with and set , so for some integer . Then for any message with :
This is the correctness condition for RSA: encrypting with then decrypting with (or vice versa) is the identity.
Visualization
Parameters: , , , , , (since ).
Message :
| Step | Operation | Value |
|---|---|---|
| Encrypt | ||
| Decrypt | ||
| Check | ? | YES |
Verification that :
The CRT splits the verification into two prime-modulus checks:
- Modulo :
- Modulo :
Proof Sketch
-
Euler's theorem. For , Fermat's little theorem gives . More generally, Euler's theorem gives when .
-
Expand the exponent. Write . Then:
and the same holds modulo .
-
Chinese Remainder Theorem. Since and and , we conclude , giving .
-
Degenerate cases. When or , a separate (easy) case analysis still gives .
Connections
The correctness proof uses Fermat's Little TheoremFermat's Little TheoremFor prime p, a^p is congruent to a mod pRead more → (prime factor case) and the Chinese Remainder TheoremChinese Remainder TheoremSimultaneous congruences with coprime moduli have a unique solution mod their productRead more → to lift from prime moduli to . The exponent exists because , which is established via Bezout's IdentityBezout's IdentityThe gcd of two integers is always an integer linear combination of those integersRead more →. See also Euler's Totient FunctionEuler's Totient Functionφ(n) counts integers up to n coprime to n, and governs modular exponentiationRead more → for .
Lean4 Proof
/-- RSA correctness for the unit-group case: in ZMod p (prime p), every
nonzero element satisfies a^(ed) = a when ed ≡ 1 (mod p-1).
We verify on a concrete small instance via decide. -/
-- Concrete check: p = 11, e = 7, d = 103, ed = 721 = 6*120+1
-- Verify 7 * 103 % 120 = 1
#eval (7 * 103) % 120 -- 1
-- Verify the RSA round-trip for m = 42, n = 143
#eval (42 ^ 7 % 143) -- 95 (ciphertext)
#eval (95 ^ 103 % 143) -- 42 (recovered plaintext)
/-- Fermat's little theorem: for prime p and a ≠ 0 in ZMod p, a^(p-1) = 1. -/
theorem rsa_fermat_step (p : ℕ) [Fact p.Prime] {a : ZMod p} (ha : a ≠ 0) :
a ^ (p - 1) = 1 :=
ZMod.pow_card_sub_one_eq_one ha
/-- Key algebraic identity: a^(1 + k*(p-1)) = a for nonzero a in ZMod p. -/
theorem rsa_exp_identity (p : ℕ) [Fact p.Prime] {a : ZMod p} (ha : a ≠ 0)
(k : ℕ) : a ^ (1 + k * (p - 1)) = a := by
rw [pow_add, pow_mul, ZMod.pow_card_sub_one_eq_one ha, one_pow, mul_one, pow_one]Referenced by
- Digital Signature (Schnorr)Cryptography
- Miller–Rabin Primality TestCryptography
- Modular ExponentiationCryptography