diff options
| author | J08nY | 2025-07-28 17:52:11 +0200 |
|---|---|---|
| committer | J08nY | 2025-07-28 17:52:11 +0200 |
| commit | 839cb94bb7ec2469b3287cfb9943ef03590724a9 (patch) | |
| tree | 708c4db2bf6c5aa36ee1de316ffe58633ff39d42 /pyecsca/ec | |
| parent | 7128a0c8eeab229a4c97057833c680314158baf3 (diff) | |
| download | pyecsca-839cb94bb7ec2469b3287cfb9943ef03590724a9.tar.gz pyecsca-839cb94bb7ec2469b3287cfb9943ef03590724a9.tar.zst pyecsca-839cb94bb7ec2469b3287cfb9943ef03590724a9.zip | |
Diffstat (limited to 'pyecsca/ec')
| -rw-r--r-- | pyecsca/ec/mult/fake.py | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/pyecsca/ec/mult/fake.py b/pyecsca/ec/mult/fake.py index e0c8610..f18d695 100644 --- a/pyecsca/ec/mult/fake.py +++ b/pyecsca/ec/mult/fake.py @@ -1,3 +1,4 @@ +from functools import lru_cache from typing import Type, Callable from copy import deepcopy @@ -9,8 +10,14 @@ from pyecsca.ec.formula import ( NegationFormula, ScalingFormula, ) -from pyecsca.ec.formula.fake import FakeAdditionFormula, FakeDifferentialAdditionFormula, \ - FakeDoublingFormula, FakeLadderFormula, FakeNegationFormula, FakeScalingFormula +from pyecsca.ec.formula.fake import ( + FakeAdditionFormula, + FakeDifferentialAdditionFormula, + FakeDoublingFormula, + FakeLadderFormula, + FakeNegationFormula, + FakeScalingFormula, +) from pyecsca.ec.mult import ScalarMultiplier from pyecsca.ec.params import DomainParameters @@ -60,3 +67,13 @@ def turn_fake(mult: ScalarMultiplier) -> ScalarMultiplier: formulas[key] = fake(formula.coordinate_model) copy.formulas = formulas return copy + + +@lru_cache(maxsize=256, typed=True) +def cached_fake_mult( + mult_class: Type[ScalarMultiplier], mult_factory: Callable, params: DomainParameters +) -> ScalarMultiplier: + fm = fake_mult(mult_class, mult_factory, params) + if getattr(fm, "short_circuit", False): + raise ValueError("The multiplier must not short-circuit.") + return fm |
