Coverage Report

Created: 2025-07-11 06:08

/src/dropbear/libtommath/bn_mp_clamp.c
Line
Count
Source
1
#include "tommath_private.h"
2
#ifdef BN_MP_CLAMP_C
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4
/* SPDX-License-Identifier: Unlicense */
5
6
/* trim unused digits
7
 *
8
 * This is used to ensure that leading zero digits are
9
 * trimed and the leading "used" digit will be non-zero
10
 * Typically very fast.  Also fixes the sign if there
11
 * are no more leading digits
12
 */
13
void mp_clamp(mp_int *a)
14
3.22k
{
15
   /* decrease used while the most significant digit is
16
    * zero.
17
    */
18
5.97k
   while ((a->used > 0) && (a->dp[a->used - 1] == 0u)) {
19
2.75k
      --(a->used);
20
2.75k
   }
21
22
   /* reset the sign flag if used == 0 */
23
3.22k
   if (a->used == 0) {
24
44
      a->sign = MP_ZPOS;
25
44
   }
26
3.22k
}
27
#endif