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.
This commit is contained in:
parent
8fe63e5654
commit
0d82732a9a
@ -40,6 +40,9 @@ static void secp256k1_scalar_cadd_bit(secp256k1_scalar *r, unsigned int bit, int
|
|||||||
if (flag && bit < 32)
|
if (flag && bit < 32)
|
||||||
*r += ((uint32_t)1 << bit);
|
*r += ((uint32_t)1 << bit);
|
||||||
#ifdef VERIFY
|
#ifdef VERIFY
|
||||||
|
VERIFY_CHECK(bit < 32);
|
||||||
|
/* Verify that adding (1 << bit) will not overflow any in-range scalar *r by overflowing the underlying uint32_t. */
|
||||||
|
VERIFY_CHECK(((uint32_t)1 << bit) - 1 <= UINT32_MAX - EXHAUSTIVE_TEST_ORDER);
|
||||||
VERIFY_CHECK(secp256k1_scalar_check_overflow(r) == 0);
|
VERIFY_CHECK(secp256k1_scalar_check_overflow(r) == 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user