summaryrefslogtreecommitdiffstats
path: root/libtommath
diff options
context:
space:
mode:
Diffstat (limited to 'libtommath')
-rw-r--r--libtommath/bn_deprecated.c4
-rw-r--r--libtommath/bn_mp_expt_u32.c2
-rw-r--r--libtommath/bn_mp_log_u32.c10
-rw-r--r--libtommath/bn_mp_radix_smap.c2
-rw-r--r--libtommath/bn_mp_root_u32.c4
-rw-r--r--libtommath/tommath.h28
-rw-r--r--libtommath/tommath_private.h4
7 files changed, 30 insertions, 24 deletions
diff --git a/libtommath/bn_deprecated.c b/libtommath/bn_deprecated.c
index 2056b20..a4004f6 100644
--- a/libtommath/bn_deprecated.c
+++ b/libtommath/bn_deprecated.c
@@ -219,7 +219,7 @@ mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
return MP_VAL;
}
- return mp_root_u32(a, (uint32_t)b, c);
+ return mp_root_u32(a, (unsigned int)b, c);
}
#endif
#ifdef BN_MP_N_ROOT_C
@@ -228,7 +228,7 @@ mp_err mp_n_root(const mp_int *a, mp_digit b, mp_int *c)
if (b > MP_MIN(MP_DIGIT_MAX, UINT32_MAX)) {
return MP_VAL;
}
- return mp_root_u32(a, (uint32_t)b, c);
+ return mp_root_u32(a, (unsigned int)b, c);
}
#endif
#ifdef BN_MP_UNSIGNED_BIN_SIZE_C
diff --git a/libtommath/bn_mp_expt_u32.c b/libtommath/bn_mp_expt_u32.c
index 2ab67ba..67c8fd2 100644
--- a/libtommath/bn_mp_expt_u32.c
+++ b/libtommath/bn_mp_expt_u32.c
@@ -4,7 +4,7 @@
/* SPDX-License-Identifier: Unlicense */
/* calculate c = a**b using a square-multiply algorithm */
-mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c)
+mp_err mp_expt_u32(const mp_int *a, unsigned int b, mp_int *c)
{
mp_err err;
diff --git a/libtommath/bn_mp_log_u32.c b/libtommath/bn_mp_log_u32.c
index b86d789..2531cd8 100644
--- a/libtommath/bn_mp_log_u32.c
+++ b/libtommath/bn_mp_log_u32.c
@@ -70,11 +70,11 @@ static mp_digit s_digit_ilogb(mp_digit base, mp_digit n)
as is the output of mp_bitcount.
With the same problem: max size is INT_MAX * MP_DIGIT not INT_MAX only!
*/
-mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
+mp_err mp_log_u32(const mp_int *a, unsigned int base, unsigned int *c)
{
mp_err err;
mp_ord cmp;
- uint32_t high, low, mid;
+ unsigned int high, low, mid;
mp_int bracket_low, bracket_high, bracket_mid, t, bi_base;
err = MP_OKAY;
@@ -98,12 +98,12 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
base >>= 1;
}
bit_count = mp_count_bits(a) - 1;
- *c = (uint32_t)(bit_count/y);
+ *c = (unsigned int)(bit_count/y);
return MP_OKAY;
}
if (a->used == 1) {
- *c = (uint32_t)s_digit_ilogb(base, a->dp[0]);
+ *c = (unsigned int)s_digit_ilogb(base, a->dp[0]);
return err;
}
@@ -146,7 +146,7 @@ mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c)
while ((high - low) > 1u) {
mid = (high + low) >> 1;
- if ((err = mp_expt_u32(&bi_base, (uint32_t)(mid - low), &t)) != MP_OKAY) {
+ if ((err = mp_expt_u32(&bi_base, mid - low, &t)) != MP_OKAY) {
goto LBL_ERR;
}
if ((err = mp_mul(&bracket_low, &t, &bracket_mid)) != MP_OKAY) {
diff --git a/libtommath/bn_mp_radix_smap.c b/libtommath/bn_mp_radix_smap.c
index a16128d..eb4765a 100644
--- a/libtommath/bn_mp_radix_smap.c
+++ b/libtommath/bn_mp_radix_smap.c
@@ -5,7 +5,7 @@
/* chars used in radix conversions */
const char *const mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
-const uint8_t mp_s_rmap_reverse[] = {
+const unsigned char mp_s_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:;<=>? */
diff --git a/libtommath/bn_mp_root_u32.c b/libtommath/bn_mp_root_u32.c
index ba65549..b60cf26 100644
--- a/libtommath/bn_mp_root_u32.c
+++ b/libtommath/bn_mp_root_u32.c
@@ -12,7 +12,7 @@
* 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_u32(const mp_int *a, unsigned int b, mp_int *c)
{
mp_int t1, t2, t3, a_;
mp_ord cmp;
@@ -40,7 +40,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 > (unsigned int)(INT_MAX/2)) {
mp_set(c, 1uL);
c->sign = a->sign;
err = MP_OKAY;
diff --git a/libtommath/tommath.h b/libtommath/tommath.h
index fd28894..8c418d1 100644
--- a/libtommath/tommath.h
+++ b/libtommath/tommath.h
@@ -4,7 +4,9 @@
#ifndef BN_H_
#define BN_H_
-#include <stdint.h>
+#ifndef MP_NO_STDINT
+# include <stdint.h>
+#endif
#include <stddef.h>
#include <limits.h>
@@ -30,7 +32,7 @@ extern "C" {
#endif
/* MS Visual C++ doesn't have a 128bit type for words, so fall back to 32bit MPI's (where words are 64bit) */
-#if (defined(_MSC_VER) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)) && !defined(MP_64BIT)
+#if (defined(_WIN32) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__)) && !defined(MP_64BIT)
# define MP_32BIT
#endif
@@ -66,23 +68,23 @@ extern "C" {
*/
#ifdef MP_8BIT
-typedef uint8_t mp_digit;
-typedef uint16_t private_mp_word;
+typedef unsigned char mp_digit;
+typedef unsigned short private_mp_word;
# define MP_DIGIT_BIT 7
#elif defined(MP_16BIT)
-typedef uint16_t mp_digit;
-typedef uint32_t private_mp_word;
+typedef unsigned short mp_digit;
+typedef unsigned int private_mp_word;
# define MP_DIGIT_BIT 15
#elif defined(MP_64BIT)
/* for GCC only on supported platforms */
-typedef uint64_t mp_digit;
+typedef unsigned long long mp_digit;
#if defined(__GNUC__)
typedef unsigned long private_mp_word __attribute__((mode(TI)));
#endif
# define MP_DIGIT_BIT 60
#else
-typedef uint32_t mp_digit;
-typedef uint64_t private_mp_word;
+typedef unsigned int mp_digit;
+typedef unsigned long long private_mp_word;
# ifdef MP_31BIT
/*
* This is an extension that uses 31-bit digits.
@@ -311,6 +313,7 @@ double mp_get_double(const mp_int *a) MP_WUR;
mp_err mp_set_double(mp_int *a, double b) MP_WUR;
/* get integer, set integer and init with integer (int32_t) */
+#ifndef MP_NO_STDINT
int32_t mp_get_i32(const mp_int *a) MP_WUR;
void mp_set_i32(mp_int *a, int32_t b);
mp_err mp_init_i32(mp_int *a, int32_t b) MP_WUR;
@@ -333,6 +336,7 @@ mp_err mp_init_u64(mp_int *a, uint64_t b) MP_WUR;
/* get magnitude */
uint32_t mp_get_mag_u32(const mp_int *a) MP_WUR;
uint64_t mp_get_mag_u64(const mp_int *a) MP_WUR;
+#endif
unsigned long mp_get_mag_ul(const mp_int *a) MP_WUR;
unsigned long long mp_get_mag_ull(const mp_int *a) MP_WUR;
@@ -563,7 +567,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_u32(const mp_int *a, unsigned int b, mp_int *c) MP_WUR;
MP_DEPRECATED(mp_root_u32) mp_err mp_n_root(const mp_int *a, mp_digit b, mp_int *c) MP_WUR;
MP_DEPRECATED(mp_root_u32) mp_err mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) MP_WUR;
@@ -726,10 +730,10 @@ MP_DEPRECATED(mp_prime_rand) mp_err mp_prime_random_ex(mp_int *a, int t, int siz
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_u32(const mp_int *a, unsigned int base, unsigned 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_u32(const mp_int *a, unsigned int b, mp_int *c) MP_WUR;
MP_DEPRECATED(mp_expt_u32) mp_err mp_expt_d(const mp_int *a, mp_digit b, mp_int *c) MP_WUR;
MP_DEPRECATED(mp_expt_u32) mp_err mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast) MP_WUR;
diff --git a/libtommath/tommath_private.h b/libtommath/tommath_private.h
index 1a0096f..637ba7f 100644
--- a/libtommath/tommath_private.h
+++ b/libtommath/tommath_private.h
@@ -212,10 +212,12 @@ MP_PRIVATE mp_err s_mp_prime_is_divisible(const mp_int *a, mp_bool *result);
/* TODO: jenkins prng is not thread safe as of now */
MP_PRIVATE mp_err s_mp_rand_jenkins(void *p, size_t n) MP_WUR;
+#ifndef MP_NO_STDINT
MP_PRIVATE void s_mp_rand_jenkins_init(uint64_t seed);
+#endif
extern MP_PRIVATE const char *const mp_s_rmap;
-extern MP_PRIVATE const uint8_t mp_s_rmap_reverse[];
+extern MP_PRIVATE const unsigned char mp_s_rmap_reverse[];
extern MP_PRIVATE const size_t mp_s_rmap_reverse_sz;
extern MP_PRIVATE const mp_digit *s_mp_prime_tab;