aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2019-12-23 13:29:42 +0100
committerJ08nY2019-12-23 13:29:42 +0100
commitae396e6d84a9f00295a66a61e17e881a8a866728 (patch)
tree64947438d42d919d1c3d6699061bd9663943843b
parent1ab370bb285f4a10e862898af1491fa238c86fad (diff)
downloadpyecsca-ae396e6d84a9f00295a66a61e17e881a8a866728.tar.gz
pyecsca-ae396e6d84a9f00295a66a61e17e881a8a866728.tar.bz2
pyecsca-ae396e6d84a9f00295a66a61e17e881a8a866728.zip
Fix op parsing.
-rw-r--r--pyecsca/ec/formula.py8
-rw-r--r--pyecsca/ec/mod.py2
-rw-r--r--pyecsca/ec/mult.py3
-rw-r--r--pyecsca/ec/op.py3
4 files changed, 14 insertions, 2 deletions
diff --git a/pyecsca/ec/formula.py b/pyecsca/ec/formula.py
index 6c9feba..8e09f71 100644
--- a/pyecsca/ec/formula.py
+++ b/pyecsca/ec/formula.py
@@ -16,6 +16,7 @@ class Formula(object):
parameters: List[str]
assumptions: List[Expression]
code: List[CodeOp]
+ shortname: ClassVar[str]
num_inputs: ClassVar[int]
num_outputs: ClassVar[int]
@@ -100,6 +101,7 @@ class EFDFormula(Formula):
@public
class AdditionFormula(Formula):
+ shortname = "add"
num_inputs = 2
num_outputs = 1
@@ -111,6 +113,7 @@ class AdditionEFDFormula(AdditionFormula, EFDFormula):
@public
class DoublingFormula(Formula):
+ shortname = "dbl"
num_inputs = 1
num_outputs = 1
@@ -122,6 +125,7 @@ class DoublingEFDFormula(DoublingFormula, EFDFormula):
@public
class TriplingFormula(Formula):
+ shortname = "tpl"
num_inputs = 1
num_outputs = 1
@@ -133,6 +137,7 @@ class TriplingEFDFormula(TriplingFormula, EFDFormula):
@public
class NegationFormula(Formula):
+ shortname = "neg"
num_inputs = 1
num_outputs = 1
@@ -144,6 +149,7 @@ class NegationEFDFormula(NegationFormula, EFDFormula):
@public
class ScalingFormula(Formula):
+ shortname = "scl"
num_inputs = 1
num_outputs = 1
@@ -155,6 +161,7 @@ class ScalingEFDFormula(ScalingFormula, EFDFormula):
@public
class DifferentialAdditionFormula(Formula):
+ shortname = "dadd"
num_inputs = 3
num_outputs = 1
@@ -166,6 +173,7 @@ class DifferentialAdditionEFDFormula(DifferentialAdditionFormula, EFDFormula):
@public
class LadderFormula(Formula):
+ shortname = "ladd"
num_inputs = 3
num_outputs = 2
diff --git a/pyecsca/ec/mod.py b/pyecsca/ec/mod.py
index dd09847..a142b71 100644
--- a/pyecsca/ec/mod.py
+++ b/pyecsca/ec/mod.py
@@ -124,6 +124,8 @@ class Mod(object):
return self.x
def __eq__(self, other):
+ if type(other) is int:
+ return self.x == (other % self.n)
if type(other) is not Mod:
return False
return self.x == other.x and self.n == other.n
diff --git a/pyecsca/ec/mult.py b/pyecsca/ec/mult.py
index 04abd74..499db1b 100644
--- a/pyecsca/ec/mult.py
+++ b/pyecsca/ec/mult.py
@@ -273,9 +273,8 @@ class SimpleLadderMultiplier(ScalarMultiplier):
top = self._group.order.bit_length() - 1
else:
top = scalar.bit_length() - 1
- q = self._point
p0 = copy(self._group.neutral)
- p1 = copy(q)
+ p1 = copy(self._point)
for i in range(top, -1, -1):
if scalar & (1 << i) == 0:
p1 = self._add(p0, p1)
diff --git a/pyecsca/ec/op.py b/pyecsca/ec/op.py
index cb186e1..43a84c0 100644
--- a/pyecsca/ec/op.py
+++ b/pyecsca/ec/op.py
@@ -34,6 +34,9 @@ class CodeOp(object):
op = node.op
self.left = self.__to_name(node.left)
self.right = self.__to_name(node.right)
+ if op is None and len(constants) == 1:
+ self.left = next(iter(constants))
+ self.right = None
self.operator = op
self.parameters = frozenset(params)
self.variables = frozenset(variables)