diff options
| author | J08nY | 2024-01-31 16:40:28 +0100 |
|---|---|---|
| committer | J08nY | 2024-01-31 16:41:58 +0100 |
| commit | 2c9550e595dd410b69bab9fa686f669d6b52e9cb (patch) | |
| tree | 90f74e5733045fa179325f1b0674f82e54bce8c8 | |
| parent | 558ad61a9aba765b2065fbec12e44313c6df206a (diff) | |
| download | pyecsca-2c9550e595dd410b69bab9fa686f669d6b52e9cb.tar.gz pyecsca-2c9550e595dd410b69bab9fa686f669d6b52e9cb.tar.zst pyecsca-2c9550e595dd410b69bab9fa686f669d6b52e9cb.zip | |
Add comparison for formulas.
| -rw-r--r-- | pyecsca/ec/formula/base.py | 9 | ||||
| -rw-r--r-- | test/ec/test_formula.py | 7 |
2 files changed, 14 insertions, 2 deletions
diff --git a/pyecsca/ec/formula/base.py b/pyecsca/ec/formula/base.py index 5cfb425..4b8d27d 100644 --- a/pyecsca/ec/formula/base.py +++ b/pyecsca/ec/formula/base.py @@ -276,6 +276,15 @@ class Formula(ABC): result.append(point) return action.exit(tuple(result)) + def __lt__(self, other): + if not isinstance(other, Formula): + raise TypeError("Cannot compare.") + if self.name is None: + return True + if other.name is None: + return False + return self.name < other.name + def __str__(self): return f"{self.shortname}[{self.name}]" diff --git a/test/ec/test_formula.py b/test/ec/test_formula.py index a2af47e..42835a9 100644 --- a/test/ec/test_formula.py +++ b/test/ec/test_formula.py @@ -31,7 +31,6 @@ from pyecsca.ec.formula.efd import ( AdditionEFDFormula, DoublingEFDFormula, LadderEFDFormula, - EFDFormula, ) from pyecsca.ec.formula import ( AdditionFormula, @@ -149,6 +148,10 @@ def test_pickle(add, dbl): assert add == pickle.loads(pickle.dumps(add)) +def test_compare(add, dbl): + assert add < dbl + + def test_formula_similarity(secp128r1): add_bl = secp128r1.curve.coordinate_model.formulas["add-2007-bl"] add_rcb = secp128r1.curve.coordinate_model.formulas["add-2015-rcb"] @@ -522,5 +525,5 @@ def test_formula_correctness(library_formula_params): def test_formula_expand(add): - res = expand_formula_set([add]) + res = expand_formula_set({add}) assert len(res) > 1 |
