2020-12-28 21:40:37 +00:00
|
|
|
#include "tommath_private.h"
|
2014-12-10 21:56:49 +00:00
|
|
|
#ifdef BN_MP_SHRINK_C
|
2020-12-28 21:40:37 +00:00
|
|
|
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
|
|
|
|
/* SPDX-License-Identifier: Unlicense */
|
2014-12-10 21:56:49 +00:00
|
|
|
|
|
|
|
/* shrink a bignum */
|
2020-12-28 21:40:37 +00:00
|
|
|
mp_err mp_shrink(mp_int *a)
|
2014-12-10 21:56:49 +00:00
|
|
|
{
|
2020-12-28 21:40:37 +00:00
|
|
|
mp_digit *tmp;
|
|
|
|
int alloc = MP_MAX(MP_MIN_PREC, a->used);
|
|
|
|
if (a->alloc != alloc) {
|
|
|
|
if ((tmp = (mp_digit *) MP_REALLOC(a->dp,
|
|
|
|
(size_t)a->alloc * sizeof(mp_digit),
|
|
|
|
(size_t)alloc * sizeof(mp_digit))) == NULL) {
|
|
|
|
return MP_MEM;
|
|
|
|
}
|
|
|
|
a->dp = tmp;
|
|
|
|
a->alloc = alloc;
|
|
|
|
}
|
|
|
|
return MP_OKAY;
|
2014-12-10 21:56:49 +00:00
|
|
|
}
|
|
|
|
#endif
|