Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions WPI_SCA_LIBRARY/Metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,31 @@ def unmasked_sbox_output_intermediate(keys: np.ndarray, plaintexts: np.ndarray)
def t_test_tvla(fixed_t: any, random_t: any, exp:any ,partition:bool=False, index:int=None, start_index:int=None, end_index:int=None,visualize: bool = False,
visualization_paths: tuple = None) -> (np.ndarray, np.ndarray):
"""
Computes the t-statistic and t-max between fixed and random trace sets. T-statistic magnitudes above or below
|th| = 4.5 indicate cryptographic vulnerabilities.
Performs a t-test to assess the statistical difference between fixed and random trace sets.
T-statistic values exceeding ±4.5 may indicate cryptographic vulnerabilities.

:param random_t: The random trace set
:type random_t: np.ndarray
:param fixed_t: The fixed trace set
:param fixed_t: The set of fixed traces.
:type fixed_t: np.ndarray
:param visualize: Whether to visualize the result
:param random_t: The set of random traces.
:type random_t: np.ndarray
:param exp: Experimental data or configuration settings.
:type exp: any
:param partition: Whether to partition the data (default: False).
:type partition: bool
:param index: Specific index for analysis, if applicable.
:type index: int, optional
:param start_index: The starting index for analysis, if applicable.
:type start_index: int, optional
:param end_index: The ending index for analysis, if applicable.
:type end_index: int, optional
:param visualize: Whether to generate visualizations of the results.
:type visualize: bool
:param visualization_paths: The paths to be used to save the t-statistic (first idx) and t-max visualizations (second idx)
:type visualization_paths: tuple
:return: The t-statistic at each time sample and t-max at each trace as a tuple of numpy arrays
:param visualization_paths: Paths to save the t-statistic (first index) and t-max (second index) visualizations.
:type visualization_paths: tuple, optional
:return: A tuple containing the t-statistic for each time sample and t-max for each trace.
:rtype: (np.ndarray, np.ndarray)
:raises ValueError: if fixed_t and random_t do not have the same length
:raises ValueError: If fixed_t and random_t do not have the same length.

:Authors: Dev Mehta (dmmehta2@wpi.edu), Samuel Karkache (swkarkache@wpi.edu)
"""
welsh_t_outer = []
Expand Down
14 changes: 8 additions & 6 deletions doc/dpa.rst
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
Differential Power Analysis (DPA)
================================

.. method:: calculate_dpa(traces, iv, order=1, key_guess=0, window_size_fma=5, num_of_traces=0):
.. method:: calculate_dpa(traces, iv, order=1, window_size_fma=5, num_of_traces=0, visualize: bool = False, visualization_path: any = None):

Unified differential power analysis method that has support for first and second order DPA.

:param traces: The power traces to be processed
:param traces: The set of power traces used for analysis.
:param iv: Intermediate algorithm values associated with the power traces
:param key_guess: The DPA key guess
:param window_size_fma: The window size of the moving average calculation
:param num_of_traces: The number of traces being processed
:returns: The result of the DPA calculation
:param order: The order of DPA analysis (default: 1).
:param window_size_fma: The window size used for filtering or moving average computations.
:param num_of_traces: The number of traces to include in the analysis
:param visualize: Whether to generate a visualization of the analysis results.
:param visualization_path: Path to save the visualization output, if applicable.
:return: The result of the DPA computation.

.. method:: calculate_second_order_dpa_mem_efficient(traces, IV, window_width):

Expand Down
40 changes: 26 additions & 14 deletions doc/metrics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,35 @@ Each metric is a standalone function and requires minimal setup to utilize.
:return: A list containing all intermediate values
:rtype: np.ndarray

.. py:function:: t_test_tvla(fixed_t: np.ndarray, random_t: np.ndarray, visualize: bool = False, visualization_paths: tuple = None) -> (np.ndarray, np.ndarray):

Computes the t-statistic and t-max between fixed and random trace sets. T-statistic magnitudes above or below
\|th\| = 4.5 indicate cryptographic vulnerabilities.

:param random_t: The random trace set
:type random_t: np.ndarray
:param fixed_t: The fixed trace set
:type fixed_t: np.ndarray
:param visualize: Whether to visualize the result
.. py:function:: t_test_tvla(fixed_t: any, random_t: any, exp:any ,partition:bool=False, index:int=None, start_index:int=None, end_index:int=None,visualize: bool = False,visualization_paths: tuple = None) -> (np.ndarray, np.ndarray):

Performs a t-test to assess the statistical difference between fixed and random trace sets.
T-statistic values exceeding ±4.5 may indicate cryptographic vulnerabilities.

:param fixed_t: The set of fixed traces.
:type fixed_t: np.ndarray
:param random_t: The set of random traces.
:type random_t: np.ndarray
:param exp: Experimental data or configuration settings.
:type exp: any
:param partition: Whether to partition the data (default: False).
:type partition: bool
:param index: Specific index for analysis, if applicable.
:type index: int, optional
:param start_index: The starting index for analysis, if applicable.
:type start_index: int, optional
:param end_index: The ending index for analysis, if applicable.
:type end_index: int, optional
:param visualize: Whether to generate visualizations of the results.
:type visualize: bool
:param visualization_paths: The paths to be used to save the t-statistic (first idx) and t-max visualizations (second idx)
:type visualization_paths: tuple
:return: The t-statistic at each time sample and t-max at each trace as a tuple of numpy arrays
:param visualization_paths: Paths to save the t-statistic (first index) and t-max (second index) visualizations.
:type visualization_paths: tuple, optional
:return: A tuple containing the t-statistic for each time sample and t-max for each trace.
:rtype: (np.ndarray, np.ndarray)
:raises ValueError: if fixed_t and random_t do not have the same length
:raises ValueError: If fixed_t and random_t do not have the same length.

:Authors: Dev Mehta (dmmehta2@wpi.edu), Samuel Karkache (swkarkache@wpi.edu)


.. py:function:: pearson_correlation(predicted_leakage: np.ndarray, observed_leakage: np.ndarray, visualize: bool = False, visualization_path: any = None) -> np.ndarray:

Expand Down