1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* shift left a certain amount of digits */
7 mp_err mp_lshd(mp_int *a, int b)
11 mp_digit *top, *bottom;
13 /* if its less than zero return */
17 /* no need to shift 0 around */
22 /* grow to fit the new digits */
23 if (a->alloc < (a->used + b)) {
24 if ((err = mp_grow(a, a->used + b)) != MP_OKAY) {
29 /* increment the used by the shift amount then copy upwards */
33 top = a->dp + a->used - 1;
36 bottom = (a->dp + a->used - 1) - b;
38 /* much like mp_rshd this is implemented using a sliding window
39 * except the window goes the otherway around. Copying from
40 * the bottom to the top. see bn_mp_rshd.c for more info.
42 for (x = a->used - 1; x >= b; x--) {
46 /* zero the lower digits */
47 MP_ZERO_DIGITS(a->dp, b);