3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality.
8 * The library was designed directly after the MPI library by
9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place.
12 * The library is free for all purposes without any express
15 * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
18 /* multiply by a digit */
20 mp_mul_d (mp_int * a, mp_digit b, mp_int * c)
22 mp_digit u, *tmpa, *tmpc;
26 /* make sure c is big enough to hold a*b */
27 if (c->alloc < a->used + 1) {
28 if ((res = mp_grow (c, a->used + 1)) != MP_OKAY) {
33 /* get the original destinations used count */
39 /* alias for a->dp [source] */
42 /* alias for c->dp [dest] */
49 for (ix = 0; ix < a->used; ix++) {
50 /* compute product and carry sum for this term */
51 r = ((mp_word) u) + ((mp_word)*tmpa++) * ((mp_word)b);
53 /* mask off higher bits to get a single digit */
54 *tmpc++ = (mp_digit) (r & ((mp_word) MP_MASK));
56 /* send carry into next iteration */
57 u = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
60 /* store final carry [if any] and increment ix offset */
64 /* now zero digits above the top */
65 while (ix++ < olduse) {
70 c->used = a->used + 1;