Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/ecdsa/ecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ def __init__(self, generator, point, verify=True):
self.point = point
n = generator.order()
p = self.curve.p()
if point == ellipticcurve.INFINITY:
raise InvalidPointError("The public point is the point at infinity.")
if not (0 <= point.x() < p) or not (0 <= point.y() < p):
raise InvalidPointError(
"The public point has x or y out of range."
Expand Down
2 changes: 2 additions & 0 deletions src/ecdsa/keys.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ def from_public_point(
self = cls(_error__please_use_generate=True)
if isinstance(curve.curve, CurveEdTw):
raise ValueError("Method incompatible with Edwards curves")
if point == ellipticcurve.INFINITY:
raise MalformedPointError("Cannot use the point at infinity as a public key")
if not isinstance(point, ellipticcurve.PointJacobi):
point = ellipticcurve.PointJacobi.from_affine(point)
self.curve = curve
Expand Down
8 changes: 7 additions & 1 deletion src/ecdsa/test_pyecdsa.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
curve_brainpoolp384r1,
curve_brainpoolp512r1,
)
from .ellipticcurve import Point
from .ellipticcurve import Point, INFINITY
from . import der
from . import rfc6979
from . import ecdsa
Expand Down Expand Up @@ -957,6 +957,12 @@ def test_decoding_with_point_at_infinity(self):
with self.assertRaises(MalformedPointError):
VerifyingKey.from_string(b"\x00")

def test_from_public_point_with_infinity_raises_malformed(self):
# passing INFINITY to from_public_point must raise MalformedPointError,
# not TypeError (GitHub issue #341)
with self.assertRaises(MalformedPointError):
VerifyingKey.from_public_point(INFINITY)

def test_not_lying_on_curve(self):
enc = number_to_string(NIST192p.curve.p(), NIST192p.curve.p() + 1)

Expand Down