/src/dropbear/libtommath/bn_mp_reduce_is_2k.c
Line | Count | Source (jump to first uncovered line) |
1 | | #include "tommath_private.h" |
2 | | #ifdef BN_MP_REDUCE_IS_2K_C |
3 | | /* LibTomMath, multiple-precision integer library -- Tom St Denis */ |
4 | | /* SPDX-License-Identifier: Unlicense */ |
5 | | |
6 | | /* determines if mp_reduce_2k can be used */ |
7 | | mp_bool mp_reduce_is_2k(const mp_int *a) |
8 | 39.5k | { |
9 | 39.5k | int ix, iy, iw; |
10 | 39.5k | mp_digit iz; |
11 | | |
12 | 39.5k | if (a->used == 0) { |
13 | 0 | return MP_NO; |
14 | 39.5k | } else if (a->used == 1) { |
15 | 0 | return MP_YES; |
16 | 39.5k | } else if (a->used > 1) { |
17 | 39.5k | iy = mp_count_bits(a); |
18 | 39.5k | iz = 1; |
19 | 39.5k | iw = 1; |
20 | | |
21 | | /* Test every bit from the second digit up, must be 1 */ |
22 | 247k | for (ix = MP_DIGIT_BIT; ix < iy; ix++) { |
23 | 247k | if ((a->dp[iw] & iz) == 0u) { |
24 | 39.5k | return MP_NO; |
25 | 39.5k | } |
26 | 208k | iz <<= 1; |
27 | 208k | if (iz > MP_DIGIT_MAX) { |
28 | 441 | ++iw; |
29 | 441 | iz = 1; |
30 | 441 | } |
31 | 208k | } |
32 | 0 | return MP_YES; |
33 | 39.5k | } else { |
34 | 0 | return MP_YES; |
35 | 0 | } |
36 | 39.5k | } |
37 | | |
38 | | #endif |