Post
Topic
Board Development & Technical Discussion
Re: Pure Python ECDSA implementation?
by
maaku
on 27/01/2014, 00:52:38 UTC
It has secp256k1 in git master, although not in the last release I tried. If you don't want to track head, it's simple enough to monkey-patch in support:

Code:
# Import as a different name so as to clearly distinguish from our ecdsa* modules
import ecdsa as pyecdsa

# Certicom secp256-k1, the ECDSA curve used by Bitcoin. This curve has recently
# been added to the python-ecdsa repository, but is still missing from the latest
# version on PyPI.
try:
    SECP256k1 = pyecdsa.curves.find_curve((1, 3, 132, 0, 10))
except pyecdsa.curves.UnknownCurveError:
    _a = 0x0000000000000000000000000000000000000000000000000000000000000000L
    _b = 0x0000000000000000000000000000000000000000000000000000000000000007L
    _p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2FL
    _Gx = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798L
    _Gy = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8L
    _r = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141L
    curve_secp256k1 = pyecdsa.ellipticcurve.CurveFp(_p, _a, _b)
    generator_secp256k1 = pyecdsa.ellipticcurve.Point(curve_secp256k1, _Gx, _Gy, _r)
    SECP256k1 = pyecdsa.curves.Curve('SECP256k1',
                                     curve_secp256k1,
                                     generator_secp256k1,
                                     (1, 3, 132, 0, 10))
    pyecdsa.curves.curves.append(SECP256k1)