diff options
| author | J08nY | 2024-06-01 14:15:39 +0200 |
|---|---|---|
| committer | J08nY | 2024-06-01 14:15:39 +0200 |
| commit | 5ddfea8c12b2e76fa7aed8eb146c8c385e2abe60 (patch) | |
| tree | 51edf08a2501553f61c9bbce506b70ac25ec9ef0 /pyecsca/ec/mult | |
| parent | e2bb0abbd98c7666b3604499272d1e40a8d3d7b7 (diff) | |
| download | pyecsca-5ddfea8c12b2e76fa7aed8eb146c8c385e2abe60.tar.gz pyecsca-5ddfea8c12b2e76fa7aed8eb146c8c385e2abe60.tar.zst pyecsca-5ddfea8c12b2e76fa7aed8eb146c8c385e2abe60.zip | |
Make imports absolute (to allow doctests).
Diffstat (limited to 'pyecsca/ec/mult')
| -rw-r--r-- | pyecsca/ec/mult/base.py | 61 | ||||
| -rw-r--r-- | pyecsca/ec/mult/binary.py | 135 | ||||
| -rw-r--r-- | pyecsca/ec/mult/comb.py | 39 | ||||
| -rw-r--r-- | pyecsca/ec/mult/fixed.py | 59 | ||||
| -rw-r--r-- | pyecsca/ec/mult/ladder.py | 62 | ||||
| -rw-r--r-- | pyecsca/ec/mult/naf.py | 102 | ||||
| -rw-r--r-- | pyecsca/ec/mult/window.py | 44 |
7 files changed, 344 insertions, 158 deletions
diff --git a/pyecsca/ec/mult/base.py b/pyecsca/ec/mult/base.py index d66f810..537f43e 100644 --- a/pyecsca/ec/mult/base.py +++ b/pyecsca/ec/mult/base.py @@ -7,15 +7,16 @@ from enum import Enum from public import public from typing import Mapping, Tuple, Optional, ClassVar, Set, Type -from ..context import ResultAction, Action -from ..formula import Formula -from ..params import DomainParameters -from ..point import Point +from pyecsca.ec.context import ResultAction, Action +from pyecsca.ec.formula import Formula +from pyecsca.ec.params import DomainParameters +from pyecsca.ec.point import Point @public class ProcessingDirection(Enum): """Scalar processing direction.""" + LTR = "Left-to-right" RTL = "Right-to-left" @@ -23,6 +24,7 @@ class ProcessingDirection(Enum): @public class AccumulationOrder(Enum): """Accumulation order (makes a difference for the projective result).""" + PeqPR = "P = P + R" PeqRP = "P = R + P" @@ -87,14 +89,14 @@ class ScalarMultiplier(ABC): def __init__(self, short_circuit: bool = True, **formulas: Optional[Formula]): if ( - len( - { - formula.coordinate_model - for formula in formulas.values() - if formula is not None - } - ) - != 1 + len( + { + formula.coordinate_model + for formula in formulas.values() + if formula is not None + } + ) + != 1 ): raise ValueError("Formulas need to belong to the same coordinate model.") self.short_circuit = short_circuit @@ -129,10 +131,7 @@ class ScalarMultiplier(ABC): def _dbl(self, point: Point) -> Point: if "dbl" not in self.formulas: raise NotImplementedError - if ( - self.short_circuit - and point == self._params.curve.neutral - ): + if self.short_circuit and point == self._params.curve.neutral: return copy(point) return self.formulas["dbl"]( self._params.curve.prime, point, **self._params.curve.parameters @@ -181,12 +180,22 @@ class ScalarMultiplier(ABC): )[0] def __hash__(self): - return hash((ScalarMultiplier, tuple(self.formulas.keys()), tuple(self.formulas.values()), self.short_circuit)) + return hash( + ( + ScalarMultiplier, + tuple(self.formulas.keys()), + tuple(self.formulas.values()), + self.short_circuit, + ) + ) def __eq__(self, other): if not isinstance(other, ScalarMultiplier): return False - return self.formulas == other.formulas and self.short_circuit == other.short_circuit + return ( + self.formulas == other.formulas + and self.short_circuit == other.short_circuit + ) def __repr__(self): return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit})" @@ -203,10 +212,12 @@ class ScalarMultiplier(ABC): """ coord_model = set(self.formulas.values()).pop().coordinate_model if ( - params.curve.coordinate_model != coord_model - or point.coordinate_model != coord_model + params.curve.coordinate_model != coord_model + or point.coordinate_model != coord_model ): - raise ValueError("Coordinate models of the parameters, formulas or point are not compatible.") + raise ValueError( + "Coordinate models of the parameters, formulas or point are not compatible." + ) self._params = params self._point = point self._initialized = True @@ -232,10 +243,16 @@ class AccumulatorMultiplier(ScalarMultiplier, ABC): :param accumulation_order: The order of accumulation of points. """ + accumulation_order: AccumulationOrder """The order of accumulation of points.""" - def __init__(self, *args, accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, **kwargs): + def __init__( + self, + *args, + accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, + **kwargs, + ): super().__init__(*args, **kwargs) self.accumulation_order = accumulation_order diff --git a/pyecsca/ec/mult/binary.py b/pyecsca/ec/mult/binary.py index 89c203c..9b6a07a 100644 --- a/pyecsca/ec/mult/binary.py +++ b/pyecsca/ec/mult/binary.py @@ -5,14 +5,15 @@ from typing import Optional from public import public -from .base import ScalarMultiplier, ProcessingDirection, AccumulationOrder, ScalarMultiplicationAction, \ - AccumulatorMultiplier -from ..formula import ( - AdditionFormula, - DoublingFormula, - ScalingFormula, +from pyecsca.ec.mult.base import ( + ScalarMultiplier, + ProcessingDirection, + AccumulationOrder, + ScalarMultiplicationAction, + AccumulatorMultiplier, ) -from ..point import Point +from pyecsca.ec.formula import AdditionFormula, DoublingFormula, ScalingFormula +from pyecsca.ec.point import Point @public @@ -30,6 +31,7 @@ class DoubleAndAddMultiplier(AccumulatorMultiplier, ScalarMultiplier, ABC): :param accumulation_order: The order of accumulation of points. :param complete: Whether it starts processing at full order-bit-length. """ + requires = {AdditionFormula, DoublingFormula} optionals = {ScalingFormula} always: bool @@ -40,28 +42,50 @@ class DoubleAndAddMultiplier(AccumulatorMultiplier, ScalarMultiplier, ABC): """Whether it starts processing at full order-bit-length.""" def __init__( - self, - add: AdditionFormula, - dbl: DoublingFormula, - scl: Optional[ScalingFormula] = None, - always: bool = False, - direction: ProcessingDirection = ProcessingDirection.LTR, - accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, - complete: bool = True, - short_circuit: bool = True, + self, + add: AdditionFormula, + dbl: DoublingFormula, + scl: Optional[ScalingFormula] = None, + always: bool = False, + direction: ProcessingDirection = ProcessingDirection.LTR, + accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, + complete: bool = True, + short_circuit: bool = True, ): - super().__init__(short_circuit=short_circuit, accumulation_order=accumulation_order, add=add, dbl=dbl, scl=scl) + super().__init__( + short_circuit=short_circuit, + accumulation_order=accumulation_order, + add=add, + dbl=dbl, + scl=scl, + ) self.always = always self.direction = direction self.complete = complete def __hash__(self): - return hash((DoubleAndAddMultiplier, super().__hash__(), self.direction, self.accumulation_order, self.always, self.complete)) + return hash( + ( + DoubleAndAddMultiplier, + super().__hash__(), + self.direction, + self.accumulation_order, + self.always, + self.complete, + ) + ) def __eq__(self, other): if not isinstance(other, DoubleAndAddMultiplier): return False - 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 + 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__}({', '.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})" @@ -130,18 +154,25 @@ class LTRMultiplier(DoubleAndAddMultiplier): """ def __init__( - self, - add: AdditionFormula, - dbl: DoublingFormula, - scl: Optional[ScalingFormula] = None, - always: bool = False, - accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, - complete: bool = True, - short_circuit: bool = True, + self, + add: AdditionFormula, + dbl: DoublingFormula, + scl: Optional[ScalingFormula] = None, + always: bool = False, + accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, + complete: bool = True, + short_circuit: bool = True, ): - super().__init__(short_circuit=short_circuit, direction=ProcessingDirection.LTR, - accumulation_order=accumulation_order, always=always, complete=complete, - add=add, dbl=dbl, scl=scl) + super().__init__( + short_circuit=short_circuit, + direction=ProcessingDirection.LTR, + accumulation_order=accumulation_order, + always=always, + complete=complete, + add=add, + dbl=dbl, + scl=scl, + ) @public @@ -157,18 +188,25 @@ class RTLMultiplier(DoubleAndAddMultiplier): """ def __init__( - self, - add: AdditionFormula, - dbl: DoublingFormula, - scl: Optional[ScalingFormula] = None, - always: bool = False, - accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, - complete: bool = True, - short_circuit: bool = True, + self, + add: AdditionFormula, + dbl: DoublingFormula, + scl: Optional[ScalingFormula] = None, + always: bool = False, + accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, + complete: bool = True, + short_circuit: bool = True, ): - super().__init__(short_circuit=short_circuit, direction=ProcessingDirection.RTL, - accumulation_order=accumulation_order, always=always, - add=add, dbl=dbl, scl=scl, complete=complete) + super().__init__( + short_circuit=short_circuit, + direction=ProcessingDirection.RTL, + accumulation_order=accumulation_order, + always=always, + add=add, + dbl=dbl, + scl=scl, + complete=complete, + ) @public @@ -186,11 +224,11 @@ class CoronMultiplier(ScalarMultiplier): optionals = {ScalingFormula} def __init__( - self, - add: AdditionFormula, - dbl: DoublingFormula, - scl: Optional[ScalingFormula] = None, - short_circuit: bool = True, + self, + add: AdditionFormula, + dbl: DoublingFormula, + scl: Optional[ScalingFormula] = None, + short_circuit: bool = True, ): super().__init__(short_circuit=short_circuit, add=add, dbl=dbl, scl=scl) @@ -200,7 +238,10 @@ class CoronMultiplier(ScalarMultiplier): def __eq__(self, other): if not isinstance(other, CoronMultiplier): return False - return self.formulas == other.formulas and self.short_circuit == other.short_circuit + return ( + self.formulas == other.formulas + and self.short_circuit == other.short_circuit + ) def multiply(self, scalar: int) -> Point: if not self._initialized: diff --git a/pyecsca/ec/mult/comb.py b/pyecsca/ec/mult/comb.py index c65adb6..8cea19c 100644 --- a/pyecsca/ec/mult/comb.py +++ b/pyecsca/ec/mult/comb.py @@ -5,8 +5,8 @@ from typing import MutableMapping, Optional from public import public -from ..formula import AdditionFormula, DoublingFormula, ScalingFormula -from ..mult import ( +from pyecsca.ec.formula import AdditionFormula, DoublingFormula, ScalingFormula +from pyecsca.ec.mult import ( AccumulatorMultiplier, ScalarMultiplier, ProcessingDirection, @@ -14,9 +14,9 @@ from ..mult import ( PrecomputationAction, ScalarMultiplicationAction, ) -from ..params import DomainParameters -from ..point import Point -from ..scalar import convert_base +from pyecsca.ec.params import DomainParameters +from pyecsca.ec.point import Point +from pyecsca.ec.scalar import convert_base @public @@ -61,12 +61,26 @@ class BGMWMultiplier(AccumulatorMultiplier, ScalarMultiplier): self.width = width def __hash__(self): - return hash((BGMWMultiplier, super().__hash__(), self.width, self.direction, self.accumulation_order)) + return hash( + ( + BGMWMultiplier, + super().__hash__(), + self.width, + self.direction, + self.accumulation_order, + ) + ) def __eq__(self, other): if not isinstance(other, BGMWMultiplier): return False - return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.width == other.width and self.direction == other.direction and self.accumulation_order == other.accumulation_order + return ( + self.formulas == other.formulas + and self.short_circuit == other.short_circuit + and self.width == other.width + and self.direction == other.direction + and self.accumulation_order == other.accumulation_order + ) def __repr__(self): return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, width={self.width}, direction={self.direction.name}, accumulation_order={self.accumulation_order.name})" @@ -147,12 +161,19 @@ class CombMultiplier(AccumulatorMultiplier, ScalarMultiplier): self.width = width def __hash__(self): - return hash((CombMultiplier, super().__hash__(), self.width, self.accumulation_order)) + return hash( + (CombMultiplier, super().__hash__(), self.width, self.accumulation_order) + ) def __eq__(self, other): if not isinstance(other, CombMultiplier): return False - return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.width == other.width and self.accumulation_order == other.accumulation_order + return ( + self.formulas == other.formulas + and self.short_circuit == other.short_circuit + and self.width == other.width + and self.accumulation_order == other.accumulation_order + ) def __repr__(self): return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, width={self.width}, accumulation_order={self.accumulation_order.name})" diff --git a/pyecsca/ec/mult/fixed.py b/pyecsca/ec/mult/fixed.py index fedc22d..afd02e5 100644 --- a/pyecsca/ec/mult/fixed.py +++ b/pyecsca/ec/mult/fixed.py @@ -4,11 +4,17 @@ from typing import MutableMapping, Optional from public import public -from ..formula import AdditionFormula, DoublingFormula, ScalingFormula -from ..mult import AccumulatorMultiplier, ScalarMultiplier, ProcessingDirection, AccumulationOrder, \ - PrecomputationAction, ScalarMultiplicationAction -from ..params import DomainParameters -from ..point import Point +from pyecsca.ec.formula import AdditionFormula, DoublingFormula, ScalingFormula +from pyecsca.ec.mult import ( + AccumulatorMultiplier, + ScalarMultiplier, + ProcessingDirection, + AccumulationOrder, + PrecomputationAction, + ScalarMultiplicationAction, +) +from pyecsca.ec.params import DomainParameters +from pyecsca.ec.point import Point @public @@ -37,30 +43,49 @@ class FullPrecompMultiplier(AccumulatorMultiplier, ScalarMultiplier): _points: MutableMapping[int, Point] def __init__( - self, - add: AdditionFormula, - dbl: DoublingFormula, - scl: Optional[ScalingFormula] = None, - always: bool = False, - direction: ProcessingDirection = ProcessingDirection.LTR, - accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, - complete: bool = True, - short_circuit: bool = True, + self, + add: AdditionFormula, + dbl: DoublingFormula, + scl: Optional[ScalingFormula] = None, + always: bool = False, + direction: ProcessingDirection = ProcessingDirection.LTR, + accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, + complete: bool = True, + short_circuit: bool = True, ): super().__init__( - short_circuit=short_circuit, accumulation_order=accumulation_order, add=add, dbl=dbl, scl=scl + short_circuit=short_circuit, + accumulation_order=accumulation_order, + add=add, + dbl=dbl, + scl=scl, ) self.always = always self.direction = direction self.complete = complete def __hash__(self): - return hash((FullPrecompMultiplier, super().__hash__(), self.direction, self.accumulation_order, self.always)) + return hash( + ( + FullPrecompMultiplier, + super().__hash__(), + self.direction, + self.accumulation_order, + self.always, + ) + ) def __eq__(self, other): if not isinstance(other, FullPrecompMultiplier): return False - 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 + 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__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, accumulation_order={self.accumulation_order.name}, always={self.always}, complete={self.complete})" diff --git a/pyecsca/ec/mult/ladder.py b/pyecsca/ec/mult/ladder.py index 2f7fd26..105587f 100644 --- a/pyecsca/ec/mult/ladder.py +++ b/pyecsca/ec/mult/ladder.py @@ -3,15 +3,15 @@ from copy import copy from typing import Optional from public import public -from .base import ScalarMultiplier, ScalarMultiplicationAction -from ..formula import ( +from pyecsca.ec.mult.base import ScalarMultiplier, ScalarMultiplicationAction +from pyecsca.ec.formula import ( AdditionFormula, DoublingFormula, ScalingFormula, LadderFormula, - DifferentialAdditionFormula + DifferentialAdditionFormula, ) -from ..point import Point +from pyecsca.ec.point import Point @public @@ -32,12 +32,12 @@ class LadderMultiplier(ScalarMultiplier): """Whether it starts processing at full order-bit-length.""" def __init__( - self, - ladd: LadderFormula, - dbl: Optional[DoublingFormula] = None, - scl: Optional[ScalingFormula] = None, - complete: bool = True, - short_circuit: bool = True, + self, + ladd: LadderFormula, + dbl: Optional[DoublingFormula] = None, + scl: Optional[ScalingFormula] = None, + complete: bool = True, + short_circuit: bool = True, ): super().__init__(short_circuit=short_circuit, ladd=ladd, dbl=dbl, scl=scl) self.complete = complete @@ -50,7 +50,11 @@ class LadderMultiplier(ScalarMultiplier): def __eq__(self, other): if not isinstance(other, LadderMultiplier): return False - return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.complete == other.complete + 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__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, complete={self.complete})" @@ -96,12 +100,12 @@ class SimpleLadderMultiplier(ScalarMultiplier): """Whether it starts processing at full order-bit-length.""" def __init__( - self, - add: AdditionFormula, - dbl: DoublingFormula, - scl: Optional[ScalingFormula] = None, - complete: bool = True, - short_circuit: bool = True, + self, + add: AdditionFormula, + dbl: DoublingFormula, + scl: Optional[ScalingFormula] = None, + complete: bool = True, + short_circuit: bool = True, ): super().__init__(short_circuit=short_circuit, add=add, dbl=dbl, scl=scl) self.complete = complete @@ -112,7 +116,11 @@ class SimpleLadderMultiplier(ScalarMultiplier): def __eq__(self, other): if not isinstance(other, SimpleLadderMultiplier): return False - return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.complete == other.complete + 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__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, complete={self.complete})" @@ -157,12 +165,12 @@ class DifferentialLadderMultiplier(ScalarMultiplier): """Whether it starts processing at full order-bit-length.""" def __init__( - self, - dadd: DifferentialAdditionFormula, - dbl: DoublingFormula, - scl: Optional[ScalingFormula] = None, - complete: bool = True, - short_circuit: bool = True, + self, + dadd: DifferentialAdditionFormula, + dbl: DoublingFormula, + scl: Optional[ScalingFormula] = None, + complete: bool = True, + short_circuit: bool = True, ): super().__init__(short_circuit=short_circuit, dadd=dadd, dbl=dbl, scl=scl) self.complete = complete @@ -173,7 +181,11 @@ class DifferentialLadderMultiplier(ScalarMultiplier): def __eq__(self, other): if not isinstance(other, DifferentialLadderMultiplier): return False - return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.complete == other.complete + 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__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, complete={self.complete})" diff --git a/pyecsca/ec/mult/naf.py b/pyecsca/ec/mult/naf.py index b21d1cf..408f489 100644 --- a/pyecsca/ec/mult/naf.py +++ b/pyecsca/ec/mult/naf.py @@ -3,17 +3,23 @@ from copy import copy from typing import Optional, List, MutableMapping from public import public -from .base import ScalarMultiplier, ScalarMultiplicationAction, ProcessingDirection, AccumulationOrder, \ - PrecomputationAction, AccumulatorMultiplier -from ..formula import ( +from pyecsca.ec.mult.base import ( + ScalarMultiplier, + ScalarMultiplicationAction, + ProcessingDirection, + AccumulationOrder, + PrecomputationAction, + AccumulatorMultiplier, +) +from pyecsca.ec.formula import ( AdditionFormula, DoublingFormula, ScalingFormula, - NegationFormula + NegationFormula, ) -from ..params import DomainParameters -from ..point import Point -from ..scalar import naf, wnaf +from pyecsca.ec.params import DomainParameters +from pyecsca.ec.point import Point +from pyecsca.ec.scalar import naf, wnaf @public @@ -33,27 +39,44 @@ class BinaryNAFMultiplier(AccumulatorMultiplier, ScalarMultiplier): _point_neg: Point def __init__( - self, - add: AdditionFormula, - dbl: DoublingFormula, - neg: NegationFormula, - scl: Optional[ScalingFormula] = None, - direction: ProcessingDirection = ProcessingDirection.LTR, - accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, - short_circuit: bool = True, + self, + add: AdditionFormula, + dbl: DoublingFormula, + neg: NegationFormula, + scl: Optional[ScalingFormula] = None, + direction: ProcessingDirection = ProcessingDirection.LTR, + accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, + short_circuit: bool = True, ): super().__init__( - short_circuit=short_circuit, accumulation_order=accumulation_order, add=add, dbl=dbl, neg=neg, scl=scl + short_circuit=short_circuit, + accumulation_order=accumulation_order, + add=add, + dbl=dbl, + neg=neg, + scl=scl, ) self.direction = direction def __hash__(self): - return hash((BinaryNAFMultiplier, super().__hash__(), self.direction, self.accumulation_order)) + return hash( + ( + BinaryNAFMultiplier, + super().__hash__(), + self.direction, + self.accumulation_order, + ) + ) def __eq__(self, other): if not isinstance(other, BinaryNAFMultiplier): return False - return self.formulas == other.formulas and self.short_circuit == other.short_circuit and self.direction == other.direction and self.accumulation_order == other.accumulation_order + 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__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, direction={self.direction.name}, accumulation_order={self.accumulation_order.name})" @@ -125,29 +148,48 @@ class WindowNAFMultiplier(AccumulatorMultiplier, ScalarMultiplier): """The width of the window.""" def __init__( - self, - add: AdditionFormula, - dbl: DoublingFormula, - neg: NegationFormula, - width: int, - scl: Optional[ScalingFormula] = None, - accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, - precompute_negation: bool = False, - short_circuit: bool = True, + self, + add: AdditionFormula, + dbl: DoublingFormula, + neg: NegationFormula, + width: int, + scl: Optional[ScalingFormula] = None, + accumulation_order: AccumulationOrder = AccumulationOrder.PeqPR, + precompute_negation: bool = False, + short_circuit: bool = True, ): super().__init__( - short_circuit=short_circuit, accumulation_order=accumulation_order, add=add, dbl=dbl, neg=neg, scl=scl + short_circuit=short_circuit, + accumulation_order=accumulation_order, + add=add, + dbl=dbl, + neg=neg, + scl=scl, ) self.width = width self.precompute_negation = precompute_negation def __hash__(self): - return hash((WindowNAFMultiplier, super().__hash__(), self.width, self.precompute_negation, self.accumulation_order)) + return hash( + ( + WindowNAFMultiplier, + super().__hash__(), + self.width, + self.precompute_negation, + self.accumulation_order, + ) + ) def __eq__(self, other): if not isinstance(other, WindowNAFMultiplier): return False - 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 + 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__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, width={self.width}, precompute_negation={self.precompute_negation}, accumulation_order={self.accumulation_order.name})" diff --git a/pyecsca/ec/mult/window.py b/pyecsca/ec/mult/window.py index d4967e8..b003e40 100644 --- a/pyecsca/ec/mult/window.py +++ b/pyecsca/ec/mult/window.py @@ -3,8 +3,8 @@ from copy import copy from typing import Optional, MutableMapping from public import public -from ..params import DomainParameters -from .base import ( +from pyecsca.ec.params import DomainParameters +from pyecsca.ec.mult.base import ( ScalarMultiplier, AccumulationOrder, ScalarMultiplicationAction, @@ -12,14 +12,19 @@ from .base import ( ProcessingDirection, AccumulatorMultiplier, ) -from ..formula import ( +from pyecsca.ec.formula import ( AdditionFormula, DoublingFormula, ScalingFormula, NegationFormula, ) -from ..point import Point -from ..scalar import convert_base, sliding_window_rtl, sliding_window_ltr, booth_window +from pyecsca.ec.point import Point +from pyecsca.ec.scalar import ( + convert_base, + sliding_window_rtl, + sliding_window_ltr, + booth_window, +) @public @@ -61,7 +66,15 @@ class SlidingWindowMultiplier(AccumulatorMultiplier, ScalarMultiplier): self.recoding_direction = recoding_direction def __hash__(self): - return hash((SlidingWindowMultiplier, super().__hash__(), self.width, self.recoding_direction, self.accumulation_order)) + return hash( + ( + SlidingWindowMultiplier, + super().__hash__(), + self.width, + self.recoding_direction, + self.accumulation_order, + ) + ) def __eq__(self, other): if not isinstance(other, SlidingWindowMultiplier): @@ -150,7 +163,14 @@ class FixedWindowLTRMultiplier(AccumulatorMultiplier, ScalarMultiplier): self.m = m def __hash__(self): - return hash((FixedWindowLTRMultiplier, super().__hash__(), self.m, self.accumulation_order)) + return hash( + ( + FixedWindowLTRMultiplier, + super().__hash__(), + self.m, + self.accumulation_order, + ) + ) def __eq__(self, other): if not isinstance(other, FixedWindowLTRMultiplier): @@ -252,7 +272,15 @@ class WindowBoothMultiplier(AccumulatorMultiplier, ScalarMultiplier): self.precompute_negation = precompute_negation def __hash__(self): - return hash((WindowBoothMultiplier, super().__hash__(), self.width, self.precompute_negation, self.accumulation_order)) + return hash( + ( + WindowBoothMultiplier, + super().__hash__(), + self.width, + self.precompute_negation, + self.accumulation_order, + ) + ) def __eq__(self, other): if not isinstance(other, WindowBoothMultiplier): |
