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@iahu.ca, http://math.libtomcrypt.org
18 /* grow as required */
19 int mp_grow (mp_int * a, int size)
24 /* if the alloc size is smaller alloc more ram */
25 if (a->alloc < size) {
26 /* ensure there are always at least MP_PREC digits extra on top */
27 size += (MP_PREC * 2) - (size % MP_PREC);
29 /* reallocate the array a->dp
31 * We store the return in a temporary variable
32 * in case the operation failed we don't want
33 * to overwrite the dp member of a.
35 tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * size);
37 /* reallocation failed but "a" is still valid [can be freed] */
41 /* reallocation succeeded so set a->dp */
44 /* zero excess digits */
47 for (; i < a->alloc; i++) {