Merge pull request #578 from PX4/fix_mp_prime_strong_lucas_lefridge_compilation
[libtommath.git] / mp_shrink.c
blob3d9b1626d2557ed55abf5fe6508d2bc9d35d73aa
1 #include "tommath_private.h"
2 #ifdef MP_SHRINK_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
6 /* shrink a bignum */
7 mp_err mp_shrink(mp_int *a)
9 int alloc = MP_MAX(MP_MIN_DIGIT_COUNT, a->used);
10 if (a->alloc != alloc) {
11 mp_digit *dp = (mp_digit *) MP_REALLOC(a->dp,
12 (size_t)a->alloc * sizeof(mp_digit),
13 (size_t)alloc * sizeof(mp_digit));
14 if (dp == NULL) {
15 return MP_MEM;
17 a->dp = dp;
18 a->alloc = alloc;
20 return MP_OKAY;
22 #endif