fixed public ky recovery bug
@@ -118,6 +118,11 @@ def _ecdsa_verhlp(ec: EC, e: int, P: Point, sig: ECDS) -> bool:
# Fail if s is not [1, n-1]
r, s = to_dsasig(ec, sig) # 1
+ # Let P = point(pk); fail if point(pk) fails.
+ ec.requireOnCurve(P)
+ if P[1] == 0:
+ raise ValueError("public key is infinite")
+
s1 = mod_inv(s, ec.n)
u = e*s1
v = r*s1 # 4
@@ -166,9 +171,11 @@ def _ecdsa_pubkey_recovery(ec: EC, e: int, sig: ECDS) -> List[Point]:
R = (x, ec.yOdd(x, 1)) # 1.2, 1.3, and 1.4
# 1.5 already taken care outside this for loop
Q = DblScalarMult(ec, r1s, R, r1e, ec.G) # 1.6.1
- keys.append(Q) # 1.6.2
+ if Q[1] != 0: # 1.6.2
+ keys.append(Q)
R = ec.opposite(R) # 1.6.3
Q = DblScalarMult(ec, r1s, R, r1e, ec.G)
+ if Q[1] != 0: # 1.6.2
keys.append(Q) # 1.6.2
except Exception: # can't get a curve's point
pass
