Click to expand challenge code
| |
This is the only Elliptic Curves challenge in the ctf. All things considered, I think it was one of the easier ones, which made surprised to see that only 2 teams managed to solve it 😕
Analysis
Functionality
You’re given a lights.sage file that has a custom ECC implementation
- Custom curve parameters (which should make you raise an eyebrow immediately whenever you see it), even though the order $p$ corresonds to the curve $BRAINPOOLp512r1$
- We generate a random secret key using a suspicious method
- We compute the public key $P$ in classic fashion
- We drive the
AESkey and iv from the secret key using a hash function - We encrypt the flag with AES using those parameters
- We spit out the ciphertext, iv, and the
xcoordinated of the publig key and generator
Red Herring
I assume most of the players looked at the ger_random_number() function and lost their mind xd
WHAT IS A j INVARIANT????
What’s so special about a point with an order above it????
The funny thing is, most points on a relatively secure curve have orders below $j$, so picking one above it makes the point not more special than any other random point, which make it no more special than any randomly generated number! (technically, this method does introduce some bias, but it will be irrelevant in this case)
So we could assume that S is nothing but a randomly generated 64 bit integer
Modified Pohlig-Hellman
The classic Pohlig-Hellman algorithm aims to solve ECDLD through divide and conquer war tactics. To put it in perspective, you can’t calculate to discrete log of some point in a group with a large order straight away. But if the order isn’t a prime number, we could theoretically calculate mini DLs over the subgroups with an order equal to the factors of the curve, and then combine our findings using the Chinese remainder theorem.
However, if you try that in this case, you’ll find that some of the factors of the curve’s order are unreasonably large. But here’s the thing…
First let’s do a quick recap of how CRT works:
Given a system of simultaneous congruences for an integer $x$:
$$ \begin{cases} x \equiv a_1 \pmod{n_1} \\ x \equiv a_2 \pmod{n_2} \\ \vdots \\ x \equiv a_k \pmod{n_k} \end{cases} $$Where the moduli $n_1, n_2, \dots, n_k$ are pairwise coprime (i.e., $\gcd(n_i, n_j) = 1$ for $i \neq j$), the Chinese Remainder Theorem states there is a unique solution for $x$ modulo $N = n_1 n_2 \cdots n_k$.
The solution is found by:
$$ x = \sum_{i=1}^{k} a_i N_i y_i \pmod{N} $$where $N = \prod_{i=1}^{k} n_i$, $N_i = N/n_i$, and $y_i$ is the modular multiplicative inverse of $N_i$ modulo $n_i$, such that $N_i y_i \equiv 1 \pmod{n_i}$.
In our case, we’re looking for $S \approx 64$ bits, so all we need is to find $x$ mod some $N \ge 64$ bits.
In short, we only need factors whose product comes out to $64$ bits or above, and we have plenty of them!
Solution
Plan
- Find the order $n$ of the curve
- Find its factors and consider those whose product comes to 64 bits, discard the others.
- Perform Pohlig-Hellman using said factors
Doing that will give us the secret key, the rest is obvious
Note: Since I only gave you the $x$ coordinate of $P$ and $G$, and since elliptic curves are symmetric in proportion to the x-axis, you should consider both $Px$ and $-Px \mod p$, same goes for $G$
Solver
Click to expand solver code
| |
FL1TZ{n0t_4LL_th4t_Gl1Tt3rs_15_G0LD}
