bn_mp_shrink.c 629 B

12345678910111213141516171819202122
  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. /* shrink a bignum */
  6. mp_err mp_shrink(mp_int *a)
  7. {
  8. mp_digit *tmp;
  9. int alloc = MP_MAX(MP_MIN_PREC, a->used);
  10. if (a->alloc != alloc) {
  11. if ((tmp = (mp_digit *) MP_REALLOC(a->dp,
  12. (size_t)a->alloc * sizeof(mp_digit),
  13. (size_t)alloc * sizeof(mp_digit))) == NULL) {
  14. return MP_MEM;
  15. }
  16. a->dp = tmp;
  17. a->alloc = alloc;
  18. }
  19. return MP_OKAY;
  20. }
  21. #endif