Tiny RSA

December 18, 2024 · View on GitHub

RSA was one of the first asymmetric cryptographic primitives in which the key used for encryption is different from the key used for decryption. The security of RSA is based on the difficulty of factoring large integers.

Key Generation

  1. Consider two large prime numbers pp and qq.
  2. Calculate n=p×qn = p \times q
  3. Calculate ϕ(n)=(p1)×(q1)\phi(n) = (p-1) \times (q-1)
  4. Choose ee such that $1 < e < \phi(n)andandeiscoprimetois coprime to\phi(n),orinotherwords, or in other words gcd(e, \phi(n)) = 1$
  5. Calculate dd such that d×e1modϕ(n)d \times e \equiv 1 \mod \phi(n)

Keys

Private Key = (d,n)(d, n) Public Key = (e,n)(e, n)

Encryption

  • c=memodnc = m^e \mod n

Decryption

  • m=cdmodnm = c^d \mod n

See the examples in the tests.rs file

Security Assumptions

The security of RSA relies on the assumption that it is computationally infeasible to factor large composite numbers into their prime factors, known as the factoring assumption. This difficulty underpins the RSA problem, which involves computing eth roots modulo n without the private key.