1 /* LibTomMath, multiple-precision integer library -- Tom St Denis
3 * LibTomMath is library that provides for multiple-precision
4 * integer arithmetic as well as number theoretic functionality.
6 * The library is designed directly after the MPI library by
7 * Michael Fromberger but has been written from scratch with
8 * additional optimizations in place.
10 * The library is free for all purposes without any express
13 * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
17 /* multiply by a digit */
19 mp_mul_d (mp_int * a, mp_digit b, mp_int * c)
23 /* make sure c is big enough to hold a*b */
25 if (c->alloc < pa + 1) {
26 if ((res = mp_grow (c, pa + 1)) != MP_OKAY) {
31 /* get the original destinations used count */
34 /* set the new temporary used count */
39 register mp_digit u, *tmpa, *tmpc;
43 /* alias for a->dp [source] */
46 /* alias for c->dp [dest] */
51 for (ix = 0; ix < pa; ix++) {
52 /* compute product and carry sum for this term */
53 r = ((mp_word) u) + ((mp_word) * tmpa++) * ((mp_word) b);
55 /* mask off higher bits to get a single digit */
56 *tmpc++ = (mp_digit) (r & ((mp_word) MP_MASK));
58 /* send carry into next iteration */
59 u = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
61 /* store final carry [if any] */
64 /* now zero digits above the top */
65 for (; pa < olduse; pa++) {