Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[analysis] Fix num_traces in TVLA plot #334

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

nasahlpa
Copy link
Member

@nasahlpa nasahlpa commented Mar 6, 2024

Previously, when number_of_steps > 1, the TVLA plot only contained the number of traces used for a step, but not the total number of traces processed. This PR fixes the issue, now the total number of used traces is printed in the figure.

Previously, when number_of_steps > 1, the TVLA plot only contained
the number of traces used for a step, but not the total number of
traces processed. This PR fixes the issue, now the total number of
used traces is printed in the figure.

Signed-off-by: Pascal Nasahl <[email protected]>
@nasahlpa nasahlpa requested review from vogelpi and vrozic as code owners March 6, 2024 09:02
@@ -457,6 +457,9 @@ def run_tvla(ctx: typer.Context):
else:
sample_step_hist = 5

# Number of traces after filtering over all steps.
num_traces_used_total = 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that this value should always be zero.
The condition of this if branch is:

if (cfg["input_histogram_file"] is None or cfg["output_histogram_file"] is not None) \
            and cfg["ttest_step_file"] is None:

so it is possible that cfg["input_histogram_file"] is not None (e.g. when we specify both input and output histogram files),
so the initial value for num_traces_used_total should be the number of traces used in the input histogram file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, thanks! However, do we actually read the number of traces of the histogram when cfg["input_histogram_file"] is provided? Should this be done here:

if cfg["input_histogram_file"] is not None:

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're both somewhat right here. The histograms are defined as follows:

                # For every time sample we make two histograms, one for Hamming weight of the
                # sensitive variable = 0 (fixed set) and one for Hamming weight > 0 (random set).
                # histograms has dimensions [num_rnds, num_bytes, 2, num_samples, trace_resolution]
                # The value stored in histograms[v][w][x][y][z] shows how many traces have value z
                # at sample y, given that HW(state byte w in AES round v) = 0 (fixed set, x = 0) or
                # > 0 (random set, x = 1).

When an input histograms file is used, the number of traces used can be computed as sum(histograms[:][:][:][:][0][:]).

Since we already didn't set num_traces_used_total correctly when loading histograms before this PR. I suggest to create a new issue for tracking and merge this on as is.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this can be merged as is.
I've added an item to issue #72 to track this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks to both of you!

Copy link
Collaborator

@vogelpi vogelpi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I suggest to create an issue for tracking the handling of the histogram loading feature.

@nasahlpa nasahlpa merged commit a8cdcdb into lowRISC:master Apr 5, 2024
9 checks passed
@nasahlpa nasahlpa deleted the fix_num_traces branch April 5, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants