ECDH and AES: decrypting the message
This is the full chain: from ECC to AES. Alice and Bob agreed on a shared secret via ECDH, derived an AES key from it, and encrypted the message. You are only given the public data — but the curve was chosen incorrectly.
Step 1 — curve order
The curve is of the form y² = x³ + b (a = 0) and p ≡ 2 (mod 3). In this case, the mapping x → x³ is a bijection in Fp, meaning for each y there corresponds exactly one x. Thus, the number of affine points is exactly p, and together with the point at infinity:
#E(F_p) = p + 1
Such curves are called supersingular and they are considered unsuitable for ECC.
Step 2 — solving the ECDLP
Factor the group order n = p + 1. You will see that it is very smooth (all prime divisors are small). In a group with a smooth order, the Pohlig-Hellman method works: for each prime divisor q
G_q = (n/q) * G , Q_q = (n/q) * Q -> d mod q (kichik BSGS)
is found, then all the remainders are combined using the Chinese Remainder Theorem and d is fully recovered.
Step 3 — ECDH and AES
Calculate the shared secret with the recovered private key: S = dA·QB (or dB·QA — the result is the same). The AES key was derived as follows:
kalit = hashlib.sha256(str(S_x).encode()).digest() # 32 bayt, AES-256
shifr = AES.new(kalit, AES.MODE_CBC, iv) # PKCS#7 to'ldirish
Here S_x is the x-coordinate of the shared secret point, as a decimal string (for example str(12345)).
Given data
All parameters are also available in the attached parametrlar.txt file:
p = 9209541988526213603
a = 0
b = 8299786374947158553
n = 9209541988526213604 (= p + 1)
G = (7792349153911848328, 8278479388786827976)
Q_A = (5521363863772437218, 533375043450371507)
Q_B = (7335454345716335732, 2209535553065762697)
iv (hex) = 3307f98e981c14c4508cf99bff6082e6
Ciphertext (hex):
25929dc835d28a58662ffba3ae6f918d533399677c34fc66f1c57da807c062a9
ec31b5fb5dac105d1dd79fbed5e57c97da456140119e8c10ce97e2400d1e20e1
5a7e9fdabb13009963496ce37f2865a3b577b6394b6a476439b88d26f58ae215
4aa4f074dfb09bfbac3665ee58b11678eb835150498e53f47c41050317626ab8
Decrypt the message and find the flag.