diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-03-28 21:21:49 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-03-28 21:21:49 (GMT) |
commit | 0817b5a4ef4f44daedf4a1c82e5f63c0641be1c3 (patch) | |
tree | 0ba1b7420ca975c14745137ccfc764843e119394 /libtommath | |
parent | 74e46544476cae3f150dfa7e28c803c3b3bfb7f6 (diff) | |
parent | abf9722f425fcd4a8327dddaf5c5ccf08b1d30d6 (diff) | |
download | tcl-0817b5a4ef4f44daedf4a1c82e5f63c0641be1c3.zip tcl-0817b5a4ef4f44daedf4a1c82e5f63c0641be1c3.tar.gz tcl-0817b5a4ef4f44daedf4a1c82e5f63c0641be1c3.tar.bz2 |
Merge 8.6
Diffstat (limited to 'libtommath')
-rw-r--r-- | libtommath/bn_mp_get_bit.c | 12 | ||||
-rw-r--r-- | libtommath/bn_mp_get_int.c | 19 | ||||
-rw-r--r-- | libtommath/tommath.h | 25 | ||||
-rw-r--r-- | libtommath/tommath_private.h | 11 |
4 files changed, 12 insertions, 55 deletions
diff --git a/libtommath/bn_mp_get_bit.c b/libtommath/bn_mp_get_bit.c index ab732c4..f5d2450 100644 --- a/libtommath/bn_mp_get_bit.c +++ b/libtommath/bn_mp_get_bit.c @@ -27,18 +27,8 @@ int mp_get_bit(const mp_int *a, int b) limb = b / DIGIT_BIT; - /* - * Zero is a special value with the member "used" set to zero. - * Needs to be tested before the check for the upper boundary - * otherwise (limb >= a->used) would be true for a = 0 - */ - - if (mp_iszero(a) != MP_NO) { - return MP_NO; - } - if (limb >= a->used) { - return MP_VAL; + return MP_NO; } bit = (mp_digit)(1) << (b % DIGIT_BIT); diff --git a/libtommath/bn_mp_get_int.c b/libtommath/bn_mp_get_int.c index 13eddbf..d9c7a11 100644 --- a/libtommath/bn_mp_get_int.c +++ b/libtommath/bn_mp_get_int.c @@ -15,25 +15,8 @@ /* get the lower 32-bits of an mp_int */ unsigned long mp_get_int(const mp_int *a) { - int i; - mp_min_u32 res; - - if (a->used == 0) { - return 0; - } - - /* get number of digits of the lsb we have to read */ - i = MIN(a->used, ((((int)sizeof(unsigned long) * CHAR_BIT) + DIGIT_BIT - 1) / DIGIT_BIT)) - 1; - - /* get most significant digit of result */ - res = DIGIT(a, i); - - while (--i >= 0) { - res = (res << DIGIT_BIT) | DIGIT(a, i); - } - /* force result to 32-bits always so it is consistent on non 32-bit platforms */ - return res & 0xFFFFFFFFUL; + return mp_get_long(a) & 0xFFFFFFFFUL; } #endif diff --git a/libtommath/tommath.h b/libtommath/tommath.h index 236d3e5..b5faf8c 100644 --- a/libtommath/tommath.h +++ b/libtommath/tommath.h @@ -23,7 +23,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__) +#if defined(_WIN32) || defined(__LLP64__) || defined(__e2k__) || defined(__LCC__) # define MP_32BIT #endif @@ -91,17 +91,7 @@ typedef unsigned long long mp_word; # endif #endif -/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */ -#ifndef DIGIT_BIT -# define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */ -typedef unsigned long mp_min_u32; -#else -typedef mp_digit mp_min_u32; -#endif - -#define MP_DIGIT_BIT DIGIT_BIT #define MP_MASK ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1)) -#define MP_DIGIT_MAX MP_MASK /* equalities */ #define MP_LT -1 /* less than */ @@ -127,12 +117,6 @@ typedef mp_digit mp_min_u32; typedef int mp_err; -/* you'll have to tune these... */ -extern int KARATSUBA_MUL_CUTOFF, - KARATSUBA_SQR_CUTOFF, - TOOM_MUL_CUTOFF, - TOOM_SQR_CUTOFF; - /* define this to use lower memory usage routines (exptmods mostly) */ /* #define MP_LOW_MEM */ @@ -145,9 +129,6 @@ extern int KARATSUBA_MUL_CUTOFF, # endif #endif -/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */ -#define MP_WARRAY (1u << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) + 1)) - /* the infamous mp_int structure */ typedef struct { int used, alloc, sign; @@ -158,10 +139,6 @@ typedef struct { typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat); -#define USED(m) ((m)->used) -#define DIGIT(m, k) ((m)->dp[(k)]) -#define SIGN(m) ((m)->sign) - /* error code to char* string */ const char *mp_error_to_string(int code); diff --git a/libtommath/tommath_private.h b/libtommath/tommath_private.h index 8fc3442..2096f77 100644 --- a/libtommath/tommath_private.h +++ b/libtommath/tommath_private.h @@ -42,15 +42,22 @@ extern "C" { # define XMALLOC malloc # define XFREE free # define XREALLOC realloc -# define XCALLOC calloc #elif 0 /* prototypes for our heap functions */ extern void *XMALLOC(size_t n); extern void *XREALLOC(void *p, size_t n); -extern void *XCALLOC(size_t n, size_t s); extern void XFREE(void *p); #endif +/* you'll have to tune these... */ +#define KARATSUBA_MUL_CUTOFF 80 /* Min. number of digits before Karatsuba multiplication is used. */ +#define KARATSUBA_SQR_CUTOFF 120 /* Min. number of digits before Karatsuba squaring is used. */ +#define TOOM_MUL_CUTOFF 350 /* no optimal values of these are known yet so set em high */ +#define TOOM_SQR_CUTOFF 400 + +/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */ +#define MP_WARRAY (1u << (((sizeof(mp_word) * CHAR_BIT) - (2 * DIGIT_BIT)) + 1)) + /* lowlevel functions, do not call! */ int s_mp_add(const mp_int *a, const mp_int *b, mp_int *c); int s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c); |