fix last occurrences of `mp_toradix()`
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
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;