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

Functions

 _bitrev7 (k)
 Bit-reversal of a 7-bit index (FIPS-203 NTT twiddle order).
 
Tuple[float, int] dca_attack (np.ndarray traces, np.ndarray hypotheses)
 Correlation-based DCA key-recovery attack.
 
np.ndarray generate_secret_key ()
 Generate secret key via centered binomial distribution CBD(eta=2).
 
np.ndarray hamming_weight (np.ndarray x)
 Hamming weight of each element treated as a 12-bit value (q=3329).
 
 main ()
 Entry point; runs the suite and writes results/dca_simulation.json.
 
np.ndarray ntt_forward (np.ndarray poly)
 Forward NTT: coefficient domain to NTT domain (full-range image).
 
np.ndarray ntt_secret ()
 Full-range NTT-domain secret shat = NTT(s), the operand the base multiply actually processes (coefficient-domain smallness does not carry into the NTT domain).
 
float pearson_correlation (np.ndarray x, np.ndarray y)
 Pearson correlation coefficient; 0.0 if either input has zero variance.
 
Dict run_dca_simulation (int num_traces=10000, bool masked=True, int num_shares=3)
 Run one DCA simulation and report correct-vs-random key correlation.
 
Dict run_full_simulation (List[int] num_traces_list=[1000, 10000, 100000, 500000])
 Run the full DCA suite comparing masked vs unmasked implementations.
 
np.ndarray simulate_masked_trace (np.ndarray secret, np.ndarray ciphertext, int num_shares=3)
 Simulated power trace for n-share arithmetic-masked implementation.
 
np.ndarray simulate_unmasked_trace (np.ndarray secret, np.ndarray ciphertext)
 Simulated power trace for unmasked implementation.
 

Variables

 _ZP = np.zeros(256, dtype=np.int64)
 
int ETA = 2
 
int N = 256
 
int Q = 3329
 
int ZETA = 17
 

Function Documentation

◆ _bitrev7()

dca_simulation._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 53 of file dca_simulation.py.

Referenced by ntt_forward().

+ Here is the caller graph for this function:

◆ dca_attack()

Tuple[float, int] dca_simulation.dca_attack ( np.ndarray  traces,
np.ndarray  hypotheses 
)

Correlation-based DCA key-recovery attack.

Parameters
tracesShape (num_traces, num_points) collected traces.
hypothesesShape (num_keys, num_traces) hypothesis values per key guess.
Returns
(max_correlation, best_key_index).

Definition at line 169 of file dca_simulation.py.

References pearson_correlation().

+ Here is the call graph for this function:

◆ generate_secret_key()

np.ndarray dca_simulation.generate_secret_key ( )

Generate secret key via centered binomial distribution CBD(eta=2).

Returns
Coefficient array in range {-2,-1,0,1,2}.

Definition at line 82 of file dca_simulation.py.

Referenced by ntt_secret().

+ Here is the caller graph for this function:

◆ hamming_weight()

np.ndarray dca_simulation.hamming_weight ( np.ndarray  x)

Hamming weight of each element treated as a 12-bit value (q=3329).

Parameters
xInput array.
Returns
Per-element bit count as float64.

Definition at line 102 of file dca_simulation.py.

Referenced by run_dca_simulation(), simulate_masked_trace(), and simulate_unmasked_trace().

+ Here is the caller graph for this function:

◆ main()

dca_simulation.main ( void  )

Entry point; runs the suite and writes results/dca_simulation.json.

Definition at line 371 of file dca_simulation.py.

References main(), and run_full_simulation().

Referenced by main().

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

◆ ntt_forward()

np.ndarray dca_simulation.ntt_forward ( np.ndarray  poly)

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

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

Definition at line 62 of file dca_simulation.py.

References _bitrev7().

+ Here is the call graph for this function:

◆ ntt_secret()

np.ndarray dca_simulation.ntt_secret ( )

Full-range NTT-domain secret shat = NTT(s), the operand the base multiply actually processes (coefficient-domain smallness does not carry into the NTT domain).

Returns
Full-range secret vector over Z_q.

Definition at line 92 of file dca_simulation.py.

References generate_secret_key().

Referenced by run_dca_simulation().

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

◆ pearson_correlation()

float dca_simulation.pearson_correlation ( np.ndarray  x,
np.ndarray  y 
)

Pearson correlation coefficient; 0.0 if either input has zero variance.

Parameters
xFirst series.
ySecond series.
Returns
Correlation coefficient.

Definition at line 157 of file dca_simulation.py.

Referenced by dca_attack(), and run_dca_simulation().

+ Here is the caller graph for this function:

◆ run_dca_simulation()

Dict dca_simulation.run_dca_simulation ( int   num_traces = 10000,
bool   masked = True,
int   num_shares = 3 
)

Run one DCA simulation and report correct-vs-random key correlation.

Parameters
num_tracesNumber of traces to collect.
maskedUse masked implementation when True.
num_sharesNumber of shares for masking.
Returns
Results dictionary.

Definition at line 193 of file dca_simulation.py.

References hamming_weight(), ntt_secret(), pearson_correlation(), simulate_masked_trace(), and simulate_unmasked_trace().

Referenced by run_full_simulation().

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

◆ run_full_simulation()

Dict dca_simulation.run_full_simulation ( List[int]   num_traces_list = [1000, 10000, 100000, 500000])

Run the full DCA suite comparing masked vs unmasked implementations.

Parameters
num_traces_listTrace counts for the masked-implementation sweep.
Returns
Aggregated results including per-simulation records and security analysis.

Definition at line 293 of file dca_simulation.py.

References run_dca_simulation().

Referenced by main().

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

◆ simulate_masked_trace()

np.ndarray dca_simulation.simulate_masked_trace ( np.ndarray  secret,
np.ndarray  ciphertext,
int   num_shares = 3 
)

Simulated power trace for n-share arithmetic-masked implementation.

Parameters
secretSecret key coefficients.
ciphertextCiphertext coefficients.
num_sharesNumber of arithmetic shares.
Returns
Summed independent per-share leakage.
Note
Each share leaks independently; combined leakage reveals nothing about the secret.

Definition at line 128 of file dca_simulation.py.

References hamming_weight().

Referenced by run_dca_simulation().

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

◆ simulate_unmasked_trace()

np.ndarray dca_simulation.simulate_unmasked_trace ( np.ndarray  secret,
np.ndarray  ciphertext 
)

Simulated power trace for unmasked implementation.

Parameters
secretSecret key coefficients.
ciphertextCiphertext coefficients.
Returns
Hamming-weight leakage plus Gaussian noise.
Note
Coefficient-wise product stands in for the actual NTT multiplication.

Definition at line 115 of file dca_simulation.py.

References hamming_weight().

Referenced by run_dca_simulation().

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

Variable Documentation

◆ _ZP

dca_simulation._ZP = np.zeros(256, dtype=np.int64)
protected

Definition at line 47 of file dca_simulation.py.

◆ ETA

int dca_simulation.ETA = 2

Definition at line 42 of file dca_simulation.py.

◆ N

int dca_simulation.N = 256

Definition at line 41 of file dca_simulation.py.

◆ Q

int dca_simulation.Q = 3329

Definition at line 40 of file dca_simulation.py.

◆ ZETA

int dca_simulation.ZETA = 17

Definition at line 43 of file dca_simulation.py.