Skip to content

Commit 93d343b

Browse files
Revert "ecdsa_impl: replace scalar if-checks with VERIFY_CHECKs in ecdsa_sig_sign"
This reverts commit 25e3cfb. The reverted commit was probably based on the assumption that this is about the touched checks cover the secret nonce k instead of r, which is the x-coord of the public nonce. A signature with a zero r is invalid by the spec, so we should return 0 to make the caller retry with a different nonce. Overflow is not an issue. Fixes bitcoin#720.
1 parent 8f78e20 commit 93d343b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/ecdsa_impl.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,14 @@ static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, sec
288288
secp256k1_fe_normalize(&r.y);
289289
secp256k1_fe_get_b32(b, &r.x);
290290
secp256k1_scalar_set_b32(sigr, b, &overflow);
291-
/* These two conditions should be checked before calling */
292-
VERIFY_CHECK(!secp256k1_scalar_is_zero(sigr));
293-
VERIFY_CHECK(overflow == 0);
294-
291+
if (secp256k1_scalar_is_zero(sigr)) {
292+
/* P.x = order is on the curve, so technically sig->r could end up zero, which would be an invalid signature.
293+
* This branch is cryptographically unreachable as hitting it requires finding the discrete log of P.x = N.
294+
*/
295+
secp256k1_gej_clear(&rp);
296+
secp256k1_ge_clear(&r);
297+
return 0;
298+
}
295299
if (recid) {
296300
/* The overflow condition is cryptographically unreachable as hitting it requires finding the discrete log
297301
* of some P where P.x >= order, and only 1 in about 2^127 points meet this criteria.

0 commit comments

Comments
 (0)