2019-05-13 09:32:42 +00:00
|
|
|
#include "tommath_private.h"
|
2019-10-19 14:24:39 +00:00
|
|
|
#ifdef S_MP_GET_BIT_C
|
2019-05-13 09:32:42 +00:00
|
|
|
|
|
|
|
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
|
|
|
/* SPDX-License-Identifier: Unlicense */
|
|
|
|
|
2019-10-24 20:02:29 +00:00
|
|
|
/* Get bit at position b and return true if the bit is 1, false if it is 0 */
|
2019-10-29 19:07:29 +00:00
|
|
|
bool s_mp_get_bit(const mp_int *a, int b)
|
2019-05-13 09:32:42 +00:00
|
|
|
{
|
|
|
|
mp_digit bit;
|
2019-10-29 19:07:29 +00:00
|
|
|
int limb = b / MP_DIGIT_BIT;
|
2019-05-13 09:32:42 +00:00
|
|
|
|
2019-10-29 19:07:29 +00:00
|
|
|
if (limb < 0 || limb >= a->used) {
|
2019-10-24 20:02:29 +00:00
|
|
|
return false;
|
2019-05-13 09:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bit = (mp_digit)1 << (b % MP_DIGIT_BIT);
|
2019-10-24 15:52:03 +00:00
|
|
|
return ((a->dp[limb] & bit) != 0u);
|
2019-05-13 09:32:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|