pyecsca.ec.curve module

Provides an elliptic curve class.

class pyecsca.ec.curve.EllipticCurve(model, coordinate_model, prime, neutral, parameters)[source]

Bases: object

Elliptic curve.

model: CurveModel

The model of the curve.

coordinate_model: CoordinateModel

The coordinate system of the curve.

prime: int

The prime specifying the base prime field of the curve.

parameters: MutableMapping[str, Mod]

The values of the parameters defining the curve, these cover the curve model and coordinate system parameters.

neutral: Point

The neutral point on the curve.

affine_add(one, other)[source]

Add two affine points using the affine addition formula.

Handles the case of point at infinity gracefully (short-circuits).

Parameters:
Return type:

Point

Returns:

The addition of the two points.

affine_double(one)[source]

Double an affine point using the affine doubling formula.

Handles the case of point at infinity gracefully (short-circuits).

Parameters:

one (Point) – A point.

Return type:

Point

Returns:

The doubling of the point.

affine_negate(one)[source]

Negate an affine point using the affine negation formula.

Handles the case of point at infinity gracefully (short-circuits).

Parameters:

one (Point) – A point.

Return type:

Point

Returns:

The negation of the point.

affine_multiply(point, scalar)[source]

Multiply an affine point by a scalar using the affine doubling and addition formulas.

Handles the case of point at infinity gracefully (short-circuits).

Parameters:
  • point (Point) – The point to multiply.

  • scalar (int) – The scalar to use.

Return type:

Point

Returns:

The scalar multiplication of point.

property affine_neutral: Point | None

Get the neutral point in affine form, if it has one, otherwise None.

Returns:

The affine neutral point or None.

property neutral_is_affine

Whether the neutral point is an affine point.

is_neutral(point)[source]

Check whether the point is the neutral point.

Parameters:

point (Point) – The point to test.

Return type:

bool

Returns:

Whether it is the neutral point.

is_on_curve(point)[source]

Check whether the point is on the curve.

Parameters:

point (Point) – The point to test.

Return type:

bool

Returns:

Whether it is on the curve.

to_coords(coordinate_model)[source]

Convert this curve into a different coordinate model, only possible if it is currently affine.

Parameters:

coordinate_model (CoordinateModel) – The target coordinate model.

Return type:

EllipticCurve

Returns:

The transformed elliptic curve.

to_affine()[source]

Convert this curve into the affine coordinate model, if possible.

Return type:

EllipticCurve

Returns:

The transformed elliptic curve.

decode_point(encoded)[source]

Decode a point encoded as a sequence of bytes (ANSI X9.62).

This decoding is the same as ANSI X9.63 for the affine coordinate system and for others it only implements the uncompressed variant.

Warning

The point is not validated to be on the curve (if the uncompressed encoding is used).

Parameters:

encoded (bytes) – The encoded representation of a point.

Return type:

Point

Returns:

The decoded point.

affine_lift_x(x)[source]

Lift an x-coordinate to the curve.

Parameters:

x (Mod) – The x-coordinate.

Return type:

Set[Point]

Returns:

Lifted (affine) points, if any.

affine_random()[source]

Generate a random affine point on the curve.

Return type:

Point