For the complete documentation index, see llms.txt. This page is also available as Markdown.

No Padding, No Problem (90)

RSA chosen-ciphertext attack (CCA)

Problem

Oracles can be your best friend, they will decrypt anything, except the flag's ciphertext. How will you break it? Connect with nc mercury.picoctf.net 30048.

Solution

This is a chosen-ciphertext attack (CCA) against RSA. We are able to choose any ciphertext, except the flag's ciphertext, to decrypt.

TL;DR: we can use c′=c∗2ec'=c * 2^e as the ciphertext, then halve the result.

Proof

Note that:

  1. cd≡m(modn)c^d \equiv m \pmod n

  2. dd is chosen such that ed≡1(modϕ(n))ed \equiv 1 \pmod {\phi(n)}, i.e. ed=1+kϕ(n),k∈N0ed=1 + k\phi(n), k\in \mathbb{N_0}.

The decryption of c′c' would yield:

(c∗2e)dmod  n≡cd∗2edmod  n≡(cdmod  n)(2edmod  n)mod  n≡m∗(21+kϕ(n)mod  n)mod  n≡m∗2∗(2kϕ(n)mod  n)mod  n\begin{align} (c * 2^e)^d \mod n &\equiv c^d * 2^{ed} \mod n \\ &\equiv (c^d \mod n)(2^{ed} \mod n) \mod n \\ &\equiv m * (2^{1+k\phi(n)} \mod n) \mod n \\ &\equiv m * 2 * (2^{k\phi(n)} \mod n) \mod n \\ \end{align}

From Euler's Theorem, if gcd(a,n)=1gcd(a,n)=1 , then

aϕ(n)≡1(modn)a^{\phi(n)} \equiv 1\pmod n

Thus, we have

m∗2∗(2kϕ(n)mod  n)mod  n≡2mmod  nm * 2 * (2^{k\phi(n)} \mod n) \mod n \equiv 2m \mod n

At this point, we can halve the result to get mm .

Script

References

Last updated