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

[tvla] Add histogram based TVLA #71

Merged
merged 34 commits into from
May 24, 2022
Merged

[tvla] Add histogram based TVLA #71

merged 34 commits into from
May 24, 2022

Conversation

vogelpi
Copy link
Collaborator

@vogelpi vogelpi commented May 23, 2022

This PR moves the current state of our TVLA code to the public repository.

vrozic and others added 30 commits May 13, 2022 16:30
Signed-off-by: Vladimir Rozic <[email protected]>
This commit contains several changes:
1. Fix leakage model computation. Previously, only the initial round and
   the first 9 regular rounds were computed. The final round couldn't be
   analyzed.
2. Now, all bytes and all rounds are computed. Basically when computing
   a single byte, the other bytes come for free. Similarly, if round 10
   is needed, all other rounds need to be computed anyway.
3. The computed leakage model is saved to disk as traces.npy and using
   a new command line argument can be loaded in a later run to re-use
   previous intermediate results and speed up the analysis.

Signed-off-by: Pirmin Vogel <[email protected]>
This gives a performance improvement of nearly 100x compared to the
previous implementation based on nested for loops.

Signed-off-by: Pirmin Vogel <[email protected]>
This commit modifies the histograms & t-test computation as well as
the plotting to run for all rounds and all bytes by default. Using new
command line arguments, the user can specify a single round and/or a
single byte if needed. Plots for all computed t-test results are saved
and the script now prints results in text format, highlighting in which
rounds and bytes, leakage above the threshold has been detected.

Signed-off-by: Pirmin Vogel <[email protected]>
This commit parallelizes the histograms computation across samples.

Signed-off-by: Pirmin Vogel <[email protected]>
In case either the fixed or random set is empty, the statistics can't
be computed. This can happen e.g. if few traces are used only, or if
using the hamming distance as sensitive variable and analyzing the
initial round. In the latter case, the hamming distance can only be
zero or non-zero if the corresponding key byte is zero or non-zero,
respectively. Thus, either the fixed or the random set is empty.

Previously we anyway computed the statistics producing meaningless
results. With this commit, we don't try to compute the statistics
anymore if either of the sets is empty and report this to the user.

Signed-off-by: Pirmin Vogel <[email protected]>
This commit switches to a t-test function provided by scipy which
operates on arrays. Also, the code around the t-test function is
refactored to make better use of numpy.ndarrays, to reduce the amount
of control code and to reduce the number of loops. All this allows for
a speedup of 20x for the t-test computation.

Signed-off-by: Pirmin Vogel <[email protected]>
Added support for general fixed-vs-random TVLA.

Signed-off-by: vrozic <[email protected]>
The most important change of this commit is that it adds the option for
step-wise processing of trace sets using the `-n` argument and related
to that the capability to plot how the t-test values evolve with
increasing number of traces. Other usability improvements include:
- Filtered traces and the computed leakage are only saved to disk if
  the `-d` argument is provided.
- Figures are only plotted and saved to disk if the `-f` argument is
  provided.
- The t-test results can be written to disk using the `-d` argument.
  They can be loaded with the `-a` argument to only display results and
  plot figures if really needed. The results table is always printed.

Signed-off-by: Pirmin Vogel <[email protected]>
This allows both specific AES TVLA (as we were doing before) and fixed-
vs-random TVLA for AES and SHA3 using a single code base.

Signed-off-by: Pirmin Vogel <[email protected]>
Fixes a way that a random set is constructed when running tvla
general tests.

Signed-off-by: vrozic <[email protected]>
Signed-off-by: Pirmin Vogel <[email protected]>
Add support for fixed-vs-random key TVLA when measurements are
taken in random order (rather than alternating between fixed and
random). The analysis works under the assumption is that the first
trace in the project is generated using a fixed key.

Signed-off-by: vrozic <[email protected]>
The inrease in sampling rate by 2x and the trigger offset needs to be
accounted for when plotting these figures.

Signed-off-by: Pirmin Vogel <[email protected]>
vogelpi added 4 commits May 18, 2022 00:17
This is not actually needed but may have a slightly negative impact when
doing more than one step as the offset may vary with each step.

Signed-off-by: Pirmin Vogel <[email protected]>
Without this commit, it could happen that the wrong bytes/rounds would
be selected for the final results/figure plotting step in case only a
subset of bytes/rounds were analyzed.

Signed-off-by: Pirmin Vogel <[email protected]>
Previously, we were generating 9 histograms one for each possible
Hamming weight of the sensitive variable. But the actual statistics
are then computed by combining the 8 histograms for the non-zero Hamming
weights (fixed vs. random). It this therefore more efficient to only
generate 2 histograms in the first place. One for Hamming weight = 0 and
one for Hamming weight > 0. Most importantly, this leads to a reduction
in memory footprint of roughly 4.5x.

Signed-off-by: Pirmin Vogel <[email protected]>
@vogelpi vogelpi requested review from alphan and moidx as code owners May 23, 2022 08:43
@vogelpi vogelpi requested review from abdullahvarici and vrozic May 23, 2022 08:43
return leakage


def parse_args():
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this would probably be shorter/simpler with typer.

Comment on lines +445 to +454
Path("tmp").mkdir(exist_ok=True)
log_format = "%(asctime)s %(levelname)s: %(message)s"
log.basicConfig(format=log_format,
datefmt="%Y-%m-%d %I:%M:%S",
handlers=[
log.FileHandler("tmp/log.txt"),
log.StreamHandler()
],
level=log.INFO,
force=True,)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this could be a command line argument.

return parser.parse_args()


def main():
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this function could benefit from some refactoring (e.g., moving chunks of code to helper functions).

@alphan
Copy link
Contributor

alphan commented May 23, 2022

Thanks @vogelpi! My comments should not block this PR, things to keep in mind going further.

@vogelpi
Copy link
Collaborator Author

vogelpi commented May 24, 2022

Thanks for the feedback everybody. I've filed issue #72 to track requested changes for the TVLA code.

@vogelpi vogelpi merged commit 57f2d28 into lowRISC:master May 24, 2022
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.

4 participants