pyecsca.sca.stacked_traces.combine module

class BaseTraceManager(traces)[source]

Bases: ABC

Base class for trace managers

abstract average()[source]

Average traces, sample-wise.

Return type:

CombinedTrace

Returns:

The average of the traces.

abstract conditional_average(cond)[source]

Average traces for which the cond is True, sample-wise.

Parameters:

cond (Callable[[ndarray[Any, dtype[number]]], bool]) – The condition for selecting the traces.

Return type:

CombinedTrace

Returns:

The average of (some of) the traces.

abstract standard_deviation()[source]

Compute the sample standard-deviation of the traces, sample-wise.

Return type:

CombinedTrace

Returns:

The standard deviation of the traces.

abstract variance()[source]

Compute the sample variance of the traces, sample-wise.

Return type:

CombinedTrace

Returns:

The variance of the traces.

abstract average_and_variance()[source]

Compute the sample average and variance of the traces, sample-wise.

Return type:

List[CombinedTrace]

Returns:

The average and variance of the traces.

abstract add()[source]

Add traces, sample-wise.

Return type:

CombinedTrace

Returns:

The sum of the traces.

abstract pearson_corr(intermediate_values)[source]

Calculates the Pearson correlation coefficient between the given samples and intermediate values sample-wise.

Parameters:

intermediate_values (npt.NDArray[np.number]) – A 1D array of shape (n,) containing the intermediate values.

Return type:

CombinedTrace

Returns:

The Pearson correlation coefficient between the samples and intermediate values.

class GPUTraceManager(traces, tpb=128, chunk=False, chunk_size=None, chunk_memory_ratio=None, stream_count=None)[source]

Bases: BaseTraceManager

Manager for operations with stacked traces on GPU

Parameters:
  • traces (StackedTraces) – Stacked traces on which to operate.

  • tpb (Union[int, Tuple[int, ...]]) – Threads per block to use for GPU operations.

  • chunk (bool) – Whether to chunk the traces.

  • chunk_size (Optional[int]) – Number of samples to use for chunking. Chunks will be chunk_size x trace_count.

  • chunk_memory_ratio (Optional[float]) – Part of available memory to use for chunking.

  • stream_count (Optional[int]) – Number of streams to use for chunking.

static chunk_size_from_ratio(chunk_memory_ratio, element_size=None, item_size=None, chunk_item_count=None)[source]
Return type:

int

property traces_shape: Tuple[int, ...][source]
average()[source]

Average traces, sample-wise.

Return type:

CombinedTrace

Returns:

The average of the traces.

conditional_average(cond)[source]

Average traces for which the cond is True, sample-wise.

Parameters:

cond (Callable[[ndarray[Any, dtype[number]]], bool]) – The condition for selecting the traces.

Return type:

CombinedTrace

Returns:

The average of (some of) the traces.

standard_deviation()[source]

Compute the sample standard-deviation of the traces, sample-wise.

Return type:

CombinedTrace

Returns:

The standard deviation of the traces.

variance()[source]

Compute the sample variance of the traces, sample-wise.

Return type:

CombinedTrace

Returns:

The variance of the traces.

average_and_variance()[source]

Compute the sample average and variance of the traces, sample-wise.

Return type:

List[CombinedTrace]

Returns:

The average and variance of the traces.

add()[source]

Add traces, sample-wise.

Return type:

CombinedTrace

Returns:

The sum of the traces.

pearson_corr(intermediate_values)[source]

Calculates the Pearson correlation coefficient between the given samples and intermediate values sample-wise.

Parameters:

intermediate_values (npt.NDArray[np.number]) – A 1D array of shape (n,) containing the intermediate values.

Return type:

CombinedTrace

Returns:

The Pearson correlation coefficient between the samples and intermediate values.

run(func, inputs=None, output_count=1)[source]
Return type:

Union[CombinedTrace, List[CombinedTrace]]

class CPUTraceManager(traces)[source]

Bases: BaseTraceManager

Manager for operations on stacked traces on CPU.

average()[source]

Average traces, sample-wise.

Return type:

CombinedTrace

Returns:

The average of the traces.

conditional_average(condition)[source]

Average traces for which the cond is True, sample-wise.

Parameters:

cond – The condition for selecting the traces.

Return type:

CombinedTrace

Returns:

The average of (some of) the traces.

standard_deviation()[source]

Compute the sample standard-deviation of the traces, sample-wise.

Return type:

CombinedTrace

Returns:

The standard deviation of the traces.

variance()[source]

Compute the sample variance of the traces, sample-wise.

Return type:

CombinedTrace

Returns:

The variance of the traces.

average_and_variance()[source]

Compute the sample average and variance of the traces, sample-wise.

Return type:

List[CombinedTrace]

Returns:

The average and variance of the traces.

add()[source]

Add traces, sample-wise.

Return type:

CombinedTrace

Returns:

The sum of the traces.

pearson_corr(intermediate_values)[source]

Calculates the Pearson correlation coefficient between the given samples and intermediate values sample-wise.

The result is equivalent to:

np.corrcoef(self.traces.samples,

intermediate_values, rowvar=False)[-1, :-1]

but a different implementation is used for better time-efficiency, which doesn’t compute the whole correlation matrix.

Parameters:

intermediate_values (npt.NDArray[np.number]) – A 1D array of shape (n,) containing the intermediate values.

Return type:

CombinedTrace