Coverage Report

Created: 2025-11-10 06:58

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
41.1k
{
9
41.1k
   int ix, iy, iw;
10
41.1k
   mp_digit iz;
11
12
41.1k
   if (a->used == 0) {
13
0
      return MP_NO;
14
41.1k
   } else if (a->used == 1) {
15
0
      return MP_YES;
16
41.1k
   } else if (a->used > 1) {
17
41.1k
      iy = mp_count_bits(a);
18
41.1k
      iz = 1;
19
41.1k
      iw = 1;
20
21
      /* Test every bit from the second digit up, must be 1 */
22
252k
      for (ix = MP_DIGIT_BIT; ix < iy; ix++) {
23
252k
         if ((a->dp[iw] & iz) == 0u) {
24
41.1k
            return MP_NO;
25
41.1k
         }
26
211k
         iz <<= 1;
27
211k
         if (iz > MP_DIGIT_MAX) {
28
362
            ++iw;
29
362
            iz = 1;
30
362
         }
31
211k
      }
32
0
      return MP_YES;
33
41.1k
   } else {
34
0
      return MP_YES;
35
0
   }
36
41.1k
}
37
38
#endif