comparison libtommath/bn_mp_grow.c @ 1655:f52919ffd3b1

update ltm to 1.1.0 and enable FIPS 186.4 compliant key-generation (#79) * make key-generation compliant to FIPS 186.4 * fix includes in tommath_class.h * update fuzzcorpus instead of error-out * fixup fuzzing make-targets * update Makefile.in * apply necessary patches to ltm sources * clean-up not required ltm files * update to vanilla ltm 1.1.0 this already only contains the required files * remove set/get double
author Steffen Jaeckel <s_jaeckel@gmx.de>
date Mon, 16 Sep 2019 15:50:38 +0200
parents 8bba51a55704
children 1051e4eea25a
comparison
equal deleted inserted replaced
1654:cc0fc5131c5c 1655:f52919ffd3b1
1 #include <tommath_private.h> 1 #include "tommath_private.h"
2 #ifdef BN_MP_GROW_C 2 #ifdef BN_MP_GROW_C
3 /* LibTomMath, multiple-precision integer library -- Tom St Denis 3 /* LibTomMath, multiple-precision integer library -- Tom St Denis
4 * 4 *
5 * LibTomMath is a library that provides multiple-precision 5 * LibTomMath is a library that provides multiple-precision
6 * integer arithmetic as well as number theoretic functionality. 6 * integer arithmetic as well as number theoretic functionality.
7 * 7 *
8 * The library was designed directly after the MPI library by 8 * The library was designed directly after the MPI library by
9 * Michael Fromberger but has been written from scratch with 9 * Michael Fromberger but has been written from scratch with
10 * additional optimizations in place. 10 * additional optimizations in place.
11 * 11 *
12 * The library is free for all purposes without any express 12 * SPDX-License-Identifier: Unlicense
13 * guarantee it works.
14 *
15 * Tom St Denis, [email protected], http://libtom.org
16 */ 13 */
17 14
18 /* grow as required */ 15 /* grow as required */
19 int mp_grow (mp_int * a, int size) 16 int mp_grow(mp_int *a, int size)
20 { 17 {
21 int i; 18 int i;
22 mp_digit *tmp; 19 mp_digit *tmp;
23 20
24 /* if the alloc size is smaller alloc more ram */ 21 /* if the alloc size is smaller alloc more ram */
25 if (a->alloc < size) { 22 if (a->alloc < size) {
26 /* ensure there are always at least MP_PREC digits extra on top */ 23 /* ensure there are always at least MP_PREC digits extra on top */
27 size += (MP_PREC * 2) - (size % MP_PREC); 24 size += (MP_PREC * 2) - (size % MP_PREC);
28 25
29 /* reallocate the array a->dp 26 /* reallocate the array a->dp
30 * 27 *
31 * We store the return in a temporary variable 28 * We store the return in a temporary variable
32 * in case the operation failed we don't want 29 * in case the operation failed we don't want
33 * to overwrite the dp member of a. 30 * to overwrite the dp member of a.
34 */ 31 */
35 tmp = OPT_CAST(mp_digit) XREALLOC (a->dp, sizeof (mp_digit) * size); 32 tmp = OPT_CAST(mp_digit) XREALLOC(a->dp, sizeof(mp_digit) * (size_t)size);
36 if (tmp == NULL) { 33 if (tmp == NULL) {
37 /* reallocation failed but "a" is still valid [can be freed] */ 34 /* reallocation failed but "a" is still valid [can be freed] */
38 return MP_MEM; 35 return MP_MEM;
39 } 36 }
40 37
41 /* reallocation succeeded so set a->dp */ 38 /* reallocation succeeded so set a->dp */
42 a->dp = tmp; 39 a->dp = tmp;
43 40
44 /* zero excess digits */ 41 /* zero excess digits */
45 i = a->alloc; 42 i = a->alloc;
46 a->alloc = size; 43 a->alloc = size;
47 for (; i < a->alloc; i++) { 44 for (; i < a->alloc; i++) {
48 a->dp[i] = 0; 45 a->dp[i] = 0;
49 } 46 }
50 } 47 }
51 return MP_OKAY; 48 return MP_OKAY;
52 } 49 }
53 #endif 50 #endif
54 51
55 /* ref: $Format:%D$ */ 52 /* ref: HEAD -> master, tag: v1.1.0 */
56 /* git commit: $Format:%H$ */ 53 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
57 /* commit time: $Format:%ai$ */ 54 /* commit time: 2019-01-28 20:32:32 +0100 */