| 
									
										
										
										
											2018-05-02 21:43:17 +02: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. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-12-29 17:56:20 +01:00
										 |  |  |  * SPDX-License-Identifier: Unlicense | 
					
						
							| 
									
										
										
										
											2003-07-02 15:39:39 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-11 16:21:36 +02:00
										 |  |  | #ifndef LTM_NO_FILE
 | 
					
						
							| 
									
										
										
										
											2017-09-20 16:59:43 +02: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 05:51:11 +02: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 19:58:35 +02: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 05:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-02 15:39:39 +00:00
										 |  |  |    if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) { | 
					
						
							| 
									
										
										
										
											2017-08-30 20:08:58 +02:00
										 |  |  |       XFREE(buf); | 
					
						
							| 
									
										
										
										
											2003-07-02 15:39:39 +00:00
										 |  |  |       return err; | 
					
						
							|  |  |  |    } | 
					
						
							| 
									
										
										
										
											2017-08-30 05:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2003-07-02 15:39:39 +00:00
										 |  |  |    for (x = 0; x < len; x++) { | 
					
						
							| 
									
										
										
										
											2017-10-15 19:58:35 +02:00
										 |  |  |       if (fputc((int)buf[x], stream) == EOF) { | 
					
						
							| 
									
										
										
										
											2017-08-29 22:23:48 +02:00
										 |  |  |          XFREE(buf); | 
					
						
							|  |  |  |          return MP_VAL; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2003-07-02 15:39:39 +00:00
										 |  |  |    } | 
					
						
							| 
									
										
										
										
											2017-08-30 05:51:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-30 20:08:58 +02:00
										 |  |  |    XFREE(buf); | 
					
						
							| 
									
										
										
										
											2003-07-02 15:39:39 +00:00
										 |  |  |    return MP_OKAY; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-04-11 16:21:36 +02: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 16:27:26 +02:00
										 |  |  | /* ref:         $Format:%D$ */ | 
					
						
							|  |  |  | /* git commit:  $Format:%H$ */ | 
					
						
							|  |  |  | /* commit time: $Format:%ai$ */ |