/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 | 0 | { |
13 | 0 | mp_err err; |
14 | |
|
15 | 0 | if (b < 0) { |
16 | 0 | return MP_VAL; |
17 | 0 | } |
18 | | |
19 | | /* zero a as per default */ |
20 | 0 | mp_zero(a); |
21 | | |
22 | | /* grow a to accomodate the single bit */ |
23 | 0 | if ((err = mp_grow(a, (b / MP_DIGIT_BIT) + 1)) != MP_OKAY) { |
24 | 0 | return err; |
25 | 0 | } |
26 | | |
27 | | /* set the used count of where the bit will go */ |
28 | 0 | a->used = (b / MP_DIGIT_BIT) + 1; |
29 | | |
30 | | /* put the single bit in its place */ |
31 | 0 | a->dp[b / MP_DIGIT_BIT] = (mp_digit)1 << (mp_digit)(b % MP_DIGIT_BIT); |
32 | |
|
33 | 0 | return MP_OKAY; |
34 | 0 | } |
35 | | #endif |