aboutsummaryrefslogtreecommitdiff
path: root/pyecsca
diff options
context:
space:
mode:
Diffstat (limited to 'pyecsca')
-rw-r--r--pyecsca/ec/coordinates.py3
-rw-r--r--pyecsca/ec/formula.py6
-rw-r--r--pyecsca/ec/key_agreement.py34
-rw-r--r--pyecsca/ec/model.py3
-rw-r--r--pyecsca/ec/mult.py163
-rw-r--r--pyecsca/ec/op.py10
-rw-r--r--pyecsca/ec/point.py3
-rw-r--r--pyecsca/ec/signature.py64
8 files changed, 151 insertions, 135 deletions
diff --git a/pyecsca/ec/coordinates.py b/pyecsca/ec/coordinates.py
index 585fb28..285e54b 100644
--- a/pyecsca/ec/coordinates.py
+++ b/pyecsca/ec/coordinates.py
@@ -100,3 +100,6 @@ class EFDCoordinateModel(CoordinateModel):
if not isinstance(other, EFDCoordinateModel):
return False
return self.curve_model == other.curve_model and self.name == other.name
+
+ def __hash__(self):
+ return hash(self.curve_model) + hash(self.name)
diff --git a/pyecsca/ec/formula.py b/pyecsca/ec/formula.py
index 5f4c7cb..6c9feba 100644
--- a/pyecsca/ec/formula.py
+++ b/pyecsca/ec/formula.py
@@ -5,7 +5,7 @@ from itertools import product
from pkg_resources import resource_stream
from public import public
-from .op import Op, CodeOp
+from .op import CodeOp
class Formula(object):
@@ -15,7 +15,7 @@ class Formula(object):
meta: MutableMapping[str, Any]
parameters: List[str]
assumptions: List[Expression]
- code: List[Op]
+ code: List[CodeOp]
num_inputs: ClassVar[int]
num_outputs: ClassVar[int]
@@ -95,6 +95,8 @@ class EFDFormula(Formula):
return False
return self.name == other.name and self.coordinate_model == other.coordinate_model
+ def __hash__(self):
+ return hash(self.name) + hash(self.coordinate_model)
@public
class AdditionFormula(Formula):
diff --git a/pyecsca/ec/key_agreement.py b/pyecsca/ec/key_agreement.py
index 018b177..4b9a99e 100644
--- a/pyecsca/ec/key_agreement.py
+++ b/pyecsca/ec/key_agreement.py
@@ -3,6 +3,7 @@ from typing import Optional, Any
from public import public
+from .group import AbelianGroup
from .mult import ScalarMultiplier
from .point import Point
@@ -11,16 +12,19 @@ from .point import Point
class KeyAgreement(object):
"""An EC based key agreement primitive. (ECDH)"""
mult: ScalarMultiplier
+ group: AbelianGroup
pubkey: Point
privkey: int
hash_algo: Optional[Any]
- def __init__(self, mult: ScalarMultiplier, pubkey: Point, privkey: int,
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int,
hash_algo: Optional[Any] = None):
self.mult = mult
+ self.group = group
self.pubkey = pubkey
self.privkey = privkey
self.hash_algo = hash_algo
+ self.mult.init(self.group, self.pubkey)
def perform_raw(self) -> Point:
"""
@@ -28,7 +32,7 @@ class KeyAgreement(object):
:return: The shared point.
"""
- point = self.mult.multiply(self.privkey, self.pubkey)
+ point = self.mult.multiply(self.privkey)
return point.to_affine() # TODO: This conversion should be somehow added to the context
def perform(self) -> bytes:
@@ -39,7 +43,7 @@ class KeyAgreement(object):
"""
affine_point = self.perform_raw()
x = int(affine_point.x)
- p = self.mult.group.curve.prime
+ p = self.group.curve.prime
n = (p.bit_length() + 7) // 8
result = x.to_bytes(n, byteorder="big")
if self.hash_algo is not None:
@@ -51,45 +55,45 @@ class KeyAgreement(object):
class ECDH_NONE(KeyAgreement):
"""Raw x-coordinate ECDH."""
- def __init__(self, mult: ScalarMultiplier, pubkey: Point, privkey: int):
- super().__init__(mult, pubkey, privkey)
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ super().__init__(mult, group, pubkey, privkey)
@public
class ECDH_SHA1(KeyAgreement):
"""ECDH with SHA1 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, pubkey: Point, privkey: int):
- super().__init__(mult, pubkey, privkey, hashlib.sha1)
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ super().__init__(mult, group, pubkey, privkey, hashlib.sha1)
@public
class ECDH_SHA224(KeyAgreement):
"""ECDH with SHA224 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, pubkey: Point, privkey: int):
- super().__init__(mult, pubkey, privkey, hashlib.sha224)
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ super().__init__(mult, group, pubkey, privkey, hashlib.sha224)
@public
class ECDH_SHA256(KeyAgreement):
"""ECDH with SHA256 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, pubkey: Point, privkey: int):
- super().__init__(mult, pubkey, privkey, hashlib.sha256)
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ super().__init__(mult, group, pubkey, privkey, hashlib.sha256)
@public
class ECDH_SHA384(KeyAgreement):
"""ECDH with SHA384 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, pubkey: Point, privkey: int):
- super().__init__(mult, pubkey, privkey, hashlib.sha384)
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ super().__init__(mult, group, pubkey, privkey, hashlib.sha384)
@public
class ECDH_SHA512(KeyAgreement):
"""ECDH with SHA512 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, pubkey: Point, privkey: int):
- super().__init__(mult, pubkey, privkey, hashlib.sha512)
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ super().__init__(mult, group, pubkey, privkey, hashlib.sha512)
diff --git a/pyecsca/ec/model.py b/pyecsca/ec/model.py
index 6e79c9b..c8a9b46 100644
--- a/pyecsca/ec/model.py
+++ b/pyecsca/ec/model.py
@@ -94,6 +94,9 @@ class EFDCurveModel(CurveModel):
return False
return self._efd_name == other._efd_name
+ def __hash__(self):
+ return hash(self._efd_name) + 1
+
def __repr__(self):
return f"{self.__class__.__name__}()"
diff --git a/pyecsca/ec/mult.py b/pyecsca/ec/mult.py
index ab6cf7b..c766ff0 100644
--- a/pyecsca/ec/mult.py
+++ b/pyecsca/ec/mult.py
@@ -12,73 +12,79 @@ from .point import Point
class ScalarMultiplier(object):
- group: AbelianGroup
+ """
+ A scalar multiplication algorithm.
+
+ :param short_circuit: Whether the use of formulas will be guarded by short-circuit on inputs
+ of the point at infinity.
+ :param formulas: Formulas this instance will use.
+ """
+ short_circuit: bool
formulas: Mapping[str, Formula]
+ _group: AbelianGroup
_point: Point = None
- def __init__(self, group: AbelianGroup, **formulas: Optional[Formula]):
- for formula in formulas.values():
- if formula is not None and formula.coordinate_model is not group.curve.coordinate_model:
- raise ValueError
- self.group = group
+ def __init__(self, short_circuit=True, **formulas: Optional[Formula]):
+ if len(set(formula.coordinate_model for formula in formulas.values() if
+ formula is not None)) != 1:
+ raise ValueError
+ self.short_circuit = short_circuit
self.formulas = dict(filter(lambda pair: pair[1] is not None, formulas.items()))
def _add(self, one: Point, other: Point) -> Point:
if "add" not in self.formulas:
raise NotImplementedError
- if one == self.group.neutral:
- return copy(other)
- if other == self.group.neutral:
- return copy(one)
+ if self.short_circuit:
+ if one == self._group.neutral:
+ return copy(other)
+ if other == self._group.neutral:
+ return copy(one)
return \
- getcontext().execute(self.formulas["add"], one, other, **self.group.curve.parameters)[0]
+ getcontext().execute(self.formulas["add"], one, other, **self._group.curve.parameters)[0]
def _dbl(self, point: Point) -> Point:
if "dbl" not in self.formulas:
raise NotImplementedError
- if point == self.group.neutral:
- return copy(point)
- return getcontext().execute(self.formulas["dbl"], point, **self.group.curve.parameters)[0]
+ if self.short_circuit:
+ if point == self._group.neutral:
+ return copy(point)
+ return getcontext().execute(self.formulas["dbl"], point, **self._group.curve.parameters)[0]
def _scl(self, point: Point) -> Point:
if "scl" not in self.formulas:
raise NotImplementedError
- return getcontext().execute(self.formulas["scl"], point, **self.group.curve.parameters)[0]
+ return getcontext().execute(self.formulas["scl"], point, **self._group.curve.parameters)[0]
def _ladd(self, start: Point, to_dbl: Point, to_add: Point) -> Tuple[Point, ...]:
if "ladd" not in self.formulas:
raise NotImplementedError
return getcontext().execute(self.formulas["ladd"], start, to_dbl, to_add,
- **self.group.curve.parameters)
+ **self._group.curve.parameters)
def _dadd(self, start: Point, one: Point, other: Point) -> Point:
if "dadd" not in self.formulas:
raise NotImplementedError
- if one == self.group.neutral:
- return copy(other)
- if other == self.group.neutral:
- return copy(one)
+ if self.short_circuit:
+ if one == self._group.neutral:
+ return copy(other)
+ if other == self._group.neutral:
+ return copy(one)
return getcontext().execute(self.formulas["dadd"], start, one, other,
- **self.group.curve.parameters)[0]
+ **self._group.curve.parameters)[0]
def _neg(self, point: Point) -> Point:
if "neg" not in self.formulas:
raise NotImplementedError
- return getcontext().execute(self.formulas["neg"], point, **self.group.curve.parameters)[0]
+ return getcontext().execute(self.formulas["neg"], point, **self._group.curve.parameters)[0]
- def init(self, point: Point):
+ def init(self, group: AbelianGroup, point: Point):
+ coord_model = set(self.formulas.values()).pop().coordinate_model
+ if group.curve.coordinate_model != coord_model or point.coordinate_model != coord_model:
+ raise ValueError
+ self._group = group
self._point = point
- def _init_multiply(self, point: Optional[Point]) -> Point:
- if point is None:
- if self._point is None:
- raise ValueError
- else:
- if self._point != point:
- self.init(point)
- return self._point
-
- def multiply(self, scalar: int, point: Optional[Point] = None) -> Point:
+ def multiply(self, scalar: int) -> Point:
raise NotImplementedError
@@ -91,16 +97,16 @@ class LTRMultiplier(ScalarMultiplier):
"""
always: bool
- def __init__(self, group: AbelianGroup, add: AdditionFormula, dbl: DoublingFormula,
+ def __init__(self, add: AdditionFormula, dbl: DoublingFormula,
scl: ScalingFormula = None, always: bool = False):
- super().__init__(group, add=add, dbl=dbl, scl=scl)
+ super().__init__(add=add, dbl=dbl, scl=scl)
self.always = always
- def multiply(self, scalar: int, point: Optional[Point] = None) -> Point:
+ def multiply(self, scalar: int) -> Point:
if scalar == 0:
- return copy(self.group.neutral)
- q = self._init_multiply(point)
- r = copy(self.group.neutral)
+ return copy(self._group.neutral)
+ q = self._point
+ r = copy(self._group.neutral)
for i in range(scalar.bit_length() - 1, -1, -1):
r = self._dbl(r)
if scalar & (1 << i) != 0:
@@ -121,16 +127,16 @@ class RTLMultiplier(ScalarMultiplier):
"""
always: bool
- def __init__(self, group: AbelianGroup, add: AdditionFormula, dbl: DoublingFormula,
+ def __init__(self, add: AdditionFormula, dbl: DoublingFormula,
scl: ScalingFormula = None, always: bool = False):
- super().__init__(group, add=add, dbl=dbl, scl=scl)
+ super().__init__(add=add, dbl=dbl, scl=scl)
self.always = always
- def multiply(self, scalar: int, point: Optional[Point] = None) -> Point:
+ def multiply(self, scalar: int) -> Point:
if scalar == 0:
- return copy(self.group.neutral)
- q = self._init_multiply(point)
- r = copy(self.group.neutral)
+ return copy(self._group.neutral)
+ q = self._point
+ r = copy(self._group.neutral)
while scalar > 0:
if scalar & 1 != 0:
r = self._add(r, q)
@@ -152,14 +158,13 @@ class CoronMultiplier(ScalarMultiplier):
https://link.springer.com/content/pdf/10.1007/3-540-48059-5_25.pdf
"""
- def __init__(self, group: AbelianGroup, add: AdditionFormula, dbl: DoublingFormula,
- scl: ScalingFormula = None):
- super().__init__(group, add=add, dbl=dbl, scl=scl)
+ def __init__(self, add: AdditionFormula, dbl: DoublingFormula, scl: ScalingFormula = None):
+ super().__init__(add=add, dbl=dbl, scl=scl)
- def multiply(self, scalar: int, point: Optional[Point] = None):
+ def multiply(self, scalar: int) -> Point:
if scalar == 0:
- return copy(self.group.neutral)
- q = self._init_multiply(point)
+ return copy(self._group.neutral)
+ q = self._point
p0 = copy(q)
for i in range(scalar.bit_length() - 2, -1, -1):
p0 = self._dbl(p0)
@@ -177,14 +182,13 @@ class LadderMultiplier(ScalarMultiplier):
Montgomery ladder multiplier, using a three input, two output ladder formula.
"""
- def __init__(self, group: AbelianGroup, ladd: LadderFormula, dbl: DoublingFormula,
- scl: ScalingFormula = None):
- super().__init__(group, ladd=ladd, dbl=dbl, scl=scl)
+ def __init__(self, ladd: LadderFormula, dbl: DoublingFormula, scl: ScalingFormula = None):
+ super().__init__(ladd=ladd, dbl=dbl, scl=scl)
- def multiply(self, scalar: int, point: Optional[Point] = None) -> Point:
+ def multiply(self, scalar: int) -> Point:
if scalar == 0:
- return copy(self.group.neutral)
- q = self._init_multiply(point)
+ return copy(self._group.neutral)
+ q = self._point
p0 = copy(q)
p1 = self._dbl(q)
for i in range(scalar.bit_length() - 2, -1, -1):
@@ -204,22 +208,21 @@ class SimpleLadderMultiplier(ScalarMultiplier):
"""
_differential: bool = False
- def __init__(self, group: AbelianGroup,
- add: Union[AdditionFormula, DifferentialAdditionFormula], dbl: DoublingFormula,
+ def __init__(self, add: Union[AdditionFormula, DifferentialAdditionFormula], dbl: DoublingFormula,
scl: ScalingFormula = None):
if isinstance(add, AdditionFormula):
- super().__init__(group, add=add, dbl=dbl, scl=scl)
+ super().__init__(add=add, dbl=dbl, scl=scl)
elif isinstance(add, DifferentialAdditionFormula):
- super().__init__(group, dadd=add, dbl=dbl, scl=scl)
+ super().__init__(dadd=add, dbl=dbl, scl=scl)
self._differential = True
else:
raise ValueError
- def multiply(self, scalar: int, point: Optional[Point] = None) -> Point:
+ def multiply(self, scalar: int) -> Point:
if scalar == 0:
- return copy(self.group.neutral)
- q = self._init_multiply(point)
- p0 = copy(self.group.neutral)
+ return copy(self._group.neutral)
+ q = self._point
+ p0 = copy(self._group.neutral)
p1 = copy(q)
for i in range(scalar.bit_length() - 1, -1, -1):
if scalar & (1 << i) == 0:
@@ -246,20 +249,19 @@ class BinaryNAFMultiplier(ScalarMultiplier):
"""
_point_neg: Point
- def __init__(self, group: AbelianGroup, add: AdditionFormula, dbl: DoublingFormula,
+ def __init__(self, add: AdditionFormula, dbl: DoublingFormula,
neg: NegationFormula, scl: ScalingFormula = None):
- super().__init__(group, add=add, dbl=dbl, neg=neg, scl=scl)
+ super().__init__(add=add, dbl=dbl, neg=neg, scl=scl)
- def init(self, point: Point):
- super().init(point)
+ def init(self, group: AbelianGroup, point: Point):
+ super().init(group, point)
self._point_neg = self._neg(point)
- def multiply(self, scalar: int, point: Optional[Point] = None) -> Point:
+ def multiply(self, scalar: int) -> Point:
if scalar == 0:
- return copy(self.group.neutral)
- self._init_multiply(point)
+ return copy(self._group.neutral)
bnaf = naf(scalar)
- q = copy(self.group.neutral)
+ q = copy(self._group.neutral)
for val in bnaf:
q = self._dbl(q)
if val == 1:
@@ -281,15 +283,15 @@ class WindowNAFMultiplier(ScalarMultiplier):
_precompute_neg: bool = False
_width: int
- def __init__(self, group: AbelianGroup, add: AdditionFormula, dbl: DoublingFormula,
+ def __init__(self, add: AdditionFormula, dbl: DoublingFormula,
neg: NegationFormula, width: int, scl: ScalingFormula = None,
precompute_negation: bool = False):
- super().__init__(group, add=add, dbl=dbl, neg=neg, scl=scl)
+ super().__init__(add=add, dbl=dbl, neg=neg, scl=scl)
self._width = width
self._precompute_neg = precompute_negation
- def init(self, point: Point):
- self._point = point
+ def init(self, group: AbelianGroup, point: Point):
+ super().init(group, point)
self._points = {}
self._points_neg = {}
current_point = point
@@ -300,12 +302,11 @@ class WindowNAFMultiplier(ScalarMultiplier):
self._points_neg[2 ** i - 1] = self._neg(current_point)
current_point = self._add(current_point, double_point)
- def multiply(self, scalar: int, point: Optional[Point] = None):
+ def multiply(self, scalar: int) -> Point:
if scalar == 0:
- return copy(self.group.neutral)
- self._init_multiply(point)
+ return copy(self._group.neutral)
naf = wnaf(scalar, self._width)
- q = copy(self.group.neutral)
+ q = copy(self._group.neutral)
for val in naf:
q = self._dbl(q)
if val > 0:
diff --git a/pyecsca/ec/op.py b/pyecsca/ec/op.py
index 11c3079..cb186e1 100644
--- a/pyecsca/ec/op.py
+++ b/pyecsca/ec/op.py
@@ -5,17 +5,10 @@ from typing import FrozenSet, Optional
from .mod import Mod
-class Op(object):
+class CodeOp(object):
result: str
parameters: FrozenSet[str]
variables: FrozenSet[str]
-
- def __call__(self, *args, **kwargs: Mod) -> Mod:
- """Execute this operation with kwargs."""
- raise NotImplementedError
-
-
-class CodeOp(Op):
code: Module
operator: Optional[operator]
compiled: CodeType
@@ -75,6 +68,7 @@ class CodeOp(Op):
return f"CodeOp({self.result} = f(params={self.parameters}, vars={self.variables}, consts={self.constants}))"
def __call__(self, *args, **kwargs: Mod) -> Mod:
+ """Execute this operation with kwargs."""
loc = dict(kwargs)
exec(self.compiled, {}, loc)
return loc[self.result]
diff --git a/pyecsca/ec/point.py b/pyecsca/ec/point.py
index 3b0b970..368dd0d 100644
--- a/pyecsca/ec/point.py
+++ b/pyecsca/ec/point.py
@@ -83,6 +83,9 @@ class Point(object):
return False
return self.coords == other.coords
+ def __hash__(self):
+ return hash(self.coords) + 1
+
def __str__(self):
args = ", ".join([f"{key}={val}" for key, val in self.coords.items()])
return f"[{args}]"
diff --git a/pyecsca/ec/signature.py b/pyecsca/ec/signature.py
index dbfb30d..8c8630b 100644
--- a/pyecsca/ec/signature.py
+++ b/pyecsca/ec/signature.py
@@ -7,6 +7,7 @@ from public import public
from .context import getcontext
from .formula import AdditionFormula
+from .group import AbelianGroup
from .mod import Mod
from .mult import ScalarMultiplier
from .point import Point
@@ -53,12 +54,13 @@ class SignatureResult(object):
class Signature(object):
"""An EC based signature primitive. (ECDSA)"""
mult: ScalarMultiplier
+ group: AbelianGroup
add: Optional[AdditionFormula]
pubkey: Optional[Point]
privkey: Optional[int]
hash_algo: Optional[Any]
- def __init__(self, mult: ScalarMultiplier, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None,
hash_algo: Optional[Any] = None):
if pubkey is None and privkey is None:
@@ -69,6 +71,7 @@ class Signature(object):
else:
add = mult.formulas["add"]
self.mult = mult
+ self.group = group
self.add = add
self.pubkey = pubkey
self.privkey = privkey
@@ -86,18 +89,19 @@ class Signature(object):
def _get_nonce(self, nonce: Optional[int]) -> Mod:
if nonce is None:
- return Mod(secrets.randbelow(self.mult.group.order), self.mult.group.order)
+ return Mod(secrets.randbelow(self.group.order), self.group.order)
else:
- return Mod(nonce, self.mult.group.order)
+ return Mod(nonce, self.group.order)
def _do_sign(self, nonce: Mod, digest: bytes) -> SignatureResult:
z = int.from_bytes(digest, byteorder="big")
- if len(digest) * 8 > self.mult.group.order.bit_length():
- z >>= len(digest) * 8 - self.mult.group.order.bit_length()
- point = self.mult.multiply(int(nonce), self.mult.group.generator)
+ if len(digest) * 8 > self.group.order.bit_length():
+ z >>= len(digest) * 8 - self.group.order.bit_length()
+ self.mult.init(self.group, self.group.generator)
+ point = self.mult.multiply(int(nonce))
affine_point = point.to_affine() #  TODO: add to context
- r = Mod(int(affine_point.x), self.mult.group.order)
- s = nonce.inverse() * (Mod(z, self.mult.group.order) + r * self.privkey)
+ r = Mod(int(affine_point.x), self.group.order)
+ s = nonce.inverse() * (Mod(z, self.group.order) + r * self.privkey)
return SignatureResult(int(r), int(s), digest=digest, nonce=int(nonce),
privkey=self.privkey)
@@ -121,16 +125,18 @@ class Signature(object):
def _do_verify(self, signature: SignatureResult, digest: bytes) -> bool:
z = int.from_bytes(digest, byteorder="big")
- if len(digest) * 8 > self.mult.group.order.bit_length():
- z >>= len(digest) * 8 - self.mult.group.order.bit_length()
- c = Mod(signature.s, self.mult.group.order).inverse()
- u1 = Mod(z, self.mult.group.order) * c
- u2 = Mod(signature.r, self.mult.group.order) * c
- p1 = self.mult.multiply(int(u1), self.mult.group.generator)
- p2 = self.mult.multiply(int(u2), self.pubkey)
- p = getcontext().execute(self.add, p1, p2, **self.mult.group.curve.parameters)[0]
+ if len(digest) * 8 > self.group.order.bit_length():
+ z >>= len(digest) * 8 - self.group.order.bit_length()
+ c = Mod(signature.s, self.group.order).inverse()
+ u1 = Mod(z, self.group.order) * c
+ u2 = Mod(signature.r, self.group.order) * c
+ self.mult.init(self.group, self.group.generator)
+ p1 = self.mult.multiply(int(u1))
+ self.mult.init(self.group, self.pubkey)
+ p2 = self.mult.multiply(int(u2))
+ p = getcontext().execute(self.add, p1, p2, **self.group.curve.parameters)[0]
affine = p.to_affine() # TODO: add to context
- v = Mod(int(affine.x), self.mult.group.order)
+ v = Mod(int(affine.x), self.group.order)
return signature.r == int(v)
def verify_hash(self, signature: SignatureResult, digest: bytes) -> bool:
@@ -154,51 +160,51 @@ class Signature(object):
class ECDSA_NONE(Signature):
"""ECDSA with raw message input."""
- def __init__(self, mult: ScalarMultiplier, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
- super().__init__(mult, add, pubkey, privkey)
+ super().__init__(mult, group, add, pubkey, privkey)
@public
class ECDSA_SHA1(Signature):
"""ECDSA with SHA1."""
- def __init__(self, mult: ScalarMultiplier, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
- super().__init__(mult, add, pubkey, privkey, hashlib.sha1)
+ super().__init__(mult, group, add, pubkey, privkey, hashlib.sha1)
@public
class ECDSA_SHA224(Signature):
"""ECDSA with SHA224."""
- def __init__(self, mult: ScalarMultiplier, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
- super().__init__(mult, add, pubkey, privkey, hashlib.sha224)
+ super().__init__(mult, group, add, pubkey, privkey, hashlib.sha224)
@public
class ECDSA_SHA256(Signature):
"""ECDSA with SHA256."""
- def __init__(self, mult: ScalarMultiplier, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
- super().__init__(mult, add, pubkey, privkey, hashlib.sha256)
+ super().__init__(mult, group, add, pubkey, privkey, hashlib.sha256)
@public
class ECDSA_SHA384(Signature):
"""ECDSA with SHA384."""
- def __init__(self, mult: ScalarMultiplier, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
- super().__init__(mult, add, pubkey, privkey, hashlib.sha384)
+ super().__init__(mult, group, add, pubkey, privkey, hashlib.sha384)
@public
class ECDSA_SHA512(Signature):
"""ECDSA with SHA512."""
- def __init__(self, mult: ScalarMultiplier, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
- super().__init__(mult, add, pubkey, privkey, hashlib.sha512)
+ super().__init__(mult, group, add, pubkey, privkey, hashlib.sha512)