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: White-Box ML-KEM-768 Implementation

PQ-WB-KEM: White-Box Post-Quantum Key Encapsulation

Table of Contents


Citation / BibTeX

If you use this software in your research, please cite:

@article{coruh2026pqwbkem,
title = {PQ-WB-KEM: Toward a White-Box Construction of ML-KEM-768
with Arithmetic Masking for M2M Communications},
author = {Coruh, Ugur},
journal = {Mathematics (MDPI)},
year = {2026},
note = {Manuscript under review}
}
Warning
Note: Citation details (volume, pages, DOI) will be updated once the paper is published.

Overview

PQ-WB-KEM is a feasibility study of table-based white-boxing for a lattice-based NIST post-quantum standard (ML-KEM-768, FIPS 203): a design-space exploration with measured footprints and delimiting negative results, for environments where adversaries have complete access to the implementation. No white-box key confidentiality is claimed against the full adversary.

The work is motivated by key protection in M2M (Machine-to-Machine) communications, where devices operate in hostile environments without trusted hardware support, and it maps the lattice white-box design space rather than delivering a fully white-box KEM.

Warning
Scope. Against the full white-box adversary this construction does not achieve key confidentiality: the base multiply forms the clear product coordinates before masking, and these yield linear equations for the secret. Every positive result below holds only against strictly weaker adversaries. See Security Hierarchy.

Key Contributions

Contribution Description
Lattice White-Box Feasibility First systematic exploration of the table-based white-box design space for a NIST-standardized lattice KEM
NTT Domain Characterization Formal proof of 128 degree-2 polynomial extensions
Design-Space Mapping Two verified lookup-only constructions, measured cores of 25.57 MB (A) and 11.08 MB (B)
Arithmetic Masking Three-share masking with second-order DCA resistance of share observation
Division-Timing Freedom No division-timing leak introduced in the protected base multiply

ML-KEM Parameters (FIPS 203)

Parameter ML-KEM-512 ML-KEM-768 ML-KEM-1024
Security Level NIST Level 1 NIST Level 3 NIST Level 5
n (degree) 256 256 256
q (modulus) 3329 3329 3329
k (rank) 2 3 4
Public Key 800 B 1,184 B 1,568 B
Ciphertext 768 B 1,088 B 1,568 B
Shared Secret 32 B 32 B 32 B

NIST PQC Migration Timeline

PQC Migration Timeline and M2M Implications

System Architecture

White-Box ML-KEM-768 Architecture Overview

Architecture Pipeline

The white-box implementation processes decapsulation through four main stages:

  1. NTT Transform: Convert ciphertext to 128 independent coefficient pairs
  2. Base-Multiply Tables: Lookup-based multiplication over the full-range NTT-domain secret
  3. Arithmetic Masking: Three-share masking preventing DCA attacks
  4. Random Shuffle: Index permutation thwarting correlation analysis

NTT Domain Structure

Mathematical Foundation

NTT Domain Factorization for ML-KEM

Theorem: NTT Factorization for ML-KEM

For \(q = 3329 = 2^8 \cdot 13 + 1\) and \(n = 256\):

\[ X^{256} + 1 \equiv \prod_{i=0}^{127} (X^2 - \zeta^{2i+1}) \pmod{q} \]

where \(\zeta = 17\) is a primitive 256th root of unity, and each factor is irreducible over \(\mathbb{Z}_q\).

Corollary: NTT Representation

\[ R_q \cong \prod_{i=0}^{127} \mathbb{Z}_q[X]/(X^2 - \zeta^{2i+1}) \]

Each component is a degree-2 extension, not a scalar field.

Coefficient-Pair Multiplication

For component \(i\) with \(\gamma_i = \zeta^{2i+1}\):

\[ (a_0, a_1) \cdot (b_0, b_1) = (a_0 b_0 + \gamma_i a_1 b_1, a_0 b_1 + a_1 b_0) \pmod{q} \]

Note
Key Insight: Unlike AES or ECC where NTT components are scalar fields, ML-KEM's NTT produces 128 quadratic extensions. This fundamentally changes the white-box design approach.

White-Box Threat Model

White-Box Adversary Model

Threat Model Summary

The white-box adversary possesses:

Capability Description Countermeasure
Complete Code Access Full binary/source of implementation Obfuscation via tables
Arbitrary Execution Can run on any chosen input IND-CCA2 security
Memory Observation Can read all RAM during execution Arithmetic masking
Trace Collection Unlimited execution traces 3-share DCA resistance
No External Access Cannot query external oracles Offline security model

Security Hierarchy

DLPR White-Box Security Hierarchy

Security Properties Achieved

Against the full white-box adversary the construction provides no key confidentiality: the base multiply forms the clear product coordinates before masking, and these yield linear equations for the secret. The two properties it does deliver are each scoped to a strictly weaker adversary, and neither is a level of the DLPR hierarchy.

Property Status Scope
Second-Order DCA Resistance Achieved Share observation: no key leakage from observing any two of the three shares
Division-Timing Freedom Achieved The protected base multiply; cache-line constant-time is not claimed

Placed against the DLPR hierarchy:

Level Status Description
Strong Incompressibility Impossible Proven impossible for key-fixing encryption schemes
Weak Incompressibility Not attained 1,536 bytes of table reads regenerate the Construction-B baked set bit-exactly; Construction A needs no read at all
Unbreakability Not attained The clear product coordinates yield linear equations for the secret
One-Wayness Inherited Black-box property of ML-KEM-768 IND-CCA2, not a white-box guarantee

Decapsulation Workflow

ML-KEM-768 White-Box Decapsulation Flow

Workflow Steps

  1. Input Processing: Parse ciphertext into polynomial components
  2. NTT Transform: Convert to 128 independent coefficient pairs
  3. Protected Computation:
    • Random shuffle prevents correlation
    • 3-share masking hides intermediate values
    • Table lookup computes the base multiply on encoded operands (no key confidentiality against the full white-box adversary)
  4. Output Processing: Inverse NTT and message decoding
  5. Validation: Re-encryption check for IND-CCA2 security

Table Construction

Base-Multiply Table Structure

Secret Coefficient Distribution (CBD with eta=2)

\(s_i\) -2 -1 0 1 2
\(\Pr[s_i]\) 1/16 4/16 6/16 4/16 1/16
Warning
This distribution governs the coefficient domain only. The base multiply operates on the NTT image \(\hat{s} = \mathrm{NTT}(s)\), which is full-range over \(\mathbb{Z}_q\): coefficient smallness does not carry into the NTT domain, so the tables are \(q\)-indexed and no small-value-set tabulation is available.

Storage Comparison

Approach Storage per Component Total Storage Practical
Naive Pair Tabulation ~368 TB >10^5 TB (all 384 = k x 128 component multiplies) No
Galissant-Goubin HFE ~2 GB 256 GB No
PQ-WB-KEM (Construction A) k-independent 22.16 MB base / 25.57 MB core Yes
PQ-WB-KEM (Construction B) ~60 KB 7.67 MB base / 11.08 MB core Yes

The reduction comes from the degree-2 extension structure of the NTT domain, which replaces pair-by-pair tabulation with \(q\)-indexed scalar tables, not from any smallness of the secret. The measured base tables are about 11,600x (A) and 33,400x (B) smaller than the 2022 Galissant-Goubin HFE white-box.

Output-Encoding Sublayer

A nonlinear output encoding is applied to the base-multiply result, at a measured 3.41 MB table cost, giving the cores of 25.57 MB (A) and 11.08 MB (B). This storage figure must not be read as key material: of the 512 stored encoding tables only 256 are independent, each inverse being reconstructible from its forward map, so the layer carries \(256\log_2(q!) \approx 1.09\) MB \(= 2^{20.06}\) bytes of entropy. The stored size overstates the secret-bearing material by a factor of 3.12 (results/encoding_layer_entropy.json).


Arithmetic Masking

Three-Share Arithmetic Masking

Three-Share Scheme

The secret \(s\) is split into three shares:

\[ s = s_1 + s_2 + s_3 \pmod{q} \]

where \(s_1, s_2\) are uniformly random and \(s_3 = s - s_1 - s_2 \pmod{q}\).

DCA Resistance Properties

Attack Order 2-Share Masking 3-Share Masking
First-Order DCA Resistant Resistant
Second-Order DCA Vulnerable Resistant
Third-Order DCA Vulnerable Vulnerable

Information-Theoretic Security

For \(n\)-share arithmetic masking, the mutual information between any \(n-1\) shares and the secret is zero:

\[ I(S; S_1, S_2, \ldots, S_{n-1}) = 0 \]


Comparison with Prior Work

Comparison with Prior White-Box PQC Work

Detailed Comparison Table

Aspect Galissant-Goubin Bicakci et al. PQ-WB-KEM
PQC Type Multivariate (HFE) Hash-based Lattice (M-LWE)
NIST Standard None FIPS 205 FIPS 203
Primitive Encryption Signature KEM
Storage 256 GB Medium 25.57 MB (A) / 11.08 MB (B) core
Practical No Moderate Yes
DCA Resistance Not addressed N/A 3-share masking
Timing Safe Unknown N/A No division-timing leak in the base multiply
Target Platform Theoretical General M2M Devices

Experimental Results

DCA Simulation Results

DCA Correlation Results
Implementation Traces Correlation (rho_max) Attack
Unmasked 1,000 0.866 Success
Unmasked 10,000 0.853 Success
3-Share Masked 1,000 0.031 Fail
3-Share Masked 5,000 0.005 Fail
3-Share Masked 10,000 0.011 Fail

\(\rho_{\max}\) is the correct-key correlation. At 10,000 traces the masked value of 0.011 is about \(1.1\times\) the \(1/\sqrt{N} = 0.01\) sampling-noise floor and below the 0.031 maximum over wrong-key hypotheses, so the attack fails. The masked values are non-monotone because all three are noise-floor samples rather than a decaying signal, and the reduction ratio is taken against that floor rather than being a security level. The simulation certifies the masked shares of the product: the clear product coordinate formed before masking still leaks at the unmasked \(\rho \approx 0.85\) level.

Performance Benchmarks

Platform Baseline Decaps White-Box Decaps (projected) Overhead
x86_64 (liboqs 0.15.0) 0.213 ms (N=20 portable mean) ~10 ms (7–14 band) ~47x deployment (proj.); 17x RNG-excluded floor
ARM64 (QEMU) 0.310 ms (instruction-level only) not projected (no ARM-device measurement) –

The \(17\times\) factor is a projection ( \(\approx 1.55\times\) protected primitive \(\times \approx 11\times\) cache), not an end-to-end white-box measurement; the \(1.55\times\) term excludes mask-generation randomness and so is a lower bound, the faithful native-C protected primitive measuring \(4.30\times\) (x86-64) and \(2.85\times\) (aarch64). Only decapsulation is protected: key generation and encapsulation run unprotected at baseline. The ARM64 row was obtained by running AArch64 binaries under qemu-aarch64 user-mode emulation on the same x86-64 host: QEMU emulates the ARM64 instruction set while the host CPU performs the work, so the figures characterise instruction-level behaviour and are not any ARM device's wall-clock. No measurement on physical ARM hardware is claimed.

Storage Requirements

Component A (shared) B (baked) Basis
Base-multiply tables 22.16 MB 7.67 MB measured
Output-encoding sublayer 3.41 MB 3.41 MB measured
Measured core 25.57 MB 11.08 MB measured
Coefficient shuffle ( \(\pi\), \(\pi^{-1}\)) 3 KB 3 KB measured
Masking support 0 0 runtime
Deployment total 25.58 MB 11.08 MB measured

The base-multiply tables are stored once, unmasked: masking is applied to lookup outputs at runtime with fresh per-decapsulation randomness, so no masked tables are stored. Construction A uses one secret-independent table shared across all components and polynomials; Construction B bakes the fixed secret into per-component tables, scaling with the module rank \(k\). The coefficient shuffle stores a permutation of the 256 secret coefficients and its inverse, per polynomial, at a measured 3 KB (results/obfuscation_storage.json); masking stores nothing because the three shares are generated at runtime. The obfuscation layers therefore add only a few kilobytes, so the deployment total equals the measured core: 25.58 MB (A) and 11.08 MB (B).

Note
The core is a size, not an extraction cost. Copying it costs \(\approx 2^{24}\) byte-reads (A) or \(\approx 2^{23}\) (B), but the measured budget at which an adversary regenerates the tables and decapsulates fresh ciphertexts is 1,536 bytes for Construction B and zero for Construction A, in neither case growing with the tables.

Quick Start Guide

Manual Installation

Step 1: Install Python Dependencies

# Windows
cd code\python
pip install numpy scipy matplotlib
# Linux/Mac
cd code/python
pip3 install numpy scipy matplotlib
# Verify installation
python -c "import numpy; import scipy; print('OK')"

Step 2: Install liboqs (Optional, for Baseline Benchmarks)

# Ubuntu/Debian
sudo apt install liboqs-dev
# From source
git clone https://github.com/open-quantum-safe/liboqs.git
cd liboqs && mkdir build && cd build
cmake .. && make && sudo make install
# Python bindings
pip install liboqs-python

Step 3: Install SageMath (Optional, for Proof Verification)

# Ubuntu/Debian
sudo apt install sagemath
# Or use conda
conda create -n sage sage python=3.11
conda activate sage

Step 4: Install Documentation Tools (Optional)

# Windows (with Chocolatey)
choco install doxygen.install graphviz
# Ubuntu/Debian
sudo apt install doxygen graphviz
# Verify
doxygen --version
dot -V

Step 5: Run Experiments Manually

# Run all experiments
cd code/python
python run_all.py
# Or run individual experiments
python baseline_benchmark.py # Reference ML-KEM-768 timing
python dca_simulation.py # DCA attack verification
python whitebox_reference.py # Base-multiply tables, measured footprints
python whitebox_encoded.py # Output-encoding sublayer
python encoding_layer_entropy.py # Encoding storage vs entropy
python entry_determinacy.py # Entry-determinacy degree
python table_extraction_witness.py # Measured extraction budget
python overhead_calculation.py # ~47x deployment projection (17x RNG-excluded floor)
python scaling_analysis.py # ML-KEM-512/768/1024 scaling
python concrete_security_bounds.py # Bit-security estimates
python algebraic_attack_analysis.py # BGE attack analysis

Step 6: Regenerate Documentation (development repository)

This archive ships the generated HTML and PDF under code/docs/. To regenerate them, run Doxygen from the development repository, whose code/Doxyfile is the build configuration:

cd code
doxygen Doxyfile
# Open documentation
# Windows: start docs/html/index.html
# Linux: xdg-open docs/html/index.html

Code-to-Output Mapping

The following table documents which scripts produce which output files:

Python Experiment Scripts

Script Output File Description
run_all.py results/experiment_summary.json Master orchestration - runs all experiments
baseline_benchmark.py results/baseline_benchmark.json Reference ML-KEM-768 performance using liboqs
whitebox_reference.py results/whitebox_reference.json Base-multiply table construction, measured footprints
whitebox_encoded.py results/whitebox_encoded.json Output-encoding sublayer (3.41 MB)
encoding_layer_entropy.py results/encoding_layer_entropy.json Encoding storage (3.41 MB) vs entropy (1.09 MB)
entry_determinacy.py results/entry_determinacy.json Entry-determinacy degree, SPACE-style control
table_extraction_witness.py results/table_extraction_witness.json Measured extraction budget (1,536 B for B, 0 for A)
share_statistics.py results/share_statistics.json Share distribution statistics
dca_simulation.py results/dca_simulation.json DCA attack simulation (rho_max = 0.011 at 10,000 traces)
overhead_calculation.py results/overhead_calculation.json White-box overhead (~47x deployment projection; 17x RNG-excluded floor)
wallclock_ci.py results/wallclock_statistics_windows.json, results/wallclock_statistics_wsl.json Wall-clock overhead statistics (N=20 mean +/- 95% CI)
scaling_analysis.py results/scaling_analysis.json ML-KEM-512/768/1024 scaling projections
concrete_security_bounds.py results/concrete_security_bounds.json Bit-security estimates
algebraic_attack_analysis.py results/algebraic_attack_analysis.json BGE-style attack resistance
obfuscation_storage.py results/obfuscation_storage.json Coefficient-shuffle / masking-support storage (measured 3 KB shuffle; deployment total)
arm64_aggregate.py results/arm64_benchmark.json ARM64/QEMU liboqs ML-KEM-768 timing (N=20 mean +/- 95% CI)

SageMath Verification Scripts

Script Output File Description
ntt_verification.sage results/ntt_verification.json NTT factorization proof verification

Output File Formats

Extension Format Usage
.json JSON Primary result format with full metadata
.log Text Detailed execution logs with timestamps
.sage SageMath Mathematical verification scripts

Results Directory Structure

Results Directory Structure

JSON Result Structure Example

Each Python experiment produces JSON with consistent structure:

{
"_metadata": {
"generated_by": "script_name.py",
"timestamp": "2026-XX-XX HH:MM:SS",
"source_file": "python/script_name.py",
"project": "PQ-WB-KEM",
"paper": "Mathematics (MDPI)"
},
"parameters": {
"q": 3329,
"n": 256,
"k": 3,
...
},
"results": {...},
"analysis": {...},
"verified": true
}

Mathematical Notation Reference

Ring and Field Notation

Symbol Definition Value/Description
\(R_q\) \(\mathbb{Z}_q[X]/(X^n+1)\) Polynomial ring
\(q\) Prime modulus 3329
\(n\) Polynomial degree 256
\(k\) Module rank 3 (ML-KEM-768)
\(\zeta\) Primitive 256th root of unity 17
\(\gamma_i\) \(\zeta^{2i+1}\) Reduction constant for component \(i\)

NTT Domain Formulas

Ring Factorization:

\[ R_q \cong \prod_{i=0}^{127} \mathbb{Z}_q[X]/(X^2 - \zeta^{2i+1}) \]

Coefficient-Pair Multiplication:

\[ (a_0, a_1) \cdot (b_0, b_1) = (a_0 b_0 + \gamma_i a_1 b_1, a_0 b_1 + a_1 b_0) \pmod{q} \]

Masking Formulas

Three-Share Split:

\[ s = s_1 + s_2 + s_3 \pmod{q} \]

Information-Theoretic Security:

\[ I(S; S_1, S_2, \ldots, S_{n-1}) = 0 \]

CBD Distribution

Binomial Coefficient Probability (eta=2):

\[ \Pr[s_i = k] = \binom{2\eta}{\eta + k} \cdot 2^{-2\eta}, \quad k \in \{-\eta, \ldots, \eta\} \]

Security Metrics

DCA Correlation:

\[ \rho = \frac{\text{Cov}(L, H)}{\sigma_L \cdot \sigma_H} \]

where \(L\) is the leakage (intermediate value) and \(H\) is the hypothesis.

Table Footprint (a size, not a security parameter):

\[ \log_2(\text{core size in bytes}) \approx 24 \;(\text{A}), \qquad \approx 23 \;(\text{B}) \]

This counts the byte-reads needed to copy the core. It is not an extraction cost: the measured budget that regenerates the tables is \(1{,}536\) bytes (Construction B) and \(0\) (Construction A).


Module Documentation

Core Implementation Modules

Module File Description
ntt_module whitebox_reference.py NTT-domain base multiply and table construction
tables_module whitebox_encoded.py Nonlinear output-encoding sublayer
masking_module share_statistics.py Three-share arithmetic masking statistics

Analysis and Verification Modules

Module File Description
dca_module dca_simulation.py DCA attack simulation
algebraic_module algebraic_attack_analysis.py BGE-style attack analysis
benchmarks_module baseline_benchmark.py Performance benchmarking
scaling_module scaling_analysis.py ML-KEM variant scaling
security_module concrete_security_bounds.py Bit-security estimation
tables_module entry_determinacy.py Entry-determinacy degree measurement
tables_module table_extraction_witness.py Measured extraction budget

SageMath Verification

Module File Description
sage_ntt ntt_verification.sage NTT factorization proof

Known Limitations

Limitation Description Mitigation
Key Confidentiality The base multiply forms the clear product coordinates before masking, and these yield linear equations for the secret, so no key confidentiality holds against the full white-box adversary None; every positive result is scoped to a strictly weaker adversary
Strong Incompressibility Proven impossible for key-fixing encryption None available
Weak Incompressibility Not attained: each baked table is \(\mathbb{Z}_q\)-linear in its public index, so 1,536 bytes of reads regenerate the Construction-B set bit-exactly and Construction A needs no read at all. Enlarging the tables cannot repair this, the budget carrying no table-size term Make the key-to-table map one-way rather than \(\mathbb{Z}_q\)-linear
Algebraic Attacks NTT linearity may enable BGE-style attacks Shuffle + masking combination
Third-Order DCA 3-share masking does not protect against 3rd-order Use 4+ shares if needed
Cache-Line Timing Division-timing freedom is claimed for the protected base multiply; cache-line constant-time is not Out of scope
Memory Requirements 11-26 MB measured deployment total Target gateway-class devices with >= 64 MB RAM; M-profile microcontrollers are out of scope
Fault Injection Hardware countermeasures required Out of scope (software-only)

Dependencies

Required

  • Python 3.8+
  • NumPy 1.20+
  • SciPy 1.7+

Optional (for Full Functionality)

Dependency Version Purpose
liboqs 0.15.0+ Baseline ML-KEM benchmarks
SageMath 9.0+ Mathematical proof verification
Matplotlib 3.5+ Result visualization
Doxygen 1.9+ Documentation generation
Graphviz 2.40+ DOT diagram rendering

Project Structure

Project Directory Structure

License

This software is provided for academic and research purposes. See the LICENSE file in the repository for details.


Contact

Asst. Prof. Dr. Ugur CORUH

Author Asst. Prof. Dr. Ugur CORUH
Email ugur..nosp@m.coru.nosp@m.h@erd.nosp@m.ogan.nosp@m..edu..nosp@m.tr
Website ugurcoruh.com
Institution Recep Tayyip Erdogan University
Faculty Faculty of Engineering
Department Department of Computer Engineering
Location Rize, Turkey


Note
This documentation was generated with Doxygen. Navigate using the sidebar or search functionality.