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@gmail.com, http://math.libtomcrypt.com
18 /* shift left by a certain bit count */
19 int mp_mul_2d (mp_int
* a
, int b
, mp_int
* c
)
26 if ((res
= mp_copy (a
, c
)) != MP_OKAY
) {
31 if (c
->alloc
< (int)(c
->used
+ b
/DIGIT_BIT
+ 1)) {
32 if ((res
= mp_grow (c
, c
->used
+ b
/ DIGIT_BIT
+ 1)) != MP_OKAY
) {
37 /* shift by as many digits in the bit count */
38 if (b
>= (int)DIGIT_BIT
) {
39 if ((res
= mp_lshd (c
, b
/ DIGIT_BIT
)) != MP_OKAY
) {
44 /* shift any bit count < DIGIT_BIT */
45 d
= (mp_digit
) (b
% DIGIT_BIT
);
47 register mp_digit
*tmpc
, shift
, mask
, r
, rr
;
50 /* bitmask for carries */
51 mask
= (((mp_digit
)1) << d
) - 1;
54 shift
= DIGIT_BIT
- d
;
61 for (x
= 0; x
< c
->used
; x
++) {
62 /* get the higher bits of the current word */
63 rr
= (*tmpc
>> shift
) & mask
;
65 /* shift the current word and OR in the carry */
66 *tmpc
= ((*tmpc
<< d
) | r
) & MP_MASK
;
69 /* set the carry to the carry bits of the current word */
75 c
->dp
[(c
->used
)++] = r
;
83 /* $Source: /cvs/libtom/libtommath/bn_mp_mul_2d.c,v $ */
84 /* $Revision: 1.3 $ */
85 /* $Date: 2006/03/31 14:18:44 $ */