1
0
mirror of http://galexander.org/git/simplesshd.git synced 2024-11-30 19:28:10 +00:00
simplesshd/dropbear/libtommath/bn_mp_init_size.c

25 lines
536 B
C
Raw Normal View History

2020-12-28 21:40:37 +00:00
#include "tommath_private.h"
2014-12-10 21:56:49 +00:00
#ifdef BN_MP_INIT_SIZE_C
2020-12-28 21:40:37 +00:00
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
/* SPDX-License-Identifier: Unlicense */
2014-12-10 21:56:49 +00:00
/* init an mp_init for a given size */
2020-12-28 21:40:37 +00:00
mp_err mp_init_size(mp_int *a, int size)
2014-12-10 21:56:49 +00:00
{
2020-12-28 21:40:37 +00:00
size = MP_MAX(MP_MIN_PREC, size);
2014-12-10 21:56:49 +00:00
2020-12-28 21:40:37 +00:00
/* alloc mem */
a->dp = (mp_digit *) MP_CALLOC((size_t)size, sizeof(mp_digit));
if (a->dp == NULL) {
return MP_MEM;
}
2014-12-10 21:56:49 +00:00
2020-12-28 21:40:37 +00:00
/* set the members */
a->used = 0;
a->alloc = size;
a->sign = MP_ZPOS;
2014-12-10 21:56:49 +00:00
2020-12-28 21:40:37 +00:00
return MP_OKAY;
2014-12-10 21:56:49 +00:00
}
#endif