Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / heimdal / dist / lib / hcrypto / libtommath / bn_mp_fwrite.c
blob014a5b74b16fb880abf08ce7d069c67a335f2a64
1 /* $NetBSD: bn_mp_fwrite.c,v 1.1.1.2 2014/04/24 12:45:31 pettai Exp $ */
3 #include <tommath.h>
4 #ifdef BN_MP_FWRITE_C
5 /* LibTomMath, multiple-precision integer library -- Tom St Denis
7 * LibTomMath is a library that provides multiple-precision
8 * integer arithmetic as well as number theoretic functionality.
10 * The library was designed directly after the MPI library by
11 * Michael Fromberger but has been written from scratch with
12 * additional optimizations in place.
14 * The library is free for all purposes without any express
15 * guarantee it works.
17 * Tom St Denis, tomstdenis@gmail.com, http://libtom.org
20 int mp_fwrite(mp_int *a, int radix, FILE *stream)
22 char *buf;
23 int err, len, x;
25 if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) {
26 return err;
29 buf = OPT_CAST(char) XMALLOC (len);
30 if (buf == NULL) {
31 return MP_MEM;
34 if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) {
35 XFREE (buf);
36 return err;
39 for (x = 0; x < len; x++) {
40 if (fputc(buf[x], stream) == EOF) {
41 XFREE (buf);
42 return MP_VAL;
46 XFREE (buf);
47 return MP_OKAY;
50 #endif
52 /* Source: /cvs/libtom/libtommath/bn_mp_fwrite.c,v */
53 /* Revision: 1.4 */
54 /* Date: 2006/12/28 01:25:13 */