ecdsa.ellipticcurve module
- class ecdsa.ellipticcurve.AbstractPoint[source]
Bases:
object
Class for common methods of elliptic curve points.
- classmethod from_bytes(curve, data, validate_encoding=True, valid_encodings=None)[source]
Initialise the object from byte encoding of a point.
The method does accept and automatically detect the type of point encoding used. It supports the raw encoding, uncompressed, compressed, and hybrid encodings.
Note: generally you will want to call the
from_bytes()
method of either a child class, PointJacobi or Point.- Parameters:
data (bytes-like object) – single point encoding of the public key
curve (CurveFp) – the curve on which the public key is expected to lay
validate_encoding (bool) – whether to verify that the encoding of the point is self-consistent, defaults to True, has effect only on
hybrid
encodingvalid_encodings (set-like object) – list of acceptable point encoding formats, supported ones are: uncompressed, compressed, hybrid, and raw encoding (specified with
raw
name). All formats by default (specified withNone
).
- Raises:
MalformedPointError – if the public point does not lay on the curve or the encoding is invalid
- Returns:
x and y coordinates of the encoded point
- Return type:
- to_bytes(encoding='raw')[source]
Convert the point to a byte string.
The method by default uses the raw encoding (specified by encoding=”raw”. It can also output points in uncompressed, compressed, and hybrid formats.
For points on Edwards curves encoding is ignored and only the encoding defined in RFC 8032 is supported.
- Returns:
raw encoding of a public on the curve
- Return type:
- class ecdsa.ellipticcurve.CurveEdTw(p, a, d, h=None, hash_func=None)[source]
Bases:
object
Parameters for a Twisted Edwards Elliptic Curve
- class ecdsa.ellipticcurve.CurveFp(p, a, b, h=None)[source]
Bases:
object
Short Weierstrass Elliptic Curve over a prime field.
- class ecdsa.ellipticcurve.Point(curve, x, y, order=None)[source]
Bases:
AbstractPoint
A point on a short Weierstrass elliptic curve. Altering x and y is forbidden, but they can be read by the x() and y() methods.
- classmethod from_bytes(curve, data, validate_encoding=True, valid_encodings=None, order=None)[source]
Initialise the object from byte encoding of a point.
The method does accept and automatically detect the type of point encoding used. It supports the raw encoding, uncompressed, compressed, and hybrid encodings.
- Parameters:
data (bytes-like object) – single point encoding of the public key
curve (CurveFp) – the curve on which the public key is expected to lay
validate_encoding (bool) – whether to verify that the encoding of the point is self-consistent, defaults to True, has effect only on
hybrid
encodingvalid_encodings (set-like object) – list of acceptable point encoding formats, supported ones are: uncompressed, compressed, hybrid, and raw encoding (specified with
raw
name). All formats by default (specified withNone
).order (int) – the point order, must be non zero when using generator=True
- Raises:
MalformedPointError – if the public point does not lay on the curve or the encoding is invalid
- Returns:
Point on curve
- Return type:
- to_bytes(encoding='raw')
Convert the point to a byte string.
The method by default uses the raw encoding (specified by encoding=”raw”. It can also output points in uncompressed, compressed, and hybrid formats.
For points on Edwards curves encoding is ignored and only the encoding defined in RFC 8032 is supported.
- Returns:
raw encoding of a public on the curve
- Return type:
- class ecdsa.ellipticcurve.PointEdwards(curve, x, y, z, t, order=None, generator=False)[source]
Bases:
AbstractPoint
Point on Twisted Edwards curve.
Internally represents the coordinates on the curve using four parameters, X, Y, Z, T. They correspond to affine parameters ‘x’ and ‘y’ like so:
x = X / Z y = Y / Z x*y = T / Z
- classmethod from_bytes(curve, data, validate_encoding=None, valid_encodings=None, order=None, generator=False)[source]
Initialise the object from byte encoding of a point.
validate_encoding and valid_encodings are provided for compatibility with Weierstrass curves, they are ignored for Edwards points.
- Parameters:
data (bytes-like object) – single point encoding of the public key
curve (ecdsa.ellipticcurve.CurveEdTw) – the curve on which the public key is expected to lay
validate_encoding (None) – Ignored, encoding is always validated
valid_encodings (None) – Ignored, there is just one encoding supported
order (int) – the point order, must be non zero when using generator=True
generator (bool) – Flag to mark the point as a curve generator, this will cause the library to pre-compute some values to make repeated usages of the point much faster
- Raises:
MalformedPointError – if the public point does not lay on the curve or the encoding is invalid
- Returns:
Initialised point on an Edwards curve
- Return type:
- to_bytes(encoding='raw')
Convert the point to a byte string.
The method by default uses the raw encoding (specified by encoding=”raw”. It can also output points in uncompressed, compressed, and hybrid formats.
For points on Edwards curves encoding is ignored and only the encoding defined in RFC 8032 is supported.
- Returns:
raw encoding of a public on the curve
- Return type:
- class ecdsa.ellipticcurve.PointJacobi(curve, x, y, z, order=None, generator=False)[source]
Bases:
AbstractPoint
Point on a short Weierstrass elliptic curve. Uses Jacobi coordinates.
In Jacobian coordinates, there are three parameters, X, Y and Z. They correspond to affine parameters ‘x’ and ‘y’ like so:
x = X / Z² y = Y / Z³
- static from_affine(point, generator=False)[source]
Create from an affine point.
- Parameters:
generator (bool) – set to True to make the point to precalculate multiplication table - useful for public point when verifying many signatures (around 100 or so) or for generator points of a curve.
- classmethod from_bytes(curve, data, validate_encoding=True, valid_encodings=None, order=None, generator=False)[source]
Initialise the object from byte encoding of a point.
The method does accept and automatically detect the type of point encoding used. It supports the raw encoding, uncompressed, compressed, and hybrid encodings.
- Parameters:
data (bytes-like object) – single point encoding of the public key
curve (CurveFp) – the curve on which the public key is expected to lay
validate_encoding (bool) – whether to verify that the encoding of the point is self-consistent, defaults to True, has effect only on
hybrid
encodingvalid_encodings (set-like object) – list of acceptable point encoding formats, supported ones are: uncompressed, compressed, hybrid, and raw encoding (specified with
raw
name). All formats by default (specified withNone
).order (int) – the point order, must be non zero when using generator=True
generator (bool) – the point provided is a curve generator, as such, it will be commonly used with scalar multiplication. This will cause to precompute multiplication table generation for it
- Raises:
MalformedPointError – if the public point does not lay on the curve or the encoding is invalid
- Returns:
Point on curve
- Return type:
- mul_add(self_mul, other, other_mul)[source]
Do two multiplications at the same time, add results.
calculates self*self_mul + other*other_mul
- to_bytes(encoding='raw')
Convert the point to a byte string.
The method by default uses the raw encoding (specified by encoding=”raw”. It can also output points in uncompressed, compressed, and hybrid formats.
For points on Edwards curves encoding is ignored and only the encoding defined in RFC 8032 is supported.
- Returns:
raw encoding of a public on the curve
- Return type:
- ecdsa.ellipticcurve.bytes_to_int(bytes, byteorder='big', *, signed=False)
Return the integer represented by the given array of bytes.
- bytes
Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.
- byteorder
The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.
- signed
Indicates whether two’s complement is used to represent the integer.