aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--pyecsca/ec/formula/fake.py6
-rw-r--r--test/sca/perf_rpa.py51
-rw-r--r--test/sca/test_rpa.py5
4 files changed, 60 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 0f40881..cd238f2 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-PERF_SCRIPTS = test.ec.perf_mod test.ec.perf_formula test.ec.perf_mult test.sca.perf_combine test.sca.perf_zvp
+PERF_SCRIPTS = test.ec.perf_mod test.ec.perf_formula test.ec.perf_mult test.sca.perf_combine test.sca.perf_zvp test.sca.perf_rpa
all: help
diff --git a/pyecsca/ec/formula/fake.py b/pyecsca/ec/formula/fake.py
index 0a3451b..a07c5ed 100644
--- a/pyecsca/ec/formula/fake.py
+++ b/pyecsca/ec/formula/fake.py
@@ -92,3 +92,9 @@ class FakePoint(Point):
def __repr__(self):
return str(self)
+
+ def __eq__(self, other):
+ return self is other
+
+ def __hash__(self):
+ return id(self)
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):