aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sca
diff options
context:
space:
mode:
authorJ08nY2023-11-07 17:16:03 +0100
committerJ08nY2023-11-10 12:21:27 +0100
commita523a8874c8d13c0e6f64dbe4b3cea1bf0771688 (patch)
tree2c10515c97b714a55b86a1e2da7ca6e8018f2b2b /test/sca
parent2e64f22c3c388b4765893c729713fcaf0937f14a (diff)
downloadpyecsca-a523a8874c8d13c0e6f64dbe4b3cea1bf0771688.tar.gz
pyecsca-a523a8874c8d13c0e6f64dbe4b3cea1bf0771688.tar.zst
pyecsca-a523a8874c8d13c0e6f64dbe4b3cea1bf0771688.zip
Add formula similarity metric.
Diffstat (limited to 'test/sca')
-rw-r--r--test/sca/test_structural.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/sca/test_structural.py b/test/sca/test_structural.py
new file mode 100644
index 0000000..db75b12
--- /dev/null
+++ b/test/sca/test_structural.py
@@ -0,0 +1,36 @@
+from importlib_resources import files, as_file
+import test.data.formulas
+from pyecsca.ec.formula import AdditionEFDFormula
+from pyecsca.ec.model import ShortWeierstrassModel
+from pyecsca.ec.params import get_params
+from pyecsca.sca.re.structural import formula_similarity, formula_similarity_fuzz
+
+
+def test_formula_match():
+ model = ShortWeierstrassModel()
+ coords = model.coordinates["jacobian"]
+ secp128r1 = get_params("secg", "secp128r1", "jacobian")
+ with as_file(
+ files(test.data.formulas).joinpath("add-bc-r1rv76")
+ ) as meta_path, as_file(
+ files(test.data.formulas).joinpath("add-bc-r1rv76.op3")
+ ) as op3_path:
+ bc_formula = AdditionEFDFormula(meta_path, op3_path, "add-bc-r1rv76", coords)
+ print()
+ for other_name, other_formula in coords.formulas.items():
+ if not other_name.startswith("add"):
+ continue
+ print(other_name, "fuzz", formula_similarity_fuzz(other_formula, bc_formula, secp128r1.curve, 1000), "symbolic", formula_similarity(other_formula, bc_formula))
+
+
+def test_efd_formula_match():
+ model = ShortWeierstrassModel()
+ coords = model.coordinates["modified"]
+ print()
+ for other_name, other_formula in coords.formulas.items():
+ if not other_name.startswith("add"):
+ continue
+ for one_name, one_formula in coords.formulas.items():
+ if not one_name.startswith("add"):
+ continue
+ print(one_name, other_name, formula_similarity(one_formula, other_formula))