diff options
| author | J08nY | 2023-02-12 23:32:18 +0100 |
|---|---|---|
| committer | J08nY | 2023-02-12 23:32:18 +0100 |
| commit | 88edf0ca2efa0062e2c766f83c0b297987875c9e (patch) | |
| tree | f50360f9734266500d777e0b7491a16919b73cdd | |
| parent | f11268d7cb7f8749312c3d85f37451ebf84649ae (diff) | |
| download | pyecsca-88edf0ca2efa0062e2c766f83c0b297987875c9e.tar.gz pyecsca-88edf0ca2efa0062e2c766f83c0b297987875c9e.tar.zst pyecsca-88edf0ca2efa0062e2c766f83c0b297987875c9e.zip | |
Cache unparsed assumptions in formula.
| -rw-r--r-- | pyecsca/ec/formula.py | 9 | ||||
| -rwxr-xr-x | test/ec/perf_formula.py | 6 |
2 files changed, 10 insertions, 5 deletions
diff --git a/pyecsca/ec/formula.py b/pyecsca/ec/formula.py index 7acdd5a..5f2c172 100644 --- a/pyecsca/ec/formula.py +++ b/pyecsca/ec/formula.py @@ -1,6 +1,8 @@ """Provides an abstract base class of a formula along with concrete instantiations.""" from abc import ABC, abstractmethod from ast import parse, Expression +from functools import cached_property + from astunparse import unparse from itertools import product from typing import List, Set, Any, ClassVar, MutableMapping, Tuple, Union, Dict @@ -114,6 +116,10 @@ class Formula(ABC): unified: bool """Whether the formula is specifies that it is unified.""" + @cached_property + def assumptions_str(self): + return [unparse(assumption)[1:-2] for assumption in self.assumptions] + def __validate_params(self, field, params): for key, value in params.items(): if not isinstance(value, Mod) or value.n != field: @@ -138,8 +144,7 @@ class Formula(ABC): # Validate assumptions and compute formula parameters. # TODO: Should this also validate coordinate assumptions and compute their parameters? is_symbolic = any(isinstance(x, SymbolicMod) for x in params.values()) - for assumption in self.assumptions: - assumption_string = unparse(assumption)[1:-2] + for assumption, assumption_string in zip(self.assumptions, self.assumptions_str): lhs, rhs = assumption_string.split(" == ") if lhs in params: # Handle an assumption check on value of input points. diff --git a/test/ec/perf_formula.py b/test/ec/perf_formula.py index b49daab..baa6347 100755 --- a/test/ec/perf_formula.py +++ b/test/ec/perf_formula.py @@ -31,7 +31,7 @@ def main(profiler, mod, operations, directory): add = coords.formulas["add-2016-rcb"] dbl = coords.formulas["dbl-2016-rcb"] click.echo( - f"Profiling {operations} {p256.curve.prime.bit_length()}-bit doubling formula executions..." + f"Profiling {operations} {p256.curve.prime.bit_length()}-bit doubling formula (dbl2016rcb) executions..." ) one_point = p256.generator with Profiler( @@ -40,7 +40,7 @@ def main(profiler, mod, operations, directory): for _ in range(operations): one_point = dbl(p256.curve.prime, one_point, **p256.curve.parameters)[0] click.echo( - f"Profiling {operations} {p256.curve.prime.bit_length()}-bit addition formula executions..." + f"Profiling {operations} {p256.curve.prime.bit_length()}-bit addition formula (add2016rcb) executions..." ) other_point = p256.generator with Profiler( @@ -54,7 +54,7 @@ def main(profiler, mod, operations, directory): ecoords = ed25519.curve.coordinate_model dblg = ecoords.formulas["mdbl-2008-hwcd"] click.echo( - f"Profiling {operations} {ed25519.curve.prime.bit_length()}-bit doubling formula executions (with assumption)..." + f"Profiling {operations} {ed25519.curve.prime.bit_length()}-bit doubling formula (mdbl2008hwcd) executions (with assumption)..." ) eone_point = ed25519.generator with Profiler( |
