forked from libtom/libtommath
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbn_mp_fput.c
More file actions
40 lines (36 loc) · 763 Bytes
/
bn_mp_fput.c
File metadata and controls
40 lines (36 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <tommath.h>
#ifdef BN_MP_FPUT_C
int mp_fput(mp_int *a, int base, FILE *stream)
{
char *str, *s0;
size_t size, n;
int err;
size = mp_digits(a, base) + 10;
str = malloc(size * sizeof(char));
if (NULL == str) {
#ifdef DEBUG
fprintf(stderr, "malloc failed to allocate %d bytes\n",
size * sizeof(char));
#endif
return MP_MEM;
}
s0 = str;
n = size;
while (--n) {
*s0++ = '\0';
}
if ((err = mp_toradix(a, str, base)) != MP_OKAY) {
return err;
}
fputs(str,stream);
// This library might get used for cryptographic purposes, so
// overwrite the memory, at least.
n = size;
s0 = str;
while (--n) {
*s0++ = '\0';
}
free(str);
return MP_OKAY;
}
#endif