aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJ08nY2020-06-29 22:39:35 +0200
committerJ08nY2020-06-29 22:39:35 +0200
commit9c8099f04ed2815dd50fd69a12d8b4e6f30aac7d (patch)
tree89a1f03ccb17574b0c2ab703aa14771a6a4b6434
parenta726c69f3e30982bde485479e81a53d24a6a759b (diff)
downloadpyecsca-9c8099f04ed2815dd50fd69a12d8b4e6f30aac7d.tar.gz
pyecsca-9c8099f04ed2815dd50fd69a12d8b4e6f30aac7d.tar.zst
pyecsca-9c8099f04ed2815dd50fd69a12d8b4e6f30aac7d.zip
Fix codestyle.
-rw-r--r--.travis.yml2
-rw-r--r--pyecsca/ec/curve.py2
-rw-r--r--pyecsca/ec/mult.py8
-rw-r--r--pyecsca/ec/params.py4
-rw-r--r--pyecsca/sca/scope/picoscope_sdk.py5
-rw-r--r--pyecsca/sca/target/ISO7816.py2
-rw-r--r--pyecsca/sca/target/binary.py2
-rw-r--r--pyecsca/sca/target/ectester.py65
-rw-r--r--pyecsca/sca/trace/combine.py3
-rw-r--r--pyecsca/sca/trace/plot.py12
-rw-r--r--pyecsca/sca/trace_set/hdf5.py7
-rw-r--r--setup.py2
12 files changed, 56 insertions, 58 deletions
diff --git a/.travis.yml b/.travis.yml
index 5ef16fc..9c61f48 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -33,7 +33,7 @@ install:
script:
- make -i typecheck
- make -i codestyle
- - make test-plots
+ - make test
after_success:
- codecov
diff --git a/pyecsca/ec/curve.py b/pyecsca/ec/curve.py
index 8cbd48e..20b3902 100644
--- a/pyecsca/ec/curve.py
+++ b/pyecsca/ec/curve.py
@@ -112,7 +112,7 @@ class EllipticCurve(object):
def to_affine(self) -> "EllipticCurve":
"""Convert this curve into the affine coordinate model, if possible."""
coord_model = AffineCoordinateModel(self.model)
- return EllipticCurve(self.model, coord_model, self.prime, self.neutral.to_affine(), self.parameters) # type: ignore[arg-type]
+ return EllipticCurve(self.model, coord_model, self.prime, self.neutral.to_affine(), self.parameters) # type: ignore[arg-type]
def decode_point(self, encoded: bytes) -> Point:
"""Decode a point encoded as a sequence of bytes (ANSI X9.62)."""
diff --git a/pyecsca/ec/mult.py b/pyecsca/ec/mult.py
index a3622f5..bfaa962 100644
--- a/pyecsca/ec/mult.py
+++ b/pyecsca/ec/mult.py
@@ -35,8 +35,8 @@ class ScalarMultiplier(ABC):
of the point at infinity.
:param formulas: Formulas this instance will use.
"""
- requires: ClassVar[Set[Type]] #Type[Formula] but mypy has a false positive
- optionals: ClassVar[Set[Type]] #Type[Formula] but mypy has a false positive
+ requires: ClassVar[Set[Type]] # Type[Formula] but mypy has a false positive
+ optionals: ClassVar[Set[Type]] # Type[Formula] but mypy has a false positive
short_circuit: bool
formulas: Mapping[str, Formula]
_params: DomainParameters
@@ -408,9 +408,9 @@ class WindowNAFMultiplier(ScalarMultiplier):
current_point = point
double_point = self._dbl(point)
for i in range(0, 2**(self.width - 2)):
- self._points[2*i + 1] = current_point
+ self._points[2 * i + 1] = current_point
if self.precompute_negation:
- self._points_neg[2*i + 1] = self._neg(current_point)
+ self._points_neg[2 * i + 1] = self._neg(current_point)
current_point = self._add(current_point, double_point)
def multiply(self, scalar: int) -> Point:
diff --git a/pyecsca/ec/params.py b/pyecsca/ec/params.py
index 8f5afd6..9f1865f 100644
--- a/pyecsca/ec/params.py
+++ b/pyecsca/ec/params.py
@@ -139,11 +139,11 @@ def get_params(category: str, name: str, coords: str, infty: bool = True) -> Dom
value = Mod(value, field)
infinity_coords[coordinate] = value
infinity = Point(coord_model, **infinity_coords)
- elliptic_curve = EllipticCurve(model, coord_model, field, infinity, params) # type: ignore[arg-type]
+ elliptic_curve = EllipticCurve(model, coord_model, field, infinity, params) # type: ignore[arg-type]
affine = Point(AffineCoordinateModel(model), x=Mod(int(curve["generator"]["x"], 16), field),
y=Mod(int(curve["generator"]["y"], 16), field))
if not isinstance(coord_model, AffineCoordinateModel):
generator = Point.from_affine(coord_model, affine)
else:
generator = affine
- return DomainParameters(elliptic_curve, generator, order, cofactor, name, category) \ No newline at end of file
+ return DomainParameters(elliptic_curve, generator, order, cofactor, name, category)
diff --git a/pyecsca/sca/scope/picoscope_sdk.py b/pyecsca/sca/scope/picoscope_sdk.py
index ac5c349..0ec59c9 100644
--- a/pyecsca/sca/scope/picoscope_sdk.py
+++ b/pyecsca/sca/scope/picoscope_sdk.py
@@ -25,8 +25,7 @@ def adc2volt(adc: Union[np.ndarray, ctypes.c_int16],
def volt2adc(volt: Union[np.ndarray, float],
- volt_range: float, adc_minmax: int) -> Union[
- np.ndarray, ctypes.c_int16]: # pragma: no cover
+ volt_range: float, adc_minmax: int) -> Union[np.ndarray, ctypes.c_int16]: # pragma: no cover
if isinstance(volt, float):
return ctypes.c_int16(int((volt / volt_range) * adc_minmax))
return (volt / volt_range) * adc_minmax
@@ -86,7 +85,7 @@ class PicoScopeSdk(Scope): # pragma: no cover
self.COUPLING[coupling], self.RANGES[range]))
self.ranges[channel] = range
- def setup_channel(self, channel: str, coupling: str, range: float, offset: float, enable: bool):
+ def setup_channel(self, channel: str, coupling: str, range: float, offset: float, enable: bool):
self.set_channel(channel, enable, coupling, range, offset)
def _set_freq(self, frequency: int, pretrig: int, posttrig: int, period_bound: float,
diff --git a/pyecsca/sca/target/ISO7816.py b/pyecsca/sca/target/ISO7816.py
index 3cf712f..2bf37f9 100644
--- a/pyecsca/sca/target/ISO7816.py
+++ b/pyecsca/sca/target/ISO7816.py
@@ -44,6 +44,7 @@ class CommandAPDU(object): # pragma: no cover
# Case 4e
return bytes([self.cls, self.ins, self.p1, self.p2, 0]) + len(self.data).to_bytes(2, "big") + self.data + (self.ne.to_bytes(2, "big") if self.ne != 65536 else bytes([0, 0]))
+
@public
@dataclass
class ResponseAPDU(object):
@@ -82,6 +83,7 @@ class ISO7816Target(Target, ABC):
"""
...
+
@public
class ISO7816:
SW_FILE_FULL = 0x6A84
diff --git a/pyecsca/sca/target/binary.py b/pyecsca/sca/target/binary.py
index f21c2e7..0455c75 100644
--- a/pyecsca/sca/target/binary.py
+++ b/pyecsca/sca/target/binary.py
@@ -44,7 +44,7 @@ class BinaryTarget(SerialTarget):
else:
read = self.process.stdout.readline()
else:
- read = bytes() # pragma: no cover
+ read = bytes() # pragma: no cover
if self.debug_output:
print("<<", read, end="")
return read.encode()
diff --git a/pyecsca/sca/target/ectester.py b/pyecsca/sca/target/ectester.py
index 05028b4..8391e32 100644
--- a/pyecsca/sca/target/ectester.py
+++ b/pyecsca/sca/target/ectester.py
@@ -17,7 +17,7 @@ from ...ec.params import DomainParameters
from ...ec.point import Point
-class ShiftableFlag(IntFlag): # pragma: no cover
+class ShiftableFlag(IntFlag): # pragma: no cover
def __lshift__(self, other):
val = int(self) << other
for e in self.__class__:
@@ -44,14 +44,14 @@ class ShiftableFlag(IntFlag): # pragma: no cover
@public
-class KeypairEnum(ShiftableFlag): # pragma: no cover
+class KeypairEnum(ShiftableFlag): # pragma: no cover
KEYPAIR_LOCAL = 0x01
KEYPAIR_REMOTE = 0x02
KEYPAIR_BOTH = KEYPAIR_LOCAL | KEYPAIR_REMOTE
@public
-class InstructionEnum(IntEnum): # pragma: no cover
+class InstructionEnum(IntEnum): # pragma: no cover
INS_ALLOCATE = 0x5a
INS_CLEAR = 0x5b
INS_SET = 0x5c
@@ -73,13 +73,13 @@ class InstructionEnum(IntEnum): # pragma: no cover
@public
-class KeyBuildEnum(IntEnum): # pragma: no cover
+class KeyBuildEnum(IntEnum): # pragma: no cover
BUILD_KEYPAIR = 0x01
BUILD_KEYBUILDER = 0x02
@public
-class ExportEnum(IntEnum): # pragma: no cover
+class ExportEnum(IntEnum): # pragma: no cover
EXPORT_TRUE = 0xff
EXPORT_FALSE = 0x00
@@ -89,32 +89,32 @@ class ExportEnum(IntEnum): # pragma: no cover
@public
-class RunModeEnum(IntEnum): # pragma: no cover
+class RunModeEnum(IntEnum): # pragma: no cover
MODE_NORMAL = 0xaa
MODE_DRY_RUN = 0xbb
@public
-class KeyEnum(ShiftableFlag): # pragma: no cover
+class KeyEnum(ShiftableFlag): # pragma: no cover
PUBLIC = 0x01
PRIVATE = 0x02
BOTH = PRIVATE | PUBLIC
@public
-class AppletBaseEnum(IntEnum): # pragma: no cover
+class AppletBaseEnum(IntEnum): # pragma: no cover
BASE_221 = 0x0221
BASE_222 = 0x0222
@public
-class KeyClassEnum(IntEnum): # pragma: no cover
+class KeyClassEnum(IntEnum): # pragma: no cover
ALG_EC_F2M = 4
ALG_EC_FP = 5
@public
-class KeyAgreementEnum(IntEnum): # pragma: no cover
+class KeyAgreementEnum(IntEnum): # pragma: no cover
ALG_EC_SVDP_DH = 1
ALG_EC_SVDP_DH_KDF = 1
ALG_EC_SVDP_DHC = 2
@@ -126,7 +126,7 @@ class KeyAgreementEnum(IntEnum): # pragma: no cover
@public
-class SignatureEnum(IntEnum): # pragma: no cover
+class SignatureEnum(IntEnum): # pragma: no cover
ALG_ECDSA_SHA = 17
ALG_ECDSA_SHA_224 = 37
ALG_ECDSA_SHA_256 = 33
@@ -135,7 +135,7 @@ class SignatureEnum(IntEnum): # pragma: no cover
@public
-class TransformationEnum(ShiftableFlag): # pragma: no cover
+class TransformationEnum(ShiftableFlag): # pragma: no cover
NONE = 0x00
FIXED = 0x01
FULLRANDOM = 0x02
@@ -151,14 +151,14 @@ class TransformationEnum(ShiftableFlag): # pragma: no cover
@public
-class FormatEnum(IntEnum): # pragma: no cover
+class FormatEnum(IntEnum): # pragma: no cover
UNCOMPRESSED = 0
COMPRESSED = 1
HYBRID = 2
@public
-class CurveEnum(IntEnum): # pragma: no cover
+class CurveEnum(IntEnum): # pragma: no cover
default = 0x00
external = 0xff
secp112r1 = 0x01
@@ -177,7 +177,7 @@ class CurveEnum(IntEnum): # pragma: no cover
@public
-class ParameterEnum(ShiftableFlag): # pragma: no cover
+class ParameterEnum(ShiftableFlag): # pragma: no cover
NONE = 0x00
FP = 0x01
F2M = 0x02
@@ -195,11 +195,11 @@ class ParameterEnum(ShiftableFlag): # pragma: no cover
@public
-class ChunkingException(Exception): # pragma: no cover
+class ChunkingException(Exception): # pragma: no cover
pass
-class Response(ABC): # pragma: no cover
+class Response(ABC): # pragma: no cover
resp: ResponseAPDU
sws: List[int]
params: List[bytes]
@@ -245,7 +245,7 @@ class Response(ABC): # pragma: no cover
@public
-class AllocateKaResponse(Response): # pragma: no cover
+class AllocateKaResponse(Response): # pragma: no cover
"""A response to the KeyAgreement allocation command."""
def __init__(self, resp: ResponseAPDU):
@@ -253,7 +253,7 @@ class AllocateKaResponse(Response): # pragma: no cover
@public
-class AllocateSigResponse(Response): # pragma: no cover
+class AllocateSigResponse(Response): # pragma: no cover
"""A response to the Signature allocation command."""
def __init__(self, resp: ResponseAPDU):
@@ -261,7 +261,7 @@ class AllocateSigResponse(Response): # pragma: no cover
@public
-class AllocateResponse(Response): # pragma: no cover
+class AllocateResponse(Response): # pragma: no cover
"""A response to the KeyPair allocation command."""
def __init__(self, resp: ResponseAPDU, keypair: KeypairEnum):
@@ -269,7 +269,7 @@ class AllocateResponse(Response): # pragma: no cover
@public
-class ClearResponse(Response): # pragma: no cover
+class ClearResponse(Response): # pragma: no cover
"""A response to the Clear key command."""
def __init__(self, resp: ResponseAPDU, keypair: KeypairEnum):
@@ -277,7 +277,7 @@ class ClearResponse(Response): # pragma: no cover
@public
-class SetResponse(Response): # pragma: no cover
+class SetResponse(Response): # pragma: no cover
"""A response to the Set command."""
def __init__(self, resp: ResponseAPDU, keypair: KeypairEnum):
@@ -285,7 +285,7 @@ class SetResponse(Response): # pragma: no cover
@public
-class TransformResponse(Response): # pragma: no cover
+class TransformResponse(Response): # pragma: no cover
"""A response to the Transform command."""
def __init__(self, resp: ResponseAPDU, keypair: KeypairEnum):
@@ -293,7 +293,7 @@ class TransformResponse(Response): # pragma: no cover
@public
-class GenerateResponse(Response): # pragma: no cover
+class GenerateResponse(Response): # pragma: no cover
"""A response to the Generate command."""
def __init__(self, resp: ResponseAPDU, keypair: KeypairEnum):
@@ -301,7 +301,7 @@ class GenerateResponse(Response): # pragma: no cover
@public
-class ExportResponse(Response): # pragma: no cover
+class ExportResponse(Response): # pragma: no cover
"""A response to the Export command, contains the exported parameters/values."""
keypair: KeypairEnum
key: KeyEnum
@@ -364,7 +364,7 @@ class ExportResponse(Response): # pragma: no cover
@public
-class ECDHResponse(Response): # pragma: no cover
+class ECDHResponse(Response): # pragma: no cover
"""A response to the ECDH and ECDH_direct KeyAgreement commands."""
def __init__(self, resp: ResponseAPDU, export: bool):
@@ -381,7 +381,7 @@ class ECDHResponse(Response): # pragma: no cover
@public
-class ECDSAResponse(Response): # pragma: no cover
+class ECDSAResponse(Response): # pragma: no cover
"""A response to the ECDSA and ECDSA sign and ECDSA verify commands."""
def __init__(self, resp: ResponseAPDU, export: bool):
@@ -398,7 +398,7 @@ class ECDSAResponse(Response): # pragma: no cover
@public
-class CleanupResponse(Response): # pragma: no cover
+class CleanupResponse(Response): # pragma: no cover
"""A response to the Cleanup command."""
def __init__(self, resp: ResponseAPDU):
@@ -406,14 +406,14 @@ class CleanupResponse(Response): # pragma: no cover
@public
-class RunModeResponse(Response): # pragma: no cover
+class RunModeResponse(Response): # pragma: no cover
"""A response to the Set run mode command."""
def __init__(self, resp: ResponseAPDU):
super().__init__(resp, 1, 0)
-class InfoResponse(Response): # pragma: no cover
+class InfoResponse(Response): # pragma: no cover
"""A response to the Info command, contains all information about the applet version/environment."""
version: str
base: AppletBaseEnum
@@ -458,7 +458,7 @@ class InfoResponse(Response): # pragma: no cover
@public
-class ECTesterTarget(PCSCTarget): # pragma: no cover
+class ECTesterTarget(PCSCTarget): # pragma: no cover
"""
A smartcard target which communicates with the `ECTester <https://github.com/crocs-muni/ECTester>`_
applet on smartcards of the JavaCard platform using PCSC.
@@ -529,8 +529,7 @@ class ECTesterTarget(PCSCTarget): # pragma: no cover
return True
@staticmethod
- def encode_parameters(params: ParameterEnum, obj: Union[DomainParameters, Point, int]) -> \
- Mapping[ParameterEnum, bytes]:
+ def encode_parameters(params: ParameterEnum, obj: Union[DomainParameters, Point, int]) -> Mapping[ParameterEnum, bytes]:
"""Encode values from `obj` into the byte parameters that the **ECTester** applet expects."""
def convert_int(obj: int) -> bytes:
diff --git a/pyecsca/sca/trace/combine.py b/pyecsca/sca/trace/combine.py
index 26a3e98..df5def6 100644
--- a/pyecsca/sca/trace/combine.py
+++ b/pyecsca/sca/trace/combine.py
@@ -24,8 +24,7 @@ def average(*traces: Trace) -> Optional[CombinedTrace]:
@public
-def conditional_average(*traces: Trace, condition: Callable[[Trace], bool]) -> Optional[
- CombinedTrace]:
+def conditional_average(*traces: Trace, condition: Callable[[Trace], bool]) -> Optional[CombinedTrace]:
"""
Average `traces` for which the `condition` is True, sample-wise.
diff --git a/pyecsca/sca/trace/plot.py b/pyecsca/sca/trace/plot.py
index e784e82..b9843cc 100644
--- a/pyecsca/sca/trace/plot.py
+++ b/pyecsca/sca/trace/plot.py
@@ -1,7 +1,7 @@
"""
This module provides functions for plotting traces.
"""
-from functools import reduce
+from functools import reduce
import holoviews as hv
from holoviews.operation.datashader import datashade
@@ -11,28 +11,28 @@ from .trace import Trace
@public
-def save_figure(figure, fname: str):
+def save_figure(figure, fname: str): # pragma: no cover
hv.save(figure, fname + ".html", fmt="html")
@public
-def save_figure_png(figure, fname: str):
+def save_figure_png(figure, fname: str): # pragma: no cover
hv.save(figure, fname + ".png", fmt="png")
@public
-def save_figure_svg(figure, fname: str):
+def save_figure_svg(figure, fname: str): # pragma: no cover
hv.save(figure, fname + ".svg", fmt="svg")
@public
-def plot_trace(trace: Trace, **kwargs):
+def plot_trace(trace: Trace, **kwargs): # pragma: no cover
line = hv.Curve((range(len(trace)), trace.samples), kdims="x", vdims="y", **kwargs)
return datashade(line, normalization="log")
@public
-def plot_traces(*traces: Trace, **kwargs):
+def plot_traces(*traces: Trace, **kwargs): # pragma: no cover
_cmaps = [
["lightblue", "darkblue"],
["lightcoral", "red"],
diff --git a/pyecsca/sca/trace_set/hdf5.py b/pyecsca/sca/trace_set/hdf5.py
index 7446bed..037ac0d 100644
--- a/pyecsca/sca/trace_set/hdf5.py
+++ b/pyecsca/sca/trace_set/hdf5.py
@@ -50,17 +50,16 @@ class HDF5Meta(MutableMapping):
class HDF5TraceSet(TraceSet):
_file: Optional[h5py.File]
_ordering: List[str]
- #_meta: Optional[HDF5Meta]
+ # _meta: Optional[HDF5Meta]
def __init__(self, *traces: Trace, _file: Optional[h5py.File] = None,
_ordering: Optional[List[str]] = None, **kwargs):
- #self._meta = HDF5Meta(_file.attrs) if _file is not None else None
+ # self._meta = HDF5Meta(_file.attrs) if _file is not None else None
self._file = _file
if _ordering is None:
_ordering = [str(uuid.uuid4()) for _ in traces]
super().__init__(*traces, **kwargs, _ordering=_ordering)
-
@classmethod
def read(cls, input: Union[str, Path, bytes, BinaryIO]) -> "HDF5TraceSet":
if isinstance(input, (str, Path)):
@@ -94,7 +93,7 @@ class HDF5TraceSet(TraceSet):
meta = HDF5Meta(hdf5[k].attrs)
samples = hdf5[k]
traces.append(Trace(samples, meta))
- return HDF5TraceSet(*traces, **kwargs, _file=hdf5) # type: ignore[misc]
+ return HDF5TraceSet(*traces, **kwargs, _file=hdf5) # type: ignore[misc]
def insert(self, index: int, value: Trace) -> Trace:
key = str(uuid.uuid4())
diff --git a/setup.py b/setup.py
index ece40be..211e99d 100644
--- a/setup.py
+++ b/setup.py
@@ -45,6 +45,6 @@ setup(
"chipwhisperer": ["chipwhisperer"],
"smartcard": ["pyscard"],
"dev": ["mypy", "flake8"],
- "test": ["nose2", "parameterized", "green", "coverage", "selenium"]
+ "test": ["nose2", "parameterized", "green", "coverage"]
}
)