`verify()` raises `TypeError` instead of rejecting when `u1*G + u2*Q` is the point at infinity

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

还没有人认领这个 Issue。

评估

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

调研方向

从 src/ecdsa/ecdsa.py 中的 Public_key.verifies 开始,其中 xy 是在 mul_add 和 plain 分支之后计算的。使用 r = s = 1 和公钥 Q = -e*G 运行提供的复现程序,以确认 TypeError,然后修改验证路径,使其拒绝无穷远点,而不是计算其 x 坐标。使用提到的 Wycheproof ecdsa_brainpool*_test.json 用例添加或更新回归测试,并确认验证会抛出 BadSignatureError。

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

描述

Versions: python-ecdsa 0.19.2 (latest release), CPython 3.13.15. The code path is unchanged on master as of
2026-11-28 (src/ecdsa/ecdsa.py, Public_key.verifies).

What happens

When the verification sum u1*G + u2*Q is the point at infinity, Public_key.verifies evaluates
v = xy.x() % n with xy.x() returning None, so VerifyingKey.verify() raises

TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

instead of BadSignatureError. This happens for a valid public key and a signature with r and s in [1, n-1],
on every curve (reproduced on NIST P-256 and brainpoolP256r1). A caller that catches only BadSignatureError, as the
documentation suggests, gets an unhandled exception on attacker-chosen input.

No forgery: the signature is never accepted.

Reproducer (no test vectors needed)

Choose r = s = 1 and the public key Q = -e*G, so u1*G + u2*Q = e*G - e*G = O:

import hashlib, ecdsa
from ecdsa import VerifyingKey, BadSignatureError
from ecdsa.curves import NIST256p
from ecdsa.util import sigencode_der, sigdecode_der

msg = b"point at infinity during verify"
n, G = NIST256p.order, NIST256p.generator
e = int.from_bytes(hashlib.sha256(msg).digest(), "big")
vk = VerifyingKey.from_public_point(G * ((-e) % n), curve=NIST256p, hashfunc=hashlib.sha256)
try:
    vk.verify(sigencode_der(1, 1, n), msg, sigdecode=sigdecode_der)
except BadSignatureError:
    print("rejected (expected)")
# actual on 0.19.2: TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

pyca/cryptography rejects the same key, signature and message with InvalidSignature.

The same exception is raised on the Wycheproof testvectors_v1 cases flagged PointDuplication /
ArithmeticError ("duplication bug", "point at infinity during verify", "comparison with point at infinity"):
67 test cases across the five ecdsa_brainpool*_test.json files.

Suggested fix

In Public_key.verifies, after computing xy (both the mul_add and the plain branch):

if xy == ellipticcurve.INFINITY:
    return False

Related, but a different path: #341 (TypeError instead of InvalidPointError from
VerifyingKey.from_public_point(INFINITY)).

主要语言
Python
星标
975
派生
346
平均合并
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 摘要。