PQ-WB-KEM: White-Box ML-KEM-768 1.0
PQ-WB-KEM: Toward a White-Box Construction of ML-KEM-768 with Arithmetic Masking for M2M Communications - Mathematics (MDPI)
Loading...
Searching...
No Matches
PQ-WB-KEM C Micro-benchmarks

Three C micro-benchmarks. primitive_bench.c and cache_effect.c are dependency-free (libc only) and measure the low-level cost of the white-box base multiplication; both are deterministic (LCG seed 42). bench_liboqs.c times the unprotected liboqs ML-KEM-768 baseline and links a cross-built aarch64 liboqs.

Source Measures Output
primitive_bench.c Protected (table + 3-share masking) vs direct arithmetic timing ratio JSON to stdout
cache_effect.c L1 / L3 / DRAM access-penalty of the Construction-B baked tables (2.56 MB per secret polynomial; 7.67 MB across k=3) results/cache_effect.json
bench_liboqs.c liboqs ML-KEM-768 KeyGen/Encaps/Decaps wall-clock under qemu-aarch64 (time-budgeted) results/arm64_benchmark.json (via build_arm64_benchmark.sh)

‍The absolute nanosecond figures are host-specific; the ratio is the comparable metric. aarch64 runs are functional QEMU emulation (not cycle-accurate).

Build & run

Run these from the repository root so that results/ resolves correctly.

primitive_bench (x86-64)

gcc -O2 -o code/c/primitive_bench code/c/primitive_bench.c
./code/c/primitive_bench x86_64 > results/primitive_bench_x86.json

primitive_bench (aarch64 via QEMU)

Requires gcc-aarch64-linux-gnu and qemu-user-static:

aarch64-linux-gnu-gcc -O2 -static -o code/c/primitive_bench_arm code/c/primitive_bench.c
qemu-aarch64 ./code/c/primitive_bench_arm aarch64 > results/primitive_bench_aarch64_qemu.json

cache_effect

gcc -O2 -o code/c/cache_effect code/c/cache_effect.c
(cd . && ./code/c/cache_effect) # writes results/cache_effect.json

cache_effect also compiles on Windows (MSVC or MinGW); it has a _WIN32 timing path and creates results/ if missing.

arm64_benchmark (liboqs ML-KEM-768 under QEMU)

One command cross-builds liboqs 0.15.0 for aarch64 (ML-KEM-768 only, static, no OpenSSL), compiles bench_liboqs.c against it, runs it under qemu-aarch64 for n_runs independent runs, and reduces them to mean +/- 95% CI with arm64_aggregate.py, writing results/arm64_benchmark.json. A single QEMU run drifts run-to-run, so the interval over N runs is the reported statistic:

code/c/build_arm64_benchmark.sh # -> results/arm64_benchmark.json (N=20)
code/c/build_arm64_benchmark.sh out.json 1.0 0.15.0 20 # output, per-op budget (s), liboqs tag, n_runs

Requires gcc-aarch64-linux-gnu, qemu-user-static, cmake, ninja, git; a missing tool is a hard error naming the apt package, never a silent fallback. The liboqs build tree lives outside the repo ($HOME/.cache/pqwbkem_arm64_build, override with ARM64_BUILD_DIR) so a run leaves git status clean and repeats skip the rebuild. Every field in the JSON is measured by bench_liboqs.c or read from the linked library; absolute times are qemu functional-emulation figures that depend on host load and CPU frequency, so the comparable metric is the ratio, not any ARM device's wall-clock.

Notes

  • primitive_bench and cache_effect take no external libraries beyond the C standard library; bench_liboqs links liboqs (cross-built by the script above).
  • primitive_bench takes the architecture label as its first argument (x86_64 or aarch64); it only tags the JSON, it does not change the code path.
  • The archived results/primitive_bench_*.json and results/cache_effect.json were produced with the commands above.