Bitcoin Forum
May 07, 2024, 08:53:57 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Pure Python ECDSA implementation?  (Read 2125 times)
itod (OP)
Legendary
*
Offline Offline

Activity: 1974
Merit: 1076


^ Will code for Bitcoins


View Profile
January 26, 2014, 10: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.
The block chain is the main innovation of Bitcoin. It is the first distributed timestamping system.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715072037
Hero Member
*
Offline Offline

Posts: 1715072037

View Profile Personal Message (Offline)

Ignore
1715072037
Reply with quote  #2

1715072037
Report to moderator
1715072037
Hero Member
*
Offline Offline

Posts: 1715072037

View Profile Personal Message (Offline)

Ignore
1715072037
Reply with quote  #2

1715072037
Report to moderator
Cytality
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
January 26, 2014, 11: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.
Sammey
Newbie
*
Offline Offline

Activity: 38
Merit: 0


View Profile
January 26, 2014, 11: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
itod (OP)
Legendary
*
Offline Offline

Activity: 1974
Merit: 1076


^ Will code for Bitcoins


View Profile
January 26, 2014, 11: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.
Evil-Knievel
Legendary
*
Offline Offline

Activity: 1260
Merit: 1168



View Profile
January 26, 2014, 11:33:46 PM
Last edit: April 17, 2016, 09:18:41 PM by Evil-Knievel
 #5

This message was too old and has been purged
Cytality
Newbie
*
Offline Offline

Activity: 4
Merit: 0


View Profile
January 26, 2014, 11: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
itod (OP)
Legendary
*
Offline Offline

Activity: 1974
Merit: 1076


^ Will code for Bitcoins


View Profile
January 26, 2014, 11: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.
maaku
Legendary
*
expert
Offline Offline

Activity: 905
Merit: 1011


View Profile
January 27, 2014, 12:52:38 AM
 #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)

I'm an independent developer working on bitcoin-core, making my living off community donations.
If you like my work, please consider donating yourself: 13snZ4ZyCzaL7358SmgvHGC9AxskqumNxP
Remember remember the 5th of November
Legendary
*
Offline Offline

Activity: 1862
Merit: 1011

Reverse engineer from time to time


View Profile
January 27, 2014, 12:54:26 AM
 #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

BTC:1AiCRMxgf1ptVQwx6hDuKMu4f7F27QmJC2
itod (OP)
Legendary
*
Offline Offline

Activity: 1974
Merit: 1076


^ Will code for Bitcoins


View Profile
January 27, 2014, 01:05:01 AM
 #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.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!