Coverage Report

Created: 2023-09-25 06:08

/src/dropbear/libtommath/bn_mp_mul_d.c
Line
Count
Source (jump to first uncovered line)
1
#include "tommath_private.h"
2
#ifdef BN_MP_MUL_D_C
3
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
4
/* SPDX-License-Identifier: Unlicense */
5
6
/* multiply by a digit */
7
mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
8
11.4k
{
9
11.4k
   mp_digit u, *tmpa, *tmpc;
10
11.4k
   mp_word  r;
11
11.4k
   mp_err   err;
12
11.4k
   int      ix, olduse;
13
14
   /* make sure c is big enough to hold a*b */
15
11.4k
   if (c->alloc < (a->used + 1)) {
16
407
      if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
17
0
         return err;
18
0
      }
19
407
   }
20
21
   /* get the original destinations used count */
22
11.4k
   olduse = c->used;
23
24
   /* set the sign */
25
11.4k
   c->sign = a->sign;
26
27
   /* alias for a->dp [source] */
28
11.4k
   tmpa = a->dp;
29
30
   /* alias for c->dp [dest] */
31
11.4k
   tmpc = c->dp;
32
33
   /* zero carry */
34
11.4k
   u = 0;
35
36
   /* compute columns */
37
160k
   for (ix = 0; ix < a->used; ix++) {
38
      /* compute product and carry sum for this term */
39
148k
      r       = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b);
40
41
      /* mask off higher bits to get a single digit */
42
148k
      *tmpc++ = (mp_digit)(r & (mp_word)MP_MASK);
43
44
      /* send carry into next iteration */
45
148k
      u       = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
46
148k
   }
47
48
   /* store final carry [if any] and increment ix offset  */
49
11.4k
   *tmpc++ = u;
50
11.4k
   ++ix;
51
52
   /* now zero digits above the top */
53
11.4k
   MP_ZERO_DIGITS(tmpc, olduse - ix);
54
55
   /* set used count */
56
11.4k
   c->used = a->used + 1;
57
11.4k
   mp_clamp(c);
58
59
11.4k
   return MP_OKAY;
60
11.4k
}
61
#endif