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
whitebox_reference.py File Reference

Reference PQ-WB-KEM base multiplication on the real NTT-domain secret: build white-box tables (two constructions), verify correctness against the reference base multiply, measure serialized table size and masking overhead. More...

Go to the source code of this file.

Namespaces

namespace  whitebox_reference
 

Functions

 whitebox_reference._bitrev7 (k)
 Bit-reversal of a 7-bit index (FIPS-203 NTT twiddle order).
 
 whitebox_reference._negacyclic (f, g)
 Schoolbook multiply in Z_q[X]/(X^256+1); independent correctness oracle.
 
 whitebox_reference._poly_mod_x2 (f, gamma)
 Reduce a length-256 polynomial modulo (X^2 - gamma) over Z_q.
 
 whitebox_reference._zeta_powers ()
 Powers of zeta mod q for the NTT.
 
 whitebox_reference.base_mul_baked (tabs, uh, i)
 Construction B base multiply via baked per-component lookups.
 
 whitebox_reference.base_mul_direct (sh, uh, i)
 Reference base multiply for degree-2 factor i (direct arithmetic).
 
 whitebox_reference.base_mul_shared (M, sh, uh, i)
 Construction A base multiply via shared-table lookups (full-range secret).
 
 whitebox_reference.build_baked_tables (sh)
 Construction B tables for one secret polynomial: per-component q-entry tables with the fixed secret baked in.
 
 whitebox_reference.build_shared_table ()
 Construction A table: one shared full multiply table M[x][y]=x*y mod q.
 
 whitebox_reference.cbd_range_occupancy (shat_polys)
 Count NTT-domain secret coordinates landing in the coefficient-domain CBD range {-2..2} mod q.
 
 whitebox_reference.main ()
 Build both constructions on the real NTT-domain secret, check correctness, measure sizes and masking overhead, write JSON.
 
 whitebox_reference.measure_cbd_range_occupancy (n_seeds=200)
 Occupancy rate over many independent secrets, so the reference-sample count is not mistaken for the underlying rate.
 
 whitebox_reference.measure_overhead (iters=100000, seed=SEED)
 Construction-B protected-primitive overhead (baked table lookup plus 3-share masking versus direct arithmetic) on the real full-range NTT-domain secret, for wall-clock CI aggregation (wallclock_ci.py).
 
 whitebox_reference.ntt_forward (poly)
 Forward NTT: coefficient domain to NTT domain.
 
 whitebox_reference.sample_cbd (rng, size, eta=ETA)
 Draw from the centered binomial distribution CBD_eta of FIPS 203.
 
 whitebox_reference.three_share (v, rng)
 Split a value into three arithmetic shares mod q.
 

Variables

dict whitebox_reference.CBD_RANGE = {(-2) % Q, (-1) % Q, 0, 1, 2}
 
int whitebox_reference.ETA = 2
 
 whitebox_reference.GAMMAS
 
int whitebox_reference.K = 3
 
int whitebox_reference.N = 256
 
int whitebox_reference.NUM_COMPONENTS = N // 2
 
int whitebox_reference.Q = 3329
 
int whitebox_reference.SEED = 42
 
int whitebox_reference.ZETA = 17
 
 whitebox_reference.ZETA_POWERS = _zeta_powers()
 

Detailed Description

Reference PQ-WB-KEM base multiplication on the real NTT-domain secret: build white-box tables (two constructions), verify correctness against the reference base multiply, measure serialized table size and masking overhead.

The ML-KEM base multiply operates in the NTT domain: the stored secret is shat = NTT(s), whose coordinates are full-range over Z_q (a CBD-small s in the coefficient domain has a full-range NTT image). Per degree-2 factor Z_q[X]/(X^2 - gamma_i), with gamma_i = zeta^(2i+1): p0 = shat0*c0 + gamma_i*shat1*c1, p1 = shat0*c1 + shat1*c0. Two lookup-only constructions realise this over full-range operands: A (shared): one q x q multiply table M[x][y] = x*y mod q; the secret enters as a full-range index and the gamma twiddle is a second lookup. Table is secret-independent and shared across all components and all k polynomials. B (baked): per-component q-entry tables with the fixed secret baked in, h0_i[x]=shat0_i*x, h1_i[x]=shat1_i*x, h2_i[x]=gamma_i*shat1_i*x, indexed by one full-range ciphertext coordinate. Smaller for small module rank k. Outputs p0,p1 are masked with three arithmetic shares each. Deterministic (seed 42); results in results/whitebox_reference.json.

Note
The masking-overhead ratio is wall-clock; wallclock_ci.py aggregates N=20 runs (mean +/- 95% CI) per environment for robust reporting.
Reference NumPy/Python measurement on the simulation host, not a deployed embedded binary; the deployed footprint is measured (base tables here, plus the encoding sublayer and coefficient shuffle), only the latency stays a projection.

Output Files

Usage

Author
Ugur Coruh

Definition in file whitebox_reference.py.