11#include "tommath_private.h"
22#include <string.h>
3- #ifdef BN_MP_TODECIMAL_FAST_C
3+ #ifdef BN_S_MP_TODECIMAL_FAST_C
44/* LibTomMath, multiple-precision integer library -- Tom St Denis */
55/* SPDX-License-Identifier: Unlicense */
66
77/* store a bignum as a decimal ASCII string */
8- mp_err mp_todecimal_fast_rec (mp_int * number , mp_int * nL , mp_int * shiftL , mp_int * mL , int precalc_array_index , int left ,
9- char * * result )
8+ mp_err s_mp_todecimal_fast_rec (const mp_int * number , mp_int * nL , mp_int * shiftL , mp_int * mL , int precalc_array_index ,
9+ int left ,
10+ char * * result )
1011{
1112 mp_int q , nLq , r ;
1213 mp_err err ;
@@ -47,14 +48,14 @@ mp_err mp_todecimal_fast_rec(mp_int *number, mp_int *nL, mp_int *shiftL, mp_int
4748
4849 -- precalc_array_index ;
4950 if (left && mp_iszero (& q )) {
50- if ((err = mp_todecimal_fast_rec (& r , nL , shiftL , mL , precalc_array_index , 1 , result )) != MP_OKAY ) {
51+ if ((err = s_mp_todecimal_fast_rec (& r , nL , shiftL , mL , precalc_array_index , 1 , result )) != MP_OKAY ) {
5152 goto LBL_ERR ;
5253 }
5354 } else {
54- if ((err = mp_todecimal_fast_rec (& q , nL , shiftL , mL , precalc_array_index , left , result )) != MP_OKAY ) {
55+ if ((err = s_mp_todecimal_fast_rec (& q , nL , shiftL , mL , precalc_array_index , left , result )) != MP_OKAY ) {
5556 goto LBL_ERR ;
5657 }
57- if ((err = mp_todecimal_fast_rec (& r , nL , shiftL , mL , precalc_array_index , 0 , result )) != MP_OKAY ) {
58+ if ((err = s_mp_todecimal_fast_rec (& r , nL , shiftL , mL , precalc_array_index , 0 , result )) != MP_OKAY ) {
5859 goto LBL_ERR ;
5960 }
6061 }
@@ -66,9 +67,9 @@ mp_err mp_todecimal_fast_rec(mp_int *number, mp_int *nL, mp_int *shiftL, mp_int
6667 return err ;
6768}
6869
69- mp_err mp_todecimal_fast ( mp_int * number , char * result )
70+ mp_err s_mp_todecimal_fast ( const mp_int * a , char * result )
7071{
71- mp_int n , shift , M , M2 , M22 , M4 , M44 ;
72+ mp_int number , n , shift , M , M2 , M22 , M4 , M44 ;
7273 mp_int nL [20 ], shiftL [20 ], mL [20 ];
7374 mp_err err ;
7475 char * * result_addr = & result ;
@@ -78,6 +79,9 @@ mp_err mp_todecimal_fast(mp_int *number, char *result)
7879 goto LBL_ERR ;
7980 }
8081
82+ if ((err = mp_init_copy (a , & number )) != MP_OKAY ) {
83+ goto LBL_ERR ;
84+ }
8185 if (mp_isneg (number )) {
8286 if ((err = mp_neg (number , number )) != MP_OKAY ) {
8387 goto LBL_ERR ;
@@ -187,7 +191,7 @@ mp_err mp_todecimal_fast(mp_int *number, char *result)
187191 precalc_array_index ++ ;
188192 }
189193
190- if ((err = mp_todecimal_fast_rec (number , nL , shiftL , mL , precalc_array_index - 1 , 1 , result_addr )) != MP_OKAY ) {
194+ if ((err = s_mp_todecimal_fast_rec (number , nL , shiftL , mL , precalc_array_index - 1 , 1 , result_addr )) != MP_OKAY ) {
191195 goto LBL_ERR ;
192196 }
193197
0 commit comments