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

未关闭 适合新手
#387 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
62/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
cryptography

调研方向

仿射倍点运算是椭圆曲线模块(src/ecdsa/ellipticcurve.py)中的 Point.double(),同一文件中的 PointJacobi 是给出正确结果的参考实现。先复现 issue 中的四行代码片段,然后找到 double() 判定结果为无穷远点的位置,检查该判断使用的是 y 还是斜率。完成标准是:对该点,P.double()、P + P 和 2 * P 返回 (2, p - y),与 PointJacobi 结果一致,并添加一个回归测试,覆盖斜率为零且 y 不为零的情况。

由索引模型根据 Issue 内容生成。

描述

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!

主要语言
Python
星标
976
派生
345
平均合并
26 分钟
30 天内合并 PR
1

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

tlsfuzzer/python-ecdsa 的其他 Issue

查看 tlsfuzzer/python-ecdsa 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。