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

Đang mở Phù hợp với người mới
#389 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
90/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
cryptography, python
Lĩnh vực
cryptography, security

Hướng nghiên cứu

Bắt đầu với Public_key.verifies trong src/ecdsa/ecdsa.py, nơi xy được tính sau các nhánh mul_add và plain. Chạy bộ tái hiện được cung cấp với r = s = 1 và khóa công khai Q = -e*G để xác nhận TypeError, sau đó sửa luồng xác minh để từ chối điểm vô cùng thay vì tính tọa độ x của nó. Thêm hoặc cập nhật phạm vi kiểm thử hồi quy bằng các trường hợp Wycheproof được đề cập trong ecdsa_brainpool*_test.json và xác nhận rằng quá trình xác minh ném BadSignatureError.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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)).

Ngôn ngữ chính
Python
Star
975
Fork
346
Merge trung bình
26 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của tlsfuzzer/python-ecdsa

Tất cả issue của tlsfuzzer/python-ecdsa

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.