Improve checks for scalar _get_bits methods
This commit is contained in:
@@ -27,8 +27,10 @@ SECP256K1_INLINE static void secp256k1_scalar_set_int(secp256k1_scalar *r, unsig
|
||||
|
||||
SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_limb32(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
|
||||
SECP256K1_SCALAR_VERIFY(a);
|
||||
|
||||
VERIFY_CHECK(count > 0 && count <= 32);
|
||||
VERIFY_CHECK(offset <= 256 - count);
|
||||
VERIFY_CHECK((offset + count - 1) >> 5 == offset >> 5);
|
||||
|
||||
if (offset < 32) {
|
||||
return (*a >> offset) & (0xFFFFFFFF >> (32 - count));
|
||||
} else {
|
||||
@@ -38,8 +40,14 @@ SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_limb32(const secp256k
|
||||
|
||||
SECP256K1_INLINE static uint32_t secp256k1_scalar_get_bits_var(const secp256k1_scalar *a, unsigned int offset, unsigned int count) {
|
||||
SECP256K1_SCALAR_VERIFY(a);
|
||||
VERIFY_CHECK(count > 0 && count <= 32);
|
||||
VERIFY_CHECK(offset <= 256 - count);
|
||||
|
||||
return secp256k1_scalar_get_bits_limb32(a, offset, count);
|
||||
if (offset < 32) {
|
||||
return (*a >> offset) & (0xFFFFFFFF >> (32 - count));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
SECP256K1_INLINE static int secp256k1_scalar_check_overflow(const secp256k1_scalar *a) { return *a >= EXHAUSTIVE_TEST_ORDER; }
|
||||
|
||||
Reference in New Issue
Block a user