This repository provides an implementation of the Stochastic Model for Differential Side-Channel Cryptanalysis (DSCA), based on the work of Schindler, Lemke, and Paar. The stochastic model combines statistical regression and side-channel analysis to efficiently approximate leakage behavior and recover secret keys with fewer traces than traditional template attacks.
The stochastic DSCA method models the side-channel leakage as a linear combination of predefined basis functions, enabling efficient profiling and key extraction. It consists of three major stages:
- Basis Function Selection
- Profiling Phase
- Key Extraction Phase
The leakage model assumes that the observed signal ( I_t(x,k) ) can be decomposed as:
where ($h_t(x,k)$) is the deterministic (data-dependent) component and (
To approximate ($h_t(x,k)$), a set of basis functions (
hw: Hamming Weighthw_bits: Bit-wise decomposition of the Hamming weightbits: Individual bits of S-box outputlsb: Least Significant Bit
The leakage function is modeled as:
where (
The profiling phase builds the regression model that estimates the deterministic part of the leakage.
-
Data Collection:
- Collect (
$N_1$ ) profiling traces under a known key ($k_b$ ). - Each trace corresponds to known plaintexts (
$x_i$ ).
- Collect (
-
Coefficient Estimation: Using least-squares regression:
$\beta_t = (G^\top G)^{-1} G^\top I_t$ ,where:
- (
$I_t$ ) is the measured leakage vector at time ($t$ ). - (
$G$ ) is the basis matrix constructed from the selected basis functions.
- (
-
Deterministic Leakage Estimation: The approximated leakage is then:
$\hat{h}_t(x,k_b) = G(\phi(x,k_b)) , \beta_t$ . -
Time Point Selection: Compute the coefficient norm (
$| \beta_t |$ ) across all time instants and select points with the strongest data dependence for key extraction. -
Noise Covariance Estimation (Optional): For the maximum-likelihood approach, compute the covariance matrix ( C ) from the residuals:
$r_{i,t} = I_t(x_i,k_b) - \hat{h}_t(x_i,k_b)$ .
In this phase, (
For each candidate key ( k' ):
The correct key minimizes the mean squared error:
If the noise is Gaussian with covariance matrix ( C ):
The maximum likelihood principle provides better robustness in noisy environments, while the minimum principle offers faster computation.