mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -05:00
New mpint function mp_get_integer().
If you have an mp_int that you know will fit in an ordinary integer type, this function gives it to you in that form.
This commit is contained in:
12
mpint.c
12
mpint.c
@ -257,6 +257,18 @@ unsigned mp_get_bit(mp_int *x, size_t bit)
|
||||
(bit % BIGNUM_INT_BITS));
|
||||
}
|
||||
|
||||
uintmax_t mp_get_integer(mp_int *x)
|
||||
{
|
||||
uintmax_t toret = 0;
|
||||
for (size_t i = x->nw; i-- > 0 ;) {
|
||||
/* Shift in two stages to avoid undefined behaviour if the
|
||||
* shift count equals the integer width */
|
||||
toret = (toret << (BIGNUM_INT_BITS/2)) << (BIGNUM_INT_BITS/2);
|
||||
toret |= x->w[i];
|
||||
}
|
||||
return toret;
|
||||
}
|
||||
|
||||
void mp_set_bit(mp_int *x, size_t bit, unsigned val)
|
||||
{
|
||||
size_t word = bit / BIGNUM_INT_BITS;
|
||||
|
Reference in New Issue
Block a user