aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2020-02-08 12:11:55 +0100
committerJ08nY2020-02-08 12:11:55 +0100
commit59b09851d4452448ffd9100aca2335f2424885e0 (patch)
tree56fe20210f54d8eb35fc31932ec11aec01bb61cb
parent8fa9f4bb7455b8153c8d50313c432a1d8bc8f020 (diff)
downloadpyecsca-59b09851d4452448ffd9100aca2335f2424885e0.tar.gz
pyecsca-59b09851d4452448ffd9100aca2335f2424885e0.tar.bz2
pyecsca-59b09851d4452448ffd9100aca2335f2424885e0.zip
Fix type errors, now mypy runs ok.
-rw-r--r--pyecsca/ec/context.py8
-rw-r--r--pyecsca/ec/coordinates.py7
-rw-r--r--pyecsca/ec/mult.py2
-rw-r--r--pyecsca/ec/op.py8
-rw-r--r--pyecsca/ec/signature.py4
-rw-r--r--pyecsca/sca/scope/picoscope_alt.py2
-rw-r--r--pyecsca/sca/trace/filter.py5
7 files changed, 19 insertions, 17 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()
diff --git a/pyecsca/sca/scope/picoscope_alt.py b/pyecsca/sca/scope/picoscope_alt.py
index 69b705a..5f8ad85 100644
--- a/pyecsca/sca/scope/picoscope_alt.py
+++ b/pyecsca/sca/scope/picoscope_alt.py
@@ -10,7 +10,7 @@ from .base import Scope
@public
-class PicoScopeAlt(Scope):
+class PicoScopeAlt(Scope): # pragma: no cover
def __init__(self, ps: Union[PS4000, PS6000]):
self.ps = ps
diff --git a/pyecsca/sca/trace/filter.py b/pyecsca/sca/trace/filter.py
index bc221ce..11cc89c 100644
--- a/pyecsca/sca/trace/filter.py
+++ b/pyecsca/sca/trace/filter.py
@@ -10,10 +10,9 @@ def filter_any(trace: Trace, sampling_frequency: int,
cutoff: Union[int, Tuple[int, int]], band_type: str) -> Trace:
nyq = 0.5 * sampling_frequency
if not isinstance(cutoff, int):
- normal_cutoff = tuple(map(lambda x: x / nyq, cutoff))
+ b, a = butter(6, tuple(map(lambda x: x / nyq, cutoff)), btype=band_type, analog=False, output='ba')
else:
- normal_cutoff = cutoff / nyq
- b, a = butter(6, normal_cutoff, btype=band_type, analog=False)
+ b, a = butter(6, cutoff / nyq, btype=band_type, analog=False, output='ba')
result_samples = lfilter(b, a, trace.samples)
return Trace(copy(trace.title), copy(trace.data), result_samples)