diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-12-13 11:05:43 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-12-13 11:05:43 (GMT) |
commit | 6fdc83ae1490b9c80fdce1c5fc60af2ce84a08f0 (patch) | |
tree | 706c6b580a9bc0024596eed55ea34254b98a5756 /libtommath | |
parent | db35fe50e94b2e2edd00d34c42c74754cfc5c74d (diff) | |
parent | 17a9125415985348b7d2b12e75a50a8c87cc21bb (diff) | |
download | tcl-6fdc83ae1490b9c80fdce1c5fc60af2ce84a08f0.zip tcl-6fdc83ae1490b9c80fdce1c5fc60af2ce84a08f0.tar.gz tcl-6fdc83ae1490b9c80fdce1c5fc60af2ce84a08f0.tar.bz2 |
Implement TIP's #538: Externalize libtommath
Diffstat (limited to 'libtommath')
36 files changed, 233 insertions, 115 deletions
diff --git a/libtommath/appveyor.yml b/libtommath/appveyor.yml index 187a09a..08bb013 100644 --- a/libtommath/appveyor.yml +++ b/libtommath/appveyor.yml @@ -4,6 +4,7 @@ branches: - master - develop - /^release/ + - /^support/ - /^travis/ image: - Visual Studio 2019 diff --git a/libtommath/bn_deprecated.c b/libtommath/bn_deprecated.c index 873414e..2056b20 100644 --- a/libtommath/bn_deprecated.c +++ b/libtommath/bn_deprecated.c @@ -25,7 +25,7 @@ mp_err mp_jacobi(const mp_int *a, const mp_int *n, int *c) } #endif #ifdef BN_MP_PRIME_RANDOM_EX_C -mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags, mp_prime_callback cb, void *dat) +mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat) { return s_mp_prime_random_ex(a, t, size, flags, cb, dat); } @@ -158,14 +158,14 @@ mp_err mp_set_int(mp_int *a, unsigned long b) #ifdef BN_MP_SET_LONG_C mp_err mp_set_long(mp_int *a, unsigned long b) { - mp_set_ul(a, b); + mp_set_u64(a, b); return MP_OKAY; } #endif #ifdef BN_MP_SET_LONG_LONG_C mp_err mp_set_long_long(mp_int *a, unsigned long long b) { - mp_set_ull(a, b); + mp_set_u64(a, b); return MP_OKAY; } #endif @@ -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, (unsigned int)b, c); + return mp_root_u32(a, (uint32_t)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, (unsigned int)b, c); + return mp_root_u32(a, (uint32_t)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 67c8fd2..2ab67ba 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, unsigned int b, mp_int *c) +mp_err mp_expt_u32(const mp_int *a, uint32_t b, mp_int *c) { mp_err err; diff --git a/libtommath/bn_mp_fread.c b/libtommath/bn_mp_fread.c index 1e5ecf7..52ea773 100644 --- a/libtommath/bn_mp_fread.c +++ b/libtommath/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_RMAP_REVERSE_SIZE < pos) { + if (mp_s_rmap_reverse_sz < pos) { break; } - y = (int)s_mp_rmap_reverse[pos]; + y = (int)mp_s_rmap_reverse[pos]; if ((y == 0xff) || (y >= radix)) { break; diff --git a/libtommath/bn_mp_init_ll.c b/libtommath/bn_mp_init_ll.c index 484d51c..dc7c4a4 100644 --- a/libtommath/bn_mp_init_ll.c +++ b/libtommath/bn_mp_init_ll.c @@ -3,5 +3,5 @@ /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ -MP_INIT_INT(mp_init_ll, mp_set_ll, Tcl_WideInt) +MP_INIT_INT(mp_init_ll, mp_set_ll, long long) #endif diff --git a/libtommath/bn_mp_init_ull.c b/libtommath/bn_mp_init_ull.c index 92ad9f9..84110c0 100644 --- a/libtommath/bn_mp_init_ull.c +++ b/libtommath/bn_mp_init_ull.c @@ -3,5 +3,5 @@ /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ -MP_INIT_INT(mp_init_ull, mp_set_ull, Tcl_WideUInt) +MP_INIT_INT(mp_init_ull, mp_set_ull, unsigned long long) #endif diff --git a/libtommath/bn_mp_log_u32.c b/libtommath/bn_mp_log_u32.c index f507b1d..b86d789 100644 --- a/libtommath/bn_mp_log_u32.c +++ b/libtommath/bn_mp_log_u32.c @@ -6,7 +6,7 @@ /* Compute log_{base}(a) */ static mp_word s_pow(mp_word base, mp_word exponent) { - mp_word result = 1; + mp_word result = 1u; while (exponent != 0u) { if ((exponent & 1u) == 1u) { result *= base; @@ -20,8 +20,8 @@ static mp_word s_pow(mp_word base, mp_word exponent) static mp_digit s_digit_ilogb(mp_digit base, mp_digit n) { - mp_word bracket_low = 1, bracket_mid, bracket_high, N; - mp_digit ret, high = 1uL, low = 0uL, mid; + mp_word bracket_low = 1u, bracket_mid, bracket_high, N; + mp_digit ret, high = 1u, low = 0uL, mid; if (n < base) { return 0uL; @@ -40,7 +40,7 @@ static mp_digit s_digit_ilogb(mp_digit base, mp_digit n) bracket_high *= bracket_high; } - while (((mp_digit)(high - low)) > 1uL) { + while (((mp_digit)(high - low)) > 1u) { mid = (low + high) >> 1; bracket_mid = bracket_low * s_pow(base, (mp_word)(mid - low)); @@ -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, unsigned int base, unsigned int *c) +mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c) { mp_err err; mp_ord cmp; - unsigned int high, low, mid; + uint32_t 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, unsigned int base, unsigned int *c) base >>= 1; } bit_count = mp_count_bits(a) - 1; - *c = (unsigned int)(bit_count/y); + *c = (uint32_t)(bit_count/y); return MP_OKAY; } if (a->used == 1) { - *c = (unsigned int)s_digit_ilogb(base, a->dp[0]); + *c = (uint32_t)s_digit_ilogb(base, a->dp[0]); return err; } @@ -146,7 +146,7 @@ mp_err mp_log_u32(const mp_int *a, unsigned int base, unsigned int *c) while ((high - low) > 1u) { mid = (high + low) >> 1; - if ((err = mp_expt_u32(&bi_base, mid - low, &t)) != MP_OKAY) { + if ((err = mp_expt_u32(&bi_base, (uint32_t)(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_montgomery_reduce.c b/libtommath/bn_mp_montgomery_reduce.c index 3ce1f15..ffe8341 100644 --- a/libtommath/bn_mp_montgomery_reduce.c +++ b/libtommath/bn_mp_montgomery_reduce.c @@ -17,8 +17,8 @@ mp_err mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho) * are fixed up in the inner loop. */ digs = (n->used * 2) + 1; - if ((digs < PRIVATE_MP_WARRAY) && - (x->used <= PRIVATE_MP_WARRAY) && + if ((digs < MP_WARRAY) && + (x->used <= MP_WARRAY) && (n->used < MP_MAXFAST)) { return s_mp_montgomery_reduce_fast(x, n, rho); } diff --git a/libtommath/bn_mp_mul.c b/libtommath/bn_mp_mul.c index c4890c5..91707cd 100644 --- a/libtommath/bn_mp_mul.c +++ b/libtommath/bn_mp_mul.c @@ -12,9 +12,7 @@ mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) digs = a->used + b->used + 1; mp_sign neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG; - if (a == b) { - return mp_sqr(a,c); - } else if (MP_HAS(S_MP_BALANCE_MUL) && + if (MP_HAS(S_MP_BALANCE_MUL) && /* Check sizes. The smaller one needs to be larger than the Karatsuba cut-off. * The bigger one needs to be at least about one MP_KARATSUBA_MUL_CUTOFF bigger * to make some sense, but it depends on architecture, OS, position of the @@ -37,10 +35,10 @@ mp_err mp_mul(const mp_int *a, const mp_int *b, mp_int *c) /* can we use the fast multiplier? * * The fast multiplier can be used if the output will - * have less than PRIVATE_MP_WARRAY digits and the number of + * have less than MP_WARRAY digits and the number of * digits won't affect carry propagation */ - (digs < PRIVATE_MP_WARRAY) && + (digs < MP_WARRAY) && (min_len <= MP_MAXFAST)) { err = s_mp_mul_digs_fast(a, b, c, digs); } else if (MP_HAS(S_MP_MUL_DIGS)) { diff --git a/libtommath/bn_mp_prime_rand.c b/libtommath/bn_mp_prime_rand.c index af19d76c..4530e9a 100644 --- a/libtommath/bn_mp_prime_rand.c +++ b/libtommath/bn_mp_prime_rand.c @@ -18,7 +18,7 @@ */ /* This is possibly the mother of all prime generation functions, muahahahahaha! */ -mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, mp_prime_callback cb, void *dat) +mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat) { unsigned char *tmp, maskAND, maskOR_msb, maskOR_lsb; int bsize, maskOR_msb_offset; diff --git a/libtommath/bn_mp_radix_smap.c b/libtommath/bn_mp_radix_smap.c index 5147c74..a16128d 100644 --- a/libtommath/bn_mp_radix_smap.c +++ b/libtommath/bn_mp_radix_smap.c @@ -4,8 +4,8 @@ /* SPDX-License-Identifier: Unlicense */ /* chars used in radix conversions */ -const char s_mp_rmap[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; -const unsigned char s_mp_rmap_reverse[] = { +const char *const mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/"; +const uint8_t 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:;<=>? */ @@ -18,4 +18,5 @@ const unsigned char s_mp_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); #endif diff --git a/libtommath/bn_mp_read_radix.c b/libtommath/bn_mp_read_radix.c index 456a387..de18e06 100644 --- a/libtommath/bn_mp_read_radix.c +++ b/libtommath/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_RMAP_REVERSE_SIZE < pos) { + if (mp_s_rmap_reverse_sz < pos) { break; } - y = (int)s_mp_rmap_reverse[pos]; + y = (int)mp_s_rmap_reverse[pos]; /* if the char was found in the map * and is less than the given radix add it diff --git a/libtommath/bn_mp_root_u32.c b/libtommath/bn_mp_root_u32.c index b60cf26..ba65549 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, unsigned int b, mp_int *c) +mp_err mp_root_u32(const mp_int *a, uint32_t 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, unsigned int 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 > (unsigned int)(INT_MAX/2)) { + if (b > (uint32_t)(INT_MAX/2)) { mp_set(c, 1uL); c->sign = a->sign; err = MP_OKAY; diff --git a/libtommath/bn_mp_set_double.c b/libtommath/bn_mp_set_double.c index a42fc70..7f1ab75 100644 --- a/libtommath/bn_mp_set_double.c +++ b/libtommath/bn_mp_set_double.c @@ -16,7 +16,7 @@ mp_err mp_set_double(mp_int *a, double b) cast.dbl = b; exp = (int)((unsigned)(cast.bits >> 52) & 0x7FFu); - frac = (cast.bits & ((1uLL << 52) - 1uLL)) | (1uLL << 52); + frac = (cast.bits & (((uint64_t)1 << 52) - (uint64_t)1)) | ((uint64_t)1 << 52); if (exp == 0x7FF) { /* +-inf, NaN */ return MP_VAL; @@ -30,7 +30,7 @@ mp_err mp_set_double(mp_int *a, double b) return err; } - if (((cast.bits >> 63) != 0uLL) && !MP_IS_ZERO(a)) { + if (((cast.bits >> 63) != 0u) && !MP_IS_ZERO(a)) { a->sign = MP_NEG; } diff --git a/libtommath/bn_mp_sqr.c b/libtommath/bn_mp_sqr.c index 571b25d..e0d0a73 100644 --- a/libtommath/bn_mp_sqr.c +++ b/libtommath/bn_mp_sqr.c @@ -14,7 +14,7 @@ mp_err mp_sqr(const mp_int *a, mp_int *b) (a->used >= MP_KARATSUBA_SQR_CUTOFF)) { err = s_mp_karatsuba_sqr(a, b); } else if (MP_HAS(S_MP_SQR_FAST) && /* can we use the fast comba multiplier? */ - (((a->used * 2) + 1) < PRIVATE_MP_WARRAY) && + (((a->used * 2) + 1) < MP_WARRAY) && (a->used < (MP_MAXFAST / 2))) { err = s_mp_sqr_fast(a, b); } else if (MP_HAS(S_MP_SQR)) { diff --git a/libtommath/bn_mp_to_radix.c b/libtommath/bn_mp_to_radix.c index 18cb504..7fa86ca 100644 --- a/libtommath/bn_mp_to_radix.c +++ b/libtommath/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++ = s_mp_rmap[d]; + *str++ = mp_s_rmap[d]; ++digs; } /* reverse the digits of the string. In this case _s points diff --git a/libtommath/bn_mp_to_ubin.c b/libtommath/bn_mp_to_ubin.c index 4913c3a..1681ca7 100644 --- a/libtommath/bn_mp_to_ubin.c +++ b/libtommath/bn_mp_to_ubin.c @@ -10,8 +10,7 @@ mp_err mp_to_ubin(const mp_int *a, unsigned char *buf, size_t maxlen, size_t *wr mp_err err; mp_int t; - size_t size = (size_t)mp_count_bits(a); - count = (size / 8u) + (((size & 7u) != 0u) ? 1u : 0u); + count = mp_ubin_size(a); if (count > maxlen) { return MP_BUF; } diff --git a/libtommath/bn_prime_tab.c b/libtommath/bn_prime_tab.c index 6bd53fe..a6c07f8 100644 --- a/libtommath/bn_prime_tab.c +++ b/libtommath/bn_prime_tab.c @@ -3,7 +3,7 @@ /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ -const mp_digit s_mp_prime_tab[] = { +const mp_digit ltm_prime_tab[] = { 0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013, 0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035, 0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059, @@ -44,4 +44,18 @@ const mp_digit s_mp_prime_tab[] = { #endif }; +#if defined(__GNUC__) && __GNUC__ >= 4 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +const mp_digit *s_mp_prime_tab = ltm_prime_tab; +#pragma GCC diagnostic pop +#elif defined(_MSC_VER) && _MSC_VER >= 1500 +#pragma warning(push) +#pragma warning(disable: 4996) +const mp_digit *s_mp_prime_tab = ltm_prime_tab; +#pragma warning(pop) +#else +const mp_digit *s_mp_prime_tab = ltm_prime_tab; +#endif + #endif diff --git a/libtommath/bn_s_mp_exptmod_fast.c b/libtommath/bn_s_mp_exptmod_fast.c index 3a0dc5b..682ded8 100644 --- a/libtommath/bn_s_mp_exptmod_fast.c +++ b/libtommath/bn_s_mp_exptmod_fast.c @@ -81,7 +81,7 @@ mp_err s_mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, mp_i /* automatically pick the comba one if available (saves quite a few calls/ifs) */ if (MP_HAS(S_MP_MONTGOMERY_REDUCE_FAST) && - (((P->used * 2) + 1) < PRIVATE_MP_WARRAY) && + (((P->used * 2) + 1) < MP_WARRAY) && (P->used < MP_MAXFAST)) { redux = s_mp_montgomery_reduce_fast; } else if (MP_HAS(MP_MONTGOMERY_REDUCE)) { diff --git a/libtommath/bn_s_mp_montgomery_reduce_fast.c b/libtommath/bn_s_mp_montgomery_reduce_fast.c index 8c3fe5e..3f0c672 100644 --- a/libtommath/bn_s_mp_montgomery_reduce_fast.c +++ b/libtommath/bn_s_mp_montgomery_reduce_fast.c @@ -15,9 +15,9 @@ mp_err s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_digit rho) { int ix, olduse; mp_err err; - mp_word W[PRIVATE_MP_WARRAY]; + mp_word W[MP_WARRAY]; - if (x->used > PRIVATE_MP_WARRAY) { + if (x->used > MP_WARRAY) { return MP_VAL; } diff --git a/libtommath/bn_s_mp_mul_digs.c b/libtommath/bn_s_mp_mul_digs.c index 6c1114e..64509d4 100644 --- a/libtommath/bn_s_mp_mul_digs.c +++ b/libtommath/bn_s_mp_mul_digs.c @@ -17,7 +17,7 @@ mp_err s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) mp_digit tmpx, *tmpt, *tmpy; /* can we use the fast multiplier? */ - if ((digs < PRIVATE_MP_WARRAY) && + if ((digs < MP_WARRAY) && (MP_MIN(a->used, b->used) < MP_MAXFAST)) { return s_mp_mul_digs_fast(a, b, c, digs); } diff --git a/libtommath/bn_s_mp_mul_digs_fast.c b/libtommath/bn_s_mp_mul_digs_fast.c index 090a099..b2a287b 100644 --- a/libtommath/bn_s_mp_mul_digs_fast.c +++ b/libtommath/bn_s_mp_mul_digs_fast.c @@ -23,7 +23,7 @@ mp_err s_mp_mul_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int digs) { int olduse, pa, ix, iz; mp_err err; - mp_digit W[PRIVATE_MP_WARRAY]; + mp_digit W[MP_WARRAY]; mp_word _W; /* grow the destination as required */ diff --git a/libtommath/bn_s_mp_mul_high_digs.c b/libtommath/bn_s_mp_mul_high_digs.c index 5c5d721..2bb2a50 100644 --- a/libtommath/bn_s_mp_mul_high_digs.c +++ b/libtommath/bn_s_mp_mul_high_digs.c @@ -17,7 +17,7 @@ mp_err s_mp_mul_high_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs) /* can we use the fast multiplier? */ if (MP_HAS(S_MP_MUL_HIGH_DIGS_FAST) - && ((a->used + b->used + 1) < PRIVATE_MP_WARRAY) + && ((a->used + b->used + 1) < MP_WARRAY) && (MP_MIN(a->used, b->used) < MP_MAXFAST)) { return s_mp_mul_high_digs_fast(a, b, c, digs); } diff --git a/libtommath/bn_s_mp_mul_high_digs_fast.c b/libtommath/bn_s_mp_mul_high_digs_fast.c index a74adc6..a0513b4 100644 --- a/libtommath/bn_s_mp_mul_high_digs_fast.c +++ b/libtommath/bn_s_mp_mul_high_digs_fast.c @@ -3,8 +3,8 @@ /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ -/* this is a modified version of fast_s_mul_digs that only produces - * output digits *above* digs. See the comments for fast_s_mul_digs +/* this is a modified version of s_mp_mul_digs_fast that only produces + * output digits *above* digs. See the comments for s_mp_mul_digs_fast * to see how it works. * * This is used in the Barrett reduction since for one of the multiplications @@ -16,7 +16,7 @@ mp_err s_mp_mul_high_digs_fast(const mp_int *a, const mp_int *b, mp_int *c, int { int olduse, pa, ix, iz; mp_err err; - mp_digit W[PRIVATE_MP_WARRAY]; + mp_digit W[MP_WARRAY]; mp_word _W; /* grow the destination as required */ diff --git a/libtommath/bn_s_mp_rand_jenkins.c b/libtommath/bn_s_mp_rand_jenkins.c index da0771c..c64afac 100644 --- a/libtommath/bn_s_mp_rand_jenkins.c +++ b/libtommath/bn_s_mp_rand_jenkins.c @@ -27,10 +27,10 @@ static uint64_t s_rand_jenkins_val(void) void s_mp_rand_jenkins_init(uint64_t seed) { - uint64_t i; + int i; jenkins_x.a = 0xf1ea5eedULL; jenkins_x.b = jenkins_x.c = jenkins_x.d = seed; - for (i = 0uLL; i < 20uLL; ++i) { + for (i = 0; i < 20; ++i) { (void)s_rand_jenkins_val(); } } diff --git a/libtommath/bn_s_mp_sqr_fast.c b/libtommath/bn_s_mp_sqr_fast.c index d5090fe..4a8a891 100644 --- a/libtommath/bn_s_mp_sqr_fast.c +++ b/libtommath/bn_s_mp_sqr_fast.c @@ -16,7 +16,7 @@ After that loop you do the squares and add them in. mp_err s_mp_sqr_fast(const mp_int *a, mp_int *b) { int olduse, pa, ix, iz; - mp_digit W[PRIVATE_MP_WARRAY], *tmpx; + mp_digit W[MP_WARRAY], *tmpx; mp_word W1; mp_err err; diff --git a/libtommath/changes.txt b/libtommath/changes.txt index ebf7382..1b3a7a3 100644 --- a/libtommath/changes.txt +++ b/libtommath/changes.txt @@ -1,4 +1,4 @@ -XXX XXth, 2019 +Oct 22nd, 2019 v1.2.0 -- A huge refactoring of the library happened - renaming, deprecating and replacing existing functions by improved API's. diff --git a/libtommath/helper.pl b/libtommath/helper.pl index e60c1a7..c624b7c 100755 --- a/libtommath/helper.pl +++ b/libtommath/helper.pl @@ -51,7 +51,7 @@ sub check_source { push @{$troubles->{tab}}, $lineno if $l =~ /\t/ && basename($file) !~ /^makefile/i; push @{$troubles->{non_ascii_char}}, $lineno if $l =~ /[^[:ascii:]]/; push @{$troubles->{cpp_comment}}, $lineno if $file =~ /\.(c|h)$/ && ($l =~ /\s\/\// || $l =~ /\/\/\s/); - # we prefer using XMALLOC, XFREE, XREALLOC, XCALLOC ... + # we prefer using MP_MALLOC, MP_FREE, MP_REALLOC, MP_CALLOC ... push @{$troubles->{unwanted_malloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bmalloc\s*\(/; push @{$troubles->{unwanted_realloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\brealloc\s*\(/; push @{$troubles->{unwanted_calloc}}, $lineno if $file =~ /^[^\/]+\.c$/ && $l =~ /\bcalloc\s*\(/; diff --git a/libtommath/makefile_include.mk b/libtommath/makefile_include.mk index 7b025e8..452d37d 100644 --- a/libtommath/makefile_include.mk +++ b/libtommath/makefile_include.mk @@ -116,10 +116,10 @@ endif # adjust coverage set ifneq ($(filter $(_ARCH), i386 i686 x86_64 amd64 ia64),) - COVERAGE = test_standalone timing + COVERAGE = test timing COVERAGE_APP = ./test && ./timing else - COVERAGE = test_standalone + COVERAGE = test COVERAGE_APP = ./test endif @@ -135,6 +135,10 @@ LIBPATH ?= $(PREFIX)/lib INCPATH ?= $(PREFIX)/include DATAPATH ?= $(PREFIX)/share/doc/libtommath/pdf +# build & run test-suite +check: test + ./test + #make the code coverage of the library # coverage: LTM_CFLAGS += -fprofile-arcs -ftest-coverage -DTIMING_NO_LOGS diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 285fc8a..8f2867e 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -4,7 +4,8 @@ #ifndef BN_H_ #define BN_H_ -#ifndef MP_NO_STDINT +#if !defined(MP_NO_STDINT) && !defined(_STDINT_H) && !defined(_STDINT_H_) \ + && !defined(__CLANG_STDINT_H) && !defined(_STDINT) # include <stdint.h> #endif #include <stddef.h> @@ -61,23 +62,30 @@ extern "C" { /* some default configurations. * * A "mp_digit" must be able to hold MP_DIGIT_BIT + 1 bits + * A "mp_word" must be able to hold 2*MP_DIGIT_BIT + 1 bits * * At the very least a mp_digit must be able to hold 7 bits * [any size beyond that is ok provided it doesn't overflow the data type] */ #ifdef MP_8BIT -typedef unsigned char mp_digit; +typedef uint8_t mp_digit; +typedef uint16_t private_mp_word; # define MP_DIGIT_BIT 7 #elif defined(MP_16BIT) -typedef unsigned short mp_digit; +typedef uint16_t mp_digit; +typedef uint32_t private_mp_word; # define MP_DIGIT_BIT 15 #elif defined(MP_64BIT) /* for GCC only on supported platforms */ -typedef unsigned long long mp_digit; +typedef uint64_t mp_digit; +#if defined(__GNUC__) +typedef unsigned long private_mp_word __attribute__((mode(TI))); +#endif # define MP_DIGIT_BIT 60 #else -typedef unsigned int mp_digit; +typedef uint32_t mp_digit; +typedef uint64_t private_mp_word; # ifdef MP_31BIT /* * This is an extension that uses 31-bit digits. @@ -93,6 +101,11 @@ typedef unsigned int mp_digit; # endif #endif +/* mp_word is a private type */ +#define mp_word MP_DEPRECATED_PRAGMA("mp_word has been made private") private_mp_word + +#define MP_SIZEOF_MP_DIGIT (MP_DEPRECATED_PRAGMA("MP_SIZEOF_MP_DIGIT has been deprecated, use sizeof (mp_digit)") sizeof (mp_digit)) + #define MP_MASK ((((mp_digit)1)<<((mp_digit)MP_DIGIT_BIT))-((mp_digit)1)) #define MP_DIGIT_MAX MP_MASK @@ -101,6 +114,10 @@ typedef unsigned int mp_digit; #define MP_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */ #define MP_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */ +#define LTM_PRIME_BBS (MP_DEPRECATED_PRAGMA("LTM_PRIME_BBS has been deprecated, use MP_PRIME_BBS") MP_PRIME_BBS) +#define LTM_PRIME_SAFE (MP_DEPRECATED_PRAGMA("LTM_PRIME_SAFE has been deprecated, use MP_PRIME_SAFE") MP_PRIME_SAFE) +#define LTM_PRIME_2MSB_ON (MP_DEPRECATED_PRAGMA("LTM_PRIME_2MSB_ON has been deprecated, use MP_PRIME_2MSB_ON") MP_PRIME_2MSB_ON) + #ifdef MP_USE_ENUMS typedef enum { MP_ZPOS = 0, /* positive */ @@ -185,6 +202,10 @@ TOOM_SQR_CUTOFF; # define MP_PREC (MP_DEPRECATED_PRAGMA("MP_PREC is an internal macro") PRIVATE_MP_PREC) #endif +/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */ +#define PRIVATE_MP_WARRAY (int)(1 << (((CHAR_BIT * (int)sizeof(private_mp_word)) - (2 * MP_DIGIT_BIT)) + 1)) +#define MP_WARRAY (MP_DEPRECATED_PRAGMA("MP_WARRAY is an internal macro") PRIVATE_MP_WARRAY) + #if defined(__GNUC__) && __GNUC__ >= 4 # define MP_NULL_TERMINATED __attribute__((sentinel)) #else @@ -216,13 +237,22 @@ TOOM_SQR_CUTOFF; #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 405) # define MP_DEPRECATED(x) __attribute__((deprecated("replaced by " #x))) +#elif defined(_MSC_VER) && _MSC_VER >= 1500 +# define MP_DEPRECATED(x) __declspec(deprecated("replaced by " #x)) +#else +# define MP_DEPRECATED(x) +#endif + +#ifndef MP_NO_DEPRECATED_PRAGMA +#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 301) # define PRIVATE_MP_DEPRECATED_PRAGMA(s) _Pragma(#s) # define MP_DEPRECATED_PRAGMA(s) PRIVATE_MP_DEPRECATED_PRAGMA(GCC warning s) #elif defined(_MSC_VER) && _MSC_VER >= 1500 -# define MP_DEPRECATED(x) __declspec(deprecated("replaced by " #x)) # define MP_DEPRECATED_PRAGMA(s) __pragma(message(s)) -#else -# define MP_DEPRECATED(s) +#endif +#endif + +#ifndef MP_DEPRECATED_PRAGMA # define MP_DEPRECATED_PRAGMA(s) #endif @@ -232,11 +262,19 @@ TOOM_SQR_CUTOFF; #define SIGN(m) (MP_DEPRECATED_PRAGMA("SIGN macro is deprecated, use z->sign instead") (m)->sign) /* the infamous mp_int structure */ -typedef struct { +#ifndef MP_INT_DECLARED +#define MP_INT_DECLARED +typedef struct mp_int mp_int; +#endif +struct mp_int { int used, alloc; mp_sign sign; mp_digit *dp; -} mp_int; +}; + +/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */ +typedef int private_mp_prime_callback(unsigned char *dst, int len, void *dat); +typedef private_mp_prime_callback MP_DEPRECATED(mp_rand_source) ltm_prime_callback; /* error code to char* string */ const char *mp_error_to_string(mp_err code) MP_WUR; @@ -280,7 +318,6 @@ 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; @@ -303,9 +340,12 @@ 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; -Tcl_WideUInt mp_get_mag_ull(const mp_int *a) MP_WUR; +#ifdef _MSC_VER +#define mp_get_mag_ull(a) ((unsigned __int64)mp_get_mag_u64(a)) +#else +unsigned long long mp_get_mag_ull(const mp_int *a) MP_WUR; +#endif /* get integer, set integer (long) */ long mp_get_l(const mp_int *a) MP_WUR; @@ -317,15 +357,27 @@ mp_err mp_init_l(mp_int *a, long b) MP_WUR; void mp_set_ul(mp_int *a, unsigned long b); mp_err mp_init_ul(mp_int *a, unsigned long b) MP_WUR; -/* get integer, set integer (Tcl_WideInt) */ -Tcl_WideInt mp_get_ll(const mp_int *a) MP_WUR; -void mp_set_ll(mp_int *a, Tcl_WideInt b); -mp_err mp_init_ll(mp_int *a, Tcl_WideInt b) MP_WUR; +#ifdef _MSC_VER +/* get integer, set integer (long long) */ +#define mp_get_ll(a) ((__int64)mp_get_i64(a)) +#define mp_set_ll(a,b) mp_set_i64(a,b) +#define mp_init_ll(a,b) mp_init_i64(a,b) -/* get integer, set integer (Tcl_WideUInt) */ -#define mp_get_ull(a) ((Tcl_WideUInt)mp_get_ll(a)) -void mp_set_ull(mp_int *a, Tcl_WideUInt b); -mp_err mp_init_ull(mp_int *a, Tcl_WideUInt b) MP_WUR; +/* get integer, set integer (unsigned long long) */ +#define mp_get_ull(a) ((unsigned __int64)mp_get_i64(a)) +#define mp_set_ull(a,b) mp_set_u64(a,b) +#define mp_init_ull(a,b) mp_init_u64(a,b) +#else +/* get integer, set integer (long long) */ +long long mp_get_ll(const mp_int *a) MP_WUR; +void mp_set_ll(mp_int *a, long long b); +mp_err mp_init_ll(mp_int *a, long long b) MP_WUR; + +/* get integer, set integer (unsigned long long) */ +#define mp_get_ull(a) ((unsigned long long)mp_get_ll(a)) +void mp_set_ull(mp_int *a, unsigned long long b); +mp_err mp_init_ull(mp_int *a, unsigned long long b) MP_WUR; +#endif /* set to single unsigned digit, up to MP_DIGIT_MAX */ void mp_set(mp_int *a, mp_digit b); @@ -334,10 +386,14 @@ mp_err mp_init_set(mp_int *a, mp_digit b) MP_WUR; /* get integer, set integer and init with integer (deprecated) */ MP_DEPRECATED(mp_get_mag_u32/mp_get_u32) unsigned long mp_get_int(const mp_int *a) MP_WUR; MP_DEPRECATED(mp_get_mag_ul/mp_get_ul) unsigned long mp_get_long(const mp_int *a) MP_WUR; -MP_DEPRECATED(mp_get_mag_ull/mp_get_ull) Tcl_WideUInt mp_get_long_long(const mp_int *a) MP_WUR; +#ifdef _MSC_VER +MP_DEPRECATED(mp_get_mag_ull/mp_get_ull) unsigned __int64 mp_get_long_long(const mp_int *a) MP_WUR; +#endif MP_DEPRECATED(mp_set_ul) mp_err mp_set_int(mp_int *a, unsigned long b); MP_DEPRECATED(mp_set_ul) mp_err mp_set_long(mp_int *a, unsigned long b); -MP_DEPRECATED(mp_set_ull) mp_err mp_set_long_long(mp_int *a, Tcl_WideUInt b); +#ifdef _MSC_VER +MP_DEPRECATED(mp_set_ull) mp_err mp_set_long_long(mp_int *a, unsigned __int64 b); +#endif MP_DEPRECATED(mp_init_ul) mp_err mp_init_set_int(mp_int *a, unsigned long b) MP_WUR; /* copy, b = a */ @@ -534,7 +590,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, unsigned int b, mp_int *c) MP_WUR; +mp_err mp_root_u32(const mp_int *a, uint32_t 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; @@ -614,6 +670,12 @@ mp_err mp_exptmod(const mp_int *G, const mp_int *X, const mp_int *P, mp_int *Y) #endif #define PRIME_SIZE (MP_DEPRECATED_PRAGMA("PRIME_SIZE has been made internal") PRIVATE_MP_PRIME_TAB_SIZE) +/* table of first PRIME_SIZE primes */ +MP_DEPRECATED(internal) extern const mp_digit ltm_prime_tab[PRIVATE_MP_PRIME_TAB_SIZE]; + +/* result=1 if a is divisible by one of the first PRIME_SIZE primes */ +MP_DEPRECATED(mp_prime_is_prime) mp_err mp_prime_is_divisible(const mp_int *a, mp_bool *result) MP_WUR; + /* performs one Fermat test of "a" using base "b". * Sets result to 0 if composite or 1 if probable prime */ @@ -662,6 +724,17 @@ mp_err mp_prime_is_prime(const mp_int *a, int t, mp_bool *result) MP_WUR; */ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style) MP_WUR; +/* makes a truly random prime of a given size (bytes), + * call with bbs = 1 if you want it to be congruent to 3 mod 4 + * + * You have to supply a callback which fills in a buffer with random bytes. "dat" is a parameter you can + * have passed to the callback (e.g. a state or something). This function doesn't use "dat" itself + * so it can be NULL + * + * The prime generated will be larger than 2^(8*size). + */ +#define mp_prime_random(a, t, size, bbs, cb, dat) (MP_DEPRECATED_PRAGMA("mp_prime_random has been deprecated, use mp_prime_rand instead") mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?MP_PRIME_BBS:0, cb, dat)) + /* makes a truly random prime of a given size (bits), * * Flags are as follows: @@ -675,13 +748,15 @@ mp_err mp_prime_next_prime(mp_int *a, int t, int bbs_style) MP_WUR; * so it can be NULL * */ +MP_DEPRECATED(mp_prime_rand) mp_err mp_prime_random_ex(mp_int *a, int t, int size, int flags, + private_mp_prime_callback cb, void *dat) 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, unsigned int base, unsigned int *c) MP_WUR; +mp_err mp_log_u32(const mp_int *a, uint32_t base, uint32_t *c) MP_WUR; /* c = a**b */ -mp_err mp_expt_u32(const mp_int *a, unsigned int b, mp_int *c) MP_WUR; +mp_err mp_expt_u32(const mp_int *a, uint32_t 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 2e3250c..7cef443 100644 --- a/libtommath/tommath_private.h +++ b/libtommath/tommath_private.h @@ -1,12 +1,18 @@ /* LibTomMath, multiple-precision integer library -- Tom St Denis */ /* SPDX-License-Identifier: Unlicense */ -#ifndef TOMMATH_PRIVATE_H_ -#define TOMMATH_PRIVATE_H_ +#ifndef TOMMATH_PRIV_H_ +#define TOMMATH_PRIV_H_ -#include <tommath.h> +#ifdef MP_NO_STDINT +#ifdef HAVE_STDINT_H +# include <stdint.h> +#else +# include "../compat/stdint.h" +#endif +#endif +#include "tclTomMath.h" #include "tommath_class.h" -#include <limits.h> /* * Private symbols @@ -118,6 +124,11 @@ do { \ # define MP_KARATSUBA_SQR_CUTOFF MP_DEFAULT_KARATSUBA_SQR_CUTOFF # define MP_TOOM_MUL_CUTOFF MP_DEFAULT_TOOM_MUL_CUTOFF # define MP_TOOM_SQR_CUTOFF MP_DEFAULT_TOOM_SQR_CUTOFF +#else +# define MP_KARATSUBA_MUL_CUTOFF KARATSUBA_MUL_CUTOFF +# define MP_KARATSUBA_SQR_CUTOFF KARATSUBA_SQR_CUTOFF +# define MP_TOOM_MUL_CUTOFF TOOM_MUL_CUTOFF +# define MP_TOOM_SQR_CUTOFF TOOM_SQR_CUTOFF #endif /* define heap macros */ @@ -145,6 +156,12 @@ extern void MP_FREE(void *mem, size_t size); #define MP__STRINGIZE(x) ""#x"" #define MP_HAS(x) (sizeof(MP_STRINGIZE(BN_##x##_C)) == 1u) +/* TODO: Remove private_mp_word as soon as deprecated mp_word is removed from tommath. */ +#if !defined(MP_64BIT) || defined(__GNUC__) +#undef mp_word +typedef private_mp_word mp_word; +#endif + #define MP_MIN(x, y) (((x) < (y)) ? (x) : (y)) #define MP_MAX(x, y) (((x) > (y)) ? (x) : (y)) @@ -159,31 +176,18 @@ extern void MP_FREE(void *mem, size_t size); #define MP_SIZEOF_BITS(type) ((size_t)CHAR_BIT * sizeof(type)) #define MP_MAXFAST (int)(1uL << (MP_SIZEOF_BITS(mp_word) - (2u * (size_t)MP_DIGIT_BIT))) -#define PRIVATE_MP_WARRAY (1 << ((MP_SIZEOF_BITS(mp_word) - (2 * MP_DIGIT_BIT)) + 1)) - -#if defined(MP_16BIT) -typedef unsigned int mp_word; -#elif defined(MP_64BIT) && defined(__GNUC__) -typedef unsigned long mp_word __attribute__((mode(TI))); -#elif defined(_WIN32) -typedef unsigned __int64 mp_word; -#else -typedef unsigned long long mp_word; -#endif +/* TODO: Remove PRIVATE_MP_WARRAY as soon as deprecated MP_WARRAY is removed from tommath.h */ +#undef MP_WARRAY +#define MP_WARRAY PRIVATE_MP_WARRAY -MP_STATIC_ASSERT(correct_word_size, sizeof(mp_word) == 2 * sizeof(mp_digit)) - -/* default precision */ -#ifndef MP_PREC -# ifndef MP_LOW_MEM -# define MP_PREC 32 /* default digits of precision */ -# else -# define MP_PREC 8 /* default digits of precision */ -# endif +/* TODO: Remove PRIVATE_MP_PREC as soon as deprecated MP_PREC is removed from tommath.h */ +#ifdef PRIVATE_MP_PREC +# undef MP_PREC +# define MP_PREC PRIVATE_MP_PREC #endif /* Minimum number of available digits in mp_int, MP_PREC >= MP_MIN_PREC */ -#define MP_MIN_PREC ((((int)MP_SIZEOF_BITS(Tcl_WideInt) + MP_DIGIT_BIT) - 1) / MP_DIGIT_BIT) +#define MP_MIN_PREC ((((int)MP_SIZEOF_BITS(uintmax_t) + MP_DIGIT_BIT) - 1) / MP_DIGIT_BIT) MP_STATIC_ASSERT(prec_geq_min_prec, MP_PREC >= MP_MIN_PREC) @@ -211,21 +215,39 @@ MP_PRIVATE mp_err s_mp_montgomery_reduce_fast(mp_int *x, const mp_int *n, mp_dig MP_PRIVATE mp_err s_mp_exptmod_fast(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_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; -typedef int mp_prime_callback(unsigned char *dst, int len, void *dat); -MP_PRIVATE mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, mp_prime_callback cb, void *dat); +MP_PRIVATE mp_err s_mp_prime_random_ex(mp_int *a, int t, int size, int flags, private_mp_prime_callback cb, void *dat); MP_PRIVATE void s_mp_reverse(unsigned char *s, size_t len); 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 -#define MP_RMAP_REVERSE_SIZE 88 -extern MP_PRIVATE const char s_mp_rmap[]; -extern MP_PRIVATE const unsigned char s_mp_rmap_reverse[]; -extern MP_PRIVATE const mp_digit s_mp_prime_tab[]; +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; +extern MP_PRIVATE const mp_digit *s_mp_prime_tab; + +/* deprecated functions */ +MP_DEPRECATED(s_mp_invmod_fast) mp_err fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c); +MP_DEPRECATED(s_mp_montgomery_reduce_fast) mp_err fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, + mp_digit rho); +MP_DEPRECATED(s_mp_mul_digs_fast) mp_err fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, + int digs); +MP_DEPRECATED(s_mp_mul_high_digs_fast) mp_err fast_s_mp_mul_high_digs(const mp_int *a, const mp_int *b, + mp_int *c, + int digs); +MP_DEPRECATED(s_mp_sqr_fast) mp_err fast_s_mp_sqr(const mp_int *a, mp_int *b); +MP_DEPRECATED(s_mp_balance_mul) mp_err mp_balance_mul(const mp_int *a, const mp_int *b, mp_int *c); +MP_DEPRECATED(s_mp_exptmod_fast) mp_err mp_exptmod_fast(const mp_int *G, const mp_int *X, const mp_int *P, + mp_int *Y, + int redmode); +MP_DEPRECATED(s_mp_invmod_slow) mp_err mp_invmod_slow(const mp_int *a, const mp_int *b, mp_int *c); +MP_DEPRECATED(s_mp_karatsuba_mul) mp_err mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c); +MP_DEPRECATED(s_mp_karatsuba_sqr) mp_err mp_karatsuba_sqr(const mp_int *a, mp_int *b); +MP_DEPRECATED(s_mp_toom_mul) mp_err mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c); +MP_DEPRECATED(s_mp_toom_sqr) mp_err mp_toom_sqr(const mp_int *a, mp_int *b); +MP_DEPRECATED(s_mp_reverse) void bn_reverse(unsigned char *s, int len); #define MP_GET_ENDIANNESS(x) \ do{\ @@ -249,6 +271,10 @@ extern MP_PRIVATE const mp_digit s_mp_prime_tab[]; MP_ZERO_DIGITS(a->dp + a->used, a->alloc - a->used); \ } +#ifdef _MSC_VER +/* Prevent false positive: unary minus operator applied to unsigned type, result still unsigned */ +#pragma warning(disable: 4146) +#endif #define MP_SET_SIGNED(name, uname, type, utype) \ void name(mp_int * a, type b) \ { \ diff --git a/libtommath/win32/libtommath.dll b/libtommath/win32/libtommath.dll Binary files differnew file mode 100755 index 0000000..aa0a8cb --- /dev/null +++ b/libtommath/win32/libtommath.dll diff --git a/libtommath/win32/tommath.lib b/libtommath/win32/tommath.lib Binary files differnew file mode 100644 index 0000000..dd3e82e --- /dev/null +++ b/libtommath/win32/tommath.lib diff --git a/libtommath/win64/libtommath.dll b/libtommath/win64/libtommath.dll Binary files differnew file mode 100755 index 0000000..2225faf --- /dev/null +++ b/libtommath/win64/libtommath.dll diff --git a/libtommath/win64/libtommath.dll.a b/libtommath/win64/libtommath.dll.a Binary files differnew file mode 100644 index 0000000..40adaf7 --- /dev/null +++ b/libtommath/win64/libtommath.dll.a diff --git a/libtommath/win64/tommath.lib b/libtommath/win64/tommath.lib Binary files differnew file mode 100755 index 0000000..434fa7c --- /dev/null +++ b/libtommath/win64/tommath.lib |