1 /* $NetBSD: bn_mp_grow.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $ */
5 /* LibTomMath, multiple-precision integer library -- Tom St Denis
7 * LibTomMath is a library that provides multiple-precision
8 * integer arithmetic as well as number theoretic functionality.
10 * The library was designed directly after the MPI library by
11 * Michael Fromberger but has been written from scratch with
12 * additional optimizations in place.
14 * The library is free for all purposes without any express
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
20 /* grow as required */
21 int mp_grow (mp_int
* a
, int size
)
26 /* if the alloc size is smaller alloc more ram */
27 if (a
->alloc
< size
) {
28 /* ensure there are always at least MP_PREC digits extra on top */
29 size
+= (MP_PREC
* 2) - (size
% MP_PREC
);
31 /* reallocate the array a->dp
33 * We store the return in a temporary variable
34 * in case the operation failed we don't want
35 * to overwrite the dp member of a.
37 tmp
= OPT_CAST(mp_digit
) XREALLOC (a
->dp
, sizeof (mp_digit
) * size
);
39 /* reallocation failed but "a" is still valid [can be freed] */
43 /* reallocation succeeded so set a->dp */
46 /* zero excess digits */
49 for (; i
< a
->alloc
; i
++) {
57 /* Source: /cvs/libtom/libtommath/bn_mp_grow.c,v */
59 /* Date: 2006/12/28 01:25:13 */