Allow IPv6 address entry in tools>ping - Loosens valid character check
[tomato/davidwu.git] / release / src / router / dropbear / libtommath / bn_mp_rshd.c
blob534bd4d371f195ce66a7f486de1fbc02272fad42
1 #include <tommath.h>
2 #ifdef BN_MP_RSHD_C
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
13 * guarantee it works.
15 * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
18 /* shift right a certain amount of digits */
19 void mp_rshd (mp_int * a, int b)
21 int x;
23 /* if b <= 0 then ignore it */
24 if (b <= 0) {
25 return;
28 /* if b > used then simply zero it and return */
29 if (a->used <= b) {
30 mp_zero (a);
31 return;
35 register mp_digit *bottom, *top;
37 /* shift the digits down */
39 /* bottom */
40 bottom = a->dp;
42 /* top [offset into digits] */
43 top = a->dp + b;
45 /* this is implemented as a sliding window where
46 * the window is b-digits long and digits from
47 * the top of the window are copied to the bottom
49 * e.g.
51 b-2 | b-1 | b0 | b1 | b2 | ... | bb | ---->
52 /\ | ---->
53 \-------------------/ ---->
55 for (x = 0; x < (a->used - b); x++) {
56 *bottom++ = *top++;
59 /* zero the top digits */
60 for (; x < a->used; x++) {
61 *bottom++ = 0;
65 /* remove excess digits */
66 a->used -= b;
68 #endif
70 /* $Source: /cvs/libtom/libtommath/bn_mp_rshd.c,v $ */
71 /* $Revision: 1.3 $ */
72 /* $Date: 2006/03/31 14:18:44 $ */