Source code for pyecsca.ec.formula.fake
from abc import ABC
from typing import Any, Tuple
from public import public
from .base import (
AdditionFormula,
FormulaAction,
Formula,
DoublingFormula,
TriplingFormula,
LadderFormula,
NegationFormula,
ScalingFormula,
DifferentialAdditionFormula,
)
from ..mod import Mod, Undefined
from ..point import Point
class FakeFormula(Formula, ABC):
"""
No matter what the input point is it just returns the right amount of FakePoints.
Useful for computing with the scalar multipliers without having concrete formulas
and points (for example to get the addition chain via the MultipleContext).
"""
def __init__(self, coordinate_model):
# TODO: This is missing all of the other attributes
self.coordinate_model = coordinate_model
self.code = []
def __call__(self, field: int, *points: Any, **params: Mod) -> Tuple[Any, ...]:
with FormulaAction(self, *points, **params) as action:
result = []
for i in range(self.num_outputs):
res = FakePoint(self.coordinate_model)
action.output_points.append(res)
result.append(res)
return action.exit(tuple(result))
[docs]
@public
class FakePoint(Point):
def __init__(self, model):
coords = {key: Undefined() for key in model.variables}
super().__init__(model, **coords)
def __str__(self):
return "FakePoint"
def __repr__(self):
return str(self)