LightECC
LightECC is a lightweight Python library for Elliptic Curve Cryptography (ECC) arithmetic. It provides support for various elliptic curve forms, including Weierstrass, Koblitz, and Edwards, along with many pre-defined curves. The library simplifies fundamental ECC operations such as point addition, subtraction, scalar multiplication, and division. As of its current version 0.0.5, LightECC aims to make ECC operations accessible without requiring deep understanding of the underlying mathematical principles. The library appears to be actively maintained, with recent updates.
Common errors
-
ModuleNotFoundError: No module named 'lightecc'
cause The 'lightecc' package is not installed in the current Python environment or there's a typo in the import statement.fixEnsure the package is installed using `pip install lightecc`. Verify the import statement is `from lightecc import LightECC`. -
AttributeError: 'LightECC' object has no attribute 'some_nonexistent_attribute'
cause Attempting to access an attribute or method on a `LightECC` object that does not exist or is misspelled. This often happens when mistaking object properties or methods.fixCheck the LightECC documentation or the object's available methods (e.g., using `dir(ec)`) to ensure the correct attribute or method name is used. -
TypeError: unsupported operand type(s) for +: 'Point' and 'int'
cause Attempting to perform an arithmetic operation (e.g., addition, subtraction) between a LightECC `Point` object and an incompatible type, such as a plain integer, when a `Point` or scalar is expected.fixEnsure that arithmetic operations are performed between compatible LightECC `Point` objects or between a `Point` and a scalar (for multiplication). For point addition/subtraction, both operands must be `Point` instances.
Warnings
- gotcha Elliptic curve point division in LightECC involves solving the Elliptic Curve Discrete Logarithm Problem (ECDLP). This operation is computationally difficult and has an O(n) time complexity with brute force, making it very slow for practical cryptographic sizes.
- gotcha LightECC supports a specific set of pre-defined elliptic curves across different forms (Weierstrass, Koblitz, Edwards). Using an unsupported curve name or form, or one with an insufficient 'order' (n), will result in errors or a cryptographically weak system.
Install
-
pip install lightecc
Imports
- LightECC
from lightecc import LightECC
Quickstart
from lightecc import LightECC
# Initialize an elliptic curve (defaults to Weierstrass if no form_name is given)
ec = LightECC(form_name="edwards", curve_name="ed25519")
# Get the base point G of the curve
G = ec.G
# Perform point arithmetic
_2G = G + G
_3G = _2G + G
_5G = _3G + _2G
_10G = _5G + _5G
_9G = _10G - G
# Scalar multiplication
_20G = 20 * G
_50G = 50 * G
# Division (solves ECDLP - computationally intensive)
_25G = _50G / G
print(f"Base point G: {G}")
print(f"2G: {_2G}")
print(f"50G divided by G (25G): {_25G}")