|
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)
|
Classes | |
| class | AlgebraicAttackResult |
| Result of an algebraic attack attempt. More... | |
Functions | |
| _bitrev7 (k) | |
| Bit-reversal of a 7-bit index (FIPS-203 NTT twiddle order). | |
| AlgebraicAttackResult | algebraic_attack_basic (np.ndarray secret_ntt, int num_queries=256) |
| Basic algebraic attack exploiting NTT linearity. | |
| AlgebraicAttackResult | algebraic_attack_protected (np.ndarray secret_ntt, np.ndarray mixing_key, np.ndarray permutation, np.ndarray inverse_permutation, int num_queries=1000) |
| Attempt the algebraic attack against the protected implementation. | |
| Dict | analyze_attack_complexity (int num_trials=10) |
| Analyze attack complexity across unprotected/protected scenarios. | |
| np.ndarray | apply_nonlinear_mixing (np.ndarray ntt_poly, np.ndarray mixing_key) |
| Apply nonlinear mixing (cubic map) to break linearity. | |
| np.ndarray | apply_random_shuffling (np.ndarray ntt_poly, np.ndarray permutation) |
| Apply coefficient shuffling by a permutation. | |
| Dict | benchmark_countermeasure_overhead () |
| Benchmark runtime overhead of the countermeasures vs baseline. | |
| np.ndarray | compute_zeta_powers () |
| Compute powers of zeta for the NTT. | |
| Tuple[np.ndarray, np.ndarray] | extract_linear_equations (List[Tuple[np.ndarray, np.ndarray]] input_output_pairs, int target_coefficients=256) |
| Extract linear equations from input-output pairs. | |
| Dict | full_module_recovery (int num_queries=3, int seed=42) |
| Full ML-KEM-768 secret recovery on the unprotected white-box base multiply. | |
| np.ndarray | generate_secret_key () |
| Generate a secret key with CBD(eta=2) distribution. | |
| main () | |
| Run the full analysis and write results JSON. | |
| int | mod_inverse (int a, int m) |
| Modular inverse of a mod m (prime m, via Fermat). | |
| np.ndarray | ntt_forward (np.ndarray poly) |
| Forward NTT: standard domain to NTT domain. | |
| np.ndarray | ntt_inverse (np.ndarray ntt_poly) |
| Inverse NTT: NTT domain to standard domain. | |
| np.ndarray | ntt_multiply (np.ndarray a_ntt, np.ndarray b_ntt) |
| Multiply two polynomials in the NTT domain. | |
| np.ndarray | simulate_protected_whitebox (np.ndarray secret_ntt, np.ndarray ciphertext_ntt, np.ndarray mixing_key, np.ndarray permutation, np.ndarray inverse_permutation) |
| Simulate a protected white-box: mix and shuffle the tabulated secret, multiply. | |
| np.ndarray | simulate_whitebox_table_lookup (np.ndarray secret_ntt, np.ndarray ciphertext_ntt) |
| Simulate a white-box table lookup returning s * c in the NTT domain. | |
| Tuple[Optional[np.ndarray], bool] | solve_linear_system_mod_q (np.ndarray A, np.ndarray b, int q=Q) |
| Solve Ax = b mod q by Gaussian elimination. | |
| solve_mod_q (np.ndarray A, np.ndarray b, int q) | |
| Solve A x = b over Z_q by Gauss-Jordan elimination. | |
Variables | |
| int | ETA = 2 |
| int | K = 3 |
| int | N = 256 |
| int | Q = 3329 |
| int | ZETA = 17 |
| np.ndarray | ZETA_POWERS = compute_zeta_powers() |
|
protected |
Bit-reversal of a 7-bit index (FIPS-203 NTT twiddle order).
| k | Index in [0, 128). |
Definition at line 66 of file algebraic_attack_analysis.py.
Referenced by extract_linear_equations(), full_module_recovery(), ntt_forward(), ntt_inverse(), and ntt_multiply().
Here is the caller graph for this function:| AlgebraicAttackResult algebraic_attack_analysis.algebraic_attack_basic | ( | np.ndarray | secret_ntt, |
| int | num_queries = 256 |
||
| ) |
Basic algebraic attack exploiting NTT linearity.
| secret_ntt | Target secret key in NTT domain. |
| num_queries | Number of random ciphertext queries. |
Definition at line 311 of file algebraic_attack_analysis.py.
References extract_linear_equations(), simulate_whitebox_table_lookup(), and solve_linear_system_mod_q().
Referenced by analyze_attack_complexity().
Here is the call graph for this function:
Here is the caller graph for this function:| AlgebraicAttackResult algebraic_attack_analysis.algebraic_attack_protected | ( | np.ndarray | secret_ntt, |
| np.ndarray | mixing_key, | ||
| np.ndarray | permutation, | ||
| np.ndarray | inverse_permutation, | ||
| int | num_queries = 1000 |
||
| ) |
Attempt the algebraic attack against the protected implementation.
| secret_ntt | Target secret key in NTT domain. |
| mixing_key | Additive mixing key. |
| permutation | Shuffling permutation. |
| inverse_permutation | Inverse of the shuffling permutation. |
| num_queries | Number of random ciphertext queries. |
Definition at line 424 of file algebraic_attack_analysis.py.
References extract_linear_equations(), simulate_protected_whitebox(), and solve_linear_system_mod_q().
Referenced by analyze_attack_complexity().
Here is the call graph for this function:
Here is the caller graph for this function:| Dict algebraic_attack_analysis.analyze_attack_complexity | ( | int | num_trials = 10 | ) |
Analyze attack complexity across unprotected/protected scenarios.
| num_trials | Trials per scenario. |
Definition at line 493 of file algebraic_attack_analysis.py.
References algebraic_attack_basic(), algebraic_attack_protected(), and generate_secret_key().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| np.ndarray algebraic_attack_analysis.apply_nonlinear_mixing | ( | np.ndarray | ntt_poly, |
| np.ndarray | mixing_key | ||
| ) |
Apply nonlinear mixing (cubic map) to break linearity.
| ntt_poly | Input polynomial in NTT domain. |
| mixing_key | Additive mixing key. |
Definition at line 371 of file algebraic_attack_analysis.py.
Referenced by benchmark_countermeasure_overhead(), and simulate_protected_whitebox().
Here is the caller graph for this function:| np.ndarray algebraic_attack_analysis.apply_random_shuffling | ( | np.ndarray | ntt_poly, |
| np.ndarray | permutation | ||
| ) |
Apply coefficient shuffling by a permutation.
| ntt_poly | Input polynomial. |
| permutation | Index permutation. |
Definition at line 386 of file algebraic_attack_analysis.py.
Referenced by benchmark_countermeasure_overhead(), and simulate_protected_whitebox().
Here is the caller graph for this function:| Dict algebraic_attack_analysis.benchmark_countermeasure_overhead | ( | ) |
Benchmark runtime overhead of the countermeasures vs baseline.
Definition at line 653 of file algebraic_attack_analysis.py.
References apply_nonlinear_mixing(), apply_random_shuffling(), generate_secret_key(), ntt_multiply(), and simulate_protected_whitebox().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| np.ndarray algebraic_attack_analysis.compute_zeta_powers | ( | ) |
Compute powers of zeta for the NTT.
Definition at line 51 of file algebraic_attack_analysis.py.
| Tuple[np.ndarray, np.ndarray] algebraic_attack_analysis.extract_linear_equations | ( | List[Tuple[np.ndarray, np.ndarray]] | input_output_pairs, |
| int | target_coefficients = 256 |
||
| ) |
Extract linear equations from input-output pairs.
| input_output_pairs | List of (ciphertext_ntt, output_ntt) pairs. |
| target_coefficients | Number of secret coefficients to solve for. |
Definition at line 271 of file algebraic_attack_analysis.py.
References _bitrev7().
Referenced by algebraic_attack_basic(), and algebraic_attack_protected().
Here is the call graph for this function:
Here is the caller graph for this function:| Dict algebraic_attack_analysis.full_module_recovery | ( | int | num_queries = 3, |
| int | seed = 42 |
||
| ) |
Full ML-KEM-768 secret recovery on the unprotected white-box base multiply.
| num_queries | Number of full ciphertext queries used. |
| seed | Deterministic seed. |
Each degree-2 component i gives, per query, two Z_q-linear equations in its two NTT-domain secret coordinates (s0, s1): p0 = c0 s0 + gamma_i c1 s1 and p1 = c1 s0 + c0 s1. Stacking the queries and solving recovers (s0, s1); across all 128 components of all k = 3 secret polynomials this recovers every one of the k*n = 768 NTT-domain coefficients. Each recovery is checked against the known secret.
Definition at line 767 of file algebraic_attack_analysis.py.
References _bitrev7(), and solve_mod_q().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| np.ndarray algebraic_attack_analysis.generate_secret_key | ( | ) |
Generate a secret key with CBD(eta=2) distribution.
Definition at line 161 of file algebraic_attack_analysis.py.
Referenced by analyze_attack_complexity(), and benchmark_countermeasure_overhead().
Here is the caller graph for this function:| algebraic_attack_analysis.main | ( | void | ) |
Run the full analysis and write results JSON.
Definition at line 819 of file algebraic_attack_analysis.py.
References analyze_attack_complexity(), benchmark_countermeasure_overhead(), full_module_recovery(), and main().
Referenced by main().
Here is the call graph for this function:
Here is the caller graph for this function:| int algebraic_attack_analysis.mod_inverse | ( | int | a, |
| int | m | ||
| ) |
Modular inverse of a mod m (prime m, via Fermat).
| a | Value to invert. |
| m | Prime modulus. |
Definition at line 184 of file algebraic_attack_analysis.py.
Referenced by solve_linear_system_mod_q(), and solve_mod_q().
Here is the caller graph for this function:| np.ndarray algebraic_attack_analysis.ntt_forward | ( | np.ndarray | poly | ) |
Forward NTT: standard domain to NTT domain.
| poly | Polynomial coefficients. |
Definition at line 75 of file algebraic_attack_analysis.py.
References _bitrev7().
Here is the call graph for this function:| np.ndarray algebraic_attack_analysis.ntt_inverse | ( | np.ndarray | ntt_poly | ) |
Inverse NTT: NTT domain to standard domain.
| ntt_poly | Coefficients in NTT domain. |
Definition at line 96 of file algebraic_attack_analysis.py.
References _bitrev7().
Here is the call graph for this function:| np.ndarray algebraic_attack_analysis.ntt_multiply | ( | np.ndarray | a_ntt, |
| np.ndarray | b_ntt | ||
| ) |
Multiply two polynomials in the NTT domain.
| a_ntt | First operand in NTT domain. |
| b_ntt | Second operand in NTT domain. |
Definition at line 120 of file algebraic_attack_analysis.py.
References _bitrev7().
Referenced by benchmark_countermeasure_overhead(), simulate_protected_whitebox(), and simulate_whitebox_table_lookup().
Here is the call graph for this function:
Here is the caller graph for this function:| np.ndarray algebraic_attack_analysis.simulate_protected_whitebox | ( | np.ndarray | secret_ntt, |
| np.ndarray | ciphertext_ntt, | ||
| np.ndarray | mixing_key, | ||
| np.ndarray | permutation, | ||
| np.ndarray | inverse_permutation | ||
| ) |
Simulate a protected white-box: mix and shuffle the tabulated secret, multiply.
| secret_ntt | Secret key in NTT domain. |
| ciphertext_ntt | Ciphertext in NTT domain. |
| mixing_key | Additive mixing key. |
| permutation | Shuffling permutation applied to the tabulated secret. |
| inverse_permutation | Unused; kept so callers need not change. |
Definition at line 396 of file algebraic_attack_analysis.py.
References apply_nonlinear_mixing(), apply_random_shuffling(), and ntt_multiply().
Referenced by algebraic_attack_protected(), and benchmark_countermeasure_overhead().
Here is the call graph for this function:
Here is the caller graph for this function:| np.ndarray algebraic_attack_analysis.simulate_whitebox_table_lookup | ( | np.ndarray | secret_ntt, |
| np.ndarray | ciphertext_ntt | ||
| ) |
Simulate a white-box table lookup returning s * c in the NTT domain.
| secret_ntt | Secret key in NTT domain. |
| ciphertext_ntt | Ciphertext in NTT domain. |
Definition at line 171 of file algebraic_attack_analysis.py.
References ntt_multiply().
Referenced by algebraic_attack_basic().
Here is the call graph for this function:
Here is the caller graph for this function:| Tuple[Optional[np.ndarray], bool] algebraic_attack_analysis.solve_linear_system_mod_q | ( | np.ndarray | A, |
| np.ndarray | b, | ||
| int | q = Q |
||
| ) |
Solve Ax = b mod q by Gaussian elimination.
| A | Coefficient matrix. |
| b | Right-hand side vector. |
| q | Prime modulus. |
Definition at line 196 of file algebraic_attack_analysis.py.
References mod_inverse().
Referenced by algebraic_attack_basic(), and algebraic_attack_protected().
Here is the call graph for this function:
Here is the caller graph for this function:| algebraic_attack_analysis.solve_mod_q | ( | np.ndarray | A, |
| np.ndarray | b, | ||
| int | q | ||
| ) |
Solve A x = b over Z_q by Gauss-Jordan elimination.
| A | Coefficient matrix (m x ncols). |
| b | Right-hand side (length m). |
| q | Prime modulus. |
Definition at line 727 of file algebraic_attack_analysis.py.
References mod_inverse().
Referenced by full_module_recovery().
Here is the call graph for this function:
Here is the caller graph for this function:| int algebraic_attack_analysis.ETA = 2 |
Definition at line 43 of file algebraic_attack_analysis.py.
| int algebraic_attack_analysis.K = 3 |
Definition at line 42 of file algebraic_attack_analysis.py.
| int algebraic_attack_analysis.N = 256 |
Definition at line 41 of file algebraic_attack_analysis.py.
| int algebraic_attack_analysis.Q = 3329 |
Definition at line 40 of file algebraic_attack_analysis.py.
| int algebraic_attack_analysis.ZETA = 17 |
Definition at line 44 of file algebraic_attack_analysis.py.
| np.ndarray algebraic_attack_analysis.ZETA_POWERS = compute_zeta_powers() |
Definition at line 63 of file algebraic_attack_analysis.py.