RSA

Work in progress. This note is still being written and incomplete.

3 min read Last updated Tue Aug 04 2026 03:56:01 GMT+0000 (Coordinated Universal Time)

RSA (Rivest, Shamir, Adleman, 1977) is a block cipher over Zn\mathbb{Z}_n used for both encryption and digital signatures. Security rests on the integer factorization problem: given n=pqn = pq for 2 large equal-size primes, finding p,qp, q is computationally intractable.

Key Pair Generation

  • Choose 2 large, distinct, equal-size primes p,qp, q, kept secret.
  • Compute n=pqn = pq, public, its bit length is the RSA key length.
  • Compute ϕ(n)=(p1)(q1)\phi(n) = (p-1)(q-1), kept secret.
  • Choose ee with 1<e<ϕ(n)1 < e < \phi(n) and gcd(e,ϕ(n))=1\gcd(e, \phi(n)) = 1, public.
  • Compute de1(modϕ(n))d \equiv e^{-1} \pmod{\phi(n)}, secret.

Public key: {e,n}\{e, n\}. Private key: {d}\{d\}. pp, qq, and ϕ(n)\phi(n) must be destroyed after generation.

Encryption and Decryption

c=memodn,m=cdmodnc = m^e \bmod n, \quad m = c^d \bmod n

Encryption cost is a single exponentiation with a small exponent ee. Decryption cost is a single exponentiation with an exponent up to the full length of nn, far more expensive.

Correctness

(memodn)dmodn=m(m^e \bmod n)^d \bmod n = m

Worked Example

p=17p = 17, q=11q = 11.

  • n=187n = 187.
  • ϕ(n)=16×10=160\phi(n) = 16 \times 10 = 160.
  • e=7e = 7, since gcd(7,160)=1\gcd(7, 160) = 1.
  • d=23d = 23, since 23×7=161=160+123 \times 7 = 161 = 160 + 1.
  • Public key {7,187}\{7, 187\}, private key {23}\{23\}.
  • For m=88m = 88: c=887mod187=11c = 88^7 \bmod 187 = 11, and m=1123mod187=88m = 11^{23} \bmod 187 = 88.

RSA Digital Signature

Uses the same key pair as RSA encryption, with the roles of ee and dd reversed.

  • With message recovery
    Applies when the message m<nm < n directly. Signature σ=mdmodn\sigma = m^d \bmod n, signed with the signer’s private key.
  • Without message recovery
    Hashes the message first. Signature σ=H(M)dmodn\sigma = H(M)^d \bmod n, sent as the pair (M,σ)(M, \sigma).

Verification

  • With recovery: compute m=σemodnm' = \sigma^e \bmod n using the signer’s public key, and check it matches the expected message.
  • Without recovery: compute h=H(M)h' = H(M') and h=σemodnh = \sigma^e \bmod n, accept iff h=hh = h'.

Signing cost is a hash plus a single exponentiation with a full-length exponent dd. Verification cost is a hash plus a single exponentiation with the small exponent ee, plus a comparison.

Was this helpful?