diff options
| -rw-r--r-- | pyecsca/sca/re/__init__.py | 2 | ||||
| -rw-r--r-- | pyecsca/sca/re/structural.py | 3 | ||||
| -rw-r--r-- | test/sca/test_structural.py | 69 |
3 files changed, 5 insertions, 69 deletions
diff --git a/pyecsca/sca/re/__init__.py b/pyecsca/sca/re/__init__.py index 4ad35ed..1b734d3 100644 --- a/pyecsca/sca/re/__init__.py +++ b/pyecsca/sca/re/__init__.py @@ -1,3 +1,5 @@ """Package for reverse-engineering.""" from .rpa import * +from .zvp import * +from .structural import * diff --git a/pyecsca/sca/re/structural.py b/pyecsca/sca/re/structural.py index 3581b0d..7b2e3ca 100644 --- a/pyecsca/sca/re/structural.py +++ b/pyecsca/sca/re/structural.py @@ -1,5 +1,6 @@ """""" from typing import Dict +from public import public from ...ec.curve import EllipticCurve from ...ec.formula import Formula @@ -8,6 +9,7 @@ from .zvp import unroll_formula from operator import itemgetter, attrgetter +@public def formula_similarity(one: Formula, other: Formula) -> Dict[str, float]: if one.coordinate_model != other.coordinate_model: raise ValueError("Mismatched coordinate model.") @@ -34,6 +36,7 @@ def formula_similarity(one: Formula, other: Formula) -> Dict[str, float]: } +@public def formula_similarity_fuzz( one: Formula, other: Formula, curve: EllipticCurve, samples: int = 1000 ) -> Dict[str, float]: diff --git a/test/sca/test_structural.py b/test/sca/test_structural.py index 7f53de6..be1f45f 100644 --- a/test/sca/test_structural.py +++ b/test/sca/test_structural.py @@ -15,75 +15,6 @@ from pyecsca.sca.re.structural import formula_similarity, formula_similarity_fuz import itertools -def test_formula_match(): - model = ShortWeierstrassModel() - coords = model.coordinates["jacobian"] - secp128r1 = get_params("secg", "secp224r1", "jacobian-3") - with as_file( - files(test.data.formulas).joinpath("dbl-boringssl-p224") - ) as meta_path, as_file( - files(test.data.formulas).joinpath("dbl-boringssl-p224.op3") - ) as op3_path: - bc_formula = DoublingEFDFormula( - meta_path, op3_path, "dbl-boringssl-p224", coords - ) - print() - for other_name, other_formula in coords.formulas.items(): - if not other_name.startswith("dbl"): - continue - print( - other_name, - "fuzz", - formula_similarity_fuzz(other_formula, bc_formula, secp128r1.curve, 1000), - "symbolic", - formula_similarity(other_formula, bc_formula), - ) - - -def test_formula_match1(): - model = MontgomeryModel() - coords = model.coordinates["xz"] - curve25519 = get_params("other", "Curve25519", "xz") - with as_file( - files(test.data.formulas).joinpath("dbl-bc-r1rv76-x25519") - ) as meta_path, as_file( - files(test.data.formulas).joinpath("dbl-bc-r1rv76-x25519.op3") - ) as op3_path: - bc_formula = DoublingEFDFormula( - meta_path, op3_path, "dbl-bc-r1rv76-x25519", coords - ) - print() - for other_name, other_formula in coords.formulas.items(): - if not other_name.startswith("dbl"): - continue - print( - other_name, - "fuzz", - formula_similarity_fuzz(other_formula, bc_formula, curve25519.curve, 1000), - "symbolic", - formula_similarity(other_formula, bc_formula), - ) - - -def test_efd_formula_match(): - model = ShortWeierstrassModel() - coords = model.coordinates["projective"] - secp128r1 = get_params("secg", "secp128r1", "projective") - print() - adds = list(filter(lambda tup: tup[0].startswith("add"), coords.formulas.items())) - for one, other in itertools.combinations_with_replacement(adds, 2): - one_name, one_formula = one - other_name, other_formula = other - print( - one_name, - other_name, - "fuzz", - formula_similarity_fuzz(one_formula, other_formula, secp128r1.curve, 1000), - "symbolic", - formula_similarity(one_formula, other_formula), - ) - - @pytest.mark.parametrize( "name,model,coords,param_spec,formula_type", [ |
