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 /* NOTE: This routine requires updating. For instance the c->used = c->alloc bit
18 is wrong. We should just shift c->used digits then set the carry as c->dp[c->used] = carry
20 To be fixed for LTM 0.18
23 /* shift left by a certain bit count */
25 mp_mul_2d (mp_int * a, int b, mp_int * c)
32 if ((res = mp_copy (a, c)) != MP_OKAY) {
37 if (c->alloc < (int)(c->used + b/DIGIT_BIT + 2)) {
38 if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 2)) != MP_OKAY) {
43 /* shift by as many digits in the bit count */
44 if (b >= (int)DIGIT_BIT) {
45 if ((res = mp_lshd (c, b / DIGIT_BIT)) != MP_OKAY) {
51 /* shift any bit count < DIGIT_BIT */
52 d = (mp_digit) (b % DIGIT_BIT);
54 register mp_digit *tmpc, mask, r, rr;
57 /* bitmask for carries */
58 mask = (((mp_digit)1) << d) - 1;
65 for (x = 0; x < c->used; x++) {
66 /* get the higher bits of the current word */
67 rr = (*tmpc >> (DIGIT_BIT - d)) & mask;
69 /* shift the current word and OR in the carry */
70 *tmpc = ((*tmpc << d) | r) & MP_MASK;
73 /* set the carry to the carry bits of the current word */