2018-05-02 19:43:17 +00:00
|
|
|
#include "tommath_private.h"
|
2004-10-29 22:07:18 +00:00
|
|
|
#ifdef BN_MP_FWRITE_C
|
2003-07-02 15:39:39 +00:00
|
|
|
/* LibTomMath, multiple-precision integer library -- Tom St Denis
|
|
|
|
*
|
2003-08-05 01:24:44 +00:00
|
|
|
* LibTomMath is a library that provides multiple-precision
|
2003-07-02 15:39:39 +00:00
|
|
|
* integer arithmetic as well as number theoretic functionality.
|
|
|
|
*
|
2003-08-05 01:24:44 +00:00
|
|
|
* The library was designed directly after the MPI library by
|
2003-07-02 15:39:39 +00:00
|
|
|
* Michael Fromberger but has been written from scratch with
|
|
|
|
* additional optimizations in place.
|
|
|
|
*
|
|
|
|
* The library is free for all purposes without any express
|
|
|
|
* guarantee it works.
|
|
|
|
*/
|
|
|
|
|
2017-04-11 14:21:36 +00:00
|
|
|
#ifndef LTM_NO_FILE
|
2017-09-20 14:59:43 +00:00
|
|
|
int mp_fwrite(const mp_int *a, int radix, FILE *stream)
|
2003-07-02 15:39:39 +00:00
|
|
|
{
|
|
|
|
char *buf;
|
|
|
|
int err, len, x;
|
2017-08-30 03:51:11 +00:00
|
|
|
|
2004-01-25 17:40:21 +00:00
|
|
|
if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) {
|
|
|
|
return err;
|
2003-07-02 15:39:39 +00:00
|
|
|
}
|
2004-01-25 17:40:21 +00:00
|
|
|
|
2017-10-15 17:58:35 +00:00
|
|
|
buf = OPT_CAST(char) XMALLOC((size_t)len);
|
2003-07-02 15:39:39 +00:00
|
|
|
if (buf == NULL) {
|
|
|
|
return MP_MEM;
|
|
|
|
}
|
2017-08-30 03:51:11 +00:00
|
|
|
|
2003-07-02 15:39:39 +00:00
|
|
|
if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) {
|
2017-08-30 18:08:58 +00:00
|
|
|
XFREE(buf);
|
2003-07-02 15:39:39 +00:00
|
|
|
return err;
|
|
|
|
}
|
2017-08-30 03:51:11 +00:00
|
|
|
|
2003-07-02 15:39:39 +00:00
|
|
|
for (x = 0; x < len; x++) {
|
2017-10-15 17:58:35 +00:00
|
|
|
if (fputc((int)buf[x], stream) == EOF) {
|
2017-08-29 20:23:48 +00:00
|
|
|
XFREE(buf);
|
|
|
|
return MP_VAL;
|
|
|
|
}
|
2003-07-02 15:39:39 +00:00
|
|
|
}
|
2017-08-30 03:51:11 +00:00
|
|
|
|
2017-08-30 18:08:58 +00:00
|
|
|
XFREE(buf);
|
2003-07-02 15:39:39 +00:00
|
|
|
return MP_OKAY;
|
|
|
|
}
|
2017-04-11 14:21:36 +00:00
|
|
|
#endif
|
2003-07-02 15:39:39 +00:00
|
|
|
|
2004-10-29 22:07:18 +00:00
|
|
|
#endif
|
2005-08-01 16:37:28 +00:00
|
|
|
|
2017-08-28 14:27:26 +00:00
|
|
|
/* ref: $Format:%D$ */
|
|
|
|
/* git commit: $Format:%H$ */
|
|
|
|
/* commit time: $Format:%ai$ */
|