comparison libtommath/bn_mp_fwrite.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_FWRITE_C 2 #ifdef BN_MP_FWRITE_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 #ifndef LTM_NO_FILE 15 #ifndef LTM_NO_FILE
19 int mp_fwrite(mp_int *a, int radix, FILE *stream) 16 int mp_fwrite(const mp_int *a, int radix, FILE *stream)
20 { 17 {
21 char *buf; 18 char *buf;
22 int err, len, x; 19 int err, len, x;
23 20
24 if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) { 21 if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) {
25 return err; 22 return err;
26 } 23 }
27 24
28 buf = OPT_CAST(char) XMALLOC (len); 25 buf = OPT_CAST(char) XMALLOC((size_t)len);
29 if (buf == NULL) { 26 if (buf == NULL) {
30 return MP_MEM; 27 return MP_MEM;
31 } 28 }
32 29
33 if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) { 30 if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) {
34 XFREE (buf); 31 XFREE(buf);
35 return err; 32 return err;
36 } 33 }
37 34
38 for (x = 0; x < len; x++) { 35 for (x = 0; x < len; x++) {
39 if (fputc(buf[x], stream) == EOF) { 36 if (fputc((int)buf[x], stream) == EOF) {
40 XFREE (buf); 37 XFREE(buf);
41 return MP_VAL; 38 return MP_VAL;
42 } 39 }
43 } 40 }
44 41
45 XFREE (buf); 42 XFREE(buf);
46 return MP_OKAY; 43 return MP_OKAY;
47 } 44 }
48 #endif 45 #endif
49 46
50 #endif 47 #endif
51 48
52 /* ref: $Format:%D$ */ 49 /* ref: HEAD -> master, tag: v1.1.0 */
53 /* git commit: $Format:%H$ */ 50 /* git commit: 08549ad6bc8b0cede0b357a9c341c5c6473a9c55 */
54 /* commit time: $Format:%ai$ */ 51 /* commit time: 2019-01-28 20:32:32 +0100 */