Skip to content

Commit

Permalink
moved to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
fametrano committed May 21, 2020
1 parent bca9b06 commit dc52cf9
Show file tree
Hide file tree
Showing 2 changed files with 574 additions and 561 deletions.
9 changes: 7 additions & 2 deletions btclib/ssa.py
Expand Up @@ -292,7 +292,8 @@ def _assert_as_valid(c: int, QJ: JacPoint, r: int, s: int, ec: Curve) -> None:

# Fail if infinite(KJ).
# Fail if jacobi(y_K) ≠ 1.
assert ec.has_square_y(KJ), "y_K is not a quadratic residue"
if not ec.has_square_y(KJ):
raise RuntimeError("y_K is not a quadratic residue")

# Fail if x_K ≠ r
assert KJ[0] == KJ[2] * KJ[2] * r % ec.p, "Signature verification failed"
Expand Down Expand Up @@ -335,6 +336,9 @@ def verify(
def _recover_pubkey(c: int, r: int, s: int, ec: Curve) -> int:
# Private function provided for testing purposes only.

if c == 0:
raise ValueError("invalid zero challenge")

KJ = r, ec.y_quadratic_residue(r, True), 1

e1 = mod_inv(c, ec.n)
Expand Down Expand Up @@ -428,7 +432,8 @@ def _batch_verify(
RHSZ2 = RHSJ[2] * RHSJ[2]
TZ2 = TJ[2] * TJ[2]
precondition = TJ[0] * RHSZ2 % ec.p == RHSJ[0] * TZ2 % ec.p
assert precondition, "Signature verification precondition failed"
if not precondition:
raise ValueError("Signature verification precondition failed")

valid_sig = TJ[1] * RHSZ2 * RHSJ[2] % ec.p == RHSJ[1] * TZ2 * TJ[2] % ec.p
assert valid_sig, "Signature verification failed"
Expand Down

0 comments on commit dc52cf9

Please sign in to comment.