diff options
| author | J08nY | 2025-06-19 14:54:29 +0200 |
|---|---|---|
| committer | J08nY | 2025-06-19 14:54:29 +0200 |
| commit | 248a3aefa3616b11bcb4d9b613328d69b2d8e076 (patch) | |
| tree | 039ae0f8731110094a15d929a0cb5faf882360d9 /test/sca | |
| parent | fbbc81029f9e3010f6a5d2e88ba4c72f4638d61c (diff) | |
| download | pyecsca-248a3aefa3616b11bcb4d9b613328d69b2d8e076.tar.gz pyecsca-248a3aefa3616b11bcb4d9b613328d69b2d8e076.tar.zst pyecsca-248a3aefa3616b11bcb4d9b613328d69b2d8e076.zip | |
Diffstat (limited to 'test/sca')
| -rw-r--r-- | test/sca/perf_rpa.py | 51 | ||||
| -rw-r--r-- | test/sca/test_rpa.py | 5 |
2 files changed, 53 insertions, 3 deletions
diff --git a/test/sca/perf_rpa.py b/test/sca/perf_rpa.py new file mode 100644 index 0000000..17ffaa2 --- /dev/null +++ b/test/sca/perf_rpa.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python +import click + +from pyecsca.ec.mod.flint import has_flint +from pyecsca.ec.mod.gmp import has_gmp +from pyecsca.ec.params import get_params +from pyecsca.ec.mult import LTRMultiplier +from pyecsca.misc.cfg import TemporaryConfig +from pyecsca.sca.re.rpa import multiples_computed +from test.utils import Profiler + + +@click.command() +@click.option( + "-p", + "--profiler", + type=click.Choice(("py", "c", "raw")), + default="py", + envvar="PROF", +) +@click.option( + "-m", + "--mod", + type=click.Choice(("python", "gmp", "flint")), + default="flint" if has_flint else "gmp" if has_gmp else "python", + envvar="MOD", +) +@click.option("-o", "--operations", type=click.INT, default=1) +@click.option( + "-d", + "--directory", + type=click.Path(file_okay=False, dir_okay=True), + default=None, + envvar="DIR", +) +def main(profiler, mod, operations, directory): + with TemporaryConfig() as cfg: + cfg.ec.mod_implementation = mod + p128 = get_params("secg", "secp128r1", "projective") + + scalar = 123456789123456789123456789123456789 + click.echo( + f"Profiling {operations} {p128.curve.prime.bit_length()}-bit (k = {scalar}) multiples_computed computations..." + ) + with Profiler(profiler, directory, f"rpa_p128_ltr_{operations}_{mod}"): + for _ in range(operations): + multiples_computed(scalar, p128, LTRMultiplier, LTRMultiplier) + + +if __name__ == "__main__": + main() diff --git a/test/sca/test_rpa.py b/test/sca/test_rpa.py index 3bcf987..07757fd 100644 --- a/test/sca/test_rpa.py +++ b/test/sca/test_rpa.py @@ -79,9 +79,7 @@ def test_multiples(rpa_params): multiples = multiples_computed( 17, rpa_params, LTRMultiplier, LTRMultiplier, True, True ) - assert 1 in multiples - assert 17 in multiples - assert 0 not in multiples + assert multiples == {1, 2, 4, 8, 16, 17} def test_multiples_bnaf(rpa_params): @@ -91,6 +89,7 @@ def test_multiples_bnaf(rpa_params): kind="all" ) assert 23 in multiples + assert 199 in multiples def test_multiples_kind(rpa_params): |
