Mercurial > dropbear
comparison libtommath/bn_mp_init_size.c @ 1739:13d834efc376 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Thu, 15 Oct 2020 19:55:15 +0800 |
parents | 1051e4eea25a |
children |
comparison
equal
deleted
inserted
replaced
1562:768ebf737aa0 | 1739:13d834efc376 |
---|---|
1 #include <tommath_private.h> | 1 #include "tommath_private.h" |
2 #ifdef BN_MP_INIT_SIZE_C | 2 #ifdef BN_MP_INIT_SIZE_C |
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis | 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis */ |
4 * | 4 /* SPDX-License-Identifier: Unlicense */ |
5 * LibTomMath is a library that provides multiple-precision | |
6 * integer arithmetic as well as number theoretic functionality. | |
7 * | |
8 * The library was designed directly after the MPI library by | |
9 * Michael Fromberger but has been written from scratch with | |
10 * additional optimizations in place. | |
11 * | |
12 * The library is free for all purposes without any express | |
13 * guarantee it works. | |
14 * | |
15 * Tom St Denis, [email protected], http://libtom.org | |
16 */ | |
17 | 5 |
18 /* init an mp_init for a given size */ | 6 /* init an mp_init for a given size */ |
19 int mp_init_size (mp_int * a, int size) | 7 mp_err mp_init_size(mp_int *a, int size) |
20 { | 8 { |
21 int x; | 9 size = MP_MAX(MP_MIN_PREC, size); |
22 | 10 |
23 /* pad size so there are always extra digits */ | 11 /* alloc mem */ |
24 size += (MP_PREC * 2) - (size % MP_PREC); | 12 a->dp = (mp_digit *) MP_CALLOC((size_t)size, sizeof(mp_digit)); |
25 | 13 if (a->dp == NULL) { |
26 /* alloc mem */ | 14 return MP_MEM; |
27 a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * size); | 15 } |
28 if (a->dp == NULL) { | |
29 return MP_MEM; | |
30 } | |
31 | 16 |
32 /* set the members */ | 17 /* set the members */ |
33 a->used = 0; | 18 a->used = 0; |
34 a->alloc = size; | 19 a->alloc = size; |
35 a->sign = MP_ZPOS; | 20 a->sign = MP_ZPOS; |
36 | 21 |
37 /* zero the digits */ | 22 return MP_OKAY; |
38 for (x = 0; x < size; x++) { | |
39 a->dp[x] = 0; | |
40 } | |
41 | |
42 return MP_OKAY; | |
43 } | 23 } |
44 #endif | 24 #endif |
45 | |
46 /* ref: $Format:%D$ */ | |
47 /* git commit: $Format:%H$ */ | |
48 /* commit time: $Format:%ai$ */ |