diff --git a/demo/test.c b/demo/test.c
index f2f5800b3..b3a14e2a2 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -729,7 +729,7 @@ static int test_mp_sqrt(void)
          printf("\nmp_sqrt() error!");
          goto LBL_ERR;
       }
-      DO(mp_root_u32(&a, 2u, &c));
+      DO(mp_root(&a, 2u, &c));
       if (mp_cmp_mag(&b, &c) != MP_EQ) {
          printf("mp_sqrt() bad result!\n");
          goto LBL_ERR;
@@ -1396,10 +1396,10 @@ static int test_mp_reduce_2k_l(void)
 /* stripped down version of mp_radix_size. The faster version can be off by up t
 o +3  */
 /* TODO: This function should be removed, replaced by mp_radix_size, mp_radix_size_overestimate in 2.0 */
-static mp_err s_rs(const mp_int *a, int radix, uint32_t *size)
+static mp_err s_rs(const mp_int *a, int radix, int *size)
 {
    mp_err res;
-   uint32_t digs = 0u;
+   int digs = 0u;
    mp_int  t;
    mp_digit d;
    *size = 0u;
@@ -1408,7 +1408,7 @@ static mp_err s_rs(const mp_int *a, int radix, uint32_t *size)
       return MP_OKAY;
    }
    if (radix == 2) {
-      *size = (uint32_t)mp_count_bits(a) + 1u;
+      *size = mp_count_bits(a) + 1;
       return MP_OKAY;
    }
    DOR(mp_init_copy(&t, a));
@@ -1424,12 +1424,12 @@ static mp_err s_rs(const mp_int *a, int radix, uint32_t *size)
    *size = digs + 1;
    return MP_OKAY;
 }
-static int test_mp_log_u32(void)
+static int test_mp_log(void)
 {
    mp_int a;
    mp_digit d;
-   uint32_t base, lb, size;
-   const uint32_t max_base = MP_MIN(UINT32_MAX, MP_DIGIT_MAX);
+   int base, lb, size;
+   const int max_base = MP_MIN(INT_MAX, MP_DIGIT_MAX);
 
    DOR(mp_init(&a));
 
@@ -1440,11 +1440,11 @@ static int test_mp_log_u32(void)
    */
    mp_set(&a, 42u);
    base = 0u;
-   if (mp_log_u32(&a, base, &lb) != MP_VAL) {
+   if (mp_log(&a, base, &lb) != MP_VAL) {
       goto LBL_ERR;
    }
    base = 1u;
-   if (mp_log_u32(&a, base, &lb) != MP_VAL) {
+   if (mp_log(&a, base, &lb) != MP_VAL) {
       goto LBL_ERR;
    }
    /*
@@ -1456,14 +1456,14 @@ static int test_mp_log_u32(void)
    */
    base = 2u;
    mp_zero(&a);
-   if (mp_log_u32(&a, base, &lb) != MP_VAL) {
+   if (mp_log(&a, base, &lb) != MP_VAL) {
       goto LBL_ERR;
    }
 
    for (d = 1; d < 4; d++) {
       mp_set(&a, d);
-      DO(mp_log_u32(&a, base, &lb));
-      if (lb != ((d == 1)?0uL:1uL)) {
+      DO(mp_log(&a, base, &lb));
+      if (lb != ((d == 1)?0:1)) {
          goto LBL_ERR;
       }
    }
@@ -1476,13 +1476,13 @@ static int test_mp_log_u32(void)
    */
    base = 3u;
    mp_zero(&a);
-   if (mp_log_u32(&a, base, &lb) != MP_VAL) {
+   if (mp_log(&a, base, &lb) != MP_VAL) {
       goto LBL_ERR;
    }
    for (d = 1; d < 4; d++) {
       mp_set(&a, d);
-      DO(mp_log_u32(&a, base, &lb));
-      if (lb != ((d < base)?0uL:1uL)) {
+      DO(mp_log(&a, base, &lb));
+      if (lb != (((int)d < base)?0:1)) {
          goto LBL_ERR;
       }
    }
@@ -1493,8 +1493,8 @@ static int test_mp_log_u32(void)
      radix_size.
    */
    DO(mp_rand(&a, 10));
-   for (base = 2u; base < 65u; base++) {
-      DO(mp_log_u32(&a, base, &lb));
+   for (base = 2; base < 65; base++) {
+      DO(mp_log(&a, base, &lb));
       DO(s_rs(&a,(int)base, &size));
       /* radix_size includes the memory needed for '\0', too*/
       size -= 2;
@@ -1508,8 +1508,8 @@ static int test_mp_log_u32(void)
      test the part of mp_ilogb that uses native types.
    */
    DO(mp_rand(&a, 1));
-   for (base = 2u; base < 65u; base++) {
-      DO(mp_log_u32(&a, base, &lb));
+   for (base = 2; base < 65; base++) {
+      DO(mp_log(&a, base, &lb));
       DO(s_rs(&a,(int)base, &size));
       size -= 2;
       if (lb != size) {
@@ -1519,9 +1519,9 @@ static int test_mp_log_u32(void)
 
    /*Test upper edgecase with base UINT32_MAX and number (UINT32_MAX/2)*UINT32_MAX^10  */
    mp_set(&a, max_base);
-   DO(mp_expt_u32(&a, 10u, &a));
-   DO(mp_add_d(&a, max_base / 2u, &a));
-   DO(mp_log_u32(&a, max_base, &lb));
+   DO(mp_expt(&a, 10uL, &a));
+   DO(mp_add_d(&a, max_base / 2, &a));
+   DO(mp_log(&a, max_base, &lb));
    if (lb != 10u) {
       goto LBL_ERR;
    }
@@ -1658,7 +1658,7 @@ static int test_mp_decr(void)
    low-mp branch.
 */
 
-static int test_mp_root_u32(void)
+static int test_mp_root(void)
 {
    mp_int a, c, r;
    int i, j;
@@ -1850,10 +1850,10 @@ static int test_mp_root_u32(void)
    for (i = 0; i < 10; i++) {
       DO(mp_read_radix(&a, input[i], 64));
       for (j = 3; j < 100; j++) {
-         DO(mp_root_u32(&a, (uint32_t)j, &c));
+         DO(mp_root(&a, j, &c));
          DO(mp_read_radix(&r, root[i][j-3], 10));
          if (mp_cmp(&r, &c) != MP_EQ) {
-            fprintf(stderr, "mp_root_u32 failed at input #%d, root #%d\n", i, j);
+            fprintf(stderr, "mp_root failed at input #%d, root #%d\n", i, j);
             goto LBL_ERR;
          }
       }
@@ -2037,8 +2037,8 @@ static int test_mp_radix_size(void)
    DOR(mp_init(&a));
 
    /* number to result in a different size for every base: 67^(4 * 67) */
-   mp_set(&a, 67u);
-   DO(mp_expt_u32(&a, 268u, &a));
+   mp_set(&a, 67);
+   DO(mp_expt(&a, 268, &a));
 
    for (radix = 2; radix < 65; radix++) {
       DO(mp_radix_size(&a, radix, &size));
@@ -2304,13 +2304,13 @@ static int unit_tests(int argc, char **argv)
       T1(mp_get_u32, MP_GET_I32),
       T1(mp_get_u64, MP_GET_I64),
       T1(mp_get_ul, MP_GET_L),
-      T1(mp_log_u32, MP_LOG_U32),
+      T1(mp_log, MP_LOG),
       T1(mp_incr, MP_ADD_D),
       T1(mp_invmod, MP_INVMOD),
       T1(mp_is_square, MP_IS_SQUARE),
       T1(mp_kronecker, MP_KRONECKER),
       T1(mp_montgomery_reduce, MP_MONTGOMERY_REDUCE),
-      T1(mp_root_u32, MP_ROOT_U32),
+      T1(mp_root, MP_ROOT),
       T1(mp_or, MP_OR),
       T1(mp_prime_is_prime, MP_PRIME_IS_PRIME),
       T1(mp_prime_next_prime, MP_PRIME_NEXT_PRIME),
@@ -2326,7 +2326,7 @@ static int unit_tests(int argc, char **argv)
       T1(mp_set_double, MP_SET_DOUBLE),
 #endif
       T1(mp_signed_rsh, MP_SIGNED_RSH),
-      T1(mp_sqrt, MP_SQRT),
+      T2(mp_sqrt, MP_SQRT, MP_ROOT),
       T1(mp_sqrtmod_prime, MP_SQRTMOD_PRIME),
       T1(mp_xor, MP_XOR),
       T2(s_mp_div_recursive, S_MP_DIV_RECURSIVE, S_MP_DIV_SCHOOL),
diff --git a/doc/bn.tex b/doc/bn.tex
index b8a6404b7..7e323753f 100644
--- a/doc/bn.tex
+++ b/doc/bn.tex
@@ -1906,9 +1906,9 @@ \section{Combined Modular Reduction}
 
 \chapter{Exponentiation}
 \section{Single Digit Exponentiation}
-\index{mp\_expt\_u32}
+\index{mp\_expt}
 \begin{alltt}
-mp_err mp_expt_u32 (const mp_int *a, uint32_t b, mp_int *c)
+mp_err mp_expt (const mp_int *a, int b, mp_int *c)
 \end{alltt}
 This function computes $c = a^b$.
 
@@ -1935,9 +1935,9 @@ \section{Modulus a Power of Two}
 It calculates $c = a \mod 2^b$.
 
 \section{Root Finding}
-\index{mp\_root\_u32}
+\index{mp\_root}
 \begin{alltt}
-mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
+mp_err mp_root(const mp_int *a, int b, mp_int *c)
 \end{alltt}
 This computes $c = a^{1/b}$ such that $c^b \le a$ and $(c+1)^b > a$. Will return a positive root
 only for even roots and return a root with the sign of the input for odd roots.  For example,
@@ -1959,9 +1959,9 @@ \section{Integer Logarithm}
 A logarithm function for positive integer input \texttt{a, base} computing  $\floor{\log_bx}$ such
 that $(\log_b x)^b \le x$.
 
-\index{mp\_log\_u32}
+\index{mp\_log}
 \begin{alltt}
-mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
+mp_err mp_log(const mp_int *a, int base, int *c)
 \end{alltt}
 
 \subsection{Example}
@@ -1976,7 +1976,7 @@ \subsection{Example}
 int main(int argc, char **argv)
 {
    mp_int x, output;
-   uint32_t base;
+   int base;
    mp_err e;
 
    if (argc != 3) {
@@ -1989,12 +1989,8 @@ \subsection{Example}
               exit(EXIT_FAILURE);
    }
    errno = 0;
-#ifdef MP_64BIT
-   /* Check for overflow skipped  */
-   base = (uint32_t)strtoull(argv[1], NULL, 10);
-#else
-   base = (uint32_t)strtoul(argv[1], NULL, 10);
-#endif
+   base = (int)strtoul(argv[1], NULL, 10);
+
    if (errno == ERANGE) {
       fprintf(stderr,"strtoul(l) failed: input out of range\textbackslash{}n");
       exit(EXIT_FAILURE);
@@ -2004,8 +2000,8 @@ \subsection{Example}
                       mp_error_to_string(e));
       exit(EXIT_FAILURE);
    }
-   if ((e = mp_log_u32(&x, base, &output)) != MP_OKAY) {
-      fprintf(stderr,"mp_ilogb failed: \textbackslash{}"%s\textbackslash{}"\textbackslash{}n",
+   if ((e = mp_log(&x, base, &output)) != MP_OKAY) {
+      fprintf(stderr,"mp_log failed: \textbackslash{}"%s\textbackslash{}"\textbackslash{}n",
                       mp_error_to_string(e));
       exit(EXIT_FAILURE);
    }
diff --git a/libtommath_VS2008.vcproj b/libtommath_VS2008.vcproj
index 215ab4a09..fb0aa0ec3 100644
--- a/libtommath_VS2008.vcproj
+++ b/libtommath_VS2008.vcproj
@@ -421,7 +421,7 @@
 			>
 		
 		
 		
 		
 		
 		
 		
 		
 		
 		
 		
 		
 		
 		
 		
 		
 		
 		 0u) {
+   while (b > 0) {
       /* if the bit is set multiply */
-      if ((b & 1u) != 0u) {
+      if ((b & 1) != 0) {
          if ((err = mp_mul(c, &g, c)) != MP_OKAY) {
             goto LBL_ERR;
          }
       }
 
       /* square */
-      if (b > 1u) {
+      if (b > 1) {
          if ((err = mp_sqr(&g, &g)) != MP_OKAY) {
             goto LBL_ERR;
          }
@@ -36,8 +35,6 @@ mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c)
       b >>= 1;
    }
 
-   err = MP_OKAY;
-
 LBL_ERR:
    mp_clear(&g);
    return err;
diff --git a/mp_log_u32.c b/mp_log.c
similarity index 56%
rename from mp_log_u32.c
rename to mp_log.c
index 31d96628c..d33f844f9 100644
--- a/mp_log_u32.c
+++ b/mp_log.c
@@ -1,9 +1,9 @@
 #include "tommath_private.h"
-#ifdef MP_LOG_U32_C
+#ifdef MP_LOG_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
 /* SPDX-License-Identifier: Unlicense */
 
-mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
+mp_err mp_log(const mp_int *a, int base, int *c)
 {
    if (a->sign == MP_NEG) {
       return MP_VAL;
@@ -13,22 +13,22 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
       return MP_VAL;
    }
 
-   if (base < 2u) {
+   if (base < 2 || (unsigned)base > (unsigned)MP_DIGIT_MAX) {
       return MP_VAL;
    }
 
-   if (MP_HAS(S_MP_LOG_POW2) && ((base & (base - 1u)) == 0u)) {
-      *c = s_mp_log_pow2(a, base);
+   if (MP_HAS(S_MP_LOG_2EXPT) && ((base & (base - 1)) == 0u)) {
+      *c = s_mp_log_2expt(a, (mp_digit)base);
       return MP_OKAY;
    }
 
    if (MP_HAS(S_MP_LOG_D) && (a->used == 1)) {
-      *c = (uint32_t)s_mp_log_d(base, a->dp[0]);
+      *c = s_mp_log_d((mp_digit)base, a->dp[0]);
       return MP_OKAY;
    }
 
    if (MP_HAS(S_MP_LOG)) {
-      return s_mp_log(a, base, c);
+      return s_mp_log(a, (mp_digit)base, c);
    }
 
    return MP_VAL;
diff --git a/mp_radix_size.c b/mp_radix_size.c
index 47f2f68c3..678cc7c01 100644
--- a/mp_radix_size.c
+++ b/mp_radix_size.c
@@ -8,7 +8,7 @@ mp_err mp_radix_size(const mp_int *a, int radix, size_t *size)
 {
    mp_err err;
    mp_int a_;
-   uint32_t b;
+   int b;
 
    /* make sure the radix is in range */
    if ((radix < 2) || (radix > 64)) {
@@ -22,14 +22,13 @@ mp_err mp_radix_size(const mp_int *a, int radix, size_t *size)
 
    a_ = *a;
    a_.sign = MP_ZPOS;
-   if ((err = mp_log_u32(&a_, (uint32_t)radix, &b)) != MP_OKAY) {
-      goto LBL_ERR;
+   if ((err = mp_log(&a_, radix, &b)) != MP_OKAY) {
+      return err;
    }
 
    /* mp_ilogb truncates to zero, hence we need one extra put on top and one for `\0`. */
-   *size = (size_t)b + 2U + ((a->sign == MP_NEG) ? 1U : 0U);
+   *size = (size_t)(b + 2 + ((a->sign == MP_NEG) ? 1 : 0));
 
-LBL_ERR:
-   return err;
+   return MP_OKAY;
 }
 #endif
diff --git a/mp_root_u32.c b/mp_root.c
similarity index 84%
rename from mp_root_u32.c
rename to mp_root.c
index f6827493c..d53180883 100644
--- a/mp_root_u32.c
+++ b/mp_root.c
@@ -1,5 +1,5 @@
 #include "tommath_private.h"
-#ifdef MP_ROOT_U32_C
+#ifdef MP_ROOT_C
 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
 /* SPDX-License-Identifier: Unlicense */
 
@@ -12,15 +12,18 @@
  * which will find the root in log(N) time where
  * each step involves a fair bit.
  */
-mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
+mp_err mp_root(const mp_int *a, int b, mp_int *c)
 {
    mp_int t1, t2, t3, a_;
-   mp_ord cmp;
    int    ilog2;
    mp_err err;
 
+   if (b < 0 || (unsigned)b > (unsigned)MP_DIGIT_MAX) {
+      return MP_VAL;
+   }
+
    /* input must be positive if b is even */
-   if (((b & 1u) == 0u) && (a->sign == MP_NEG)) {
+   if (((b & 1) == 0) && (a->sign == MP_NEG)) {
       return MP_VAL;
    }
 
@@ -40,7 +43,7 @@ mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
      log_2(n) because the bit-length of the "n" is measured
      with an int and hence the root is always < 2 (two).
    */
-   if (b > (uint32_t)(INT_MAX/2)) {
+   if (b > INT_MAX/2) {
       mp_set(c, 1uL);
       c->sign = a->sign;
       err = MP_OKAY;
@@ -48,13 +51,13 @@ mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
    }
 
    /* "b" is smaller than INT_MAX, we can cast safely */
-   if (ilog2 < (int)b) {
+   if (ilog2 < b) {
       mp_set(c, 1uL);
       c->sign = a->sign;
       err = MP_OKAY;
       goto LBL_ERR;
    }
-   ilog2 =  ilog2 / ((int)b);
+   ilog2 =  ilog2 / b;
    if (ilog2 == 0) {
       mp_set(c, 1uL);
       c->sign = a->sign;
@@ -71,7 +74,7 @@ mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
       /* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
 
       /* t3 = t1**(b-1) */
-      if ((err = mp_expt_u32(&t1, b - 1u, &t3)) != MP_OKAY)       goto LBL_ERR;
+      if ((err = mp_expt(&t1, b - 1, &t3)) != MP_OKAY)       goto LBL_ERR;
 
       /* numerator */
       /* t2 = t1**b */
@@ -82,7 +85,7 @@ mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
 
       /* denominator */
       /* t3 = t1**(b-1) * b  */
-      if ((err = mp_mul_d(&t3, b, &t3)) != MP_OKAY)               goto LBL_ERR;
+      if ((err = mp_mul_d(&t3, (mp_digit)b, &t3)) != MP_OKAY)               goto LBL_ERR;
 
       /* t3 = (t1**b - a)/(b * t1**(b-1)) */
       if ((err = mp_div(&t2, &t3, &t3, NULL)) != MP_OKAY)         goto LBL_ERR;
@@ -101,7 +104,8 @@ mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
    /* result can be off by a few so check */
    /* Loop beneath can overshoot by one if found root is smaller than actual root */
    for (;;) {
-      if ((err = mp_expt_u32(&t1, b, &t2)) != MP_OKAY)            goto LBL_ERR;
+      mp_ord cmp;
+      if ((err = mp_expt(&t1, b, &t2)) != MP_OKAY)            goto LBL_ERR;
       cmp = mp_cmp(&t2, &a_);
       if (cmp == MP_EQ) {
          err = MP_OKAY;
@@ -115,7 +119,7 @@ mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
    }
    /* correct overshoot from above or from recurrence */
    for (;;) {
-      if ((err = mp_expt_u32(&t1, b, &t2)) != MP_OKAY)            goto LBL_ERR;
+      if ((err = mp_expt(&t1, b, &t2)) != MP_OKAY)            goto LBL_ERR;
       if (mp_cmp(&t2, &a_) == MP_GT) {
          if ((err = mp_sub_d(&t1, 1uL, &t1)) != MP_OKAY)          goto LBL_ERR;
       } else {
@@ -129,8 +133,6 @@ mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c)
    /* set the sign of the result */
    c->sign = a->sign;
 
-   err = MP_OKAY;
-
 LBL_ERR:
    mp_clear_multi(&t1, &t2, &t3, NULL);
    return err;
diff --git a/s_mp_log.c b/s_mp_log.c
index eba279ef7..f535bed53 100644
--- a/s_mp_log.c
+++ b/s_mp_log.c
@@ -3,14 +3,13 @@
 /* LibTomMath, multiple-precision integer library -- Tom St Denis */
 /* SPDX-License-Identifier: Unlicense */
 
-mp_err s_mp_log(const mp_int *a, uint32_t base, uint32_t *c)
+mp_err s_mp_log(const mp_int *a, mp_digit base, int *c)
 {
    mp_err err;
-   mp_ord cmp;
-   uint32_t high, low, mid;
+   int high, low;
    mp_int bracket_low, bracket_high, bracket_mid, t, bi_base;
 
-   cmp = mp_cmp_d(a, base);
+   mp_ord cmp = mp_cmp_d(a, base);
    if ((cmp == MP_LT) || (cmp == MP_EQ)) {
       *c = cmp == MP_EQ;
       return MP_OKAY;
@@ -22,9 +21,9 @@ mp_err s_mp_log(const mp_int *a, uint32_t base, uint32_t *c)
       return err;
    }
 
-   low = 0u;
+   low = 0;
    mp_set(&bracket_low, 1uL);
-   high = 1u;
+   high = 1;
 
    mp_set(&bracket_high, base);
 
@@ -46,10 +45,10 @@ mp_err s_mp_log(const mp_int *a, uint32_t base, uint32_t *c)
    }
    mp_set(&bi_base, base);
 
-   while ((high - low) > 1u) {
-      mid = (high + low) >> 1;
+   while ((high - low) > 1) {
+      int mid = (high + low) >> 1;
 
-      if ((err = mp_expt_u32(&bi_base, (uint32_t)(mid - low), &t)) != MP_OKAY) {
+      if ((err = mp_expt(&bi_base, mid - low, &t)) != MP_OKAY) {
          goto LBL_END;
       }
       if ((err = mp_mul(&bracket_low, &t, &bracket_mid)) != MP_OKAY) {
diff --git a/s_mp_log_2expt.c b/s_mp_log_2expt.c
new file mode 100644
index 000000000..ec0fda3b7
--- /dev/null
+++ b/s_mp_log_2expt.c
@@ -0,0 +1,12 @@
+#include "tommath_private.h"
+#ifdef S_MP_LOG_2EXPT_C
+/* LibTomMath, multiple-precision integer library -- Tom St Denis */
+/* SPDX-License-Identifier: Unlicense */
+
+int s_mp_log_2expt(const mp_int *a, mp_digit base)
+{
+   int y;
+   for (y = 0; (base & 1) == 0; y++, base >>= 1) {}
+   return (mp_count_bits(a) - 1) / y;
+}
+#endif
diff --git a/s_mp_log_d.c b/s_mp_log_d.c
index 44edd0755..62b154818 100644
--- a/s_mp_log_d.c
+++ b/s_mp_log_d.c
@@ -17,21 +17,18 @@ static mp_word s_pow(mp_word base, mp_word exponent)
    return result;
 }
 
-mp_digit s_mp_log_d(mp_digit base, mp_digit n)
+int s_mp_log_d(mp_digit base, mp_digit n)
 {
-   mp_word bracket_low = 1uLL, bracket_mid, bracket_high, N;
-   mp_digit ret, high = 1uL, low = 0uL, mid;
+   mp_word bracket_low = 1uLL, bracket_high = base, N = n;
+   int ret, high = 1, low = 0;
 
    if (n < base) {
-      return 0uL;
+      return 0;
    }
    if (n == base) {
-      return 1uL;
+      return 1;
    }
 
-   bracket_high = (mp_word) base ;
-   N = (mp_word) n;
-
    while (bracket_high < N) {
       low = high;
       bracket_low = bracket_high;
@@ -40,8 +37,8 @@ mp_digit s_mp_log_d(mp_digit base, mp_digit n)
    }
 
    while (((mp_digit)(high - low)) > 1uL) {
-      mid = (low + high) >> 1;
-      bracket_mid = bracket_low * s_pow(base, (mp_word)(mid - low));
+      int mid = (low + high) >> 1;
+      mp_word bracket_mid = bracket_low * s_pow(base, (mp_word)(mid - low));
 
       if (N < bracket_mid) {
          high = mid ;
@@ -52,7 +49,7 @@ mp_digit s_mp_log_d(mp_digit base, mp_digit n)
          bracket_low = bracket_mid ;
       }
       if (N == bracket_mid) {
-         return (mp_digit) mid;
+         return mid;
       }
    }
 
diff --git a/s_mp_log_pow2.c b/s_mp_log_pow2.c
deleted file mode 100644
index 74271c68f..000000000
--- a/s_mp_log_pow2.c
+++ /dev/null
@@ -1,12 +0,0 @@
-#include "tommath_private.h"
-#ifdef S_MP_LOG_POW2_C
-/* LibTomMath, multiple-precision integer library -- Tom St Denis */
-/* SPDX-License-Identifier: Unlicense */
-
-uint32_t s_mp_log_pow2(const mp_int *a, uint32_t base)
-{
-   int y;
-   for (y = 0; (base & 1u) == 0u; y++, base >>= 1) {}
-   return (uint32_t)((mp_count_bits(a) - 1) / y);
-}
-#endif
diff --git a/tommath.def b/tommath.def
index d2509e1f1..39c4d2564 100644
--- a/tommath.def
+++ b/tommath.def
@@ -32,7 +32,7 @@ EXPORTS
     mp_dr_setup
     mp_error_to_string
     mp_exch
-    mp_expt_u32
+    mp_expt
     mp_exptmod
     mp_exteuclid
     mp_fread
@@ -67,7 +67,7 @@ EXPORTS
     mp_is_square
     mp_kronecker
     mp_lcm
-    mp_log_u32
+    mp_log
     mp_lshd
     mp_mod
     mp_mod_2d
@@ -102,7 +102,7 @@ EXPORTS
     mp_reduce_is_2k
     mp_reduce_is_2k_l
     mp_reduce_setup
-    mp_root_u32
+    mp_root
     mp_rshd
     mp_sbin_size
     mp_set
diff --git a/tommath.h b/tommath.h
index 68a1592c9..8db3b133b 100644
--- a/tommath.h
+++ b/tommath.h
@@ -430,7 +430,7 @@ mp_err mp_lcm(const mp_int *a, const mp_int *b, mp_int *c) MP_WUR;
  *
  * returns error if a < 0 and b is even
  */
-mp_err mp_root_u32(const mp_int *a, uint32_t b, mp_int *c) MP_WUR;
+mp_err mp_root(const mp_int *a, int b, mp_int *c) MP_WUR;
 
 /* special sqrt algo */
 mp_err mp_sqrt(const mp_int *arg, mp_int *ret) MP_WUR;
@@ -561,10 +561,10 @@ mp_err mp_prime_next_prime(mp_int *a, int t, bool bbs_style) MP_WUR;
 mp_err mp_prime_rand(mp_int *a, int t, int size, int flags) MP_WUR;
 
 /* Integer logarithm to integer base */
-mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c) MP_WUR;
+mp_err mp_log(const mp_int *a, int base, int *c) MP_WUR;
 
 /* c = a**b */
-mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c) MP_WUR;
+mp_err mp_expt(const mp_int *a, int b, mp_int *c) MP_WUR;
 
 /* ---> radix conversion <--- */
 int mp_count_bits(const mp_int *a) MP_WUR;
diff --git a/tommath_class.h b/tommath_class.h
index b11c57438..1822dae87 100644
--- a/tommath_class.h
+++ b/tommath_class.h
@@ -38,7 +38,7 @@
 #   define MP_DR_SETUP_C
 #   define MP_ERROR_TO_STRING_C
 #   define MP_EXCH_C
-#   define MP_EXPT_U32_C
+#   define MP_EXPT_C
 #   define MP_EXPTMOD_C
 #   define MP_EXTEUCLID_C
 #   define MP_FREAD_C
@@ -73,7 +73,7 @@
 #   define MP_IS_SQUARE_C
 #   define MP_KRONECKER_C
 #   define MP_LCM_C
-#   define MP_LOG_U32_C
+#   define MP_LOG_C
 #   define MP_LSHD_C
 #   define MP_MOD_C
 #   define MP_MOD_2D_C
@@ -108,7 +108,7 @@
 #   define MP_REDUCE_IS_2K_C
 #   define MP_REDUCE_IS_2K_L_C
 #   define MP_REDUCE_SETUP_C
-#   define MP_ROOT_U32_C
+#   define MP_ROOT_C
 #   define MP_RSHD_C
 #   define MP_SBIN_SIZE_C
 #   define MP_SET_C
@@ -148,8 +148,8 @@
 #   define S_MP_INVMOD_C
 #   define S_MP_INVMOD_ODD_C
 #   define S_MP_LOG_C
+#   define S_MP_LOG_2EXPT_C
 #   define S_MP_LOG_D_C
-#   define S_MP_LOG_POW2_C
 #   define S_MP_MONTGOMERY_REDUCE_COMBA_C
 #   define S_MP_MUL_C
 #   define S_MP_MUL_BALANCE_C
@@ -303,7 +303,7 @@
 #if defined(MP_EXCH_C)
 #endif
 
-#if defined(MP_EXPT_U32_C)
+#if defined(MP_EXPT_C)
 #   define MP_CLEAR_C
 #   define MP_INIT_COPY_C
 #   define MP_MUL_C
@@ -504,10 +504,10 @@
 #   define MP_MUL_C
 #endif
 
-#if defined(MP_LOG_U32_C)
+#if defined(MP_LOG_C)
+#   define S_MP_LOG_2EXPT_C
 #   define S_MP_LOG_C
 #   define S_MP_LOG_D_C
-#   define S_MP_LOG_POW2_C
 #endif
 
 #if defined(MP_LSHD_C)
@@ -710,7 +710,7 @@
 #endif
 
 #if defined(MP_RADIX_SIZE_C)
-#   define MP_LOG_U32_C
+#   define MP_LOG_C
 #endif
 
 #if defined(MP_RAND_C)
@@ -795,7 +795,7 @@
 #   define MP_DIV_C
 #endif
 
-#if defined(MP_ROOT_U32_C)
+#if defined(MP_ROOT_C)
 #   define MP_2EXPT_C
 #   define MP_ADD_D_C
 #   define MP_CLEAR_MULTI_C
@@ -804,7 +804,7 @@
 #   define MP_COUNT_BITS_C
 #   define MP_DIV_C
 #   define MP_EXCH_C
-#   define MP_EXPT_U32_C
+#   define MP_EXPT_C
 #   define MP_INIT_MULTI_C
 #   define MP_MUL_C
 #   define MP_MUL_D_C
@@ -1106,18 +1106,18 @@
 #   define MP_CMP_D_C
 #   define MP_COPY_C
 #   define MP_EXCH_C
-#   define MP_EXPT_U32_C
+#   define MP_EXPT_C
 #   define MP_INIT_MULTI_C
 #   define MP_MUL_C
 #   define MP_SET_C
 #   define MP_SQR_C
 #endif
 
-#if defined(S_MP_LOG_D_C)
+#if defined(S_MP_LOG_2EXPT_C)
+#   define MP_COUNT_BITS_C
 #endif
 
-#if defined(S_MP_LOG_POW2_C)
-#   define MP_COUNT_BITS_C
+#if defined(S_MP_LOG_D_C)
 #endif
 
 #if defined(S_MP_MONTGOMERY_REDUCE_COMBA_C)
diff --git a/tommath_private.h b/tommath_private.h
index 17bbb733a..6ccfd3cac 100644
--- a/tommath_private.h
+++ b/tommath_private.h
@@ -179,9 +179,9 @@ MP_PRIVATE mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_i
 MP_PRIVATE mp_err s_mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y, int redmode) MP_WUR;
 MP_PRIVATE mp_err s_mp_rand_platform(void *p, size_t n) MP_WUR;
 MP_PRIVATE mp_err s_mp_prime_is_divisible(const mp_int *a, bool *result);
-MP_PRIVATE mp_digit s_mp_log_d(mp_digit base, mp_digit n);
-MP_PRIVATE mp_err s_mp_log(const mp_int *a, uint32_t base, uint32_t *c);
-MP_PRIVATE uint32_t s_mp_log_pow2(const mp_int *a, uint32_t base);
+MP_PRIVATE int s_mp_log_d(mp_digit base, mp_digit n);
+MP_PRIVATE mp_err s_mp_log(const mp_int *a, mp_digit base, int *c);
+MP_PRIVATE int s_mp_log_2expt(const mp_int *a, mp_digit base);
 MP_PRIVATE mp_err s_mp_div_recursive(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r);
 MP_PRIVATE mp_err s_mp_div_school(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d);
 MP_PRIVATE mp_err s_mp_div_small(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d);