aboutsummaryrefslogtreecommitdiffhomepage
path: root/pyecsca
diff options
context:
space:
mode:
authorJ08nY2023-10-16 18:36:56 +0200
committerJ08nY2023-10-16 18:36:56 +0200
commit1b05664444fdaa785b90055d2a235ec81b4e9b0d (patch)
tree397ca22a4b37268901e852945b59da04124b64f6 /pyecsca
parent149e16806d9db7442b87f76259af740e27a77875 (diff)
downloadpyecsca-1b05664444fdaa785b90055d2a235ec81b4e9b0d.tar.gz
pyecsca-1b05664444fdaa785b90055d2a235ec81b4e9b0d.tar.zst
pyecsca-1b05664444fdaa785b90055d2a235ec81b4e9b0d.zip
Make multiplier reprs more concise.
Diffstat (limited to '')
-rw-r--r--pyecsca/ec/coordinates.py5
-rw-r--r--pyecsca/ec/formula.py3
-rw-r--r--pyecsca/ec/mult/base.py2
-rw-r--r--pyecsca/ec/mult/binary.py2
-rw-r--r--pyecsca/ec/mult/fixed.py2
-rw-r--r--pyecsca/ec/mult/ladder.py6
-rw-r--r--pyecsca/ec/mult/naf.py4
-rw-r--r--pyecsca/ec/mult/window.py4
8 files changed, 17 insertions, 11 deletions
diff --git a/pyecsca/ec/coordinates.py b/pyecsca/ec/coordinates.py
index fe55d42..49452c7 100644
--- a/pyecsca/ec/coordinates.py
+++ b/pyecsca/ec/coordinates.py
@@ -51,8 +51,11 @@ class CoordinateModel:
formulas: MutableMapping[str, Formula]
"""Formulas available on the coordinate system."""
+ def __str__(self):
+ return f"{self.curve_model.shortname}/{self.name}"
+
def __repr__(self):
- return f'{self.__class__.__name__}("{self.name}" on {self.curve_model.name})'
+ return f"{self.__class__.__name__}(\"{self.name}\", curve_model={self.curve_model})"
def __getstate__(self):
state = self.__dict__.copy()
diff --git a/pyecsca/ec/formula.py b/pyecsca/ec/formula.py
index 91e551b..a22cf51 100644
--- a/pyecsca/ec/formula.py
+++ b/pyecsca/ec/formula.py
@@ -397,6 +397,9 @@ class EFDFormula(Formula):
)
self.code.append(CodeOp(code_module))
+ def __str__(self):
+ return f"{self.coordinate_model!s}/{self.name}"
+
@cached_property
def input_index(self):
return 1
diff --git a/pyecsca/ec/mult/base.py b/pyecsca/ec/mult/base.py
index 5bfef73..71ddc44 100644
--- a/pyecsca/ec/mult/base.py
+++ b/pyecsca/ec/mult/base.py
@@ -189,7 +189,7 @@ class ScalarMultiplier(ABC):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit})"
def init(self, params: DomainParameters, point: Point):
"""
diff --git a/pyecsca/ec/mult/binary.py b/pyecsca/ec/mult/binary.py
index f8acb16..6a8d717 100644
--- a/pyecsca/ec/mult/binary.py
+++ b/pyecsca/ec/mult/binary.py
@@ -64,7 +64,7 @@ class DoubleAndAddMultiplier(AccumulatorMultiplier, ScalarMultiplier, ABC):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.direction == other.direction and self.accumulation_order == other.accumulation_order and self.always == other.always and self.complete == other.complete
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit}, direction={self.direction}, accumulation_order={self.accumulation_order}, always={self.always}, complete={self.complete})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, direction={self.direction.name}, accumulation_order={self.accumulation_order.name}, always={self.always}, complete={self.complete})"
def _ltr(self, scalar: int) -> Point:
if self.complete:
diff --git a/pyecsca/ec/mult/fixed.py b/pyecsca/ec/mult/fixed.py
index 010767b..da14e5f 100644
--- a/pyecsca/ec/mult/fixed.py
+++ b/pyecsca/ec/mult/fixed.py
@@ -63,7 +63,7 @@ class FullPrecompMultiplier(AccumulatorMultiplier, ScalarMultiplier):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.direction == other.direction and self.accumulation_order == other.accumulation_order and self.always == other.always and self.complete == other.complete
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit}, accumulation_order={self.accumulation_order}, always={self.always}, complete={self.complete})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, accumulation_order={self.accumulation_order.name}, always={self.always}, complete={self.complete})"
def init(self, params: DomainParameters, point: Point):
with PrecomputationAction(params, point):
diff --git a/pyecsca/ec/mult/ladder.py b/pyecsca/ec/mult/ladder.py
index 2fc1244..b950899 100644
--- a/pyecsca/ec/mult/ladder.py
+++ b/pyecsca/ec/mult/ladder.py
@@ -53,7 +53,7 @@ class LadderMultiplier(ScalarMultiplier):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.complete == other.complete
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit}, complete={self.complete})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, complete={self.complete})"
def multiply(self, scalar: int) -> Point:
if not self._initialized:
@@ -115,7 +115,7 @@ class SimpleLadderMultiplier(ScalarMultiplier):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.complete == other.complete
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit}, complete={self.complete})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, complete={self.complete})"
def multiply(self, scalar: int) -> Point:
if not self._initialized:
@@ -176,7 +176,7 @@ class DifferentialLadderMultiplier(ScalarMultiplier):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.complete == other.complete
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit}, complete={self.complete})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, complete={self.complete})"
def multiply(self, scalar: int) -> Point:
if not self._initialized:
diff --git a/pyecsca/ec/mult/naf.py b/pyecsca/ec/mult/naf.py
index 9304475..c7dfa4a 100644
--- a/pyecsca/ec/mult/naf.py
+++ b/pyecsca/ec/mult/naf.py
@@ -56,7 +56,7 @@ class BinaryNAFMultiplier(AccumulatorMultiplier, ScalarMultiplier):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.direction == other.direction and self.accumulation_order == other.accumulation_order
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit}, direction={self.direction}, accumulation_order={self.accumulation_order})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, direction={self.direction.name}, accumulation_order={self.accumulation_order.name})"
def init(self, params: DomainParameters, point: Point):
with PrecomputationAction(params, point):
@@ -150,7 +150,7 @@ class WindowNAFMultiplier(AccumulatorMultiplier, ScalarMultiplier):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.width == other.width and self.precompute_negation == other.precompute_negation and self.accumulation_order == other.accumulation_order
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit}, precompute_negation={self.precompute_negation}, accumulation_order={self.accumulation_order})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, precompute_negation={self.precompute_negation}, accumulation_order={self.accumulation_order.name})"
def init(self, params: DomainParameters, point: Point):
with PrecomputationAction(params, point):
diff --git a/pyecsca/ec/mult/window.py b/pyecsca/ec/mult/window.py
index 8317965..f85a58a 100644
--- a/pyecsca/ec/mult/window.py
+++ b/pyecsca/ec/mult/window.py
@@ -58,7 +58,7 @@ class SlidingWindowMultiplier(AccumulatorMultiplier, ScalarMultiplier):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.width == other.width and self.recoding_direction == other.recoding_direction and self.accumulation_order == other.accumulation_order
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit}, width={self.width}, recoding_direction={self.recoding_direction}, accumulation_order={self.accumulation_order})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, width={self.width}, recoding_direction={self.recoding_direction.name}, accumulation_order={self.accumulation_order.name})"
def init(self, params: DomainParameters, point: Point):
with PrecomputationAction(params, point):
@@ -137,7 +137,7 @@ class FixedWindowLTRMultiplier(AccumulatorMultiplier, ScalarMultiplier):
return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.m == other.m and self.accumulation_order == other.accumulation_order
def __repr__(self):
- return f"{self.__class__.__name__}({tuple(self.formulas.values())}, short_circuit={self.short_circuit}, m={self.m}, accumulation_order={self.accumulation_order})"
+ return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, m={self.m}, accumulation_order={self.accumulation_order.name})"
def init(self, params: DomainParameters, point: Point):
with PrecomputationAction(params, point):