diff options
| author | J08nY | 2023-08-29 16:15:00 +0200 |
|---|---|---|
| committer | J08nY | 2023-08-29 16:15:00 +0200 |
| commit | 501d17b11a86d6a3780435db5416830c9d6175e2 (patch) | |
| tree | 871b8051a9ca748b595fc196123789f6641a7e4f /pyecsca/ec | |
| parent | 06465b2455587dd3d747081258971c3023ac8b3e (diff) | |
| download | pyecsca-501d17b11a86d6a3780435db5416830c9d6175e2.tar.gz pyecsca-501d17b11a86d6a3780435db5416830c9d6175e2.tar.zst pyecsca-501d17b11a86d6a3780435db5416830c9d6175e2.zip | |
Add ZVP point computation.
Diffstat (limited to 'pyecsca/ec')
| -rw-r--r-- | pyecsca/ec/configuration.py | 4 | ||||
| -rw-r--r-- | pyecsca/ec/curve.py | 17 |
2 files changed, 19 insertions, 2 deletions
diff --git a/pyecsca/ec/configuration.py b/pyecsca/ec/configuration.py index 03dc86b..6ed2190 100644 --- a/pyecsca/ec/configuration.py +++ b/pyecsca/ec/configuration.py @@ -1,5 +1,6 @@ """Provides a way to work with and enumerate implementation configurations.""" import warnings +from abc import ABC from dataclasses import dataclass from enum import Enum from itertools import product @@ -146,7 +147,7 @@ def all_configurations(**kwargs) -> Generator[Configuration, Configuration, None for subclass in subs: if subclass.__subclasses__(): result.update(leaf_subclasses(subclass)) - else: + elif not issubclass(subclass, ABC): result.add(subclass) return result @@ -240,6 +241,7 @@ def all_configurations(**kwargs) -> Generator[Configuration, Configuration, None continue coords_formulas = coords.formulas.values() mult_classes = leaf_subclasses(ScalarMultiplier) + if "scalarmult" in kwargs: if isinstance(kwargs["scalarmult"], ScalarMultiplier): mults = [kwargs["scalarmult"]] diff --git a/pyecsca/ec/curve.py b/pyecsca/ec/curve.py index fb567e8..8cc7dba 100644 --- a/pyecsca/ec/curve.py +++ b/pyecsca/ec/curve.py @@ -2,7 +2,7 @@ from ast import Module from astunparse import unparse from copy import copy -from typing import MutableMapping, Union, List, Optional, Dict +from typing import MutableMapping, Union, List, Optional, Dict, Set from public import public from sympy import FF, sympify @@ -303,6 +303,21 @@ class EllipticCurve: f"Wrong encoding type: {hex(encoded[0])}, should be one of 0x04, 0x06, 0x02, 0x03 or 0x00" ) + def affine_lift_x(self, x: Mod) -> Set[Point]: + """ + Lift an x-coordinate to the curve. + + :param x: The x-coordinate. + :return: Lifted (affine) points, if any. + """ + loc = {**self.parameters, "x": x} + ysquared = eval(compile(self.model.ysquared, "", mode="eval"), loc) + if not ysquared.is_residue(): + return set() + y = ysquared.sqrt() + return {Point(AffineCoordinateModel(self.model), x=x, y=y), + Point(AffineCoordinateModel(self.model), x=x, y=-y)} + def affine_random(self) -> Point: """Generate a random affine point on the curve.""" while True: |
