AntonKueltz / fastecdsa

Python library for fast elliptic curve crypto
https://pypi.python.org/pypi/fastecdsa
The Unlicense
263 stars 76 forks source link

ValueError when multiplying the generator with the order of the curve #54

Closed ghost closed 4 years ago

ghost commented 4 years ago

Multiplying the generator with the order of the curve gives a ValueError:

$ python -c 'from fastecdsa.curve import secp256k1; secp256k1.q * secp256k1.G'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/bbralf/brainbot-com/venv/lib64/python3.8/site-packages/fastecdsa/point.py", line 163, in __rmul__
    return self.__mul__(scalar)
  File "/home/bbralf/brainbot-com/venv/lib64/python3.8/site-packages/fastecdsa/point.py", line 150, in __mul__
    return Point(int(x), int(y), self.curve)
  File "/home/bbralf/brainbot-com/venv/lib64/python3.8/site-packages/fastecdsa/point.py", line 33, in __init__
    raise ValueError(
ValueError: coordinates are not on curve <secp256k1>
        x=0
        y=0
AntonKueltz commented 4 years ago

Good catch, v2.1.2 broke this when it fixed the C extension's handling of the point at infinity. (The joys of Weierstrass curves, this is why the Montgomery curves like Curve25519 are better for implementors and more resistant to side channels). Fixed in commit a591b79 (version v2.1.3).

➜  ~ pip install fastecdsa==2.1.3
Collecting fastecdsa==2.1.3
  Using cached fastecdsa-2.1.3-cp38-cp38-macosx_10_14_x86_64.whl (53 kB)
Installing collected packages: fastecdsa
Successfully installed fastecdsa-2.1.3
➜  ~ python -c 'from fastecdsa.curve import secp256k1; secp256k1.q * secp256k1.G'
➜  ~
ghost commented 4 years ago

Thanks!