Debian Codegraph @

libtommath/bn_mp_init_size.c

raw
1 #include "tommath_private.h"
2 #ifdef BN_MP_INIT_SIZE_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
4 /* SPDX-License-Identifier: Unlicense */
5
6 /* init an mp_init for a given size */
7 mp_err mp_init_size(mp_int *a, int size)
8 {
9
10 if (size < 0) {
11 return MP_VAL;
12 }
13
14 size = MP_MAX(MP_MIN_PREC, size);
15
16 /* alloc mem */
17 a->dp = (mp_digit *) MP_CALLOC((size_t)size, sizeof(mp_digit));
18 if (a->dp == NULL) {
19 return MP_MEM;
20 }
21
22 /* set the members */
23 a->used = 0;
24 a->alloc = size;
25 a->sign = MP_ZPOS;
26
27 return MP_OKAY;
28 }
29 #endif