Commit 72f9251939fa1191cd434ec4b09d479af07382cc

Steffen Jaeckel 2019-09-03T10:59:32

fix last occurrences of `mp_toradix()`

diff --git a/demo/timing.c b/demo/timing.c
index 5db905b..5ce576e 100644
--- a/demo/timing.c
+++ b/demo/timing.c
@@ -22,7 +22,7 @@ static void ndraw(mp_int *a, const char *name)
    char buf[4096];
 
    printf("%s: ", name);
-   mp_toradix(a, buf, 64);
+   mp_to_radix(a, buf, sizeof(buf), 64);
    printf("%s\n", buf);
 }
 
diff --git a/doc/bn.tex b/doc/bn.tex
index a13aee5..bc3baba 100644
--- a/doc/bn.tex
+++ b/doc/bn.tex
@@ -2100,19 +2100,13 @@ The random number generated with these two functions is cryptographically secure
 \subsection{To ASCII}
 \index{mp\_toradix}
 \begin{alltt}
-int mp_toradix (mp_int * a, char *str, int radix);
+int mp_to_radix (mp_int * a, char *str, size_t maxlen, int radix);
 \end{alltt}
-This still store $a$ in ``str'' as a base-``radix'' string of ASCII chars.  This function appends a NUL character
-to terminate the string.  Valid values of ``radix'' line in the range $[2, 64]$.  To determine the size (exact) required
+This stores $a$ in ``str'' of maximum length ``maxlen'' as a base-``radix'' string of ASCII chars.
+This function appends a NUL character to terminate the string.
+Valid values of ``radix'' line in the range $[2, 64]$.  To determine the size (exact) required
 by the conversion before storing any data use the following function.
 
-\index{mp\_toradix\_n}
-\begin{alltt}
-int mp_toradix_n (mp_int * a, char *str, int radix, int maxlen);
-\end{alltt}
-
-Like \texttt{mp\_toradix} but stores upto maxlen-1 chars and always a NULL byte.
-
 \index{mp\_radix\_size}
 \begin{alltt}
 int mp_radix_size (mp_int * a, int radix, int *size)
@@ -2374,27 +2368,27 @@ Other macros which are either shortcuts to normal functions or just other names 
 
 \subsection{Shortcuts}
 
-\index{mp\_tobinary}
+\index{mp\_to\_binary}
 \begin{alltt}
-#define mp_tobinary(M, S) mp_toradix((M), (S), 2)
+#define mp_to_binary(M, S, N)  mp_to_radix((M), (S), (N), 2)
 \end{alltt}
 
 
-\index{mp\_tooctal}
+\index{mp\_to\_octal}
 \begin{alltt}
-#define mp_tooctal(M, S) mp_toradix((M), (S), 8)
+#define mp_to_octal(M, S, N)   mp_to_radix((M), (S), (N), 8)
 \end{alltt}
 
 
-\index{mp\_todecimal}
+\index{mp\_to\_decimal}
 \begin{alltt}
-#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
+#define mp_to_decimal(M, S, N) mp_to_radix((M), (S), (N), 10)
 \end{alltt}
 
 
-\index{mp\_tohex}
+\index{mp\_to\_hex}
 \begin{alltt}
-#define mp_tohex(M, S)     mp_toradix((M), (S), 16)
+#define mp_to_hex(M, S, N)     mp_to_radix((M), (S), (N), 16)
 \end{alltt}
 
 
diff --git a/etc/2kprime.c b/etc/2kprime.c
index a075e18..55cb5f4 100644
--- a/etc/2kprime.c
+++ b/etc/2kprime.c
@@ -69,7 +69,7 @@ top:
             goto top;
          }
 
-         mp_toradix(&q, buf, 10);
+         mp_to_decimal(&q, buf, sizeof(buf));
          printf("\n\n%d-bits (k = %lu) = %s\n", sizes[x], z, buf);
          fprintf(out, "%d-bits (k = %lu) = %s\n", sizes[x], z, buf);
          fflush(out);
diff --git a/etc/drprime.c b/etc/drprime.c
index 1714e68..146455e 100644
--- a/etc/drprime.c
+++ b/etc/drprime.c
@@ -50,7 +50,7 @@ top:
             sizes[x] += 1;
             goto top;
          } else {
-            mp_toradix(&a, buf, 10);
+            mp_to_decimal(&a, buf, sizeof(buf));
             printf("\n\np == %s\n\n", buf);
             fprintf(out, "%d-bit prime:\np == %s\n\n", mp_count_bits(&a), buf);
             fflush(out);
diff --git a/etc/pprime.c b/etc/pprime.c
index 4c60331..706aec8 100644
--- a/etc/pprime.c
+++ b/etc/pprime.c
@@ -331,11 +331,11 @@ top:
       {
          char buf[4096];
 
-         mp_toradix(&n, buf, 10);
+         mp_to_decimal(&n, buf, sizeof(buf));
          printf("Certificate of primality for:\n%s\n\n", buf);
-         mp_toradix(&a, buf, 10);
+         mp_to_decimal(&a, buf, sizeof(buf));
          printf("A == \n%s\n\n", buf);
-         mp_toradix(&b, buf, 10);
+         mp_to_decimal(&b, buf, sizeof(buf));
          printf("B == \n%s\n\nG == %lu\n", buf, bases[ii]);
          printf("----------------------------------------------------------------\n");
       }
@@ -400,9 +400,9 @@ int main(void)
 
    printf("\n\nTook %d ticks, %d bits\n", t1, mp_count_bits(&p));
 
-   mp_toradix(&p, buf, 10);
+   mp_to_decimal(&p, buf, sizeof(buf));
    printf("P == %s\n", buf);
-   mp_toradix(&q, buf, 10);
+   mp_to_decimal(&q, buf, sizeof(buf));
    printf("Q == %s\n", buf);
 
    return 0;