Coverage Report

Created: 2025-07-12 06:23

/src/dropbear/libtommath/bn_mp_count_bits.c
Line
Count
Source
1
#include "tommath_private.h"
2
#ifdef BN_MP_COUNT_BITS_C
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4
/* SPDX-License-Identifier: Unlicense */
5
6
/* returns the number of bits in an int */
7
int mp_count_bits(const mp_int *a)
8
145k
{
9
145k
   int     r;
10
145k
   mp_digit q;
11
12
   /* shortcut */
13
145k
   if (MP_IS_ZERO(a)) {
14
833
      return 0;
15
833
   }
16
17
   /* get number of digits and add that */
18
144k
   r = (a->used - 1) * MP_DIGIT_BIT;
19
20
   /* take the last digit and count the bits in it */
21
144k
   q = a->dp[a->used - 1];
22
5.52M
   while (q > 0u) {
23
5.38M
      ++r;
24
5.38M
      q >>= 1u;
25
5.38M
   }
26
144k
   return r;
27
145k
}
28
#endif