Skip to content

Commit 0d82732

Browse files
Improve VERIFY_CHECK of overflow in secp256k1_scalar_cadd_bit.
This added check ensures that any curve order overflow doesn't go undetected due a uint32_t overflow.
1 parent 8fe63e5 commit 0d82732

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/scalar_low_impl.h

+3
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ static void secp256k1_scalar_cadd_bit(secp256k1_scalar *r, unsigned int bit, int
4040
if (flag && bit < 32)
4141
*r += ((uint32_t)1 << bit);
4242
#ifdef VERIFY
43+
VERIFY_CHECK(bit < 32);
44+
/* Verify that adding (1 << bit) will not overflow any in-range scalar *r by overflowing the underlying uint32_t. */
45+
VERIFY_CHECK(((uint32_t)1 << bit) - 1 <= UINT32_MAX - EXHAUSTIVE_TEST_ORDER);
4346
VERIFY_CHECK(secp256k1_scalar_check_overflow(r) == 0);
4447
#endif
4548
}

0 commit comments

Comments
 (0)