1 #include "tommath_private.h"
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
7 mp_err
mp_grow(mp_int
*a
, int size
)
13 /* if the alloc size is smaller alloc more ram */
14 if (a
->alloc
< size
) {
17 if (size
> MP_MAX_DIGIT_COUNT
) {
21 /* reallocate the array a->dp
23 * We store the return in a temporary variable
24 * in case the operation failed we don't want
25 * to overwrite the dp member of a.
27 dp
= (mp_digit
*) MP_REALLOC(a
->dp
,
28 (size_t)a
->alloc
* sizeof(mp_digit
),
29 (size_t)size
* sizeof(mp_digit
));
31 /* reallocation failed but "a" is still valid [can be freed] */
35 /* reallocation succeeded so set a->dp */
38 /* zero excess digits */
39 s_mp_zero_digs(a
->dp
+ a
->alloc
, size
- a
->alloc
);