`Point.double()` gives infinity for a valid point on NIST192p

Open Beginner friendly
#387 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
62/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
cryptography

Research direction

The affine doubling is Point.double() in the elliptic-curve module (src/ecdsa/ellipticcurve.py), and PointJacobi in the same file is the reference that gives the right answer. Start by reproducing the four-line snippet from the issue, then find where double() decides the result is infinity and check whether that test uses y or the slope. Done when P.double(), P + P and 2 * P return (2, p - y) for this point, match PointJacobi, and a regression test covering a zero slope with nonzero y is added.

Written by the indexing model from the issue text.

Description

Hi,

I've been using python-ecdsa as a reference while writing some test vectors for my own curve code, and ran into something odd with the affine Point class on NIST192p: doubling this point gives INFINITY.

from ecdsa.curves import NIST192p
from ecdsa.ellipticcurve import Point, PointJacobi

curve = NIST192p.curve
p, a, b = curve.p(), curve.a(), curve.b()

x = p - 1
y = pow(x**3 + a*x + b, (p + 1) // 4, p)
P = Point(curve, x, y)  # on the curve, the constructor accepts it

print("P.double()", P.double())
print("P + P     ", P + P)
print("2 * P     ", 2 * P)
print("Jacobi    ", PointJacobi.from_affine(P).double().to_affine())

Output:

P.double() infinity
P + P      infinity
2 * P      infinity
Jacobi     (2,5150145059219101967911223597381767395814993794044679600504)

$y$ isn't 0 here, so the double shouldn't be infinity; it should be $(2,\ p - y)$, which is what PointJacobi gives. P + P and 2 * P are wrong the same way. This is with ecdsa 0.19.2 from pip.

Some potential clues: for this point $3x^2 + a \equiv 0 \pmod{p}$, so the slope in double() is 0 even though $y \neq 0$. I guess the zero slope ends up being treated as the infinity case, which is only right when $y = 0$.

Thank you!

Dominant language
Python
Stars
976
Forks
345
Avg merge
26m
Merged PRs (30d)
1

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from tlsfuzzer/python-ecdsa

All issues in tlsfuzzer/python-ecdsa

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.