Commit 20dcc923f693de2110ab52fc14ac7675644445e5

Daniel Mendler 2019-10-17T16:59:02

rename internal constant radix arrays

diff --git a/bn_mp_fread.c b/bn_mp_fread.c
index 52ea773..1e5ecf7 100644
--- a/bn_mp_fread.c
+++ b/bn_mp_fread.c
@@ -30,11 +30,11 @@ mp_err mp_fread(mp_int *a, int radix, FILE *stream)
    do {
       int y;
       unsigned pos = (unsigned)(ch - (int)'(');
-      if (mp_s_rmap_reverse_sz < pos) {
+      if (MP_RMAP_REVERSE_SIZE < pos) {
          break;
       }
 
-      y = (int)mp_s_rmap_reverse[pos];
+      y = (int)s_mp_rmap_reverse[pos];
 
       if ((y == 0xff) || (y >= radix)) {
          break;
diff --git a/bn_mp_radix_smap.c b/bn_mp_radix_smap.c
index a16128d..e7d7c06 100644
--- a/bn_mp_radix_smap.c
+++ b/bn_mp_radix_smap.c
@@ -4,8 +4,8 @@
 /* SPDX-License-Identifier: Unlicense */
 
 /* chars used in radix conversions */
-const char *const mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
-const uint8_t mp_s_rmap_reverse[] = {
+const char s_mp_rmap[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
+const uint8_t s_mp_rmap_reverse[] = {
    0xff, 0xff, 0xff, 0x3e, 0xff, 0xff, 0xff, 0x3f, /* ()*+,-./ */
    0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, /* 01234567 */
    0x08, 0x09, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 89:;<=>? */
@@ -18,5 +18,5 @@ const uint8_t mp_s_rmap_reverse[] = {
    0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, /* pqrstuvw */
    0x3b, 0x3c, 0x3d, 0xff, 0xff, 0xff, 0xff, 0xff, /* xyz{|}~. */
 };
-const size_t mp_s_rmap_reverse_sz = sizeof(mp_s_rmap_reverse);
+MP_STATIC_ASSERT(correct_rmap_reverse_size, sizeof(s_mp_rmap_reverse) == MP_RMAP_REVERSE_SIZE)
 #endif
diff --git a/bn_mp_read_radix.c b/bn_mp_read_radix.c
index de18e06..456a387 100644
--- a/bn_mp_read_radix.c
+++ b/bn_mp_read_radix.c
@@ -43,10 +43,10 @@ mp_err mp_read_radix(mp_int *a, const char *str, int radix)
        */
       ch = (radix <= 36) ? (char)MP_TOUPPER((int)*str) : *str;
       pos = (unsigned)(ch - '(');
-      if (mp_s_rmap_reverse_sz < pos) {
+      if (MP_RMAP_REVERSE_SIZE < pos) {
          break;
       }
-      y = (int)mp_s_rmap_reverse[pos];
+      y = (int)s_mp_rmap_reverse[pos];
 
       /* if the char was found in the map
        * and is less than the given radix add it
diff --git a/bn_mp_to_radix.c b/bn_mp_to_radix.c
index 7fa86ca..18cb504 100644
--- a/bn_mp_to_radix.c
+++ b/bn_mp_to_radix.c
@@ -60,7 +60,7 @@ mp_err mp_to_radix(const mp_int *a, char *str, size_t maxlen, size_t *written, i
       if ((err = mp_div_d(&t, (mp_digit)radix, &t, &d)) != MP_OKAY) {
          goto LBL_ERR;
       }
-      *str++ = mp_s_rmap[d];
+      *str++ = s_mp_rmap[d];
       ++digs;
    }
    /* reverse the digits of the string.  In this case _s points
diff --git a/tommath_private.h b/tommath_private.h
index 0909fa5..3f4b23a 100644
--- a/tommath_private.h
+++ b/tommath_private.h
@@ -215,9 +215,9 @@ MP_PRIVATE mp_err s_mp_prime_is_divisible(const mp_int *a, mp_bool *result);
 MP_PRIVATE mp_err s_mp_rand_jenkins(void *p, size_t n) MP_WUR;
 MP_PRIVATE void s_mp_rand_jenkins_init(uint64_t seed);
 
-extern MP_PRIVATE const char *const mp_s_rmap;
-extern MP_PRIVATE const uint8_t mp_s_rmap_reverse[];
-extern MP_PRIVATE const size_t mp_s_rmap_reverse_sz;
+#define MP_RMAP_REVERSE_SIZE 88
+extern MP_PRIVATE const char s_mp_rmap[];
+extern MP_PRIVATE const uint8_t s_mp_rmap_reverse[];
 extern MP_PRIVATE const mp_digit s_mp_prime_tab[];
 
 /* number of primes */