Coverage Report

Created: 2025-07-18 06:54

/src/dropbear/libtommath/bn_mp_cmp_mag.c
Line
Count
Source
1
#include "tommath_private.h"
2
#ifdef BN_MP_CMP_MAG_C
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4
/* SPDX-License-Identifier: Unlicense */
5
6
/* compare maginitude of two ints (unsigned) */
7
mp_ord mp_cmp_mag(const mp_int *a, const mp_int *b)
8
198M
{
9
198M
   int     n;
10
198M
   const mp_digit *tmpa, *tmpb;
11
12
   /* compare based on # of non-zero digits */
13
198M
   if (a->used > b->used) {
14
8.55M
      return MP_GT;
15
8.55M
   }
16
17
190M
   if (a->used < b->used) {
18
2.30M
      return MP_LT;
19
2.30M
   }
20
21
   /* alias for a */
22
187M
   tmpa = a->dp + (a->used - 1);
23
24
   /* alias for b */
25
187M
   tmpb = b->dp + (a->used - 1);
26
27
   /* compare based on digits  */
28
191M
   for (n = 0; n < a->used; ++n, --tmpa, --tmpb) {
29
191M
      if (*tmpa > *tmpb) {
30
46.3M
         return MP_GT;
31
46.3M
      }
32
33
145M
      if (*tmpa < *tmpb) {
34
141M
         return MP_LT;
35
141M
      }
36
145M
   }
37
82.4k
   return MP_EQ;
38
187M
}
39
#endif