Author

Topic: Pure Python ECDSA implementation? (Read 2151 times)

legendary
Activity: 1974
Merit: 1077
Honey badger just does not care
January 26, 2014, 08:05:01 PM
#10
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:



Thanks to both of you, will try it tommorow.
legendary
Activity: 1862
Merit: 1011
Reverse engineer from time to time
January 26, 2014, 07:54:26 PM
#9
Take a look at my "MINING" thread currently to be found in the Service->Marketplace section.
There you have a pure python secp256k1 implementation in my github project.

Thanks, Evil-Knievel! No wonder I haven't found it when it's so fresh. Off to take a good look how to use it.




It was updated a long time ago to include the secp521r1 curve. Look:

https://github.com/warner/python-ecdsa/blob/master/README.md

Bitcoin is Secp256k1, not Secp521r1, different curves.



https://github.com/warner/python-ecdsa/blob/master/ecdsa/curves.py
legendary
Activity: 905
Merit: 1012
January 26, 2014, 07:52:38 PM
#8
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)
legendary
Activity: 1974
Merit: 1077
Honey badger just does not care
January 26, 2014, 06:49:48 PM
#7
Take a look at my "MINING" thread currently to be found in the Service->Marketplace section.
There you have a pure python secp256k1 implementation in my github project.

Thanks, Evil-Knievel! No wonder I haven't found it when it's so fresh. Off to take a good look how to use it.




It was updated a long time ago to include the secp521r1 curve. Look:

https://github.com/warner/python-ecdsa/blob/master/README.md

Bitcoin is Secp256k1, not Secp521r1, different curves.
newbie
Activity: 4
Merit: 0
January 26, 2014, 06:35:59 PM
#6
It was updated a long time ago to include the secp521r1 curve. Look:

https://github.com/warner/python-ecdsa/blob/master/README.md
legendary
Activity: 1260
Merit: 1168
January 26, 2014, 06:33:46 PM
#5
This message was too old and has been purged
legendary
Activity: 1974
Merit: 1077
Honey badger just does not care
January 26, 2014, 06:27:11 PM
#4
Is there a pure Python ECDSA Secp256k1 implementation? I don't care how slow it is, because calling libcrypto in a loop gives me Segmentation fault every 3-4 million loops. I'm using Joric/bitcoin-dev implementation and I've tried to find the cause with gdb, but give up on it, have no more nerves for it.

Using some utility through RPC is not an attractive option because of overhead. If anyone has a link to a native Python solution I would be grateful.


https://github.com/warner/python-ecdsa



Sorry, but just a slightly off-kilter question for you... Why not use C++? I assume you may develop Python on a Linux platform, so development and IDE usage would be similar. Hell, even the syntax is similar. With C++, however, you get more control from your code.

I've found that, but README says:
Curves included:  prime192v1, secp224r1, prime256v1, secp384r1, and secp521r1.
Problem is Bitcoin's Secp256k1 is not there, and I'm not sure if I would dare to do that myself.

Regarding your C++ question, I've never done any serious C++ work, just very small things, but this thing made me ask that same question myself. If I don't find a solution by tomorrow I'll give up on Python for this job. Even tried to see how Armory is doing that, and it also depends on non-native library. I've Googled it everywhere before I've posted a question here.
newbie
Activity: 38
Merit: 0
January 26, 2014, 06:08:03 PM
#3
Is there a pure Python ECDSA Secp256k1 implementation? I don't care how slow it is, because calling libcrypto in a loop gives me Segmentation fault every 3-4 million loops. I'm using Joric/bitcoin-dev implementation and I've tried to find the cause with gdb, but give up on it, have no more nerves for it.

Using some utility through RPC is not an attractive option because of overhead. If anyone has a link to a native Python solution I would be grateful.


https://github.com/warner/python-ecdsa



Sorry, but just a slightly off-kilter question for you... Why not use C++? I assume you may develop Python on a Linux platform, so development and IDE usage would be similar. Hell, even the syntax is similar. With C++, however, you get more control from your code.

Was going to post that link. Looks like you beat me to it.  Roll Eyes
newbie
Activity: 4
Merit: 0
January 26, 2014, 06:05:56 PM
#2
Is there a pure Python ECDSA Secp256k1 implementation? I don't care how slow it is, because calling libcrypto in a loop gives me Segmentation fault every 3-4 million loops. I'm using Joric/bitcoin-dev implementation and I've tried to find the cause with gdb, but give up on it, have no more nerves for it.

Using some utility through RPC is not an attractive option because of overhead. If anyone has a link to a native Python solution I would be grateful.


https://github.com/warner/python-ecdsa



Sorry, but just a slightly off-kilter question for you... Why not use C++? I assume you may develop Python on a Linux platform, so development and IDE usage would be similar. Hell, even the syntax is similar. With C++, however, you get more control from your code.
legendary
Activity: 1974
Merit: 1077
Honey badger just does not care
January 26, 2014, 05:59:42 PM
#1
Is there a pure Python ECDSA Secp256k1 implementation? I don't care how slow it is, because calling libcrypto in a loop gives me Segmentation fault every 3-4 million loops. I'm using Joric/bitcoin-dev implementation and I've tried to find the cause with gdb, but give up on it, have no more nerves for it.

Using some utility through RPC is not an attractive option because of overhead. If anyone has a link to a native Python solution I would be grateful.
Jump to: