Skip to content

Curves

This module, named curves, provides a set of predefined elliptic curve parameters commonly used in cryptographic systems, particularly in the realm of Elliptic Curve Cryptography (ECC). These curves are standardized and have undergone extensive review to ensure their cryptographic strength.

Table of Curves

The module includes parameters for the following well-known elliptic curves:

  • secp192k1
  • secp192r1
  • secp224k1
  • secp224r1
  • secp256k1 (also known for its use in the Bitcoin cryptocurrency system)
  • secp256r1
  • secp384r1
  • secp521r1

Curve Object Properties

Each predefined curve, represented as an EllipticCurve object, includes the following properties:

  • p: The prime number that defines the finite field over which the elliptic curve is defined.
  • a: The 'a' coefficient in the elliptic curve equation.
  • b: The 'b' coefficient in the elliptic curve equation.
  • G: The base point (or generator point) on the elliptic curve. It is a point with the coordinates (x, y) lying on the curve.
  • n: The order of the base point, which is the total number of points in the subgroup generated by the base point.
  • h: The cofactor, which is the ratio of the total number of points on the elliptic curve to the order of the base point.

Using the get Function

The get function is the primary method for retrieving an EllipticCurve object from the module:

Signature:

def get(name: str) -> EllipticCurve:

Parameters:

  • name: A string representing the standard name of the elliptic curve you wish to retrieve. The name should match one of those listed in the "Table of Curves" section above.

Returns:

  • EllipticCurve: An object encapsulating all the aforementioned properties associated with the named curve.

Raises:

  • KeyError: This exception is raised if the named curve is not available within the module's predefined set.

Examples:

from ecutils.curves import get

# To retrieve parameters for the 'secp256k1' curve
secp256k1_curve = get('secp256k1')

# With 'secp256k1_curve', you can now access its properties
print(secp256k1_curve.p)  # Outputs the prime 'p' defining the finite field
print(secp256k1_curve.G)  # Outputs the base point 'G' as a Point object with 'x' and 'y' attributes

Notes on Exception Handling:

It is recommended to handle potential KeyError exceptions when using the get function to gracefully manage cases where a curve name may be mistyped or not in the module.

try:
    custom_curve = get('typoCurveName')
except KeyError as e:
    print(e)  # Prints an appropriate message indicating the curve name was not found

Other Considerations:

  • For secure applications, it is critical to use standardized and vetted curves to ensure the cryptographic strength and security of the system.
  • The curves provided by the curves module conform to established standards, making them suitable for cryptographic applications that require elliptic curve parameters.