libtommath/s_mp_get_bit.c
Daniel Mendler bf9507a9d4
replace mp_bool by stdbool
* This gives the advantage that static analysis **understands** bool,
  but complains about using an enum type instead of bool.

* If stdbool.h is not desired, true/false/bool can be replaced using sed
  as in the no-stdint-h branch.

* We already include stdint.h and stdbool.h is not more harmful than
  this header
2019-10-27 18:36:56 +01:00

22 lines
496 B
C

#include "tommath_private.h"
#ifdef S_MP_GET_BIT_C
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
/* Get bit at position b and return true if the bit is 1, false if it is 0 */
bool s_mp_get_bit(const mp_int *a, unsigned int b)
{
mp_digit bit;
int limb = (int)(b / MP_DIGIT_BIT);
if (limb >= a->used) {
return false;
}
bit = (mp_digit)1 << (b % MP_DIGIT_BIT);
return ((a->dp[limb] & bit) != 0u);
}
#endif