Debian Codegraph @

libtommath/bn_mp_shrink.c

raw
1 #include "tommath_private.h"
2 #ifdef BN_MP_SHRINK_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
5
6 /* shrink a bignum */
7 mp_err mp_shrink(mp_int *a)
8 {
9 mp_digit *tmp;
10 int alloc = MP_MAX(MP_MIN_PREC, a->used);
11 if (a->alloc != alloc) {
12 if ((tmp = (mp_digit *) MP_REALLOC(a->dp,
13 (size_t)a->alloc * sizeof(mp_digit),
14 (size_t)alloc * sizeof(mp_digit))) == NULL) {
15 return MP_MEM;
16 }
17 a->dp = tmp;
18 a->alloc = alloc;
19 }
20 return MP_OKAY;
21 }
22 #endif