diff options
Diffstat (limited to 'pyecsca/ec')
| -rw-r--r-- | pyecsca/ec/context.py | 8 | ||||
| -rw-r--r-- | pyecsca/ec/coordinates.py | 7 | ||||
| -rw-r--r-- | pyecsca/ec/mult.py | 2 | ||||
| -rw-r--r-- | pyecsca/ec/op.py | 8 | ||||
| -rw-r--r-- | pyecsca/ec/signature.py | 4 |
5 files changed, 16 insertions, 13 deletions
diff --git a/pyecsca/ec/context.py b/pyecsca/ec/context.py index 9ec22f5..b5ae389 100644 --- a/pyecsca/ec/context.py +++ b/pyecsca/ec/context.py @@ -16,11 +16,11 @@ from .point import Point class OpResult(object): """A result of an operation.""" parents: Tuple - op: ast.operator + op: Optional[ast.operator] name: str value: Mod - def __init__(self, name: str, value: Mod, op: ast.operator, *parents: Any): + def __init__(self, name: str, value: Mod, op: Optional[ast.operator], *parents: Any): self.parents = tuple(parents) self.name = name self.value = value @@ -48,7 +48,7 @@ class Action(object): """An execution of some operations with inputs and outputs.""" inputs: MutableMapping[str, Mod] input_points: List[Point] - intermediates: MutableMapping[str, Union[Mod, OpResult]] + intermediates: MutableMapping[str, OpResult] outputs: MutableMapping[str, OpResult] output_points: List[Point] @@ -60,7 +60,7 @@ class Action(object): self.output_points = [] def add_operation(self, op: CodeOp, value: Mod): - parents = [] + parents: List[Union[Mod, OpResult]] = [] for parent in {*op.variables, *op.parameters}: if parent in self.intermediates: parents.append(self.intermediates[parent]) diff --git a/pyecsca/ec/coordinates.py b/pyecsca/ec/coordinates.py index 285e54b..e082a41 100644 --- a/pyecsca/ec/coordinates.py +++ b/pyecsca/ec/coordinates.py @@ -14,7 +14,7 @@ class CoordinateModel(object): full_name: str curve_model: Any variables: List[str] - satisfying: List[Union[Module, Expression]] + satisfying: List[Module] parameters: List[str] assumptions: List[Expression] formulas: MutableMapping[str, Formula] @@ -86,9 +86,10 @@ class EFDCoordinateModel(CoordinateModel): elif line.startswith("satisfying"): try: code = parse(line[11:].replace("^", "**"), mode="exec") + self.satisfying.append(code) except SyntaxError: - code = parse(line[11:].replace("=", "==").replace("^", "**"), mode="eval") - self.satisfying.append(code) + #code = parse(line[11:].replace("=", "==").replace("^", "**"), mode="eval") + pass elif line.startswith("parameter"): self.parameters.append(line[10:]) elif line.startswith("assume"): diff --git a/pyecsca/ec/mult.py b/pyecsca/ec/mult.py index 499db1b..ef74bc8 100644 --- a/pyecsca/ec/mult.py +++ b/pyecsca/ec/mult.py @@ -32,7 +32,7 @@ class ScalarMultiplier(object): formula is not None)) != 1: raise ValueError self.short_circuit = short_circuit - self.formulas = dict(filter(lambda pair: pair[1] is not None, formulas.items())) + self.formulas = {k:v for k, v in formulas.items() if v is not None} def _add(self, one: Point, other: Point) -> Point: if "add" not in self.formulas: diff --git a/pyecsca/ec/op.py b/pyecsca/ec/op.py index 43a84c0..72b06f3 100644 --- a/pyecsca/ec/op.py +++ b/pyecsca/ec/op.py @@ -1,6 +1,6 @@ -from ast import Module, walk, Name, BinOp, Constant, operator, Mult, Div, Add, Sub, Pow +from ast import Module, walk, Name, BinOp, Constant, operator, Mult, Div, Add, Sub, Pow, Assign from types import CodeType -from typing import FrozenSet, Optional +from typing import FrozenSet, Optional, cast from .mod import Mod @@ -15,8 +15,8 @@ class CodeOp(object): def __init__(self, code: Module): self.code = code - assign = code.body[0] - self.result = assign.targets[0].id + assign = cast(Assign, code.body[0]) + self.result = cast(Name, assign.targets[0]).id params = set() variables = set() constants = set() diff --git a/pyecsca/ec/signature.py b/pyecsca/ec/signature.py index 8c8630b..1c239b5 100644 --- a/pyecsca/ec/signature.py +++ b/pyecsca/ec/signature.py @@ -68,7 +68,7 @@ class Signature(object): if add is None: if "add" not in mult.formulas: raise ValueError - else: + elif isinstance(mult.formulas["add"], AdditionFormula): add = mult.formulas["add"] self.mult = mult self.group = group @@ -124,6 +124,8 @@ class Signature(object): return self._do_sign(k, digest) def _do_verify(self, signature: SignatureResult, digest: bytes) -> bool: + if self.pubkey is None: + return False z = int.from_bytes(digest, byteorder="big") if len(digest) * 8 > self.group.order.bit_length(): z >>= len(digest) * 8 - self.group.order.bit_length() |
