diff options
Diffstat (limited to 'test')
| -rwxr-xr-x | test/ec/bench_divpoly.py (renamed from test/ec/perf_divpoly.py) | 4 | ||||
| -rw-r--r-- | test/sca/perf_zvp.py | 46 | ||||
| -rw-r--r-- | test/sca/test_zvp.py | 28 |
3 files changed, 65 insertions, 13 deletions
diff --git a/test/ec/perf_divpoly.py b/test/ec/bench_divpoly.py index 2937af1..0df7d59 100755 --- a/test/ec/perf_divpoly.py +++ b/test/ec/bench_divpoly.py @@ -1,4 +1,6 @@ #!/usr/bin/env python +import sys + import click from pyecsca.ec.divpoly import mult_by_n @@ -11,6 +13,8 @@ from datetime import datetime def main(n): p256 = get_params("secg", "secp256r1", "projective") + print("Benchmarking divpoly computation on P-256...", file=sys.stderr) + ns = [] durs = [] mems = [] diff --git a/test/sca/perf_zvp.py b/test/sca/perf_zvp.py new file mode 100644 index 0000000..fd0e7d1 --- /dev/null +++ b/test/sca/perf_zvp.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python +import click + +from datetime import datetime +from pyecsca.ec.mod import has_gmp +from pyecsca.misc.cfg import TemporaryConfig +from pyecsca.sca.re.zvp import zvp_point, unroll_formula +from pyecsca.ec.params import get_params +from test.utils import Profiler + + +@click.command() +@click.option("-p", "--profiler", type=click.Choice(("py", "c")), default="py") +@click.option( + "-m", + "--mod", + type=click.Choice(("python", "gmp")), + default="gmp" if has_gmp else "python", +) +@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") + formula = p128.curve.coordinate_model.formulas["add-2016-rcb"] + unrolled = unroll_formula(formula, p128.curve.prime) + poly = unrolled[7] + k = 5 + + click.echo( + f"Profiling {operations} {p128.curve.prime.bit_length()}-bit (k = {k}) ZVP computations..." + ) + with Profiler(profiler, directory, f"zvp_p128_{operations}_{mod}"): + for _ in range(operations): + zvp_point(poly, p128.curve, k) + + +if __name__ == "__main__": + main() diff --git a/test/sca/test_zvp.py b/test/sca/test_zvp.py index bcca4e1..28ed5d9 100644 --- a/test/sca/test_zvp.py +++ b/test/sca/test_zvp.py @@ -3,7 +3,6 @@ import pytest from pyecsca.sca.re.zvp import unroll_formula, subs_curve_equation, remove_z, eliminate_y, subs_dlog, subs_curve_params, \ zvp_point from pyecsca.ec.context import local, DefaultContext -from pyecsca.ec.formula import FormulaAction from sympy import symbols, Poly @@ -68,18 +67,21 @@ def test_full(secp128r1, formula): assert final.gens == (X1,) +@pytest.mark.slow def test_zvp(secp128r1, formula): unrolled = unroll_formula(formula, secp128r1.curve.prime) - poly = unrolled[-2] - points = zvp_point(poly, secp128r1.curve, 5) - assert isinstance(points, set) + # Try all intermediates, zvp_point should return empty set if ZVP points do not exist + for poly in unrolled: + points = zvp_point(poly, secp128r1.curve, 5) + assert isinstance(points, set) - for point in points: - second_point = secp128r1.curve.affine_multiply(point, 5) - p = point.to_model(formula.coordinate_model, secp128r1.curve) - q = second_point.to_model(formula.coordinate_model, secp128r1.curve) - with local(DefaultContext()) as ctx: - formula(secp128r1.curve.prime, p, q, **secp128r1.curve.parameters) - action = next(iter(ctx.actions.keys())) - results = list(map(lambda o: int(o.value), action.op_results)) - assert 0 in results + # If points are produced, try them all. + for point in points: + second_point = secp128r1.curve.affine_multiply(point, 5) + p = point.to_model(formula.coordinate_model, secp128r1.curve) + q = second_point.to_model(formula.coordinate_model, secp128r1.curve) + with local(DefaultContext()) as ctx: + formula(secp128r1.curve.prime, p, q, **secp128r1.curve.parameters) + action = next(iter(ctx.actions.keys())) + results = list(map(lambda o: int(o.value), action.op_results)) + assert 0 in results |
