diff options
| author | J08nY | 2020-02-15 14:57:55 +0100 |
|---|---|---|
| committer | J08nY | 2020-02-15 14:57:55 +0100 |
| commit | 3fc44b54ebe364a1c38cdc3e7f59b20b22fc2220 (patch) | |
| tree | ed3d3b6b18db15c75e6afef1c2d010c41a8ce30d | |
| parent | eef8b99dad6f43d97d9194a1a6f16bc5e2ef66b0 (diff) | |
| download | pyecsca-3fc44b54ebe364a1c38cdc3e7f59b20b22fc2220.tar.gz pyecsca-3fc44b54ebe364a1c38cdc3e7f59b20b22fc2220.tar.zst pyecsca-3fc44b54ebe364a1c38cdc3e7f59b20b22fc2220.zip | |
| -rw-r--r-- | docs/index.rst | 6 | ||||
| m--------- | notebook | 0 | ||||
| -rw-r--r-- | pyecsca/ec/context.py | 4 | ||||
| -rw-r--r-- | pyecsca/ec/curve.py | 5 | ||||
| -rw-r--r-- | pyecsca/ec/curves.py | 5 | ||||
| -rw-r--r-- | pyecsca/ec/formula.py | 6 | ||||
| -rw-r--r-- | pyecsca/ec/model.py | 3 | ||||
| -rw-r--r-- | pyecsca/ec/params.py | 26 |
8 files changed, 48 insertions, 7 deletions
diff --git a/docs/index.rst b/docs/index.rst index d2e96f4..4fe5814 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -31,12 +31,16 @@ API Notebooks ========= +The notebooks below contain a showcase of what is possible using *pyecsca* and +are the best source of documentation on how to use *pyecsca*. .. toctree:: :titlesonly: - :maxdepth: 3 + :maxdepth: 1 notebook/configuration_space + notebook/simulation + notebook/codegen Requirements diff --git a/notebook b/notebook -Subproject ddbc1b6d5cc5d5275b623b7f7315828ddf340c8 +Subproject b57f8b21f5ff49657d4d052dc179d2d3831200e diff --git a/pyecsca/ec/context.py b/pyecsca/ec/context.py index c4e1a3c..9b57be6 100644 --- a/pyecsca/ec/context.py +++ b/pyecsca/ec/context.py @@ -1,4 +1,4 @@ -from abc import ABCMeta, abstractmethod, ABC +from abc import abstractmethod, ABC from collections import OrderedDict from contextvars import ContextVar, Token from copy import deepcopy @@ -143,7 +143,7 @@ class DefaultContext(Context): self.current = [] def __repr__(self): - return f"{self.__class__.__name__}({self.actions}, current={self.current})" + return f"{self.__class__.__name__}({self.actions!r}, current={self.current!r})" _actual_context: ContextVar[Context] = ContextVar("operational_context", default=NullContext()) diff --git a/pyecsca/ec/curve.py b/pyecsca/ec/curve.py index 85081ea..b161f7b 100644 --- a/pyecsca/ec/curve.py +++ b/pyecsca/ec/curve.py @@ -44,6 +44,9 @@ class EllipticCurve(object): return False return self.model == other.model and self.coordinate_model == other.coordinate_model and self.prime == other.prime and self.parameters == other.parameters + def __str__(self): + return "EllipticCurve" + def __repr__(self): params = ", ".join((f"{key}={val}" for key, val in self.parameters.items())) - return f"EllipticCurve([{params}] on {self.model} using {self.coordinate_model})" + return f"{self.__class__.__name__}([{params}] on {self.model} using {self.coordinate_model})" diff --git a/pyecsca/ec/curves.py b/pyecsca/ec/curves.py index 4ae1d5c..09964ea 100644 --- a/pyecsca/ec/curves.py +++ b/pyecsca/ec/curves.py @@ -1,6 +1,5 @@ import json from os.path import join -from typing import Mapping, Any from pkg_resources import resource_listdir, resource_isdir, resource_stream from public import public @@ -13,6 +12,7 @@ from .model import (ShortWeierstrassModel, MontgomeryModel, TwistedEdwardsModel, from .params import DomainParameters from .point import Point, InfinityPoint + @public def get_params(category: str, name: str, coords: str) -> DomainParameters: """ @@ -65,4 +65,5 @@ def get_params(category: str, name: str, coords: str) -> DomainParameters: affine = Point(AffineCoordinateModel(model), x=Mod(int(curve["generator"]["x"], 16), field), y=Mod(int(curve["generator"]["y"], 16), field)) generator = Point.from_affine(coord_model, affine) - return DomainParameters(elliptic_curve, generator, InfinityPoint(coord_model), order, cofactor) + return DomainParameters(elliptic_curve, generator, InfinityPoint(coord_model), order, cofactor, + name, category) diff --git a/pyecsca/ec/formula.py b/pyecsca/ec/formula.py index 95ca246..2e56f42 100644 --- a/pyecsca/ec/formula.py +++ b/pyecsca/ec/formula.py @@ -68,6 +68,9 @@ class FormulaAction(Action): self.outputs[k] = self.intermediates[k] self.output_points.append(point) + def __str__(self): + return f"{self.__class__.__name__}({self.formula})" + def __repr__(self): return f"{self.__class__.__name__}({self.formula}, {self.input_points}) = {self.output_points}" @@ -122,6 +125,9 @@ class Formula(ABC): result.append(point) return tuple(result) + def __str__(self): + return f"{self.shortname}[{self.name}]" + def __repr__(self): return f"{self.__class__.__name__}({self.name} for {self.coordinate_model})" diff --git a/pyecsca/ec/model.py b/pyecsca/ec/model.py index 08ba70e..093a3cb 100644 --- a/pyecsca/ec/model.py +++ b/pyecsca/ec/model.py @@ -99,6 +99,9 @@ class EFDCurveModel(CurveModel): def __hash__(self): return hash(self._efd_name) + 1 + def __str__(self): + return f"{self.__class__.__name__.replace('Model', '')}" + def __repr__(self): return f"{self.__class__.__name__}()" diff --git a/pyecsca/ec/params.py b/pyecsca/ec/params.py index 374c327..7c2e504 100644 --- a/pyecsca/ec/params.py +++ b/pyecsca/ec/params.py @@ -1,3 +1,5 @@ +from typing import Optional + from public import public from .curve import EllipticCurve @@ -12,14 +14,18 @@ class DomainParameters(object): neutral: Point order: int cofactor: int + name: Optional[str] + category: Optional[str] def __init__(self, curve: EllipticCurve, generator: Point, neutral: Point, order: int, - cofactor: int): + cofactor: int, name: Optional[str] = None, category: Optional[str] = None): self.curve = curve self.generator = generator self.neutral = neutral self.order = order self.cofactor = cofactor + self.name = name + self.category = category def is_neutral(self, point: Point) -> bool: return self.neutral == point @@ -28,3 +34,21 @@ class DomainParameters(object): 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 + + def __get_name(self): + if self.name and self.category: + return f"{self.category}/{self.name}" + elif self.name: + return self.name + elif self.category: + return self.category + return "" + + def __str__(self): + name = self.__get_name() + if not name: + name = str(self.curve) + return f"{self.__class__.__name__}({name})" + + def __repr__(self): + return f"{self.__class__.__name__}({self.curve!r}, {self.generator!r}, {self.neutral!r}, {self.order}, {self.cofactor})" |
