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_encoded Namespace Reference

Functions

 _bitrev7 (k)
 Bit-reversal of a 7-bit index (FIPS-203 NTT twiddle order).
 
 _gauss_solve_modq (rows, rhs)
 Solve the over-determined linear system rows*x = rhs mod Q for x in Z_q^2.
 
 _zeta_powers ()
 Powers of zeta mod q for the NTT.
 
 base_mul_direct (s0, s1, c0, c1, gamma)
 Base multiply for one degree-2 factor from full-range operands.
 
 base_mul_encoded (s0, s1, c0, c1, gamma, E, i)
 Encoded output E_{i,0}(p0), E_{i,1}(p1) of the plain product.
 
 build_encodings (rng)
 Secret nonlinear I/O encodings: two random bijections on Z_q per component plus their inverses.
 
 main ()
 Build encodings over the real full-range secret, verify decode correctness, measure encoding footprint, run the algebraic attack.
 
 ntt_forward (poly)
 Forward NTT: coefficient domain to NTT domain (full-range image).
 
 solve_component (observations, gamma, encoding_inverse=None)
 Recover full-range (s0,s1) for one component from chosen-ciphertext observations by linear solve over Z_q.
 

Variables

list GAMMAS = [pow(ZETA, 2 * _bitrev7(i) + 1, Q) for i in range(NUM_COMPONENTS)]
 
int K = 3
 
int N = 256
 
int NUM_COMPONENTS = N // 2
 
int Q = 3329
 
int SEED = 42
 
int ZETA = 17
 
 ZETA_POWERS = _zeta_powers()
 

Function Documentation

◆ _bitrev7()

whitebox_encoded._bitrev7 (   k)
protected

Bit-reversal of a 7-bit index (FIPS-203 NTT twiddle order).

Parameters
kIndex in [0, 128).
Returns
Bit-reversed 7-bit index.

Definition at line 64 of file whitebox_encoded.py.

Referenced by ntt_forward().

+ Here is the caller graph for this function:

◆ _gauss_solve_modq()

whitebox_encoded._gauss_solve_modq (   rows,
  rhs 
)
protected

Solve the over-determined linear system rows*x = rhs mod Q for x in Z_q^2.

Returns
(x0, x1) or None if under-determined.

Definition at line 159 of file whitebox_encoded.py.

Referenced by solve_component().

+ Here is the caller graph for this function:

◆ _zeta_powers()

whitebox_encoded._zeta_powers ( )
protected

Powers of zeta mod q for the NTT.

Returns
Array of 256 zeta powers.

Definition at line 49 of file whitebox_encoded.py.

◆ base_mul_direct()

whitebox_encoded.base_mul_direct (   s0,
  s1,
  c0,
  c1,
  gamma 
)

Base multiply for one degree-2 factor from full-range operands.

Parameters
s0s1 Full-range NTT-domain secret coordinates.
c0c1 Ciphertext coordinates;
gammaComponent twiddle.
Returns
(p0, p1) product pair mod q.

Definition at line 115 of file whitebox_encoded.py.

◆ base_mul_encoded()

whitebox_encoded.base_mul_encoded (   s0,
  s1,
  c0,
  c1,
  gamma,
  E,
  i 
)

Encoded output E_{i,0}(p0), E_{i,1}(p1) of the plain product.

Returns
Encoded (o0, o1) pair.

Definition at line 127 of file whitebox_encoded.py.

Referenced by main().

+ Here is the caller graph for this function:

◆ build_encodings()

whitebox_encoded.build_encodings (   rng)

Secret nonlinear I/O encodings: two random bijections on Z_q per component plus their inverses.

Parameters
rngSeeded NumPy generator.
Returns
(E, Einv) forward and inverse permutation tables.

Definition at line 96 of file whitebox_encoded.py.

Referenced by encoding_layer_entropy.main().

+ Here is the caller graph for this function:

◆ main()

whitebox_encoded.main ( void  )

Build encodings over the real full-range secret, verify decode correctness, measure encoding footprint, run the algebraic attack.

Definition at line 195 of file whitebox_encoded.py.

References base_mul_encoded(), main(), and solve_component().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ntt_forward()

whitebox_encoded.ntt_forward (   poly)

Forward NTT: coefficient domain to NTT domain (full-range image).

Parameters
polyLength-256 coefficient vector.
Returns
NTT-domain coefficient vector.

Definition at line 76 of file whitebox_encoded.py.

References _bitrev7().

+ Here is the call graph for this function:

◆ solve_component()

whitebox_encoded.solve_component (   observations,
  gamma,
  encoding_inverse = None 
)

Recover full-range (s0,s1) for one component from chosen-ciphertext observations by linear solve over Z_q.

Parameters
observationsList of (c0,c1,o0,o1) tuples.
gammaComponent twiddle constant.
encoding_inverseOptional (inv0,inv1) tables; decodes outputs first.
Returns
(s0,s1) or None.

Relation is linear in (s0,s1): o0 = s0*c0 + gamma*s1*c1, o1 = s0*c1 + s1*c0; queries are stacked into the system.

Definition at line 136 of file whitebox_encoded.py.

References _gauss_solve_modq().

Referenced by main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ GAMMAS

list whitebox_encoded.GAMMAS = [pow(ZETA, 2 * _bitrev7(i) + 1, Q) for i in range(NUM_COMPONENTS)]

Definition at line 73 of file whitebox_encoded.py.

◆ K

int whitebox_encoded.K = 3

Definition at line 43 of file whitebox_encoded.py.

◆ N

int whitebox_encoded.N = 256

Definition at line 42 of file whitebox_encoded.py.

◆ NUM_COMPONENTS

int whitebox_encoded.NUM_COMPONENTS = N // 2

Definition at line 44 of file whitebox_encoded.py.

◆ Q

int whitebox_encoded.Q = 3329

Definition at line 41 of file whitebox_encoded.py.

◆ SEED

int whitebox_encoded.SEED = 42

Definition at line 46 of file whitebox_encoded.py.

◆ ZETA

int whitebox_encoded.ZETA = 17

Definition at line 45 of file whitebox_encoded.py.

◆ ZETA_POWERS

whitebox_encoded.ZETA_POWERS = _zeta_powers()

Definition at line 61 of file whitebox_encoded.py.