Coverage Report

Created: 2025-12-05 06:47

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
2.11k
{
13
2.11k
   int x;
14
2.11k
   mp_digit q, qq;
15
16
   /* easy out */
17
2.11k
   if (MP_IS_ZERO(a)) {
18
0
      return 0;
19
0
   }
20
21
   /* scan lower digits until non-zero */
22
3.14k
   for (x = 0; (x < a->used) && (a->dp[x] == 0u); x++) {}
23
2.11k
   q = a->dp[x];
24
2.11k
   x *= MP_DIGIT_BIT;
25
26
   /* now scan this digit until a 1 is found */
27
2.11k
   if ((q & 1u) == 0u) {
28
7.63k
      do {
29
7.63k
         qq  = q & 15u;
30
7.63k
         x  += lnz[qq];
31
7.63k
         q >>= 4;
32
7.63k
      } while (qq == 0u);
33
1.91k
   }
34
2.11k
   return x;
35
2.11k
}
36
37
#endif