aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca
diff options
context:
space:
mode:
authorJ08nY2018-12-15 17:11:33 +0100
committerJ08nY2019-03-21 11:00:14 +0100
commit618426e9010c7966751b8e24b99a20f59692b60c (patch)
treea3677613c653b04830380c4147270917c53150bc /pyecsca
parentbec2c56a86ce1d0b2285aaed50726fbdba42d620 (diff)
downloadpyecsca-618426e9010c7966751b8e24b99a20f59692b60c.tar.gz
pyecsca-618426e9010c7966751b8e24b99a20f59692b60c.tar.zst
pyecsca-618426e9010c7966751b8e24b99a20f59692b60c.zip
Add more tests and cleanup some typing errors.
Diffstat (limited to 'pyecsca')
-rw-r--r--pyecsca/ec/curve.py4
-rw-r--r--pyecsca/ec/mod.py14
-rw-r--r--pyecsca/ec/mult.py6
3 files changed, 16 insertions, 8 deletions
diff --git a/pyecsca/ec/curve.py b/pyecsca/ec/curve.py
index 79939b7..d4cef5d 100644
--- a/pyecsca/ec/curve.py
+++ b/pyecsca/ec/curve.py
@@ -12,11 +12,13 @@ class EllipticCurve(object):
neutral: Point
def __init__(self, model: Type[CurveModel], coordinate_model: CoordinateModel,
- parameters: Mapping[str, int], neutral: Point = None):
+ parameters: Mapping[str, int], neutral: Point):
if coordinate_model not in model.coordinates.values():
raise ValueError
if set(model.parameter_names).symmetric_difference(parameters.keys()):
raise ValueError
+ if neutral.coordinate_model != coordinate_model:
+ raise ValueError
self.model = model
self.coordinate_model = coordinate_model
self.parameters = dict(parameters)
diff --git a/pyecsca/ec/mod.py b/pyecsca/ec/mod.py
index f75952d..bc1ebff 100644
--- a/pyecsca/ec/mod.py
+++ b/pyecsca/ec/mod.py
@@ -77,8 +77,6 @@ class Mod(object):
@check
def __mul__(self, other):
- if self.n != other.n:
- raise ValueError
return Mod((self.x * other.x) % self.n, self.n)
@check
@@ -94,12 +92,20 @@ class Mod(object):
return ~self * other
@check
+ def __floordiv__(self, other):
+ return self * ~other
+
+ @check
+ def __rfloordiv__(self, other):
+ return ~self * other
+
+ @check
def __div__(self, other):
- return self.__truediv__(other)
+ return self.__floordiv__(other)
@check
def __rdiv__(self, other):
- return self.__rtruediv__(other)
+ return self.__rfloordiv__(other)
@check
def __divmod__(self, divisor):
diff --git a/pyecsca/ec/mult.py b/pyecsca/ec/mult.py
index a32a54b..9255342 100644
--- a/pyecsca/ec/mult.py
+++ b/pyecsca/ec/mult.py
@@ -1,5 +1,5 @@
from copy import copy
-from typing import Mapping, Tuple
+from typing import Mapping, Tuple, Optional
from .context import Context
from .curve import EllipticCurve
@@ -12,7 +12,7 @@ class ScalarMultiplier(object):
formulas: Mapping[str, Formula]
context: Context
- def __init__(self, curve: EllipticCurve, ctx: Context = None, **formulas: Formula):
+ def __init__(self, curve: EllipticCurve, ctx: Context = None, **formulas: Optional[Formula]):
for formula in formulas.values():
if formula is not None and formula.coordinate_model is not curve.coordinate_model:
raise ValueError
@@ -21,7 +21,7 @@ class ScalarMultiplier(object):
self.context = ctx
else:
self.context = Context()
- self.formulas = dict(formulas)
+ self.formulas = dict(filter(lambda pair: pair[1] is not None, formulas.items()))
def _add(self, one: Point, other: Point) -> Point:
if "add" not in self.formulas: