diff options
| author | J08nY | 2025-10-02 21:39:58 +0200 |
|---|---|---|
| committer | J08nY | 2025-10-02 21:39:58 +0200 |
| commit | e09d15a667a5cc0285319c17ce6de806b9681d06 (patch) | |
| tree | b954ad1ff125769a7fb0c829f3bc370336d27a71 | |
| parent | d22476cf8135282214e596ed47e2746c7f403735 (diff) | |
| download | pyecsca-codegen-e09d15a667a5cc0285319c17ce6de806b9681d06.tar.gz pyecsca-codegen-e09d15a667a5cc0285319c17ce6de806b9681d06.tar.zst pyecsca-codegen-e09d15a667a5cc0285319c17ce6de806b9681d06.zip | |
Render (some) assumptions.
Does some progress towards #5.
| -rw-r--r-- | pyecsca/codegen/render.py | 15 | ||||
| -rw-r--r-- | test/test_regress.py | 1 |
2 files changed, 14 insertions, 2 deletions
diff --git a/pyecsca/codegen/render.py b/pyecsca/codegen/render.py index 9bc01b1..aa5d4d2 100644 --- a/pyecsca/codegen/render.py +++ b/pyecsca/codegen/render.py @@ -43,6 +43,7 @@ from pyecsca.ec.mult import ( from pyecsca.ec.op import OpType, CodeOp from pyecsca.codegen.common import Platform, DeviceConfiguration +from pyecsca.misc.utils import pexec env = Environment(loader=PackageLoader("pyecsca.codegen")) @@ -300,8 +301,20 @@ def render_formula_impl(formula: Formula, short_circuit: bool = False) -> str: var = output[0] num = int(output[1:]) - formula.output_index renames[output] = "{}->{}".format(outputs[num], var) + ops = [] + for assumption_str in formula.assumptions_str: + lhs, rhs = assumption_str.split(" == ") + if lhs in formula.parameters: + try: + code = CodeOp(pexec(assumption_str.replace("==", "=").replace("^", "**"))) + ops.append(code) + except Exception as e: + raise ValueError("Could not parse assumption: {}".format(assumption_str)) from e + else: + raise ValueError("WIP: assumption not supported: {}".format(assumption_str)) + ops.extend(formula.code) namespace = transform_ops( - formula.code, + ops, formula.coordinate_model.curve_model.parameter_names, formula.outputs, renames, diff --git a/test/test_regress.py b/test/test_regress.py index d85d6f6..24eedb5 100644 --- a/test/test_regress.py +++ b/test/test_regress.py @@ -13,7 +13,6 @@ from pyecsca.codegen.common import Platform, DeviceConfiguration from pyecsca.codegen.render import render_and_build -@pytest.mark.xfail(reason="Issue not resolved yet.") def test_regress_5(secp128r1, tmp_path): platform = Platform.HOST hash_type = HashType.SHA1 |
