RSA Cryptosystem

Monish Singhal

Why a new cryptosystem?

  • Weakness in existing cryptosystems
  • Text can be mapped to numbers easily – Usage of number theory

The basics

Primes and co-primes

Modular Arithmatic

  • \(a \equiv r \pmod{N}\) where \(a = qN + r\)

Modular Division

  • \(a \cdot a^{-1} \equiv 1 \pmod{N}\)
  • EGCD Algorithm to find the inverse

Euler's Totient Function

  • \(\phi(n) = \sum_{k = 1}^{n} 1\) such that \(k\) is coprime to \(n\)
  • Example: \(\phi(6) = 2 \{1, 5\}\)
  • For a prime number: \(\phi(p) = p - 1\)
  • Why?
  • For two coprime numbers \(m\) and \(n\): \(\phi(mn) = \phi(m) \phi(n)\)
  • Why?

Euler's Theorem

  • \(a ^ {\phi(n)} \equiv 1 \pmod{n}\)
  • Why?
  • Hint: Try finding a bijection

The Actual Cryptosystem

  • Two primes \(p\) and \(q\)
  • \(n = pq\)
  • \(de \equiv 1 \mod (p - 1)(q - 1)\)

  • Encryption: \(m^e \pmod n\)
  • Decryption: \(c^d \pmod n\)

Security of the RSA

Attacks

1. Small Values of \(m\) or \(n\)

  • If \(m\) is small: Bruteforce
  • If \(n\) is small: factorise

2. Unpadded Message Recovery

\(C' = C \cdot S^E\), find \(P' = \text{decrypt}(C')\), and hence \(P = P' S^{-1}\)

Flipping Bits (Square CTF 2018 C2)

ct1: <long num 1> ct2: <long num 2> e1: 13 e2: 15 modulus: <modulo>

You have two captured ciphertexts. The public key is (e1, n). But, due to a transient bit flip, the second ciphertext was encrypted with a faulty public key: (e2, n). Recover the plaintexts.

Bezout's Theorem

\(xa + yb = \gcd(a, b)\) for all \(a, b\)

The Attack

  • \(C_1 = M^{e_1}\), \(C_2 = M^{e_2}\)
  • \(C_1^{x} \cdot C_2^{y} = M^{xe_1} \cdot M^{ye_2} = M^{\gcd(a, b)}\)

4. Broadcast Attacks for small values of \(e\)

Given some number of ciphertexts encrypting the same plaintext, knowning the values of public keys, find the plaintext

Chinese Remainder Theorem

For a set of congruences \[x \equiv a_i \pmod n_i,\; 0 < i \leq k,\] there exists a solution, and that solution is unique under the congruence of \(N = \prod_{i = 1}^{k} n_i\), where each of \(n_i\) is pairwise coprime

Bonus: GCTF 2022 Cycling

Problem

It is well known that any RSA encryption can be undone by just encrypting the ciphertext over and over again. If the RSA modulus has been chosen badly then the number of encryptions necessary to undo an encryption is small. However, if the modulus is well chosen then a cycle attack can take much longer. This property can be used for a timed release of a message. We have confirmed that it takes a whopping 21025-3 encryptions to decrypt the flag. Pack out your quantum computer and perform 21025-3 encryptions to solve this challenge. Good luck doing this in 48h.

How to attack the problem?

  • Bruteforce clearly out of the way
  • Need to use smart maths

Observations made

  • \(M^{e^{R + 1}} = M \mod {N}\)

Carmicheal Function

  • \(\lambda(n)\) = smallest positive integer such that \(a^m \equiv 1 \pmod n, \forall a\) coprime to \(n\)
  • Observe: \(\lambda(n) | \phi(n)\), and \(\lambda(n)\) can be used in RSA
  • Clean expression for \(\lambda(n)\)?

More observations

  • \(e^{R + 1} \equiv 1 \pmod{\lambda(n)}\)
  • Euler theorem vibes?

Assumptions pt. 1

  • \(R + 1 = \lambda(\lambda(n))\)?

More observations pt. 2

Final Solution?

  • Lazy approach: Find \[\prod_{i = 1}^{m} s_i\], use that as exponent
  • Actual Solution: Pollard's \(p - 1\) Algorithm to factorise numbers

Implicit Assumptions

  • \(p - 1\), \(q - 1\) were square-free