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
19 int mp_mul_2(mp_int
* a
, mp_int
* b
)
23 /* grow to accomodate result */
24 if (b
->alloc
< a
->used
+ 1) {
25 if ((res
= mp_grow (b
, a
->used
+ 1)) != MP_OKAY
) {
34 register mp_digit r
, rr
, *tmpa
, *tmpb
;
36 /* alias for source */
44 for (x
= 0; x
< a
->used
; x
++) {
46 /* get what will be the *next* carry bit from the
47 * MSB of the current digit
49 rr
= *tmpa
>> ((mp_digit
)(DIGIT_BIT
- 1));
51 /* now shift up this digit, add in the carry [from the previous] */
52 *tmpb
++ = ((*tmpa
++ << ((mp_digit
)1)) | r
) & MP_MASK
;
54 /* copy the carry that would be from the source
55 * digit into the next iteration
60 /* new leading digit? */
62 /* add a MSB which is always 1 at this point */
67 /* now zero any excess digits on the destination
68 * that we didn't write to
70 tmpb
= b
->dp
+ b
->used
;
71 for (x
= b
->used
; x
< oldused
; x
++) {
80 /* $Source: /cvs/libtom/libtommath/bn_mp_mul_2.c,v $ */
81 /* $Revision: 1.3 $ */
82 /* $Date: 2006/03/31 14:18:44 $ */