diff options
| author | J08nY | 2021-01-05 00:44:14 +0100 |
|---|---|---|
| committer | J08nY | 2021-01-05 00:44:14 +0100 |
| commit | 9a3bc0379b5033e03dec6473fa645c4bf1770105 (patch) | |
| tree | c3782efe50632c9f8286c24e400ab21dc398ba2f | |
| parent | 8ad589af29138edc9ad9fe1ff649c8c7743981b3 (diff) | |
| download | pyecsca-9a3bc0379b5033e03dec6473fa645c4bf1770105.tar.gz pyecsca-9a3bc0379b5033e03dec6473fa645c4bf1770105.tar.zst pyecsca-9a3bc0379b5033e03dec6473fa645c4bf1770105.zip | |
Fix type-checking, codestyle and update EFD.
| m--------- | pyecsca/ec/efd | 0 | ||||
| -rw-r--r-- | pyecsca/ec/error.py | 1 | ||||
| -rw-r--r-- | pyecsca/ec/mod.py | 12 | ||||
| -rw-r--r-- | pyecsca/ec/params.py | 2 | ||||
| -rw-r--r-- | pyecsca/ec/point.py | 4 | ||||
| -rw-r--r-- | pyecsca/misc/cfg.py | 4 | ||||
| -rw-r--r-- | pyecsca/sca/trace_set/hdf5.py | 2 |
7 files changed, 11 insertions, 14 deletions
diff --git a/pyecsca/ec/efd b/pyecsca/ec/efd -Subproject f6afbf7f603450d0155fdd3c0fde172431bf115 +Subproject a39cbee81c9a5c0ec720abf3eb97cfd4a3d06af diff --git a/pyecsca/ec/error.py b/pyecsca/ec/error.py index 27a4ab9..ecbe4d2 100644 --- a/pyecsca/ec/error.py +++ b/pyecsca/ec/error.py @@ -1,6 +1,7 @@ from public import public from ..misc.cfg import getconfig + @public class NonInvertibleError(ArithmeticError): pass diff --git a/pyecsca/ec/mod.py b/pyecsca/ec/mod.py index 45db08a..8a4b66a 100644 --- a/pyecsca/ec/mod.py +++ b/pyecsca/ec/mod.py @@ -1,7 +1,8 @@ import random import secrets from functools import wraps, lru_cache -from abc import abstractmethod +from typing import Type, Dict + from public import public from .error import raise_non_invertible, raise_non_residue @@ -104,7 +105,7 @@ class RandomModAction(ResultAction): return f"{self.__class__.__name__}({self.order:x})" -_mod_classes = {} +_mod_classes: Dict[str, Type] = {} @public @@ -144,7 +145,6 @@ class Mod(object): def __neg__(self): return self.__class__(self.n - self.x, self.n) - @abstractmethod def inverse(self) -> "Mod": """ Invert the element. @@ -157,12 +157,10 @@ class Mod(object): def __invert__(self): return self.inverse() - @abstractmethod def is_residue(self) -> bool: """Whether this element is a quadratic residue (only implemented for prime modulus).""" ... - @abstractmethod def sqrt(self) -> "Mod": """ The modular square root of this element (only implemented for prime modulus). @@ -208,11 +206,9 @@ class Mod(object): q, r = divmod(self.x, divisor.x) return self.__class__(q, self.n), self.__class__(r, self.n) - @abstractmethod def __bytes__(self): ... - @abstractmethod def __int__(self): ... @@ -227,7 +223,6 @@ class Mod(object): with RandomModAction(n) as action: return action.exit(cls(secrets.randbelow(n), n)) - @abstractmethod def __pow__(self, n): ... @@ -531,5 +526,4 @@ if has_gmp: return GMPMod(self.x, self.n) return GMPMod(gmpy2.powmod(self.x, gmpy2.mpz(n), self.n), self.n) - _mod_classes["gmp"] = GMPMod diff --git a/pyecsca/ec/params.py b/pyecsca/ec/params.py index b2c989d..a48b70d 100644 --- a/pyecsca/ec/params.py +++ b/pyecsca/ec/params.py @@ -242,7 +242,7 @@ def load_params(file: Union[str, Path, BinaryIO], coords: str, infty: bool = Tru @public def get_category(category: str, coords: Union[str, Callable[[str], str]], - infty: Union[bool, Callable[[str], bool]] = True) -> DomainParameterCategory: + infty: Union[bool, Callable[[str], bool]] = True) -> DomainParameterCategory: """ Retrieve a category from the std-curves database at https://github.com/J08nY/std-curves. diff --git a/pyecsca/ec/point.py b/pyecsca/ec/point.py index 62e4b05..480c47f 100644 --- a/pyecsca/ec/point.py +++ b/pyecsca/ec/point.py @@ -1,5 +1,5 @@ from copy import copy -from typing import Mapping, Any +from typing import Mapping, TYPE_CHECKING from public import public @@ -7,6 +7,8 @@ from .context import ResultAction from .coordinates import AffineCoordinateModel, CoordinateModel, EFDCoordinateModel from .mod import Mod, Undefined from .op import CodeOp +if TYPE_CHECKING: + from .curve import EllipticCurve @public diff --git a/pyecsca/misc/cfg.py b/pyecsca/misc/cfg.py index b1c4007..1c1d214 100644 --- a/pyecsca/misc/cfg.py +++ b/pyecsca/misc/cfg.py @@ -100,7 +100,7 @@ class ECConfig(object): @mod_implementation.setter def mod_implementation(self, value: str): if value not in ("python", "gmp"): - raise ValueError(f"Bad Mod implementaiton, can be one of 'python' or 'gmp'.") + raise ValueError("Bad Mod implementaiton, can be one of 'python' or 'gmp'.") self._mod_implementation = value @@ -142,4 +142,4 @@ class TemporaryConfig(object): return self.new_config def __exit__(self, t, v, tb): - resetconfig(self.token)
\ No newline at end of file + resetconfig(self.token) diff --git a/pyecsca/sca/trace_set/hdf5.py b/pyecsca/sca/trace_set/hdf5.py index 0a45e01..08dedeb 100644 --- a/pyecsca/sca/trace_set/hdf5.py +++ b/pyecsca/sca/trace_set/hdf5.py @@ -174,6 +174,6 @@ class HDF5TraceSet(TraceSet): status = " (opened)" fname = self._file.filename else: - status = "(closed)" + status = "(closed)" args = ", ".join([f"{key}={getattr(self, key)!r}" for key in self._keys if not key.startswith("_")]) return f"HDF5TraceSet('{fname}'{status}, {args})" |
