1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* multiply by a digit */
7 mp_err mp_mul_d(const mp_int *a, mp_digit b, mp_int *c)
9 mp_digit u, *tmpa, *tmpc;
14 /* make sure c is big enough to hold a*b */
15 if (c->alloc < (a->used + 1)) {
16 if ((err = mp_grow(c, a->used + 1)) != MP_OKAY) {
21 /* get the original destinations used count */
27 /* alias for a->dp [source] */
30 /* alias for c->dp [dest] */
37 for (ix = 0; ix < a->used; ix++) {
38 /* compute product and carry sum for this term */
39 r = (mp_word)u + ((mp_word)*tmpa++ * (mp_word)b);
41 /* mask off higher bits to get a single digit */
42 *tmpc++ = (mp_digit)(r & (mp_word)MP_MASK);
44 /* send carry into next iteration */
45 u = (mp_digit)(r >> (mp_word)MP_DIGIT_BIT);
48 /* store final carry [if any] and increment ix offset */
52 /* now zero digits above the top */
53 MP_ZERO_DIGITS(tmpc, olduse - ix);
56 c->used = a->used + 1;