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'[source]
RTL = 'Right-to-left'[source]
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'[source]
PeqRP = 'P = R + P'[source]
class ScalarMultiplicationAction(point, params, scalar)[source]

Bases: ResultAction

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

point: Point[source]
params: DomainParameters[source]
scalar: int[source]
exit(result)[source]
property result: Any[source]

The result of the action.

inside: bool[source]
class PrecomputationAction(params, point)[source]

Bases: Action

A precomputation of a point in scalar multiplication.

params: DomainParameters[source]
point: Point[source]
inside: bool[source]
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]][source]

The set of formula types that the multiplier requires.

optionals: ClassVar[Set[Type]][source]

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

short_circuit: bool[source]

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

formulas: Mapping[str, Formula][source]

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)[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.

requires: ClassVar[Set[Type]][source]

The set of formula types that the multiplier requires.

optionals: ClassVar[Set[Type]][source]

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

short_circuit: bool[source]

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

formulas: Mapping[str, Formula][source]

All formulas the multiplier was initialized with.

accumulation_order: AccumulationOrder[source]

The order of accumulation of points.