diff options
author | dgp <dgp@users.sourceforge.net> | 2019-04-12 19:21:08 (GMT) |
---|---|---|
committer | dgp <dgp@users.sourceforge.net> | 2019-04-12 19:21:08 (GMT) |
commit | 3947892f31c2a8a132cde0ee81977d8882639390 (patch) | |
tree | 468373346bbdfe29973495d4c407bc0b60767841 /generic | |
parent | e0b6a53069be24ac23e8ec3d5390613041d28c44 (diff) | |
parent | 71ae5810dc6d2d626841ee68af71d69df5fd7bd3 (diff) | |
download | tcl-3947892f31c2a8a132cde0ee81977d8882639390.zip tcl-3947892f31c2a8a132cde0ee81977d8882639390.tar.gz tcl-3947892f31c2a8a132cde0ee81977d8882639390.tar.bz2 |
merge 8.7
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tclExecute.c | 16 | ||||
-rw-r--r-- | generic/tclTomMath.h | 28 | ||||
-rw-r--r-- | generic/tclTomMathDecls.h | 17 | ||||
-rw-r--r-- | generic/tclTomMathInterface.c | 4 | ||||
-rw-r--r-- | generic/tclVar.c | 11 | ||||
-rw-r--r-- | generic/tclZlib.c | 2 |
6 files changed, 49 insertions, 29 deletions
diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 680bdd0..d5dc9e1 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -5631,7 +5631,7 @@ TEBCresume( /* [string is wideinteger] is WIDE_MIN to WIDE_MAX range */ Tcl_WideInt w; - if (Tcl_GetWideIntFromObj(NULL, OBJ_AT_TOS, &w) == TCL_OK) { + if (TclGetWideIntFromObj(NULL, OBJ_AT_TOS, &w) == TCL_OK) { type1 = TCL_NUMBER_INT; } } @@ -8399,22 +8399,18 @@ ExecuteExtendedBinaryMathOp( } overflowExpon: - Tcl_TakeBignumFromObj(NULL, value2Ptr, &big2); - if ((big2.used > 1) -#if DIGIT_BIT > 28 - || ((big2.used == 1) && (big2.dp[0] >= (1<<28))) -#endif - ) { - mp_clear(&big2); + + if ((TclGetWideIntFromObj(NULL, value2Ptr, &w2) != TCL_OK) + || (value2Ptr->typePtr != &tclIntType) + || (Tcl_WideUInt)w2 >= (1<<28)) { Tcl_SetObjResult(interp, Tcl_NewStringObj( "exponent too large", -1)); return GENERAL_ARITHMETIC_ERROR; } Tcl_TakeBignumFromObj(NULL, valuePtr, &big1); mp_init(&bigResult); - mp_expt_d_ex(&big1, big2.dp[0], &bigResult, 1); + mp_expt_d_ex(&big1, w2, &bigResult, 1); mp_clear(&big1); - mp_clear(&big2); BIG_RESULT(&bigResult); } diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h index 3f23fd6..26eef26 100644 --- a/generic/tclTomMath.h +++ b/generic/tclTomMath.h @@ -7,8 +7,7 @@ * Michael Fromberger but has been written from scratch with * additional optimizations in place. * - * The library is free for all purposes without any express - * guarantee it works. + * SPDX-License-Identifier: Unlicense */ #ifndef BN_H_ #define BN_H_ @@ -128,6 +127,7 @@ typedef unsigned long long mp_word; #define MP_MEM -2 /* out of mem */ #define MP_VAL -3 /* invalid input */ #define MP_RANGE MP_VAL +#define MP_ITER -4 /* Max. iterations reached */ #define MP_YES 1 /* yes response */ #define MP_NO 0 /* no response */ @@ -346,15 +346,20 @@ int mp_cnt_lsb(const mp_int *a); /* I Love Earth! */ -/* makes a pseudo-random int of a given size */ +/* makes a pseudo-random mp_int of a given size */ /* int mp_rand(mp_int *a, int digits); */ +/* makes a pseudo-random small int of a given size */ +/* +int mp_rand_digit(mp_digit *r); +*/ #ifdef MP_PRNG_ENABLE_LTM_RNG -/* as last resort we will fall back to libtomcrypt's rng_get_bytes() - * in case you don't use libtomcrypt or use it w/o rng_get_bytes() - * you have to implement it somewhere else, as it's required */ +/* A last resort to provide random data on systems without any of the other + * implemented ways to gather entropy. + * It is compatible with `rng_get_bytes()` from libtomcrypt so you could + * provide that one and then set `ltm_rng = rng_get_bytes;` */ extern unsigned long (*ltm_rng)(unsigned char *out, unsigned long outlen, void (*callback)(void)); extern void (*ltm_rng_callback)(void); #endif @@ -691,10 +696,17 @@ int mp_prime_miller_rabin(const mp_int *a, const mp_int *b, int *result); int mp_prime_rabin_miller_trials(int size); */ -/* performs t rounds of Miller-Rabin on "a" using the first - * t prime bases. Also performs an initial sieve of trial +/* performs t random rounds of Miller-Rabin on "a" additional to + * bases 2 and 3. Also performs an initial sieve of trial * division. Determines if "a" is prime with probability * of error no more than (1/4)**t. + * Both a strong Lucas-Selfridge to complete the BPSW test + * and a separate Frobenius test are available at compile time. + * With t<0 a deterministic test is run for primes up to + * 318665857834031151167461. With t<13 (abs(t)-13) additional + * tests with sequential small primes are run starting at 43. + * Is Fips 186.4 compliant if called with t as computed by + * mp_prime_rabin_miller_trials(); * * Sets result to 1 if probably prime, 0 otherwise */ diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h index 52ab26f..165e3b7 100644 --- a/generic/tclTomMathDecls.h +++ b/generic/tclTomMathDecls.h @@ -30,12 +30,17 @@ /* Define custom memory allocation for libtommath */ -/* MODULE_SCOPE void* XMALLOC( size_t ); */ -#define XMALLOC(s) ((void*)ckalloc((size_t)(s))) -/* MODULE_SCOPE void* XREALLOC( void*, size_t ); */ -#define XREALLOC(x,s) ((void*)ckrealloc((char*)(x),(size_t)(s))) -/* MODULE_SCOPE void XFREE( void* ); */ -#define XFREE(x) (ckfree((char*)(x))) +/* MODULE_SCOPE void* TclBNAlloc( size_t ); */ +#define TclBNAlloc(s) ((void*)ckalloc((size_t)(s))) +/* MODULE_SCOPE void* TclBNRealloc( void*, size_t ); */ +#define TclBNRealloc(x,s) ((void*)ckrealloc((char*)(x),(size_t)(s))) +/* MODULE_SCOPE void TclBNFree( void* ); */ +#define TclBNFree(x) (ckfree((char*)(x))) + +#define XMALLOC(size) TclBNAlloc(size) +#define XFREE(mem, size) TclBNFree(mem) +#define XREALLOC(mem, oldsize, newsize) TclBNRealloc(mem, newsize) + /* Rename the global symbols in libtommath to avoid linkage conflicts */ diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c index 236a8cf..ae1eb7e 100644 --- a/generic/tclTomMathInterface.c +++ b/generic/tclTomMathInterface.c @@ -111,7 +111,7 @@ TclInitBignumFromWideInt( mp_int *a, /* Bignum to initialize */ Tcl_WideInt v) /* Initial value */ { - if (mp_init_size(a, (CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT) != MP_OKAY) { + if (mp_init(a) != MP_OKAY) { Tcl_Panic("initialization failure in TclInitBignumFromWideInt"); } if (v < 0) { @@ -143,7 +143,7 @@ TclInitBignumFromWideUInt( mp_int *a, /* Bignum to initialize */ Tcl_WideUInt v) /* Initial value */ { - if (mp_init_size(a, (CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT) != MP_OKAY) { + if (mp_init(a) != MP_OKAY) { Tcl_Panic("initialization failure in TclInitBignumFromWideUInt"); } mp_set_long_long(a, v); diff --git a/generic/tclVar.c b/generic/tclVar.c index 3271935..e400369 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -722,7 +722,7 @@ TclObjLookupVarEx( Tcl_Obj *cachedNamePtr = localName(varFramePtr, index); if (part1Ptr == cachedNamePtr) { - cachedNamePtr = NULL; + LocalSetIntRep(part1Ptr, index, NULL); } else { /* * [80304238ac] Trickiness here. We will store and incr the @@ -735,6 +735,14 @@ TclObjLookupVarEx( * cachedNamePtr and leave it as string only. This is * radical and destructive, so a better idea would be welcome. */ + + /* + * Firstly set cached local var reference (avoid free before set, + * see [45b9faf103f2]) + */ + LocalSetIntRep(part1Ptr, index, cachedNamePtr); + + /* Then wipe it */ TclFreeIntRep(cachedNamePtr); /* @@ -744,7 +752,6 @@ TclObjLookupVarEx( */ LocalSetIntRep(cachedNamePtr, index, NULL); } - LocalSetIntRep(part1Ptr, index, cachedNamePtr); } else { /* * At least mark part1Ptr as already parsed. diff --git a/generic/tclZlib.c b/generic/tclZlib.c index 5a7abec..8dbe807 100644 --- a/generic/tclZlib.c +++ b/generic/tclZlib.c @@ -422,7 +422,7 @@ GenerateHeader( { Tcl_Obj *value; int len, result = TCL_ERROR; - Tcl_WideInt wideValue; + Tcl_WideInt wideValue = 0; const char *valueStr; Tcl_Encoding latin1enc; static const char *const types[] = { |