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://libtom.org
19 int mp_div_2(mp_int
* a
, mp_int
* b
)
24 if (b
->alloc
< a
->used
) {
25 if ((res
= mp_grow (b
, a
->used
)) != MP_OKAY
) {
33 register mp_digit r
, rr
, *tmpa
, *tmpb
;
36 tmpa
= a
->dp
+ b
->used
- 1;
39 tmpb
= b
->dp
+ b
->used
- 1;
43 for (x
= b
->used
- 1; x
>= 0; x
--) {
44 /* get the carry for the next iteration */
47 /* shift the current digit, add in carry and store */
48 *tmpb
-- = (*tmpa
-- >> 1) | (r
<< (DIGIT_BIT
- 1));
50 /* forward carry to next iteration */
54 /* zero excess digits */
55 tmpb
= b
->dp
+ b
->used
;
56 for (x
= b
->used
; x
< oldused
; x
++) {
66 /* $Source: /cvs/libtom/libtommath/bn_mp_div_2.c,v $ */
67 /* $Revision: 1.4 $ */
68 /* $Date: 2006/12/28 01:25:13 $ */