1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
8 * Simple algorithm which zeroes the int, grows it then just sets one bit
11 mp_err
mp_2expt(mp_int
*a
, int b
)
19 /* zero a as per default */
22 /* grow a to accommodate the single bit */
23 if ((err
= mp_grow(a
, (b
/ MP_DIGIT_BIT
) + 1)) != MP_OKAY
) {
27 /* set the used count of where the bit will go */
28 a
->used
= (b
/ MP_DIGIT_BIT
) + 1;
30 /* put the single bit in its place */
31 a
->dp
[b
/ MP_DIGIT_BIT
] = (mp_digit
)1 << (mp_digit
)(b
% MP_DIGIT_BIT
);