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 Python Experiments

Simulation and analysis scripts that regenerate the reproducible numbers cited in the paper. All security-critical scripts are deterministic (numpy seed 42); timing scripts report host-specific wall-clock values whose ratios are the comparable metric.

Run everything from the repository root so that results/ resolves:

python code/python/run_all.py # runs all experiments -> results/*.json

run_all.py hard-fails if a producer script is missing (it does not silently skip an experiment). Individual scripts write their own JSON into results/. Each script carries a Doxygen @brief/@details header describing its method and outputs.

Script catalogue

Legend: M = measured / directly computed from a real run; E = analytical estimate or projection (a hand-set constant or formula, not an end-to-end measurement). The paper labels every number in the same two classes.

Script Purpose Key output(s) Result file Class
run_all.py Orchestrator: runs every experiment and aggregates status run manifest experiment_summary.json —
whitebox_reference.py Working reference implementation: builds the base-multiply tables, verifies correctness against a schoolbook negacyclic oracle over all 128 NTT components and all 3 secret polynomials, and times the protected primitive correctness passes; base tables 22.16 MB (Construction A) / 7.67 MB (B, k=3); protected-primitive overhead ~1.55× (baked-table lookup + share recombination, mask-RNG excluded — a lower bound; the faithful native figure is 4.30×/2.85×) whitebox_reference.json M
whitebox_encoded.py Secret nonlinear-encoding countermeasure vs. the NTT-linearity attack plain recovery 128/128; 0/128 against an encoding-unaware (mixing-aware) adversary; 128/128 against an encoding-aware one; 3.41 MB encoding tables (storage; the layer's entropy is 1.09 MB — see encoding_layer_entropy.py) whitebox_encoded.json M
share_statistics.py Masking uniformity / independence checks χ² uniformity mean p ≈ 0.50; joint share–secret corr 0.037; masked-output corr 0.023 (both at the 1/√N = 0.01 floor) share_statistics.json M
dca_simulation.py Differential-computation-analysis Pearson correlation masked ρ_max = 0.011 at 10,000 traces (near the 1/√N = 0.01 noise floor, below the 0.031 wrong-key maximum) vs 0.86 unmasked dca_simulation.json M
algebraic_attack_analysis.py NTT-linearity Gaussian-elimination key recovery, full-module recovery, and nonlinear-mixing countermeasure cost unprotected 100% recovery; full ML-KEM-768 recovery 768/768 coefficients in 3 queries; mixing/shuffle overheads algebraic_attack_analysis.json M
baseline_benchmark.py liboqs ML-KEM-768 baseline timing (requires liboqs; exits with a hint otherwise, no fallback) host-specific KeyGen/Encaps/Decaps times; the build-invariant ratios are the metric baseline_benchmark.json M
overhead_calculation.py Bookkeeping for the deployment-overhead projection ~47× deployment overhead (native-C 4.30× × ≈11× cache, Construction B); ~17× RNG-excluded lower bound (≈1.55× masking floor × ≈11× cache); the ~10 ms (7–14) protected-decaps estimate is x86-host-anchored (0.213 ms × 47); no ARM-device wall-clock is claimed overhead_calculation.json E
scaling_analysis.py ML-KEM-512/768/1024 footprint/overhead scaling and higher-order (5/7-share) masking 768: 11.08 MB (B) / 25.57 MB (A) total, ~47× deployment (~17× RNG-excluded floor); higher-order DCA-order estimates scaling_analysis.json E
entry_determinacy.py Entry-determinacy degree d and the budget M* at which an access-pattern-oblivious, table-access-bounded adversary attains Z = 1; SPACE-style AES-128 PRF control of identical shape and byte count d = 1 (B baked, h(x) = ŝ·x is Z_q-linear) / d = 0 (A shared, a public function) vs d = q−1 (random bijection) and 0 linear regenerations over all 3,328 candidate reads (PRF control); M* = 1,536 B (B) / 0 B (A); separator is efficient local invertibility, not key-determinism (both families rebuild byte-identically from their key) entry_determinacy.json M
table_extraction_witness.py Runs the extraction end to end against the repo's own builders: reads the determining entries, regenerates the table set, and measures Z on fresh ciphertexts 1,536 B (768 entries) regenerate all 7,670,016 B of B's baked set bit-exactly, 5/5 seeds and 384/384 component-polynomial pairs (4,993.5×), Z = 1.0 on 1,000/1,000 fresh ciphertexts; A's table is secret-independent (identical SHA-256 across secrets), so 0 reads; two-point check: budget unchanged (1,536 B) while the stored set grew 7.67 → 11.08 MB table_extraction_witness.json M
encoding_layer_entropy.py Storage-vs-entropy accounting for the output-encoding sublayer and its entry-determinacy degree 3.41 MB stored but only 256 of 512 tables independent (each inverse rebuilt from its forward map), so 1.09 MB = 2^20.06 of entropy — storage overstates the secret-bearing material by a measured 3.12×; d = q−1 = 3,328 and an omitted entry stays at the ≈6.0×10⁻⁴ bijectivity-aware chance floor (the positive side of the dichotomy) encoding_layer_entropy.json M (entropy: E)
concrete_security_bounds.py Engineering security estimates DCA ~2^12 first-order trace-complexity estimate (1/ρ², ρ near the noise floor; not a proof); core table footprint ~2^24.6 (A) / ~2^23.4 (B) byte-reads to copy the core (a size; is_security_bound: false) concrete_security_bounds.json E
obfuscation_storage.py Storage of the two obfuscation layers wrapping the base multiply, plus the deployment total coefficient shuffle 3 KB (a permutation of the 256 NTT coefficients + its inverse, per polynomial, k=3, uint16, round-trip-checked); runtime three-share masking 0 bytes; deployment total = measured core + a few KB → 25.58 MB (A) / 11.08 MB (B) obfuscation_storage.json M
wallclock_ci.py Repeats each wall-clock benchmark N times and reports mean ± 95% CI (masking / algebraic overhead, liboqs baseline); run once per environment dual-environment N=20 statistics wallclock_statistics_{windows,wsl}.json M
arm64_aggregate.py Aggregates the N=20 aarch64/QEMU liboqs runs from code/c/build_arm64_benchmark.sh to mean ± 95% CI; not part of run_all (needs the aarch64 cross-toolchain and QEMU) decaps 0.310 ± 0.015 ms (N=20, Student-t) arm64_benchmark.json M

Honesty note

The paper reports no security figure derived from the table footprint. The ~2^24.6 (A) / ~2^23.4 (B) byte-reads are the size of the core a deployment ships and holds resident — what it costs to copy the program in order to run it — and no adversary is obliged to pay it: table_extraction_witness.py measures 1,536 bytes of table reads that regenerate Construction B's baked set bit-exactly and decapsulate fresh ciphertexts at Z = 1.0, and zero for Construction A, whose shared table is a public function of q. That budget is the independent secret scalars times the bytes per entry and carries no table-size term, so it is not lowered by smaller tables nor raised by larger ones; the 1,536 bytes are a measured read budget of this one attack and not a description length of ŝ. Nor is any floor here information-theoretic: the adversary holds pk = (A, b = As+e), which determines (s,e) uniquely, so every floor in this construction is computational and rests on module learning-with-errors. The DCA correlation sits near the sampling-noise floor (a measurement-resolution lower bound, not a security proof). The ~1.55× masking overhead is a lower bound (the mask-RNG is excluded from that timing loop), and the ~11× cache factor and the ~47× deployment overhead are projections, not end-to-end measured white-box timings. Crucially, the construction hardens the key-recovery path but does not provide key confidentiality against the full white-box (Definition 5) adversary that reads all intermediates. See the manuscript's Security Analysis / Open Problems sections and results/SIMULATION_SUMMARY.md.

What <tt>run_all.py</tt> does and does not regenerate

run_all.py runs the fourteen Python producers above (every catalogue producer row except run_all.py itself, the orchestrator, and arm64_aggregate.py, which needs the aarch64 cross-toolchain and QEMU). It does not invoke the native C benchmarks or the Sage check; regenerate those manually:

The x86 baseline_benchmark.json is an archived measurement. The QEMU-aarch64 arm64_benchmark.json (decaps 0.310 ± 0.015 ms, mean ± 95% CI over N=20 runs) is regenerated by code/c/build_arm64_benchmark.sh under WSL (aarch64 cross-toolchain and qemu-aarch64), separate from the Python run_all because it needs that toolchain.

Wall-clock measurement methodology (N=20, two environments)

Wall-clock figures (masking overhead, algebraic-countermeasure overhead, liboqs baseline) are platform-, build-, and run-dependent, so they are not cited from a single run. wallclock_ci.py repeats each such measurement N=20 times and reports the mean ± 95% confidence interval, run separately in two environments on the same host (Intel Core i9-13980HX); the aggregated values live in results/wallclock_statistics_{windows,wsl}.json:

  • Windows 11 native (Python 3.12.6, liboqs 0.15.0 portable build)
  • WSL2 Ubuntu-20.04 (Python 3.8.10; liboqs unavailable, pure-Python overhead ratios only)

The dimensionless ratios (masking overhead, the ~47× deployment projection and its ~17× RNG-excluded floor) rather than absolute liboqs times—which are build- and platform-specific—are the comparable, platform-invariant metric. Deterministic experiments (masking χ², the full ML-KEM-768 algebraic recovery, the DCA correlation, the entry-determinacy degrees and the 1,536-byte extraction witness, the encoding-layer storage and entropy, footprints, NTT correctness) use a fixed seed and reproduce exactly on any platform.

Requirements

Python 3.10–3.12 (not the free-threaded 3.13t build) with NumPy/SciPy; see ../requirements.txt (pip) or ../environment.yml (conda). baseline_benchmark.py additionally needs liboqs-python. The reference implementation and DCA simulation are the heaviest (a few seconds each).