1/*	$NetBSD: bn_mp_init_size.c,v 1.2 2017/01/28 21:31:47 christos Exp $	*/
2
3#include <tommath.h>
4#ifdef BN_MP_INIT_SIZE_C
5/* LibTomMath, multiple-precision integer library -- Tom St Denis
6 *
7 * LibTomMath is a library that provides multiple-precision
8 * integer arithmetic as well as number theoretic functionality.
9 *
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.
13 *
14 * The library is free for all purposes without any express
15 * guarantee it works.
16 *
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
18 */
19
20/* init an mp_init for a given size */
21int mp_init_size (mp_int * a, int size)
22{
23  int x;
24
25  /* pad size so there are always extra digits */
26  size += (MP_PREC * 2) - (size % MP_PREC);
27
28  /* alloc mem */
29  a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * size);
30  if (a->dp == NULL) {
31    return MP_MEM;
32  }
33
34  /* set the members */
35  a->used  = 0;
36  a->alloc = size;
37  a->sign  = MP_ZPOS;
38
39  /* zero the digits */
40  for (x = 0; x < size; x++) {
41      a->dp[x] = 0;
42  }
43
44  return MP_OKAY;
45}
46#endif
47
48/* Source: /cvs/libtom/libtommath/bn_mp_init_size.c,v  */
49/* Revision: 1.4  */
50/* Date: 2006/12/28 01:25:13  */
51