aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca/ec
diff options
context:
space:
mode:
authorJ08nY2020-02-04 20:02:22 +0100
committerJ08nY2020-02-04 20:02:22 +0100
commit2c4b3d2c50c6acff1e5db988183040c0f616054a (patch)
tree603246bea3f833d8b3dc9e72dfcd37fc49f79164 /pyecsca/ec
parent228dfa8c785b8b9ae47ac1712f5fef71cd1e5c90 (diff)
downloadpyecsca-2c4b3d2c50c6acff1e5db988183040c0f616054a.tar.gz
pyecsca-2c4b3d2c50c6acff1e5db988183040c0f616054a.tar.zst
pyecsca-2c4b3d2c50c6acff1e5db988183040c0f616054a.zip
Add support for PicoScope scopes, sketch out scope interface.
Diffstat (limited to 'pyecsca/ec')
-rw-r--r--pyecsca/ec/formula.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/pyecsca/ec/formula.py b/pyecsca/ec/formula.py
index 8e09f71..2da6ad5 100644
--- a/pyecsca/ec/formula.py
+++ b/pyecsca/ec/formula.py
@@ -1,4 +1,4 @@
-from ast import parse, Expression
+from ast import parse, Expression, Mult, Add, Sub, Pow, Div
from typing import List, Set, Any, ClassVar, MutableMapping
from itertools import product
@@ -25,6 +25,7 @@ class Formula(object):
@property
def input_index(self):
+ """The starting index where this formula reads its inputs."""
raise NotImplementedError
@property
@@ -34,12 +35,38 @@ class Formula(object):
@property
def inputs(self) -> Set[str]:
+ """The input variables of the formula."""
raise NotImplementedError
@property
def outputs(self) -> Set[str]:
+ """The output variables of the formula."""
raise NotImplementedError
+ @property
+ def num_operations(self) -> int:
+ """Number of operations."""
+ return len(list(filter(lambda op: op.operator is not None, self.code)))
+
+ @property
+ def num_multiplications(self) -> int:
+ """Number of multiplications."""
+ return len(list(filter(lambda op: isinstance(op.operator, Mult), self.code)))
+
+ @property
+ def num_inversions(self) -> int:
+ """Number of inversions."""
+ return len(list(filter(lambda op: isinstance(op.operator, Div), self.code)))
+
+ @property
+ def num_squarings(self) -> int:
+ """Number of squarings."""
+ return len(list(filter(lambda op: isinstance(op.operator, Pow), self.code)))
+
+ @property
+ def num_addsubs(self) -> int:
+ """Number of additions and subtractions."""
+ return len(list(filter(lambda op: isinstance(op.operator, (Add, Sub)), self.code)))
class EFDFormula(Formula):