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

TypeError instead of InvalidPointError on VerifyingKey.from_public_point(INFINITY) #341

Open
akarve opened this issue Jun 11, 2024 · 1 comment
Labels
bug unintended behaviour in ecdsa code help wanted
Milestone

Comments

@akarve
Copy link

akarve commented Jun 11, 2024

I was experimenting to understand how the library handles failures. I don't expect the following line to work but I do expect it to raise a different error (MalformedPoint, not Type).

VerifyingKey.from_public_point(INFINITY)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 VerifyingKey.from_public_point(INFINITY)

File ~/miniconda3/envs/de/lib/python3.9/site-packages/ecdsa/keys.py:170, in VerifyingKey.from_public_point(cls, point, curve, hashfunc, validate_point)
    168 self.default_hashfunc = hashfunc
    169 try:
--> 170     self.pubkey = ecdsa.Public_key(
    171         curve.generator, point, validate_point
    172     )
    173 except ecdsa.InvalidPointError:
    174     raise MalformedPointError("Point does not lay on the curve")

File ~/miniconda3/envs/de/lib/python3.9/site-packages/ecdsa/ecdsa.py:151, in Public_key.__init__(self, generator, point, verify)
    149 n = generator.order()
    150 p = self.curve.p()
--> 151 if not (0 <= point.x() < p) or not (0 <= point.y() < p):
    152     raise InvalidPointError(
    153         "The public point has x or y out of range."
    154     )
    155 if verify and not self.curve.contains_point(point.x(), point.y()):

TypeError: '<=' not supported between instances of 'int' and 'NoneType'

Related: for cases where one wishes to avoid the point at infinity is this the right way to detect it if point == ellipticcurve.INFINITY? I kind of expected infinity to vary by the curve family but there's nothing under eg SECKP256k1 that I can find.

@tomato42
Copy link
Member

the INFINITY is a special kind of object that's it's a point at infinity for all curves and all representations, and yes, it should raise MalformedPointError here

@tomato42 tomato42 added the bug unintended behaviour in ecdsa code label Jun 12, 2024
@tomato42 tomato42 added this to the v0.20.0 milestone Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unintended behaviour in ecdsa code help wanted
Projects
None yet
Development

No branches or pull requests

2 participants