/src/dropbear/libtommath/bn_mp_2expt.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "tommath_private.h" |
2 | | #ifdef BN_MP_2EXPT_C |
3 | | /* LibTomMath, multiple-precision integer library -- Tom St Denis */ |
4 | | /* SPDX-License-Identifier: Unlicense */ |
5 | | |
6 | | /* computes a = 2**b |
7 | | * |
8 | | * Simple algorithm which zeroes the int, grows it then just sets one bit |
9 | | * as required. |
10 | | */ |
11 | | mp_err mp_2expt(mp_int *a, int b) |
12 | 3.51k | { |
13 | 3.51k | mp_err err; |
14 | | |
15 | | /* zero a as per default */ |
16 | 3.51k | mp_zero(a); |
17 | | |
18 | | /* grow a to accomodate the single bit */ |
19 | 3.51k | if ((err = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) { |
20 | 0 | return err; |
21 | 0 | } |
22 | | |
23 | | /* set the used count of where the bit will go */ |
24 | 3.51k | a->used = (b / MP_DIGIT_BIT) + 1; |
25 | | |
26 | | /* put the single bit in its place */ |
27 | 3.51k | a->dp[b / MP_DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT); |
28 | | |
29 | 3.51k | return MP_OKAY; |
30 | 3.51k | } |
31 | | #endif |