CSCTF 2026Cryptography
emanation
The traces leak the Hamming weight of a first-round AES S-box output, protected by two countermeasures: a random delay and a Boolean mask that is fresh for every trace.
- Competition
CSCTF 2026- Category
- CryptographyMedium
- Source status
- Source-documented · not platform-verified
- Document
- PDF edition4 min read
Brief
The challenge
- Category
- CRYPTO (side-channel)
- Difficulty
- Medium
- Points
- 310
- File
emanation.zip(traces.npy,plaintexts.npy,sealed_order.hex)
Analysts modelled a captured enemy QARVETH-73 field encryptor running its protected AES-128 first round under known plaintexts. The supplied traces are a synthetic corpus generated from the standard Hamming-weight leakage model, with the device's countermeasures preserved. Recover the device key and read the sealed order.

TL;DR
The traces leak the Hamming weight of a first-round AES S-box output, protected by two countermeasures: a random delay and a Boolean mask that is fresh for every trace. The random delay goes away once each trace is aligned on its trigger spike. The mask is defeated with a second-order CPA: multiply the centred mask sample by each centred masked S-box sample, then correlate the product with HW(Sbox(p ^ k)). That recovers all 16 key bytes, and the key decrypts the AES-CTR order.
align on spike → mask × masked sample → CPA vs HW(Sbox(p^k)) → AES-128 key → CTR decrypt01
Recon
README.txt describes the corpus:
plaintexts.npy: 8000 × 16uint8known plaintexts.traces.npy: 8000 × 56float32samples, one row per plaintext.Countermeasures: "a modeled random delay and a fresh byte mask per row".
sealed_order.hex: the order, encrypted under the same key with AES-CTR and an all-zero 16-byte initial counter block.
02
Removing the random delay
Every trace contains one large sample (about 25, while everything else is under about 10). Its position is spread uniformly over offsets 0–16, so it is the trigger, and the random delay is simply that offset.
After cutting each trace at its spike, the per-sample statistics are very regular:
Even offsets have mean 0 and variance 1, so they are pure noise.
Odd offsets 3, 5, …, 35 (17 samples) have mean 4 and variance about 3. That matches
HW(uniform byte) + N(0,1), since HW has mean 4 and variance 2.

17 leaky samples means one mask byte plus 16 masked S-box outputs.
03
Why first-order CPA fails
Each leaky sample is HW(Sbox(p ^ k) ^ m) with a fresh random m for every trace, so on its own it has no correlation with any key hypothesis. However, the mask is also leaked separately as HW(m).
04
Second-order CPA (centred product)
For a mask sample x ≈ HW(m) and a masked sample y ≈ HW(z ^ m), the centred product satisfies
[ E[(x-4)(y-4) \mid z] = -\tfrac{1}{2},(HW(z) - 4) ]
so it is linearly (negatively) correlated with HW(z). With z = Sbox(p_b ^ k_b), a standard CPA over the 256 guesses of each byte works.
I tried both candidate layouts. With the first leaky sample as the mask and the next 16 as bytes 0–15 under the S-box output model, every byte has a clear winner at |ρ| ≈ 0.24, while the runner-up sits around 0.06–0.08. The other combinations (last sample as mask, or an AddRoundKey model) stay at noise level, around 0.03.

byte 0: k=52 |rho|=0.238 runner-up=0.059byte 1: k=cc |rho|=0.236 runner-up=0.061...byte 15: k=ea |rho|=0.220 runner-up=0.056key : 52cc11fc4a2ecfc066e3349f4af9fdeaThe correlations are negative, which matches the formula above.
05
Decrypting the order
The key is used with AES-128-CTR and a zero initial counter block:
AES.new(key, AES.MODE_CTR, nonce=b"", initial_value=0).decrypt(ct)CSCTF{relay_order_55a10bd8f06393bcc1ae8065}Solve script
solve.py handles alignment, the second-order CPA, and decryption. render_images.py regenerates the figures.
d = T.argmax(1) # trigger spike = random delayA = np.stack([T[i, d[i]:d[i] + 40] for i in range(len(T))])S = A[:, 3:36:2]; S = S - S.mean(0) # mask + 16 masked S-box samplesmask = S[:, 0]for b in range(16): combined = mask * S[:, b + 1] H = HW[SBOX[P[:, b][:, None] ^ np.arange(256)[None, :]]] key.append(np.abs(corr(combined, H)).argmax())pt = AES.new(bytes(key), AES.MODE_CTR, nonce=b"", initial_value=0).decrypt(ct)Flag
Flag
CSCTF{relay_order_55a10bd8f06393bcc1ae8065}
Source-documented · not platform-verified
Takeaways
Random delays that come with a visible trigger are removed by simple alignment.
First-order Boolean masking falls to second-order CPA whenever the mask itself leaks. Combining the two samples with a centred product turns the problem back into ordinary CPA.
Data-variance profiling (mean 4, variance about 3) shows which samples carry Hamming-weight leakage before any key guessing.
Note: the downloaded zip's SHA-256 (
0937…b6a4) differed from the one in the briefing (f1d1…c03f), but the contents decrypted correctly.