aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJ08nY2020-02-10 00:02:42 +0100
committerJ08nY2020-02-10 00:02:42 +0100
commit75805f4c8b7521bb031024e1576c8c6b2d2099cf (patch)
tree312cdaef4442ff6060bf96e715df458c23a935ae
parent0d2311a18fd03c0d17393cf4cc92b05a2b8b4e45 (diff)
downloadpyecsca-75805f4c8b7521bb031024e1576c8c6b2d2099cf.tar.gz
pyecsca-75805f4c8b7521bb031024e1576c8c6b2d2099cf.tar.bz2
pyecsca-75805f4c8b7521bb031024e1576c8c6b2d2099cf.zip
Rename AbelianGroup to DomainParameters.
-rw-r--r--.travis.yml2
-rw-r--r--Makefile2
-rw-r--r--pyecsca/ec/curves.py22
-rw-r--r--pyecsca/ec/key_agreement.py18
-rw-r--r--pyecsca/ec/mult.py10
-rw-r--r--pyecsca/ec/params.py (renamed from pyecsca/ec/group.py)4
-rw-r--r--pyecsca/ec/signature.py18
-rw-r--r--pyecsca/sca/scope/__init__.py6
-rw-r--r--pyecsca/sca/target/__init__.py4
-rw-r--r--test/ec/test_params.py (renamed from test/ec/test_group.py)2
10 files changed, 44 insertions, 44 deletions
diff --git a/.travis.yml b/.travis.yml
index 3056665..a65f1a1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -26,7 +26,7 @@ before_install:
install:
- pip install codecov
- - pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, test, dev]"
+ - pip install -e ".[picoscope_sdk, picoscope_alt, chipwhisperer, smartcard, test, dev]"
script:
- make -i typecheck
diff --git a/Makefile b/Makefile
index e8609e3..691556c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-EC_TESTS = ec.test_context ec.test_curve ec.test_group ec.test_key_agreement ec.test_mod ec.test_model \
+EC_TESTS = ec.test_context ec.test_curve ec.test_params ec.test_key_agreement ec.test_mod ec.test_model \
ec.test_mult ec.test_naf ec.test_op ec.test_point ec.test_signature
SCA_TESTS = sca.test_align sca.test_combine sca.test_edit sca.test_filter sca.test_match sca.test_process \
diff --git a/pyecsca/ec/curves.py b/pyecsca/ec/curves.py
index 7fcfcbd..496edf2 100644
--- a/pyecsca/ec/curves.py
+++ b/pyecsca/ec/curves.py
@@ -1,13 +1,13 @@
from public import public
from typing import Mapping, Any
-from pyecsca.ec.coordinates import AffineCoordinateModel
-from pyecsca.ec.curve import EllipticCurve
-from pyecsca.ec.group import AbelianGroup
-from pyecsca.ec.mod import Mod
-from pyecsca.ec.model import (ShortWeierstrassModel, MontgomeryModel, TwistedEdwardsModel,
+from .coordinates import AffineCoordinateModel
+from .curve import EllipticCurve
+from .params import DomainParameters
+from .mod import Mod
+from .model import (ShortWeierstrassModel, MontgomeryModel, TwistedEdwardsModel,
EdwardsModel)
-from pyecsca.ec.point import Point, InfinityPoint
+from .point import Point, InfinityPoint
SHORT_WEIERSTRASS: Mapping[str, Mapping[str, Any]] = {
@@ -191,7 +191,7 @@ TWISTED_EDWARDS: Mapping[str, Mapping[str, Any]] = {
@public
-def get_curve(name: str, coords: str) -> AbelianGroup:
+def get_curve(name: str, coords: str) -> DomainParameters:
"""
Retrieve a curve from a set of stored parameters.
@@ -207,7 +207,7 @@ def get_curve(name: str, coords: str) -> AbelianGroup:
affine = Point(AffineCoordinateModel(model), x=Mod(params["g"][0], params["p"]),
y=Mod(params["g"][1], params["p"]))
generator = Point.from_affine(coord_model, affine)
- return AbelianGroup(curve, generator, InfinityPoint(coord_model), params["n"], params["h"])
+ return DomainParameters(curve, generator, InfinityPoint(coord_model), params["n"], params["h"])
elif name in MONTGOMERY:
params = MONTGOMERY[name]
model = MontgomeryModel()
@@ -215,7 +215,7 @@ def get_curve(name: str, coords: str) -> AbelianGroup:
curve = EllipticCurve(model, coord_model, params["p"], dict(a=params["a"], b=params["b"]))
generator = Point(coord_model, X=Mod(params["x"], params["p"]),
Z=Mod(params["z"], params["p"]))
- return AbelianGroup(curve, generator, InfinityPoint(coord_model), params["n"], params["h"])
+ return DomainParameters(curve, generator, InfinityPoint(coord_model), params["n"], params["h"])
elif name in TWISTED_EDWARDS:
params = TWISTED_EDWARDS[name]
model = TwistedEdwardsModel()
@@ -224,7 +224,7 @@ def get_curve(name: str, coords: str) -> AbelianGroup:
affine = Point(AffineCoordinateModel(model), x=Mod(params["g"][0], params["p"]),
y=Mod(params["g"][1], params["p"]))
generator = Point.from_affine(coord_model, affine)
- return AbelianGroup(curve, generator, InfinityPoint(coord_model), params["n"], params["h"])
+ return DomainParameters(curve, generator, InfinityPoint(coord_model), params["n"], params["h"])
elif name in EDWARDS:
params = EDWARDS[name]
model = EdwardsModel()
@@ -233,6 +233,6 @@ def get_curve(name: str, coords: str) -> AbelianGroup:
affine = Point(AffineCoordinateModel(model), x=Mod(params["g"][0], params["p"]),
y=Mod(params["g"][1], params["p"]))
generator = Point.from_affine(coord_model, affine)
- return AbelianGroup(curve, generator, InfinityPoint(coord_model), params["n"], params["h"])
+ return DomainParameters(curve, generator, InfinityPoint(coord_model), params["n"], params["h"])
else:
raise ValueError("Unknown curve: {}".format(name))
diff --git a/pyecsca/ec/key_agreement.py b/pyecsca/ec/key_agreement.py
index 4b9a99e..3071ffb 100644
--- a/pyecsca/ec/key_agreement.py
+++ b/pyecsca/ec/key_agreement.py
@@ -3,7 +3,7 @@ from typing import Optional, Any
from public import public
-from .group import AbelianGroup
+from .params import DomainParameters
from .mult import ScalarMultiplier
from .point import Point
@@ -12,12 +12,12 @@ from .point import Point
class KeyAgreement(object):
"""An EC based key agreement primitive. (ECDH)"""
mult: ScalarMultiplier
- group: AbelianGroup
+ group: DomainParameters
pubkey: Point
privkey: int
hash_algo: Optional[Any]
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int,
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, pubkey: Point, privkey: int,
hash_algo: Optional[Any] = None):
self.mult = mult
self.group = group
@@ -55,7 +55,7 @@ class KeyAgreement(object):
class ECDH_NONE(KeyAgreement):
"""Raw x-coordinate ECDH."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, pubkey: Point, privkey: int):
super().__init__(mult, group, pubkey, privkey)
@@ -63,7 +63,7 @@ class ECDH_NONE(KeyAgreement):
class ECDH_SHA1(KeyAgreement):
"""ECDH with SHA1 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, pubkey: Point, privkey: int):
super().__init__(mult, group, pubkey, privkey, hashlib.sha1)
@@ -71,7 +71,7 @@ class ECDH_SHA1(KeyAgreement):
class ECDH_SHA224(KeyAgreement):
"""ECDH with SHA224 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, pubkey: Point, privkey: int):
super().__init__(mult, group, pubkey, privkey, hashlib.sha224)
@@ -79,7 +79,7 @@ class ECDH_SHA224(KeyAgreement):
class ECDH_SHA256(KeyAgreement):
"""ECDH with SHA256 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, pubkey: Point, privkey: int):
super().__init__(mult, group, pubkey, privkey, hashlib.sha256)
@@ -87,7 +87,7 @@ class ECDH_SHA256(KeyAgreement):
class ECDH_SHA384(KeyAgreement):
"""ECDH with SHA384 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, pubkey: Point, privkey: int):
super().__init__(mult, group, pubkey, privkey, hashlib.sha384)
@@ -95,5 +95,5 @@ class ECDH_SHA384(KeyAgreement):
class ECDH_SHA512(KeyAgreement):
"""ECDH with SHA512 of x-coordinate."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, pubkey: Point, privkey: int):
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, pubkey: Point, privkey: int):
super().__init__(mult, group, pubkey, privkey, hashlib.sha512)
diff --git a/pyecsca/ec/mult.py b/pyecsca/ec/mult.py
index 5a76a18..4f937fa 100644
--- a/pyecsca/ec/mult.py
+++ b/pyecsca/ec/mult.py
@@ -6,7 +6,7 @@ from public import public
from .context import getcontext
from .formula import (Formula, AdditionFormula, DoublingFormula, DifferentialAdditionFormula,
ScalingFormula, LadderFormula, NegationFormula)
-from .group import AbelianGroup
+from .params import DomainParameters
from .naf import naf, wnaf
from .point import Point
@@ -23,7 +23,7 @@ class ScalarMultiplier(object):
optionals: ClassVar[Set[Type[Formula]]]
short_circuit: bool
formulas: Mapping[str, Formula]
- _group: AbelianGroup
+ _group: DomainParameters
_point: Point
_initialized: bool = False
@@ -86,7 +86,7 @@ class ScalarMultiplier(object):
raise NotImplementedError
return getcontext().execute(self.formulas["neg"], point, **self._group.curve.parameters)[0]
- def init(self, group: AbelianGroup, point: Point):
+ def init(self, group: DomainParameters, point: Point):
"""Initialize the scalar multiplier with a group and a point."""
coord_model = set(self.formulas.values()).pop().coordinate_model
if group.curve.coordinate_model != coord_model or point.coordinate_model != coord_model:
@@ -336,7 +336,7 @@ class BinaryNAFMultiplier(ScalarMultiplier):
neg: NegationFormula, scl: ScalingFormula = None, short_circuit: bool = True):
super().__init__(short_circuit=short_circuit, add=add, dbl=dbl, neg=neg, scl=scl)
- def init(self, group: AbelianGroup, point: Point):
+ def init(self, group: DomainParameters, point: Point):
super().init(group, point)
self._point_neg = self._neg(point)
@@ -375,7 +375,7 @@ class WindowNAFMultiplier(ScalarMultiplier):
self.width = width
self.precompute_negation = precompute_negation
- def init(self, group: AbelianGroup, point: Point):
+ def init(self, group: DomainParameters, point: Point):
super().init(group, point)
self._points = {}
self._points_neg = {}
diff --git a/pyecsca/ec/group.py b/pyecsca/ec/params.py
index 6d8694d..374c327 100644
--- a/pyecsca/ec/group.py
+++ b/pyecsca/ec/params.py
@@ -5,7 +5,7 @@ from .point import Point
@public
-class AbelianGroup(object):
+class DomainParameters(object):
"""A (sub)group of an elliptic curve."""
curve: EllipticCurve
generator: Point
@@ -25,6 +25,6 @@ class AbelianGroup(object):
return self.neutral == point
def __eq__(self, other):
- if not isinstance(other, AbelianGroup):
+ if not isinstance(other, DomainParameters):
return False
return self.curve == other.curve and self.generator == other.generator and self.neutral == other.neutral and self.order == other.order and self.cofactor == other.cofactor
diff --git a/pyecsca/ec/signature.py b/pyecsca/ec/signature.py
index 1c239b5..90ed9fb 100644
--- a/pyecsca/ec/signature.py
+++ b/pyecsca/ec/signature.py
@@ -7,7 +7,7 @@ from public import public
from .context import getcontext
from .formula import AdditionFormula
-from .group import AbelianGroup
+from .params import DomainParameters
from .mod import Mod
from .mult import ScalarMultiplier
from .point import Point
@@ -54,13 +54,13 @@ class SignatureResult(object):
class Signature(object):
"""An EC based signature primitive. (ECDSA)"""
mult: ScalarMultiplier
- group: AbelianGroup
+ group: DomainParameters
add: Optional[AdditionFormula]
pubkey: Optional[Point]
privkey: Optional[int]
hash_algo: Optional[Any]
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, 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:
@@ -162,7 +162,7 @@ class Signature(object):
class ECDSA_NONE(Signature):
"""ECDSA with raw message input."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
super().__init__(mult, group, add, pubkey, privkey)
@@ -171,7 +171,7 @@ class ECDSA_NONE(Signature):
class ECDSA_SHA1(Signature):
"""ECDSA with SHA1."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
super().__init__(mult, group, add, pubkey, privkey, hashlib.sha1)
@@ -180,7 +180,7 @@ class ECDSA_SHA1(Signature):
class ECDSA_SHA224(Signature):
"""ECDSA with SHA224."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
super().__init__(mult, group, add, pubkey, privkey, hashlib.sha224)
@@ -189,7 +189,7 @@ class ECDSA_SHA224(Signature):
class ECDSA_SHA256(Signature):
"""ECDSA with SHA256."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
super().__init__(mult, group, add, pubkey, privkey, hashlib.sha256)
@@ -198,7 +198,7 @@ class ECDSA_SHA256(Signature):
class ECDSA_SHA384(Signature):
"""ECDSA with SHA384."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
super().__init__(mult, group, add, pubkey, privkey, hashlib.sha384)
@@ -207,6 +207,6 @@ class ECDSA_SHA384(Signature):
class ECDSA_SHA512(Signature):
"""ECDSA with SHA512."""
- def __init__(self, mult: ScalarMultiplier, group: AbelianGroup, add: Optional[AdditionFormula] = None,
+ def __init__(self, mult: ScalarMultiplier, group: DomainParameters, add: Optional[AdditionFormula] = None,
pubkey: Optional[Point] = None, privkey: Optional[int] = None):
super().__init__(mult, group, add, pubkey, privkey, hashlib.sha512)
diff --git a/pyecsca/sca/scope/__init__.py b/pyecsca/sca/scope/__init__.py
index b609e94..112f29c 100644
--- a/pyecsca/sca/scope/__init__.py
+++ b/pyecsca/sca/scope/__init__.py
@@ -12,21 +12,21 @@ try:
import picoscope
has_picoscope = True
-except ImportError:
+except ImportError: # pragma: no cover
pass
try:
import picosdk
has_picosdk = True
-except ImportError:
+except ImportError: # pragma: no cover
pass
try:
import chipwhisperer
has_chipwhisperer = True
-except ImportError:
+except ImportError: # pragma: no cover
pass
PicoScope: Type[Scope]
diff --git a/pyecsca/sca/target/__init__.py b/pyecsca/sca/target/__init__.py
index e9d41d6..e75526a 100644
--- a/pyecsca/sca/target/__init__.py
+++ b/pyecsca/sca/target/__init__.py
@@ -10,14 +10,14 @@ try:
import chipwhisperer
has_chipwhisperer = True
-except ImportError:
+except ImportError: # pragma: no cover
pass
try:
import pyscard
has_pyscard = True
-except ImportError:
+except ImportError: # pragma: no cover
pass
if has_pyscard:
diff --git a/test/ec/test_group.py b/test/ec/test_params.py
index ca0ea91..222698d 100644
--- a/test/ec/test_group.py
+++ b/test/ec/test_params.py
@@ -4,7 +4,7 @@ from pyecsca.ec.curves import get_curve
from pyecsca.ec.point import InfinityPoint
-class AbelianGroupTests(TestCase):
+class DomainParameterTests(TestCase):
def setUp(self):
self.secp128r1 = get_curve("secp128r1", "projective")