Skip to content

Commit 37ed51a

Browse files
Make ecdsa_sig_sign constant-time again after reverting 25e3cfb
1 parent 93d343b commit 37ed51a

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

src/ecdsa_impl.h

+4-9
Original file line numberDiff line numberDiff line change
@@ -288,14 +288,6 @@ 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-
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-
}
299291
if (recid) {
300292
/* The overflow condition is cryptographically unreachable as hitting it requires finding the discrete log
301293
* of some P where P.x >= order, and only 1 in about 2^127 points meet this criteria.
@@ -314,7 +306,10 @@ static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context *ctx, sec
314306
if (recid) {
315307
*recid ^= high;
316308
}
317-
return !secp256k1_scalar_is_zero(sigs);
309+
/* P.x = order is on the curve, so technically sig->r could end up being zero, which would be an invalid signature.
310+
* This is cryptographically unreachable as hitting it requires finding the discrete log of P.x = N.
311+
*/
312+
return !secp256k1_scalar_is_zero(sigr) & !secp256k1_scalar_is_zero(sigs);
318313
}
319314

320315
#endif /* SECP256K1_ECDSA_IMPL_H */

0 commit comments

Comments
 (0)