LCOV - code coverage report
Current view: top level - third_party/heimdal/lib/hcrypto/libtommath - bn_mp_count_bits.c (source / functions) Hit Total Coverage
Test: coverage report for support-claim-type-attributes 6b5c566e Lines: 10 11 90.9 %
Date: 2023-11-21 12:31:41 Functions: 1 1 100.0 %

          Line data    Source code
       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        5532 : int mp_count_bits(const mp_int *a)
       8             : {
       9         209 :    int     r;
      10         209 :    mp_digit q;
      11             : 
      12             :    /* shortcut */
      13        5532 :    if (MP_IS_ZERO(a)) {
      14           0 :       return 0;
      15             :    }
      16             : 
      17             :    /* get number of digits and add that */
      18        5532 :    r = (a->used - 1) * MP_DIGIT_BIT;
      19             : 
      20             :    /* take the last digit and count the bits in it */
      21        5532 :    q = a->dp[a->used - 1];
      22       75043 :    while (q > 0u) {
      23       69511 :       ++r;
      24       69511 :       q >>= 1u;
      25             :    }
      26        5323 :    return r;
      27             : }
      28             : #endif

Generated by: LCOV version 1.14