pyecsca.ec.mult.binary module

Provides binary scalar multipliers (LTR and RTL), that process the scalar as-is, bit-by-bit.

class DoubleAndAddMultiplier(add, dbl, scl=None, always=False, direction=ProcessingDirection.LTR, accumulation_order=AccumulationOrder.PeqPR, complete=True, short_circuit=True)[source]

Bases: AccumulatorMultiplier, ScalarMultiplier, ABC

Classic double and add scalar multiplication algorithm.

Note

This is an ABC, you should use the LTRMultiplier and RTLMultiplier classes.

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

  • always (bool) – Whether the double and add always method is used.

  • direction (ProcessingDirection) – Whether it is LTR or RTL.

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

  • complete (bool) – Whether it starts processing at full order-bit-length.

requires: ClassVar[Set[Type]] = {<class 'pyecsca.ec.formula.base.AdditionFormula'>, <class 'pyecsca.ec.formula.base.DoublingFormula'>}[source]

The set of formula types that the multiplier requires.

optionals: ClassVar[Set[Type]] = {<class 'pyecsca.ec.formula.base.ScalingFormula'>}[source]

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

always: bool[source]

Whether the double and add always method is used.

direction: ProcessingDirection[source]

Whether it is LTR or RTL.

complete: bool[source]

Whether it starts processing at full order-bit-length.

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.

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.

accumulation_order: AccumulationOrder[source]

The order of accumulation of points.

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.

class LTRMultiplier(add, dbl, scl=None, always=False, accumulation_order=AccumulationOrder.PeqPR, complete=True, short_circuit=True)[source]

Bases: DoubleAndAddMultiplier

Classic double and add scalar multiplication algorithm, that scans the scalar left-to-right (msb to lsb).

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

  • always (bool) – Whether the double and add always method is used.

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

  • complete (bool) – Whether it starts processing at full order-bit-length.

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.

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.

optionals: ClassVar[Set[Type]] = {<class 'pyecsca.ec.formula.base.ScalingFormula'>}[source]

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

requires: ClassVar[Set[Type]] = {<class 'pyecsca.ec.formula.base.AdditionFormula'>, <class 'pyecsca.ec.formula.base.DoublingFormula'>}[source]

The set of formula types that the multiplier requires.

always: bool[source]

Whether the double and add always method is used.

direction: ProcessingDirection[source]

Whether it is LTR or RTL.

complete: bool[source]

Whether it starts processing at full order-bit-length.

accumulation_order: AccumulationOrder[source]

The order of accumulation of points.

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.

class RTLMultiplier(add, dbl, scl=None, always=False, accumulation_order=AccumulationOrder.PeqPR, complete=True, short_circuit=True)[source]

Bases: DoubleAndAddMultiplier

Classic double and add scalar multiplication algorithm, that scans the scalar right-to-left (lsb to msb).

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

  • always (bool) – Whether the double and add always method is used.

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

  • complete (bool) – Whether it starts processing at full order-bit-length.

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.

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.

optionals: ClassVar[Set[Type]] = {<class 'pyecsca.ec.formula.base.ScalingFormula'>}[source]

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

requires: ClassVar[Set[Type]] = {<class 'pyecsca.ec.formula.base.AdditionFormula'>, <class 'pyecsca.ec.formula.base.DoublingFormula'>}[source]

The set of formula types that the multiplier requires.

always: bool[source]

Whether the double and add always method is used.

direction: ProcessingDirection[source]

Whether it is LTR or RTL.

complete: bool[source]

Whether it starts processing at full order-bit-length.

accumulation_order: AccumulationOrder[source]

The order of accumulation of points.

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.

class CoronMultiplier(add, dbl, scl=None, short_circuit=True)[source]

Bases: ScalarMultiplier

Coron’s double and add resistant against SPA.

From [CO2002].

Parameters:

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

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.

requires: ClassVar[Set[Type]] = {<class 'pyecsca.ec.formula.base.AdditionFormula'>, <class 'pyecsca.ec.formula.base.DoublingFormula'>}[source]

The set of formula types that the multiplier requires.

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.

optionals: ClassVar[Set[Type]] = {<class 'pyecsca.ec.formula.base.ScalingFormula'>}[source]

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

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.