Coverage Report

Created: 2025-10-13 07:08

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dropbear/libtommath/bn_mp_cnt_lsb.c
Line
Count
Source
1
#include "tommath_private.h"
2
#ifdef BN_MP_CNT_LSB_C
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4
/* SPDX-License-Identifier: Unlicense */
5
6
static const int lnz[16] = {
7
   4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
8
};
9
10
/* Counts the number of lsbs which are zero before the first zero bit */
11
int mp_cnt_lsb(const mp_int *a)
12
1.96k
{
13
1.96k
   int x;
14
1.96k
   mp_digit q, qq;
15
16
   /* easy out */
17
1.96k
   if (MP_IS_ZERO(a)) {
18
0
      return 0;
19
0
   }
20
21
   /* scan lower digits until non-zero */
22
2.99k
   for (x = 0; (x < a->used) && (a->dp[x] == 0u); x++) {}
23
1.96k
   q = a->dp[x];
24
1.96k
   x *= MP_DIGIT_BIT;
25
26
   /* now scan this digit until a 1 is found */
27
1.96k
   if ((q & 1u) == 0u) {
28
6.96k
      do {
29
6.96k
         qq  = q & 15u;
30
6.96k
         x  += lnz[qq];
31
6.96k
         q >>= 4;
32
6.96k
      } while (qq == 0u);
33
1.76k
   }
34
1.96k
   return x;
35
1.96k
}
36
37
#endif