Mercurial > dropbear
comparison libtommath/bn_mp_init_size.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_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 * |
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 /* init an mp_init for a given size */ | 15 /* init an mp_init for a given size */ |
19 int mp_init_size (mp_int * a, int size) | 16 int mp_init_size(mp_int *a, int size) |
20 { | 17 { |
21 int x; | 18 int x; |
22 | 19 |
23 /* pad size so there are always extra digits */ | 20 /* pad size so there are always extra digits */ |
24 size += (MP_PREC * 2) - (size % MP_PREC); | 21 size += (MP_PREC * 2) - (size % MP_PREC); |
25 | |
26 /* alloc mem */ | |
27 a->dp = OPT_CAST(mp_digit) XMALLOC (sizeof (mp_digit) * size); | |
28 if (a->dp == NULL) { | |
29 return MP_MEM; | |
30 } | |
31 | 22 |
32 /* set the members */ | 23 /* alloc mem */ |
33 a->used = 0; | 24 a->dp = OPT_CAST(mp_digit) XMALLOC(sizeof(mp_digit) * (size_t)size); |
34 a->alloc = size; | 25 if (a->dp == NULL) { |
35 a->sign = MP_ZPOS; | 26 return MP_MEM; |
27 } | |
36 | 28 |
37 /* zero the digits */ | 29 /* set the members */ |
38 for (x = 0; x < size; x++) { | 30 a->used = 0; |
31 a->alloc = size; | |
32 a->sign = MP_ZPOS; | |
33 | |
34 /* zero the digits */ | |
35 for (x = 0; x < size; x++) { | |
39 a->dp[x] = 0; | 36 a->dp[x] = 0; |
40 } | 37 } |
41 | 38 |
42 return MP_OKAY; | 39 return MP_OKAY; |
43 } | 40 } |
44 #endif | 41 #endif |
45 | 42 |
46 /* ref: $Format:%D$ */ | 43 /* ref: HEAD -> master, tag: v1.1.0 */ |
47 /* git commit: $Format:%H$ */ | 44 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */ |
48 /* commit time: $Format:%ai$ */ | 45 /* commit time: 2019-01-28 20:32:32 +0100 */ |