Skip to content

Commit 953d558

Browse files
vubvub
authored andcommitted
Added r/s != 0 checks
1 parent b48243e commit 953d558

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

bitcoin/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ def ecdsa_raw_verify(msghash, vrs, pub):
503503
u1, u2 = z*w % N, r*w % N
504504
x, y = fast_add(fast_multiply(G, u1), fast_multiply(decode_pubkey(pub), u2))
505505

506-
return r == x
506+
return r == x and r % N and s % N
507507

508508

509509
def ecdsa_verify(msg, sig, pub):
@@ -518,7 +518,7 @@ def ecdsa_raw_recover(msghash, vrs):
518518
y = beta if v % 2 ^ beta % 2 else (P - beta)
519519
# If xcubedaxb is not a quadratic residue, then r cannot be the x coord
520520
# for a point on the curve, and so the sig is invalid
521-
if (xcubedaxb - y*y) % P != 0:
521+
if (xcubedaxb - y*y) % P != 0 or not (r % N) or not (s % N):
522522
return False
523523
z = hash_to_int(msghash)
524524
Gz = jacobian_multiply((Gx, Gy, 1), (N - z) % N)

0 commit comments

Comments
 (0)