Merge pull request #4 from thesamesam/develop
[libtompoly.git] / pb_lshd.c
blob155b391a8f104acfa1270d2f426d60b06a4c8c8d
1 /* LibTomPoly, Polynomial Basis Math -- Tom St Denis
2 *
3 * LibTomPoly is a public domain library that provides
4 * polynomial basis arithmetic support. It relies on
5 * LibTomMath for large integer support.
7 * This library is free for all purposes without any
8 * express guarantee that it works.
10 * Tom St Denis, tomstdenis@iahu.ca, http://poly.libtomcrypt.org
12 #include <tompoly.h>
14 int pb_lshd(pb_poly *a, int x)
16 int err, y;
18 if (x <= 0) {
19 return MP_OKAY;
22 /* grow as required */
23 if (a->alloc < (a->used + x)) {
24 if ((err = pb_grow(a, a->used + x)) != MP_OKAY) {
25 return err;
29 /* shift */
30 for (y = a->used + x; y >= x; y--) {
31 mp_exch(&(a->terms[y-x]), &(a->terms[y]));
34 /* zero lower digits */
35 for (y = 0; y < x; y++) {
36 mp_zero(&(a->terms[y]));
38 a->used += x;
40 return MP_OKAY;