Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / hcrypto / libtommath / bn_mp_grow.c
blob400d29a4d1a41f1685dcfbd0b3bab5e55694569d
1 /* $NetBSD: bn_mp_grow.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $ */
3 #include <tommath.h>
4 #ifdef BN_MP_GROW_C
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
15 * guarantee it works.
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
20 /* grow as required */
21 int mp_grow (mp_int * a, int size)
23 int i;
24 mp_digit *tmp;
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);
38 if (tmp == NULL) {
39 /* reallocation failed but "a" is still valid [can be freed] */
40 return MP_MEM;
43 /* reallocation succeeded so set a->dp */
44 a->dp = tmp;
46 /* zero excess digits */
47 i = a->alloc;
48 a->alloc = size;
49 for (; i < a->alloc; i++) {
50 a->dp[i] = 0;
53 return MP_OKAY;
55 #endif
57 /* Source: /cvs/libtom/libtommath/bn_mp_grow.c,v */
58 /* Revision: 1.4 */
59 /* Date: 2006/12/28 01:25:13 */