1
1
#include "tommath_private.h"
2
2
#include <string.h>
3
- #ifdef BN_MP_TODECIMAL_FAST_C
3
+ #ifdef BN_S_MP_TODECIMAL_FAST_C
4
4
/* LibTomMath, multiple-precision integer library -- Tom St Denis */
5
5
/* SPDX-License-Identifier: Unlicense */
6
6
7
7
/* 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 )
10
11
{
11
12
mp_int q , nLq , r ;
12
13
mp_err err ;
@@ -47,14 +48,14 @@ mp_err mp_todecimal_fast_rec(mp_int *number, mp_int *nL, mp_int *shiftL, mp_int
47
48
48
49
-- precalc_array_index ;
49
50
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 ) {
51
52
goto LBL_ERR ;
52
53
}
53
54
} 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 ) {
55
56
goto LBL_ERR ;
56
57
}
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 ) {
58
59
goto LBL_ERR ;
59
60
}
60
61
}
@@ -66,9 +67,9 @@ mp_err mp_todecimal_fast_rec(mp_int *number, mp_int *nL, mp_int *shiftL, mp_int
66
67
return err ;
67
68
}
68
69
69
- mp_err mp_todecimal_fast ( mp_int * number , char * result )
70
+ mp_err s_mp_todecimal_fast ( const mp_int * a , char * result )
70
71
{
71
- mp_int n , shift , M , M2 , M22 , M4 , M44 ;
72
+ mp_int number , n , shift , M , M2 , M22 , M4 , M44 ;
72
73
mp_int nL [20 ], shiftL [20 ], mL [20 ];
73
74
mp_err err ;
74
75
char * * result_addr = & result ;
@@ -78,6 +79,9 @@ mp_err mp_todecimal_fast(mp_int *number, char *result)
78
79
goto LBL_ERR ;
79
80
}
80
81
82
+ if ((err = mp_init_copy (a , & number )) != MP_OKAY ) {
83
+ goto LBL_ERR ;
84
+ }
81
85
if (mp_isneg (number )) {
82
86
if ((err = mp_neg (number , number )) != MP_OKAY ) {
83
87
goto LBL_ERR ;
@@ -187,7 +191,7 @@ mp_err mp_todecimal_fast(mp_int *number, char *result)
187
191
precalc_array_index ++ ;
188
192
}
189
193
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 ) {
191
195
goto LBL_ERR ;
192
196
}
193
197
0 commit comments