Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

point+point addition #210

Closed
hamnaz opened this issue Oct 7, 2020 · 11 comments
Closed

point+point addition #210

hamnaz opened this issue Oct 7, 2020 · 11 comments
Labels

Comments

@hamnaz
Copy link

hamnaz commented Oct 7, 2020

pls someone can correct to get result

from ecdsa.curves import SECP256k1
from ecdsa.ellipticcurve import Point
from ecdsa import keys, curves
import gmpy2

x1 = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
y1 = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8

S = Point(x1, y1)

S1 = S+S

print (S1)

@tomato42
Copy link
Member

tomato42 commented Oct 7, 2020

not sure what you're attempting to do, but if you want the coordinates of the resulting point, you'll have to call x() and y(), like so:

print(S1.x())
print(S1.y())

@hamnaz
Copy link
Author

hamnaz commented Oct 7, 2020

example work and result, pls correct above script for get result
https://gist.github.com/nlitsme/c9031c7b9bf6bb009e5a
thankx

@tomato42
Copy link
Member

tomato42 commented Oct 7, 2020

you mean, something like this?

from ecdsa.curves import SECP256k1
from ecdsa.ellipticcurve import Point

x1 = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798
y1 = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8

S = Point(SECP256k1.curve, x1, y1)

S1 = S+S

print((hex(S1.x()), hex(S1.y())))

@hamnaz
Copy link
Author

hamnaz commented Oct 7, 2020

yes, but you remove import gmpy2
will above script will use gmpy2 auto or need to call import gmpy2 ?

@tomato42
Copy link
Member

tomato42 commented Oct 7, 2020

yes, it will use gmpy2 when it's installed, irrespective if other modules load it

but if speed is what you're after, you should use PointJacobi, not Point; the difference is to also specify Z=1 when initialising the object

@hamnaz
Copy link
Author

hamnaz commented Oct 7, 2020

an other thing is gmpy2 you use, but not for inverse calc, 2nd is multiprocess capabilities for refrence, where gmpy2 uses for inverse too and multiprocess import in above script setting will help to load big lists and multiprocess will done job more fast
https://github.com/Telariust/pollard-kangaroo/blob/master/pollard-kangaroo-multi.py

@tomato42
Copy link
Member

tomato42 commented Oct 7, 2020

an other thing is gmpy2 you use, but not for inverse calc,

no, the code does use gmpy2 for inverse modulo:
https://github.com/warner/python-ecdsa/blob/f27b20ff2a67c6b1afe473dd347c8da5c4017e34/src/ecdsa/numbertheory.py#L222-L229
https://github.com/warner/python-ecdsa/blob/f27b20ff2a67c6b1afe473dd347c8da5c4017e34/src/ecdsa/numbertheory.py#L21-L25

and I did recently verify that it does use a special case algorithm for the x^-1 power: #204 (comment)

2nd is multiprocess capabilities for refrence, where gmpy2 uses for inverse too and multiprocess import in above script setting will help to load big lists and multiprocess will done job more fast
https://github.com/Telariust/pollard-kangaroo/blob/master/pollard-kangaroo-multi.py

I can imagine using multiprocessing to calculate scalar multiply with precomputed multiples, but without precomputation? No, I don't think the point-double&add algorithm is parallelizable...

@hamnaz
Copy link
Author

hamnaz commented Oct 10, 2020

prev i were useing fastecdsa lib in python script, now i tested with python-ecdsa, same speed work, how i could check if my script is useing gmpy2, or you know fastecdsa also useing gmpy2
both script same speed, or maybe more fast we need to use cupy( cuda work ) for these python script, have you ever experiance with cupy ?

@tomato42
Copy link
Member

tomato42 commented Oct 10, 2020

As far as I know, fastecdsa 1.7.5 is slower than python-ecdsa 0.15 and later: AntonKueltz/fastecdsa#45. While fastecdsa doesn't use gmpy2 it does use libgmp, so in the end we both use the same arbitrary precision arithmetic library...

both script same speed

that seems unlikely, I don't see any configuration in which python-ecdsa performance would be equal to fastecdsa performance... even without gmpy2 python-ecdsa 0.15 and later should be faster

or maybe more fast we need to use cupy( cuda work ) for these python script, have you ever experiance with cupy ?

no, never used cupy, but it's compatible with numpy, not gmpy2; numpy is good for vector and matrix operations, gmpy2 is for arbitrary precision arithmetic, they target completely different problems

finally, I don't think running a single scalar multiplication with CUDA would be faster than on a CPU, I'd be surprised if the communication overhead wouldn't kill any performance improvements

now, you could use CUDA to perform multiple scalar multiplications at the same time, if you'd use Montgomery ladder for it, and Fermat's theorem for calculating inverses modulo, but you'd have to completely rewrite this library to do that—as this is a general-purpose ECC/ECDSA library, I'd consider addition of such code to it to be out of scope

@hamnaz
Copy link
Author

hamnaz commented Oct 18, 2020

can i send you email at [email protected] for discus more ?

@tomato42
Copy link
Member

tomato42 commented Oct 18, 2020

  1. it's not my email
  2. I'm not interested in work for hire.
    1. If it is security related: please see the security section in README.md — python-ecdsa is a toy library
    2. If it is performance related: you're looking at wrong programming language. And I'm not interested in writing performance-critical assembly, C or C++ code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants