pyecsca.ec.mult.base module

Provides (mostly abstract) base classes for scalar multipliers, enums used to specify their parameters and actions used in them.

class ProcessingDirection(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Scalar processing direction.

LTR = 'Left-to-right'
RTL = 'Right-to-left'
class AccumulationOrder(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Accumulation order (makes a difference for the projective result).

PeqPR = 'P = P + R'
PeqRP = 'P = R + P'
class ScalarMultiplicationAction(point, scalar)[source]

Bases: ResultAction

A scalar multiplication of a point on a curve by a scalar.

point: Point
scalar: int
exit(result)
property result: Any
inside: bool
class PrecomputationAction(params, point)[source]

Bases: Action

A precomputation of a point in scalar multiplication.

params: DomainParameters
point: Point
inside: bool
class ScalarMultiplier(short_circuit=True, **formulas)[source]

Bases: ABC

A scalar multiplication algorithm.

Note

The __init__ method of all concrete subclasses needs to have type annotations so that configuration enumeration works.

Parameters:
  • short_circuit (bool) – Whether the use of formulas will be guarded by short-circuit on inputs of the point at infinity.

  • formulas (Optional[Formula]) – Formulas this instance will use.

requires: ClassVar[Set[Type]]

The set of formula types that the multiplier requires.

optionals: ClassVar[Set[Type]]

The optional set of formula types that the multiplier can use.

short_circuit: bool

Whether the formulas will short-circuit upon input of the point at infinity.

formulas: Mapping[str, Formula]

All formulas the multiplier was initialized with.

init(params, point)[source]

Initialize the scalar multiplier with params and a point.

Warning

The point is not verified to be on the curve represented in the domain parameters.

Parameters:
  • params (DomainParameters) – The domain parameters to initialize the multiplier with.

  • point (Point) – The point to initialize the multiplier with.

abstract multiply(scalar)[source]

Multiply the point with the scalar.

Note

The multiplier needs to be initialized by a call to the init() method.

Parameters:

scalar (int) – The scalar to use.

Return type:

Point

Returns:

The resulting multiple.

class AccumulatorMultiplier(*args, accumulation_order=AccumulationOrder.PeqPR, **kwargs)[source]

Bases: ScalarMultiplier, ABC

A scalar multiplication algorithm mix-in class for a multiplier that accumulates.

Parameters:

accumulation_order (AccumulationOrder) – The order of accumulation of points.

init(params, point)

Initialize the scalar multiplier with params and a point.

Warning

The point is not verified to be on the curve represented in the domain parameters.

Parameters:
  • params (DomainParameters) – The domain parameters to initialize the multiplier with.

  • point (Point) – The point to initialize the multiplier with.

abstract multiply(scalar)

Multiply the point with the scalar.

Note

The multiplier needs to be initialized by a call to the init() method.

Parameters:

scalar (int) – The scalar to use.

Return type:

Point

Returns:

The resulting multiple.

requires: ClassVar[Set[Type]]

The set of formula types that the multiplier requires.

optionals: ClassVar[Set[Type]]

The optional set of formula types that the multiplier can use.

short_circuit: bool

Whether the formulas will short-circuit upon input of the point at infinity.

formulas: Mapping[str, Formula]

All formulas the multiplier was initialized with.

accumulation_order: AccumulationOrder

The order of accumulation of points.