Danger
Nothing here should be used for any security purposes.
Elliptic curves¶
This module is imported with:
import toy_crypto.ec
I wrote this for the sole purposes of
Providing a working context to illustrate the double-and-add algorithm in the
Point.scaler_multiply()
method.Doing calculations over floats that I could use for diagrams. (That code has been removed.)
from toy_crypto.ec import Curve
from toy_crypto.nt import Modulus
# Example curve from Serious Cryptography
curve = Curve(-4, 0, 191)
assert str(curve) == "y^2 = x^3 - 4x + 0 (mod 191)"
# set a generator (base-point), G
G = curve.point(146, 131)
assert G.on_curve() is True
five_G = G.scaler_multiply(5)
assert five_G.x == 61
assert five_G.y == 163
The ec
classes¶
- class toy_crypto.ec.Curve(a: int, b: int, p: int)¶
Define a curve of the form \(y^2 = x^3 + ax + b \pmod p\).
- class toy_crypto.ec.Point(x: int, y: int, curve: Curve)¶
Point on elliptic curve over finite field.
Create a mutable point on a curve.
- iadd(Q: Self) Self ¶
add point to self in place.
The Point at Infinity is not mutable. But you can make a mutable copy with
curve.PAI.cp()
. Or you could just usePoint.add()
.- Raises:
ValueError – if Q is not on its own curve
ValueError – if Q and self are on different curves
NotImplementedError – if self is not a mutable point.
- Parameters:
- Return type:
- idouble() Self ¶
Double point in place.
The Point at Infinity is not mutable. But you can make a mutable copy with
curve.PAI.cp()
or just usePoint.double()
.- Raises:
NotImplementedError – if self is not a mutable point.
- Return type: