Avalanche evaluation campaign for AES-like SPN cipher variants
/app/cpu/main.cpp is a multicore CPU program (C++17, OpenMP). It is built as
/app/bin/cpu_baseline with g++ -O3 -march=native -fopenmp -std=c++17 and run as
cpu_baseline INPUT_FILE
It reads one input file and writes its result to stdout.
What the program computes
An avalanche-evaluation campaign over a family of AES-like SPN block ciphers (the kind of diffusion study a cipher designer runs when comparing candidate S-boxes and linear layers). Each input line describes one cipher variant:
- S-box
SB:0is the AES S-box (GF(2^8) inverse plus the AES affine map, computed in the program), any other value is a random bijection made by a Fisher-Yates shuffle seeded withSB. - MixColumns is the circulant matrix with first row
(A, B, C, D)over GF(2^8) with the AES polynomial0x11b: output rowiof a column issum_k coef[(k - i) mod 4] * in[k]((2,3,1,1)is AES). Singular or zero matrices are allowed. - ShiftRows rotates row
rleft byS_r(AES:0 1 2 3). Rrounds after an initial key addition; rounds1..R-1are SubBytes, ShiftRows, MixColumns, AddRoundKey, roundRomits MixColumns. Round keys come from the AES-128 key schedule (RotWord, SubWord with the variant S-box, round constantsx^(i-1)), extended toRrounds.- The 16-byte state is stored as four 32-bit column words, row
rin byter(AES byte order: input bytebis rowb mod 4, columnb / 4). The program uses T-tables (T_k[x]= columnkof the matrix timesS[x]), exactly as in the CPU source.
For pair i (0 <= i < NPAIRS), bit j = i mod 128 is flipped. Plaintext words are
gen64(SEED, 4i) and gen64(SEED, 4i+1) (little-endian bytes). In MODE 0 all pairs share one
key (gen64(SEED ^ 0x5bd1e9955bd1e995, 0/1)) and the plaintext bit j is flipped; in MODE 1
each pair has its own key (gen64(SEED, 4i+2), gen64(SEED, 4i+3)), the plaintext is shared and
key bit j is flipped, so both keys are expanded per pair. Both members are encrypted in lockstep
and after every round r the program records the Hamming distance HD (0..128) of the two
states, whether all 16 byte differences are nonzero, and adds HD to a per-(r, j) sum.
Analysis per variant and round: sum and sum of squares of HD, min, max, mode (most frequent
HD, smallest on ties), the number of fully active pairs, the slowest input bit (smallest mean
HD for that j, compared exactly by cross-multiplication, smallest j on ties) and a
histogram hash. The avalanche round is the first round with |mean - 64| <= 1/4,
|variance - 32| <= 1 and at least 93 % fully active pairs, all tested in exact integer
arithmetic (0 if never reached). Variants are ranked by avalanche round (0 counts as last), then
by larger mean HD after round 2 (round 1 if R = 1), then by index.
Input format
V
R SB A B C D S0 S1 S2 S3 MODE NPAIRS SEED (V lines)
1 <= V <= 8, 1 <= R <= 10, 0 <= SB <= 10^6, 0 <= A,B,C,D <= 255, 0 <= S_r <= 3,
MODE in {0, 1}, 0 <= NPAIRS <= 2*10^8, SEED an unsigned 64-bit integer.
Output format
For every variant: a header line variant v R=.. mode=.. pairs=.., one line per round
r<k> sum=.. sum2=.. min=.. max=.. mode=.. full=.. worstbit=.. worstsum=.. hist=<16 hex digits>
(min, max, mode, worstbit are -1 when there are no pairs), then
variant v avalanche_round=.. early_sum=... The last line is ranking v0 v1 ....
Hidden inputs
Correctness inputs (10 files, 1 to 5 variants each) include the real AES (both modes),
NPAIRS in {0, 1, 127, 128, 129}, R = 1, R = 10, zero, singular and identity-like
MixColumns, all-zero ShiftRows, seeds 0 and 2^64-1, and random variants with
NPAIRS <= 200000. The timing input has 6 variants (the first is the real AES in mode 0, the
others random with R in [6, 10], about a third in mode 1), each with NPAIRS uniform in
[1.2*10^8, 1.6*10^8].
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The CPU source is the specification: when this text and the code disagree, the code wins.
How you are scored
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. Inputs are generated with a new random seed at grading time, so they cannot be known in advance. - Correctness: every hidden input (small edge cases plus the timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- Speed: The timing input has 6 cipher variants (the first is the real AES-128 in plaintext-flip mode, the others random variants with 6 to 10 rounds, some in key-flip mode), each with 1.2e8 to 1.6e8 flipped-bit pairs. Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds a few public inputs./app/bin/run_public.shcompiles your port with the flags above and compares it against the CPU baseline on each of them.