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

オープン 初心者向け
#389 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
1

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tlsfuzzer/python-ecdsa のほかの issue

tlsfuzzer/python-ecdsa の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。