aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca
diff options
context:
space:
mode:
authorJ08nY2018-12-13 19:05:20 +0100
committerJ08nY2019-03-21 11:00:14 +0100
commit251811d90066e561b99b6580838abc20eaaa2009 (patch)
treeb14acdf69f4bbb983de6478a13dfd3605ada1295 /pyecsca
parent2b8e8c4e162e8902c93e1c5d4a18e4e7ceee52fa (diff)
downloadpyecsca-251811d90066e561b99b6580838abc20eaaa2009.tar.gz
pyecsca-251811d90066e561b99b6580838abc20eaaa2009.tar.zst
pyecsca-251811d90066e561b99b6580838abc20eaaa2009.zip
Fix basic scalar multiplier.
Diffstat (limited to 'pyecsca')
-rw-r--r--pyecsca/ec/mult.py17
-rw-r--r--pyecsca/ec/point.py5
2 files changed, 18 insertions, 4 deletions
diff --git a/pyecsca/ec/mult.py b/pyecsca/ec/mult.py
index 6a127d3..6bf40ec 100644
--- a/pyecsca/ec/mult.py
+++ b/pyecsca/ec/mult.py
@@ -42,21 +42,30 @@ class LTRMultiplier(ScalarMultiplier):
class RTLMultiplier(ScalarMultiplier):
always: bool
+ scale: bool
def __init__(self, curve: EllipticCurve, add: AdditionFormula, dbl: DoublingFormula,
scl: ScalingFormula = None,
- ctx: Context = None, always: bool = False):
+ ctx: Context = None, scale: bool = True, always: bool = False):
super().__init__(curve, ctx, add=add, dbl=dbl, scl=scl)
self.always = always
+ self.scale = scale
def multiply(self, scalar: int, point: Point) -> Point:
q = copy(point)
r = copy(self.curve.neutral)
while scalar > 0:
q = self.context.execute(self.formulas["dbl"], q, **self.curve.parameters)
+ if self.always:
+ tmp = self.context.execute(self.formulas["add"], r, q, **self.curve.parameters)
+ else:
+ if r == self.curve.neutral:
+ tmp = copy(q)
+ else:
+ tmp = self.context.execute(self.formulas["add"], r, q, **self.curve.parameters)
if scalar & 1 != 0:
- r = self.context.execute(self.formulas["add"], q, r, **self.curve.parameters)
- elif self.always:
- self.context.execute(self.formulas["add"], q, r, **self.curve.parameters)
+ r = tmp
scalar >>= 1
+ if self.scale:
+ r = self.context.execute(self.formulas["scl"], r, **self.curve.parameters)
return r
diff --git a/pyecsca/ec/point.py b/pyecsca/ec/point.py
index 6c793b8..e81b028 100644
--- a/pyecsca/ec/point.py
+++ b/pyecsca/ec/point.py
@@ -14,6 +14,11 @@ class Point(object):
self.coordinate_model = model
self.coords = coords
+ def __eq__(self, other):
+ if type(other) is not Point:
+ return False
+ return self.coordinate_model == other.coordinate_model and self.coords == other.coords
+
def __repr__(self):
args = ", ".join(["{}={}".format(key, value) for key, value in self.coords.items()])
return "Point([{}] in {})".format(args, self.coordinate_model)