1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* shift right a certain amount of digits */
7 void mp_rshd(mp_int *a, int b)
10 mp_digit *bottom, *top;
12 /* if b <= 0 then ignore it */
17 /* if b > used then simply zero it and return */
23 /* shift the digits down */
28 /* top [offset into digits] */
31 /* this is implemented as a sliding window where
32 * the window is b-digits long and digits from
33 * the top of the window are copied to the bottom
37 b-2 | b-1 | b0 | b1 | b2 | ... | bb | ---->
39 \-------------------/ ---->
41 for (x = 0; x < (a->used - b); x++) {
45 /* zero the top digits */
46 MP_ZERO_DIGITS(bottom, a->used - x);
48 /* remove excess digits */