Skip to content

Commit 25e3cfb

Browse files
committed
ecdsa_impl: replace scalar if-checks with VERIFY_CHECKs in ecdsa_sig_sign
Whenever ecdsa_sig_sign is called, in the case that r == 0 or r overflows, we want to retry with a different nonce rather than fail signing entirely. Because of this, we always check the nonce conditions before calling sig_sign, so these checks should always pass (and in particular, they are inaccessible through the API and appear as uncovered code in test coverage).
1 parent a8abae7 commit 25e3cfb

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/ecdsa_impl.h

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

0 commit comments

Comments
 (0)