Coverage Report

Created: 2025-11-13 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dropbear/libtommath/bn_mp_reduce_is_2k.c
Line
Count
Source
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
40.4k
{
9
40.4k
   int ix, iy, iw;
10
40.4k
   mp_digit iz;
11
12
40.4k
   if (a->used == 0) {
13
0
      return MP_NO;
14
40.4k
   } else if (a->used == 1) {
15
0
      return MP_YES;
16
40.4k
   } else if (a->used > 1) {
17
40.4k
      iy = mp_count_bits(a);
18
40.4k
      iz = 1;
19
40.4k
      iw = 1;
20
21
      /* Test every bit from the second digit up, must be 1 */
22
246k
      for (ix = MP_DIGIT_BIT; ix < iy; ix++) {
23
246k
         if ((a->dp[iw] & iz) == 0u) {
24
40.4k
            return MP_NO;
25
40.4k
         }
26
206k
         iz <<= 1;
27
206k
         if (iz > MP_DIGIT_MAX) {
28
350
            ++iw;
29
350
            iz = 1;
30
350
         }
31
206k
      }
32
0
      return MP_YES;
33
40.4k
   } else {
34
0
      return MP_YES;
35
0
   }
36
40.4k
}
37
38
#endif