aboutsummaryrefslogtreecommitdiff
path: root/pyecsca/ec/mult/ladder.py
diff options
context:
space:
mode:
authorJ08nY2024-08-28 14:33:04 +0200
committerJ08nY2024-08-28 14:33:04 +0200
commit57b68a73b1c49b6eeb5b668bff4efb5ac1aef881 (patch)
treef01704e1277a2e7da27edb050d313e294e5c2ab6 /pyecsca/ec/mult/ladder.py
parent979d86979313de02c4dab71f99ce1c5dddd5877a (diff)
downloadpyecsca-57b68a73b1c49b6eeb5b668bff4efb5ac1aef881.tar.gz
pyecsca-57b68a73b1c49b6eeb5b668bff4efb5ac1aef881.tar.zst
pyecsca-57b68a73b1c49b6eeb5b668bff4efb5ac1aef881.zip
Diffstat (limited to 'pyecsca/ec/mult/ladder.py')
-rw-r--r--pyecsca/ec/mult/ladder.py94
1 files changed, 0 insertions, 94 deletions
diff --git a/pyecsca/ec/mult/ladder.py b/pyecsca/ec/mult/ladder.py
index 9f31b7f..3c141cd 100644
--- a/pyecsca/ec/mult/ladder.py
+++ b/pyecsca/ec/mult/ladder.py
@@ -107,100 +107,6 @@ class LadderMultiplier(ScalarMultiplier):
@public
-class SwapLadderMultiplier(ScalarMultiplier):
- """
- Montgomery ladder multiplier, using a three input, two output ladder formula.
-
- Optionally takes a doubling formula, and if `complete` is false, it requires one.
-
- :param short_circuit: Whether the use of formulas will be guarded by short-circuit on inputs
- of the point at infinity.
- :param complete: Whether it starts processing at full order-bit-length.
- :param full: Whether it start processing at top bit of the scalar.
- """
-
- requires = {LadderFormula}
- optionals = {DoublingFormula, ScalingFormula}
- complete: bool
- """Whether it starts processing at full order-bit-length."""
- full: bool
- """Whether it start processing at top bit of the scalar."""
-
- def __init__(
- self,
- ladd: LadderFormula,
- dbl: Optional[DoublingFormula] = None,
- scl: Optional[ScalingFormula] = None,
- complete: bool = True,
- short_circuit: bool = True,
- full: bool = False,
- ):
- super().__init__(short_circuit=short_circuit, ladd=ladd, dbl=dbl, scl=scl)
- self.complete = complete
- self.full = full
-
- if complete and full:
- raise ValueError("Only one of `complete` and `full` can be set.")
-
- if dbl is None:
- if short_circuit:
- raise ValueError(
- "When `short_circuit` is set SwapLadderMultiplier requires a doubling formula."
- )
- if not (complete or full):
- raise ValueError(
- "When neither `complete` nor `full` is not set SwapLadderMultiplier requires a doubling formula."
- )
-
- def __hash__(self):
- return hash((SwapLadderMultiplier, super().__hash__(), self.complete, self.full))
-
- def __eq__(self, other):
- if not isinstance(other, SwapLadderMultiplier):
- return False
- return (
- self.formulas == other.formulas
- and self.short_circuit == other.short_circuit
- and self.complete == other.complete
- and self.full == other.full
- )
-
- def __repr__(self):
- return f"{self.__class__.__name__}({', '.join(map(str, self.formulas.values()))}, short_circuit={self.short_circuit}, complete={self.complete}, full={self.full})"
-
- def multiply(self, scalar: int) -> Point:
- if not self._initialized:
- raise ValueError("ScalarMultiplier not initialized.")
- with ScalarMultiplicationAction(self._point, self._params, scalar) as action:
- if scalar == 0:
- return action.exit(copy(self._params.curve.neutral))
- q = self._point
- if self.complete:
- p0 = copy(self._params.curve.neutral)
- p1 = self._point
- top = self._params.full_order.bit_length() - 1
- elif self.full:
- p0 = copy(self._params.curve.neutral)
- p1 = self._point
- top = scalar.bit_length() - 1
- else:
- p0 = copy(q)
- p1 = self._dbl(q)
- top = scalar.bit_length() - 2
- prev_bit = 0
- for i in range(top, -1, -1):
- k = (scalar & (1 << i)) >> i
- swap = prev_bit ^ k
- prev_bit = k
- p0, p1 = (p1, p0) if swap else (p0, p1)
- p0, p1 = self._ladd(q, p0, p1)
- p0, p1 = (p1, p0) if prev_bit else (p0, p1)
- if "scl" in self.formulas:
- p0 = self._scl(p0)
- return action.exit(p0)
-
-
-@public
class SimpleLadderMultiplier(ScalarMultiplier):
"""
Montgomery ladder multiplier, using addition and doubling formulas.