summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/regc_nfa.c2
-rw-r--r--generic/regcomp.c2
-rw-r--r--generic/tcl.h4
-rw-r--r--generic/tclBasic.c4
-rw-r--r--generic/tclBinary.c2
-rw-r--r--generic/tclDecls.h9
-rw-r--r--generic/tclExecute.c6
-rw-r--r--generic/tclHash.c13
-rw-r--r--generic/tclInt.h3
-rw-r--r--generic/tclObj.c6
-rw-r--r--generic/tclStrToD.c32
-rw-r--r--generic/tclStubInit.c10
-rw-r--r--generic/tclTomMath.decls85
-rw-r--r--generic/tclTomMath.h262
-rw-r--r--generic/tclTomMathDecls.h202
-rw-r--r--generic/tclTomMathInterface.c166
16 files changed, 377 insertions, 431 deletions
diff --git a/generic/regc_nfa.c b/generic/regc_nfa.c
index 44d0ad3..240fcfe 100644
--- a/generic/regc_nfa.c
+++ b/generic/regc_nfa.c
@@ -3084,7 +3084,7 @@ dumparc(
case EMPTY:
break;
default:
- fprintf(f, "0x%x/0o%lo", a->type, (long) a->co);
+ fprintf(f, "0x%x/0%lo", a->type, (long) a->co);
break;
}
if (a->from != s) {
diff --git a/generic/regcomp.c b/generic/regcomp.c
index 0c2aa99..58d55fb 100644
--- a/generic/regcomp.c
+++ b/generic/regcomp.c
@@ -2086,7 +2086,7 @@ dump(
}
fprintf(f, "\n\n\n========= DUMP ==========\n");
- fprintf(f, "nsub %d, info 0o%lo, csize %d, ntree %d\n",
+ fprintf(f, "nsub %d, info 0%lo, csize %d, ntree %d\n",
(int) re->re_nsub, re->re_info, re->re_csize, g->ntree);
dumpcolors(&g->cmap, f);
diff --git a/generic/tcl.h b/generic/tcl.h
index a5999cd..b847fef 100644
--- a/generic/tcl.h
+++ b/generic/tcl.h
@@ -55,10 +55,10 @@ extern "C" {
#define TCL_MAJOR_VERSION 8
#define TCL_MINOR_VERSION 7
#define TCL_RELEASE_LEVEL TCL_ALPHA_RELEASE
-#define TCL_RELEASE_SERIAL 0
+#define TCL_RELEASE_SERIAL 2
#define TCL_VERSION "8.7"
-#define TCL_PATCH_LEVEL "8.7a0"
+#define TCL_PATCH_LEVEL "8.7a2"
#if !defined(TCL_NO_DEPRECATED) || defined(RC_INVOKED)
/*
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index cceef45..d4fa833 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -7460,7 +7460,7 @@ ExprAbsFunc(
}
goto unChanged;
} else if (l == LONG_MIN) {
- TclBNInitBignumFromLong(&big, l);
+ TclInitBignumFromLong(&big, l);
goto tooLarge;
}
Tcl_SetObjResult(interp, Tcl_NewLongObj(-l));
@@ -7495,7 +7495,7 @@ ExprAbsFunc(
goto unChanged;
}
if (w == LLONG_MIN) {
- TclBNInitBignumFromWideInt(&big, w);
+ TclInitBignumFromWideInt(&big, w);
goto tooLarge;
}
Tcl_SetObjResult(interp, Tcl_NewWideIntObj(-w));
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index a693894..cb5a5cb 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -2284,7 +2284,7 @@ ScanNumber(
Tcl_Obj *bigObj = NULL;
mp_int big;
- TclBNInitBignumFromWideUInt(&big, uwvalue);
+ TclInitBignumFromWideUInt(&big, uwvalue);
bigObj = Tcl_NewBignumObj(&big);
return bigObj;
}
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index d543238..464fc0f 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -23,6 +23,15 @@
# endif
#endif
+#if !defined(BUILD_tcl)
+# define TCL_DEPRECATED(msg) EXTERN TCL_DEPRECATED_API(msg)
+#elif defined(TCL_NO_DEPRECATED)
+# define TCL_DEPRECATED(msg) MODULE_SCOPE
+#else
+# define TCL_DEPRECATED(msg) EXTERN
+#endif
+
+
/*
* WARNING: This file is automatically generated by the tools/genStubs.tcl
* script. Any modifications to the function declarations below should be made
diff --git a/generic/tclExecute.c b/generic/tclExecute.c
index 824ec5e..a4ce7ea 100644
--- a/generic/tclExecute.c
+++ b/generic/tclExecute.c
@@ -8218,7 +8218,7 @@ ExecuteExtendedBinaryMathOp(
* Arguments are opposite sign; remainder is sum.
*/
- TclBNInitBignumFromWideInt(&big1, w1);
+ TclInitBignumFromWideInt(&big1, w1);
mp_add(&big2, &big1, &big2);
mp_clear(&big1);
BIG_RESULT(&big2);
@@ -9184,7 +9184,7 @@ ExecuteExtendedUnaryMathOp(
if (w != LLONG_MIN) {
WIDE_RESULT(-w);
}
- TclBNInitBignumFromLong(&big, *(const long *) ptr);
+ TclInitBignumFromLong(&big, *(const long *) ptr);
break;
#ifndef TCL_WIDE_INT_IS_LONG
case TCL_NUMBER_WIDE:
@@ -9192,7 +9192,7 @@ ExecuteExtendedUnaryMathOp(
if (w != LLONG_MIN) {
WIDE_RESULT(-w);
}
- TclBNInitBignumFromWideInt(&big, w);
+ TclInitBignumFromWideInt(&big, w);
break;
#endif
default:
diff --git a/generic/tclHash.c b/generic/tclHash.c
index 78ad514..3c820c0 100644
--- a/generic/tclHash.c
+++ b/generic/tclHash.c
@@ -46,19 +46,6 @@ static int CompareArrayKeys(void *keyPtr, Tcl_HashEntry *hPtr);
static TCL_HASH_TYPE HashArrayKey(Tcl_HashTable *tablePtr, void *keyPtr);
/*
- * Prototypes for the one word hash key methods. Not actually declared because
- * this is a critical path that is implemented in the core hash table access
- * function.
- */
-
-#if 0
-static Tcl_HashEntry * AllocOneWordEntry(Tcl_HashTable *tablePtr,
- void *keyPtr);
-static int CompareOneWordKeys(void *keyPtr, Tcl_HashEntry *hPtr);
-static unsigned int HashOneWordKey(Tcl_HashTable *tablePtr, void *keyPtr);
-#endif
-
-/*
* Prototypes for the string hash key methods.
*/
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 118af85..0b5ff0c 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3007,6 +3007,9 @@ MODULE_SCOPE int TclInfoLocalsCmd(ClientData dummy, Tcl_Interp *interp,
MODULE_SCOPE int TclInfoVarsCmd(ClientData dummy, Tcl_Interp *interp,
int objc, Tcl_Obj *const objv[]);
MODULE_SCOPE void TclInitAlloc(void);
+MODULE_SCOPE void TclInitBignumFromLong(mp_int *, long);
+MODULE_SCOPE void TclInitBignumFromWideInt(mp_int *, Tcl_WideInt);
+MODULE_SCOPE void TclInitBignumFromWideUInt(mp_int *, Tcl_WideUInt);
MODULE_SCOPE void TclInitDbCkalloc(void);
MODULE_SCOPE void TclInitDoubleConversion(void);
MODULE_SCOPE void TclInitEmbeddedConfigurationInformation(
diff --git a/generic/tclObj.c b/generic/tclObj.c
index f4b81f2..1a00011 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -3038,7 +3038,7 @@ Tcl_SetWideIntObj(
#else
mp_int big;
- TclBNInitBignumFromWideInt(&big, wideValue);
+ TclInitBignumFromWideInt(&big, wideValue);
Tcl_SetBignumObj(objPtr, &big);
#endif
}
@@ -3402,12 +3402,12 @@ GetBignumFromObj(
return TCL_OK;
}
if (objPtr->typePtr == &tclIntType) {
- TclBNInitBignumFromLong(bignumValue, objPtr->internalRep.longValue);
+ TclInitBignumFromLong(bignumValue, objPtr->internalRep.longValue);
return TCL_OK;
}
#ifndef TCL_WIDE_INT_IS_LONG
if (objPtr->typePtr == &tclWideIntType) {
- TclBNInitBignumFromWideInt(bignumValue,
+ TclInitBignumFromWideInt(bignumValue,
objPtr->internalRep.wideValue);
return TCL_OK;
}
diff --git a/generic/tclStrToD.c b/generic/tclStrToD.c
index 539a92c..630e498 100644
--- a/generic/tclStrToD.c
+++ b/generic/tclStrToD.c
@@ -711,7 +711,7 @@ TclParseNumber(
|| (octalSignificandWide >
(~(Tcl_WideUInt)0 >> shift)))) {
octalSignificandOverflow = 1;
- TclBNInitBignumFromWideUInt(&octalSignificandBig,
+ TclInitBignumFromWideUInt(&octalSignificandBig,
octalSignificandWide);
}
}
@@ -828,7 +828,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
significandWide > (~(Tcl_WideUInt)0 >> shift))) {
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig,
+ TclInitBignumFromWideUInt(&significandBig,
significandWide);
}
}
@@ -869,7 +869,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
significandWide > (~(Tcl_WideUInt)0 >> shift))) {
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig,
+ TclInitBignumFromWideUInt(&significandBig,
significandWide);
}
}
@@ -1214,7 +1214,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
significandWide > (MOST_BITS + signum) >> shift)) {
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig, significandWide);
+ TclInitBignumFromWideUInt(&significandBig, significandWide);
}
if (shift) {
if (!significandOverflow) {
@@ -1235,7 +1235,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
significandWide > (MOST_BITS + signum) >> shift)) {
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig, significandWide);
+ TclInitBignumFromWideUInt(&significandBig, significandWide);
}
if (shift) {
if (!significandOverflow) {
@@ -1256,7 +1256,7 @@ TclParseNumber(
((size_t)shift >= CHAR_BIT*sizeof(Tcl_WideUInt) ||
octalSignificandWide > (MOST_BITS + signum) >> shift)) {
octalSignificandOverflow = 1;
- TclBNInitBignumFromWideUInt(&octalSignificandBig,
+ TclInitBignumFromWideUInt(&octalSignificandBig,
octalSignificandWide);
}
if (shift) {
@@ -1283,7 +1283,7 @@ TclParseNumber(
break;
}
#endif
- TclBNInitBignumFromWideUInt(&octalSignificandBig,
+ TclInitBignumFromWideUInt(&octalSignificandBig,
octalSignificandWide);
octalSignificandOverflow = 1;
} else {
@@ -1311,7 +1311,7 @@ TclParseNumber(
&significandWide, &significandBig, significandOverflow);
if (!significandOverflow && (significandWide > MOST_BITS+signum)){
significandOverflow = 1;
- TclBNInitBignumFromWideUInt(&significandBig, significandWide);
+ TclInitBignumFromWideUInt(&significandBig, significandWide);
}
returnInteger:
if (!significandOverflow) {
@@ -1330,7 +1330,7 @@ TclParseNumber(
break;
}
#endif
- TclBNInitBignumFromWideUInt(&significandBig,
+ TclInitBignumFromWideUInt(&significandBig,
significandWide);
significandOverflow = 1;
} else {
@@ -1485,7 +1485,7 @@ AccumulateDecimalDigit(
* bignum and fall through into the bignum case.
*/
- TclBNInitBignumFromWideUInt(bignumRepPtr, w);
+ TclInitBignumFromWideUInt(bignumRepPtr, w);
} else {
/*
* Wide multiplication.
@@ -1628,7 +1628,7 @@ MakeLowPrecisionDouble(
* call MakeHighPrecisionDouble to do it the hard way.
*/
- TclBNInitBignumFromWideUInt(&significandBig, significand);
+ TclInitBignumFromWideUInt(&significandBig, significand);
retval = MakeHighPrecisionDouble(0, &significandBig, numSigDigs,
exponent);
mp_clear(&significandBig);
@@ -3315,7 +3315,7 @@ ShorteningBignumConversionPowD(
* mminus = 5**m5
*/
- TclBNInitBignumFromWideUInt(&b, bw);
+ TclInitBignumFromWideUInt(&b, bw);
mp_init_set_int(&mminus, 1);
MulPow5(&b, b5, &b);
mp_mul_2d(&b, b2, &b);
@@ -3502,7 +3502,7 @@ StrictBignumConversionPowD(
* b = bw * 2**b2 * 5**b5
*/
- TclBNInitBignumFromWideUInt(&b, bw);
+ TclInitBignumFromWideUInt(&b, bw);
MulPow5(&b, b5, &b);
mp_mul_2d(&b, b2, &b);
@@ -3710,7 +3710,7 @@ ShorteningBignumConversion(
* S = 2**s2 * 5*s5
*/
- TclBNInitBignumFromWideUInt(&b, bw);
+ TclInitBignumFromWideUInt(&b, bw);
mp_mul_2d(&b, b2, &b);
mp_init_set_int(&S, 1);
MulPow5(&S, s5, &S); mp_mul_2d(&S, s2, &S);
@@ -3923,7 +3923,7 @@ StrictBignumConversion(
*/
mp_init_multi(&temp, &dig, NULL);
- TclBNInitBignumFromWideUInt(&b, bw);
+ TclInitBignumFromWideUInt(&b, bw);
mp_mul_2d(&b, b2, &b);
mp_init_set_int(&S, 1);
MulPow5(&S, s5, &S); mp_mul_2d(&S, s2, &S);
@@ -4579,7 +4579,7 @@ Tcl_InitBignumFromDouble(
Tcl_WideInt w = (Tcl_WideInt) ldexp(fract, mantBits);
int shift = expt - mantBits;
- TclBNInitBignumFromWideInt(b, w);
+ TclInitBignumFromWideInt(b, w);
if (shift < 0) {
mp_div_2d(b, -shift, b, NULL);
} else if (shift > 0) {
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index 8cc21aa..ebd2086 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -69,6 +69,9 @@ static int TclSockMinimumBuffersOld(int sock, int size)
# define TclWinGetSockOpt 0
# define TclWinSetSockOpt 0
# define TclWinNToHS 0
+# define TclBNInitBignumFromWideUInt 0
+# define TclBNInitBignumFromWideInt 0
+# define TclBNInitBignumFromLong 0
#else
#define TclSetStartupScriptPath setStartupScriptPath
static void TclSetStartupScriptPath(Tcl_Obj *path)
@@ -103,6 +106,9 @@ static unsigned short TclWinNToHS(unsigned short ns) {
return ntohs(ns);
}
#endif
+# define TclBNInitBignumFromWideUInt TclInitBignumFromWideUInt
+# define TclBNInitBignumFromWideInt TclInitBignumFromWideInt
+# define TclBNInitBignumFromLong TclInitBignumFromLong
#endif /* TCL_NO_DEPRECATED */
#ifdef _WIN32
@@ -859,6 +865,10 @@ const TclTomMathStubs tclTomMathStubs = {
TclBNInitBignumFromWideInt, /* 65 */
TclBNInitBignumFromWideUInt, /* 66 */
TclBN_mp_expt_d_ex, /* 67 */
+ TclBN_mp_set_long_long, /* 68 */
+ TclBN_mp_get_long_long, /* 69 */
+ TclBN_mp_set_long, /* 70 */
+ TclBN_mp_get_long, /* 71 */
};
static const TclStubHooks tclStubHooks = {
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
index 74ccefc..10df919 100644
--- a/generic/tclTomMath.decls
+++ b/generic/tclTomMath.decls
@@ -30,13 +30,13 @@ declare 1 {
}
declare 2 {
- int TclBN_mp_add(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 3 {
- int TclBN_mp_add_d(mp_int *a, mp_digit b, mp_int *c)
+ int TclBN_mp_add_d(const mp_int *a, mp_digit b, mp_int *c)
}
declare 4 {
- int TclBN_mp_and(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_and(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 5 {
void TclBN_mp_clamp(mp_int *a)
@@ -63,25 +63,25 @@ declare 12 {
int TclBN_mp_count_bits(const mp_int *a)
}
declare 13 {
- int TclBN_mp_div(mp_int *a, mp_int *b, mp_int *q, mp_int *r)
+ int TclBN_mp_div(const mp_int *a, const mp_int *b, mp_int *q, mp_int *r)
}
declare 14 {
- int TclBN_mp_div_d(mp_int *a, mp_digit b, mp_int *q, mp_digit *r)
+ int TclBN_mp_div_d(const mp_int *a, mp_digit b, mp_int *q, mp_digit *r)
}
declare 15 {
- int TclBN_mp_div_2(mp_int *a, mp_int *q)
+ int TclBN_mp_div_2(const mp_int *a, mp_int *q)
}
declare 16 {
int TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q, mp_int *r)
}
declare 17 {
- int TclBN_mp_div_3(mp_int *a, mp_int *q, mp_digit *r)
+ int TclBN_mp_div_3(const mp_int *a, mp_int *q, mp_digit *r)
}
declare 18 {
void TclBN_mp_exch(mp_int *a, mp_int *b)
}
declare 19 {
- int TclBN_mp_expt_d(mp_int *a, mp_digit b, mp_int *c)
+ int TclBN_mp_expt_d(const mp_int *a, mp_digit b, mp_int *c)
}
declare 20 {
int TclBN_mp_grow(mp_int *a, int size)
@@ -105,19 +105,19 @@ declare 26 {
int TclBN_mp_lshd(mp_int *a, int shift)
}
declare 27 {
- int TclBN_mp_mod(mp_int *a, mp_int *b, mp_int *r)
+ int TclBN_mp_mod(const mp_int *a, const mp_int *b, mp_int *r)
}
declare 28 {
int TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r)
}
declare 29 {
- int TclBN_mp_mul(mp_int *a, mp_int *b, mp_int *p)
+ int TclBN_mp_mul(const mp_int *a, const mp_int *b, mp_int *p)
}
declare 30 {
- int TclBN_mp_mul_d(mp_int *a, mp_digit b, mp_int *p)
+ int TclBN_mp_mul_d(const mp_int *a, mp_digit b, mp_int *p)
}
declare 31 {
- int TclBN_mp_mul_2(mp_int *a, mp_int *p)
+ int TclBN_mp_mul_2(const mp_int *a, mp_int *p)
}
declare 32 {
int TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p)
@@ -126,7 +126,7 @@ declare 33 {
int TclBN_mp_neg(const mp_int *a, mp_int *b)
}
declare 34 {
- int TclBN_mp_or(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_or(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 35 {
int TclBN_mp_radix_size(const mp_int *a, int radix, int *size)
@@ -144,32 +144,32 @@ declare 39 {
void TclBN_mp_set(mp_int *a, mp_digit b)
}
declare 40 {
- int TclBN_mp_sqr(mp_int *a, mp_int *b)
+ int TclBN_mp_sqr(const mp_int *a, mp_int *b)
}
declare 41 {
- int TclBN_mp_sqrt(mp_int *a, mp_int *b)
+ int TclBN_mp_sqrt(const mp_int *a, mp_int *b)
}
declare 42 {
- int TclBN_mp_sub(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 43 {
- int TclBN_mp_sub_d(mp_int *a, mp_digit b, mp_int *c)
+ int TclBN_mp_sub_d(const mp_int *a, mp_digit b, mp_int *c)
}
declare 44 {
- int TclBN_mp_to_unsigned_bin(mp_int *a, unsigned char *b)
+ int TclBN_mp_to_unsigned_bin(const mp_int *a, unsigned char *b)
}
declare 45 {
- int TclBN_mp_to_unsigned_bin_n(mp_int *a, unsigned char *b,
+ int TclBN_mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b,
unsigned long *outlen)
}
declare 46 {
- int TclBN_mp_toradix_n(mp_int *a, char *str, int radix, int maxlen)
+ int TclBN_mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen)
}
declare 47 {
- int TclBN_mp_unsigned_bin_size(mp_int *a)
+ int TclBN_mp_unsigned_bin_size(const mp_int *a)
}
declare 48 {
- int TclBN_mp_xor(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_xor(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 49 {
void TclBN_mp_zero(mp_int *a)
@@ -182,34 +182,34 @@ declare 50 {
void TclBN_reverse(unsigned char *s, int len)
}
declare 51 {
- int TclBN_fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
+ int TclBN_fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
}
declare 52 {
- int TclBN_fast_s_mp_sqr(mp_int *a, mp_int *b)
+ int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b)
}
declare 53 {
- int TclBN_mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_karatsuba_mul(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 54 {
- int TclBN_mp_karatsuba_sqr(mp_int *a, mp_int *b)
+ int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b)
}
declare 55 {
- int TclBN_mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 56 {
- int TclBN_mp_toom_sqr(mp_int *a, mp_int *b)
+ int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b)
}
declare 57 {
- int TclBN_s_mp_add(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_s_mp_add(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 58 {
- int TclBN_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
+ int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs)
}
declare 59 {
- int TclBN_s_mp_sqr(mp_int *a, mp_int *b)
+ int TclBN_s_mp_sqr(const mp_int *a, mp_int *b)
}
declare 60 {
- int TclBN_s_mp_sub(mp_int *a, mp_int *b, mp_int *c)
+ int TclBN_s_mp_sub(const mp_int *a, const mp_int *b, mp_int *c)
}
declare 61 {
int TclBN_mp_init_set_int(mp_int *a, unsigned long i)
@@ -223,19 +223,32 @@ declare 63 {
# Formerly internal API to allow initialisation of bignums without knowing the
# typedefs of how a bignum works internally.
-declare 64 {
+declare 64 {deprecated {Use mp_init() + mp_set_long_long()}} {
void TclBNInitBignumFromLong(mp_int *bignum, long initVal)
}
-declare 65 {
+declare 65 {deprecated {Use mp_init() + mp_set_long_long()}} {
void TclBNInitBignumFromWideInt(mp_int *bignum, Tcl_WideInt initVal)
}
-declare 66 {
+declare 66 {deprecated {Use mp_init() + mp_set_long_long()}} {
void TclBNInitBignumFromWideUInt(mp_int *bignum, Tcl_WideUInt initVal)
}
# Added in libtommath 1.0
declare 67 {
- int TclBN_mp_expt_d_ex(mp_int *a, mp_digit b, mp_int *c, int fast)
+ int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast)
+}
+# Added in libtommath 1.0.1
+declare 68 {
+ int TclBN_mp_set_long_long(mp_int *a, Tcl_WideUInt i)
+}
+declare 69 {
+ Tcl_WideUInt TclBN_mp_get_long_long(const mp_int *a)
+}
+declare 70 {
+ int TclBN_mp_set_long(mp_int *a, unsigned long i)
+}
+declare 71 {
+ unsigned long TclBN_mp_get_long(const mp_int *a)
}
# Local Variables:
diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h
index 508fadd..c8b2a87 100644
--- a/generic/tclTomMath.h
+++ b/generic/tclTomMath.h
@@ -27,10 +27,10 @@ extern "C" {
#endif
/* detect 64-bit mode if possible */
-#if defined(NEVER) /* 128-bit ints fail in too many places */
- #if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
- #define MP_64BIT
- #endif
+#if defined(NEVER) /* 128-bit ints fail in too many places */
+# if !(defined(MP_32BIT) || defined(MP_16BIT) || defined(MP_8BIT))
+# define MP_64BIT
+# endif
#endif
/* some default configurations.
@@ -43,94 +43,94 @@ extern "C" {
*/
#ifdef MP_8BIT
#ifndef MP_DIGIT_DECLARED
- typedef uint8_t mp_digit;
+typedef uint8_t mp_digit;
#define MP_DIGIT_DECLARED
#endif
#ifndef MP_WORD_DECLARED
- typedef uint16_t mp_word;
+typedef uint16_t mp_word;
#define MP_WORD_DECLARED
#endif
-#define MP_SIZEOF_MP_DIGIT 1
-#ifdef DIGIT_BIT
-#error You must not define DIGIT_BIT when using MP_8BIT
-#endif
+# define MP_SIZEOF_MP_DIGIT 1
+# ifdef DIGIT_BIT
+# error You must not define DIGIT_BIT when using MP_8BIT
+# endif
#elif defined(MP_16BIT)
#ifndef MP_DIGIT_DECLARED
- typedef uint16_t mp_digit;
+typedef uint16_t mp_digit;
#define MP_DIGIT_DECLARED
#endif
#ifndef MP_WORD_DECLARED
- typedef uint32_t mp_word;
+typedef uint32_t mp_word;
#define MP_WORD_DECLARED
#endif
-#define MP_SIZEOF_MP_DIGIT 2
-#ifdef DIGIT_BIT
-#error You must not define DIGIT_BIT when using MP_16BIT
-#endif
+# define MP_SIZEOF_MP_DIGIT 2
+# ifdef DIGIT_BIT
+# error You must not define DIGIT_BIT when using MP_16BIT
+# endif
#elif defined(MP_64BIT)
- /* for GCC only on supported platforms */
+/* for GCC only on supported platforms */
#ifndef MP_DIGIT_DECLARED
- typedef uint64_t mp_digit;
+typedef uint64_t mp_digit;
#define MP_DIGIT_DECLARED
#endif
-#if defined(_WIN32)
+# if defined(_WIN32)
#ifndef MP_WORD_DECLARED
- typedef unsigned __int128 mp_word;
+typedef unsigned __int128 mp_word;
#define MP_WORD_DECLARED
#endif
-#elif defined(__GNUC__)
- typedef unsigned long mp_word __attribute__ ((mode(TI)));
-#else
- /* it seems you have a problem
- * but we assume you can somewhere define your own uint128_t */
+# elif defined(__GNUC__)
+typedef unsigned long mp_word __attribute__((mode(TI)));
+# else
+/* it seems you have a problem
+ * but we assume you can somewhere define your own uint128_t */
#ifndef MP_WORD_DECLARED
- typedef uint128_t mp_word;
+typedef uint128_t mp_word;
#define MP_WORD_DECLARED
#endif
-#endif
+# endif
- #define DIGIT_BIT 60
+# define DIGIT_BIT 60
#else
- /* this is the default case, 28-bit digits */
+/* this is the default case, 28-bit digits */
- /* this is to make porting into LibTomCrypt easier :-) */
+/* this is to make porting into LibTomCrypt easier :-) */
#ifndef MP_DIGIT_DECLARED
- typedef uint32_t mp_digit;
+typedef uint32_t mp_digit;
#define MP_DIGIT_DECLARED
#endif
#ifndef MP_WORD_DECLARED
- typedef uint64_t mp_word;
+typedef uint64_t mp_word;
#define MP_WORD_DECLARED
#endif
-#ifdef MP_31BIT
- /* this is an extension that uses 31-bit digits */
- #define DIGIT_BIT 31
-#else
- /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
- #define DIGIT_BIT 28
- #define MP_28BIT
-#endif
+# ifdef MP_31BIT
+/* this is an extension that uses 31-bit digits */
+# define DIGIT_BIT 31
+# else
+/* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
+# define DIGIT_BIT 28
+# define MP_28BIT
+# 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 uint_least32_t mp_min_u32;
+# define DIGIT_BIT (((CHAR_BIT * MP_SIZEOF_MP_DIGIT) - 1)) /* bits per digit */
+typedef uint_least32_t mp_min_u32;
#else
- typedef mp_digit mp_min_u32;
+typedef mp_digit mp_min_u32;
#endif
/* use arc4random on platforms that support it */
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
- #define MP_GEN_RANDOM() arc4random()
- #define MP_GEN_RANDOM_MAX 0xffffffff
+# define MP_GEN_RANDOM() arc4random()
+# define MP_GEN_RANDOM_MAX 0xffffffff
#endif
/* use rand() as fall-back if there's no better rand function */
#ifndef MP_GEN_RANDOM
- #define MP_GEN_RANDOM() rand()
- #define MP_GEN_RANDOM_MAX RAND_MAX
+# define MP_GEN_RANDOM() rand()
+# define MP_GEN_RANDOM_MAX RAND_MAX
#endif
#define MP_DIGIT_BIT DIGIT_BIT
@@ -163,9 +163,9 @@ typedef int mp_err;
/* you'll have to tune these... */
#if defined(BUILD_tcl) || !defined(_WIN32)
MODULE_SCOPE int KARATSUBA_MUL_CUTOFF,
- KARATSUBA_SQR_CUTOFF,
- TOOM_MUL_CUTOFF,
- TOOM_SQR_CUTOFF;
+ KARATSUBA_SQR_CUTOFF,
+ TOOM_MUL_CUTOFF,
+ TOOM_SQR_CUTOFF;
#endif
/* define this to use lower memory usage routines (exptmods mostly) */
@@ -173,11 +173,11 @@ MODULE_SCOPE int KARATSUBA_MUL_CUTOFF,
/* 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
+# ifndef MP_LOW_MEM
+# define MP_PREC 32 /* default digits of precision */
+# else
+# define MP_PREC 8 /* default digits of precision */
+# endif
#endif
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
@@ -189,17 +189,17 @@ MODULE_SCOPE int KARATSUBA_MUL_CUTOFF,
typedef struct mp_int mp_int;
#endif
struct mp_int {
- int used, alloc, sign;
- mp_digit *dp;
+ int used, alloc, sign;
+ mp_digit *dp;
};
/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
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)
+#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);
@@ -273,32 +273,32 @@ int mp_set_long(mp_int *a, unsigned long b);
/* set a platform dependent unsigned long long value */
/*
-int mp_set_long_long(mp_int *a, unsigned long long b);
+int mp_set_long_long(mp_int *a, Tcl_WideUInt b);
*/
/* get a 32-bit value */
/*
-unsigned long mp_get_int(const mp_int * a);
+unsigned long mp_get_int(const mp_int *a);
*/
/* get a platform dependent unsigned long value */
/*
-unsigned long mp_get_long(const mp_int * a);
+unsigned long mp_get_long(const mp_int *a);
*/
/* get a platform dependent unsigned long long value */
/*
-unsigned long long mp_get_long_long(const mp_int * a);
+Tcl_WideUInt mp_get_long_long(const mp_int *a);
*/
/* initialize and set a digit */
/*
-int mp_init_set (mp_int * a, mp_digit b);
+int mp_init_set(mp_int *a, mp_digit b);
*/
/* initialize and set 32-bit value */
/*
-int mp_init_set_int (mp_int * a, unsigned long b);
+int mp_init_set_int(mp_int *a, unsigned long b);
*/
/* copy, b = a */
@@ -318,12 +318,12 @@ void mp_clamp(mp_int *a);
/* import binary data */
/*
-int mp_import(mp_int* rop, size_t count, int order, size_t size, int endian, size_t nails, const void* op);
+int mp_import(mp_int *rop, size_t count, int order, size_t size, int endian, size_t nails, const void *op);
*/
/* export binary data */
/*
-int mp_export(void* rop, size_t* countp, int order, size_t size, int endian, size_t nails, mp_int* op);
+int mp_export(void *rop, size_t *countp, int order, size_t size, int endian, size_t nails, mp_int *op);
*/
/* ---> digit manipulation <--- */
@@ -383,17 +383,17 @@ int mp_rand(mp_int *a, int digits);
/* ---> binary operations <--- */
/* c = a XOR b */
/*
-int mp_xor(mp_int *a, mp_int *b, mp_int *c);
+int mp_xor(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = a OR b */
/*
-int mp_or(mp_int *a, mp_int *b, mp_int *c);
+int mp_or(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = a AND b */
/*
-int mp_and(mp_int *a, mp_int *b, mp_int *c);
+int mp_and(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* ---> Basic arithmetic <--- */
@@ -405,7 +405,7 @@ int mp_neg(const mp_int *a, mp_int *b);
/* b = |a| */
/*
-int mp_abs(mp_int *a, mp_int *b);
+int mp_abs(const mp_int *a, mp_int *b);
*/
/* compare a to b */
@@ -420,32 +420,32 @@ int mp_cmp_mag(const mp_int *a, const mp_int *b);
/* c = a + b */
/*
-int mp_add(mp_int *a, mp_int *b, mp_int *c);
+int mp_add(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = a - b */
/*
-int mp_sub(mp_int *a, mp_int *b, mp_int *c);
+int mp_sub(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = a * b */
/*
-int mp_mul(mp_int *a, mp_int *b, mp_int *c);
+int mp_mul(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* b = a*a */
/*
-int mp_sqr(mp_int *a, mp_int *b);
+int mp_sqr(const mp_int *a, mp_int *b);
*/
/* a/b => cb + d == a */
/*
-int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
+int mp_div(const mp_int *a, const mp_int *b, mp_int *c, mp_int *d);
*/
/* c = a mod b, 0 <= c < b */
/*
-int mp_mod(mp_int *a, mp_int *b, mp_int *c);
+int mp_mod(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* ---> single digit functions <--- */
@@ -457,82 +457,82 @@ int mp_cmp_d(const mp_int *a, mp_digit b);
/* c = a + b */
/*
-int mp_add_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_add_d(const mp_int *a, mp_digit b, mp_int *c);
*/
/* c = a - b */
/*
-int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_sub_d(const mp_int *a, mp_digit b, mp_int *c);
*/
/* c = a * b */
/*
-int mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_mul_d(const mp_int *a, mp_digit b, mp_int *c);
*/
/* a/b => cb + d == a */
/*
-int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
+int mp_div_d(const mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
*/
/* a/3 => 3c + d == a */
/*
-int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
+int mp_div_3(const mp_int *a, mp_int *c, mp_digit *d);
*/
/* c = a**b */
/*
-int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
+int mp_expt_d(const mp_int *a, mp_digit b, mp_int *c);
*/
/*
-int mp_expt_d_ex (mp_int * a, mp_digit b, mp_int * c, int fast);
+int mp_expt_d_ex(const mp_int *a, mp_digit b, mp_int *c, int fast);
*/
/* c = a mod b, 0 <= c < b */
/*
-int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
+int mp_mod_d(const mp_int *a, mp_digit b, mp_digit *c);
*/
/* ---> number theory <--- */
/* d = a + b (mod c) */
/*
-int mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
+int mp_addmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d);
*/
/* d = a - b (mod c) */
/*
-int mp_submod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
+int mp_submod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d);
*/
/* d = a * b (mod c) */
/*
-int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
+int mp_mulmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d);
*/
/* c = a * a (mod b) */
/*
-int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c);
+int mp_sqrmod(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = 1/a (mod b) */
/*
-int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
+int mp_invmod(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* c = (a, b) */
/*
-int mp_gcd(mp_int *a, mp_int *b, mp_int *c);
+int mp_gcd(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* produces value such that U1*a + U2*b = U3 */
/*
-int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3);
+int mp_exteuclid(const mp_int *a, const mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3);
*/
/* c = [a, b] or (a*b)/(a, b) */
/*
-int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
+int mp_lcm(const mp_int *a, const mp_int *b, mp_int *c);
*/
/* finds one of the b'th root of a, such that |c|**b <= |a|
@@ -540,35 +540,35 @@ int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
* returns error if a < 0 and b is even
*/
/*
-int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
+int mp_n_root(const mp_int *a, mp_digit b, mp_int *c);
*/
/*
-int mp_n_root_ex (mp_int * a, mp_digit b, mp_int * c, int fast);
+int mp_n_root_ex(const mp_int *a, mp_digit b, mp_int *c, int fast);
*/
/* special sqrt algo */
/*
-int mp_sqrt(mp_int *arg, mp_int *ret);
+int mp_sqrt(const mp_int *arg, mp_int *ret);
*/
/* special sqrt (mod prime) */
/*
-int mp_sqrtmod_prime(mp_int *arg, mp_int *prime, mp_int *ret);
+int mp_sqrtmod_prime(const mp_int *arg, const mp_int *prime, mp_int *ret);
*/
/* is number a square? */
/*
-int mp_is_square(mp_int *arg, int *ret);
+int mp_is_square(const mp_int *arg, int *ret);
*/
/* computes the jacobi c = (a | n) (or Legendre if b is prime) */
/*
-int mp_jacobi(mp_int *a, mp_int *n, int *c);
+int mp_jacobi(const mp_int *a, const mp_int *n, int *c);
*/
/* used to setup the Barrett reduction for a given modulus b */
/*
-int mp_reduce_setup(mp_int *a, mp_int *b);
+int mp_reduce_setup(mp_int *a, const mp_int *b);
*/
/* Barrett Reduction, computes a (mod b) with a precomputed value c
@@ -577,83 +577,83 @@ int mp_reduce_setup(mp_int *a, mp_int *b);
* compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
*/
/*
-int mp_reduce(mp_int *a, mp_int *b, mp_int *c);
+int mp_reduce(mp_int *a, const mp_int *b, mp_int *c);
*/
/* setups the montgomery reduction */
/*
-int mp_montgomery_setup(mp_int *a, mp_digit *mp);
+int mp_montgomery_setup(const mp_int *a, mp_digit *mp);
*/
/* computes a = B**n mod b without division or multiplication useful for
* normalizing numbers in a Montgomery system.
*/
/*
-int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
+int mp_montgomery_calc_normalization(mp_int *a, const mp_int *b);
*/
/* computes x/R == x (mod N) via Montgomery Reduction */
/*
-int mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
+int mp_montgomery_reduce(mp_int *a, const mp_int *m, mp_digit mp);
*/
/* returns 1 if a is a valid DR modulus */
/*
-int mp_dr_is_modulus(mp_int *a);
+int mp_dr_is_modulus(const mp_int *a);
*/
/* sets the value of "d" required for mp_dr_reduce */
/*
-void mp_dr_setup(mp_int *a, mp_digit *d);
+void mp_dr_setup(const mp_int *a, mp_digit *d);
*/
/* reduces a modulo b using the Diminished Radix method */
/*
-int mp_dr_reduce(mp_int *a, mp_int *b, mp_digit mp);
+int mp_dr_reduce(mp_int *a, const mp_int *b, mp_digit mp);
*/
/* returns true if a can be reduced with mp_reduce_2k */
/*
-int mp_reduce_is_2k(mp_int *a);
+int mp_reduce_is_2k(const mp_int *a);
*/
/* determines k value for 2k reduction */
/*
-int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
+int mp_reduce_2k_setup(const mp_int *a, mp_digit *d);
*/
/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
/*
-int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
+int mp_reduce_2k(mp_int *a, const mp_int *n, mp_digit d);
*/
/* returns true if a can be reduced with mp_reduce_2k_l */
/*
-int mp_reduce_is_2k_l(mp_int *a);
+int mp_reduce_is_2k_l(const mp_int *a);
*/
/* determines k value for 2k reduction */
/*
-int mp_reduce_2k_setup_l(mp_int *a, mp_int *d);
+int mp_reduce_2k_setup_l(const mp_int *a, mp_int *d);
*/
/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
/*
-int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d);
+int mp_reduce_2k_l(mp_int *a, const mp_int *n, mp_int *d);
*/
/* d = a**b (mod c) */
/*
-int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
+int mp_exptmod(const mp_int *a, const mp_int *b, const mp_int *c, mp_int *d);
*/
/* ---> Primes <--- */
/* number of primes */
#ifdef MP_8BIT
-# define PRIME_SIZE 31
+# define PRIME_SIZE 31
#else
-# define PRIME_SIZE 256
+# define PRIME_SIZE 256
#endif
/* table of first PRIME_SIZE primes */
@@ -663,21 +663,21 @@ MODULE_SCOPE const mp_digit ltm_prime_tab[PRIME_SIZE];
/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
/*
-int mp_prime_is_divisible(mp_int *a, int *result);
+int mp_prime_is_divisible(const mp_int *a, int *result);
*/
/* performs one Fermat test of "a" using base "b".
* Sets result to 0 if composite or 1 if probable prime
*/
/*
-int mp_prime_fermat(mp_int *a, mp_int *b, int *result);
+int mp_prime_fermat(const mp_int *a, const mp_int *b, int *result);
*/
/* performs one Miller-Rabin test of "a" using base "b".
* Sets result to 0 if composite or 1 if probable prime
*/
/*
-int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
+int mp_prime_miller_rabin(const mp_int *a, const mp_int *b, int *result);
*/
/* This gives [for a given bit size] the number of trials required
@@ -695,7 +695,7 @@ int mp_prime_rabin_miller_trials(int size);
* Sets result to 1 if probably prime, 0 otherwise
*/
/*
-int mp_prime_is_prime(mp_int *a, int t, int *result);
+int mp_prime_is_prime(const mp_int *a, int t, int *result);
*/
/* finds the next prime after the number "a" using "t" trials
@@ -741,39 +741,39 @@ int mp_count_bits(const mp_int *a);
*/
/*
-int mp_unsigned_bin_size(mp_int *a);
+int mp_unsigned_bin_size(const mp_int *a);
*/
/*
int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
*/
/*
-int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
+int mp_to_unsigned_bin(const mp_int *a, unsigned char *b);
*/
/*
-int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
+int mp_to_unsigned_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen);
*/
/*
-int mp_signed_bin_size(mp_int *a);
+int mp_signed_bin_size(const mp_int *a);
*/
/*
int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
*/
/*
-int mp_to_signed_bin(mp_int *a, unsigned char *b);
+int mp_to_signed_bin(const mp_int *a, unsigned char *b);
*/
/*
-int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
+int mp_to_signed_bin_n(const mp_int *a, unsigned char *b, unsigned long *outlen);
*/
/*
int mp_read_radix(mp_int *a, const char *str, int radix);
*/
/*
-int mp_toradix(mp_int *a, char *str, int radix);
+int mp_toradix(const mp_int *a, char *str, int radix);
*/
/*
-int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
+int mp_toradix_n(const mp_int *a, char *str, int radix, int maxlen);
*/
/*
int mp_radix_size(const mp_int *a, int radix, int *size);
@@ -784,7 +784,7 @@ int mp_radix_size(const mp_int *a, int radix, int *size);
int mp_fread(mp_int *a, int radix, FILE *stream);
*/
/*
-int mp_fwrite(mp_int *a, int radix, FILE *stream);
+int mp_fwrite(const mp_int *a, int radix, FILE *stream);
*/
#endif
@@ -801,7 +801,7 @@ int mp_fwrite(mp_int *a, int radix, FILE *stream);
#define mp_tohex(M, S) mp_toradix((M), (S), 16)
#ifdef __cplusplus
- }
+}
#endif
#endif
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
index 209c486..f3145d7 100644
--- a/generic/tclTomMathDecls.h
+++ b/generic/tclTomMathDecls.h
@@ -74,6 +74,9 @@
#define mp_exch TclBN_mp_exch
#define mp_expt_d TclBN_mp_expt_d
#define mp_expt_d_ex TclBN_mp_expt_d_ex
+#define mp_get_int TclBN_mp_get_int
+#define mp_get_long TclBN_mp_get_long
+#define mp_get_long_long TclBN_mp_get_long_long
#define mp_grow TclBN_mp_grow
#define mp_init TclBN_mp_init
#define mp_init_copy TclBN_mp_init_copy
@@ -98,6 +101,8 @@
#define mp_s_rmap TclBNMpSRmap
#define mp_set TclBN_mp_set
#define mp_set_int TclBN_mp_set_int
+#define mp_set_long TclBN_mp_set_long
+#define mp_set_long_long TclBN_mp_set_long_long
#define mp_shrink TclBN_mp_shrink
#define mp_sqr TclBN_mp_sqr
#define mp_sqrt TclBN_mp_sqrt
@@ -148,11 +153,14 @@ EXTERN int TclBN_epoch(void);
/* 1 */
EXTERN int TclBN_revision(void);
/* 2 */
-EXTERN int TclBN_mp_add(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_add(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 3 */
-EXTERN int TclBN_mp_add_d(mp_int *a, mp_digit b, mp_int *c);
+EXTERN int TclBN_mp_add_d(const mp_int *a, mp_digit b,
+ mp_int *c);
/* 4 */
-EXTERN int TclBN_mp_and(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_and(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 5 */
EXTERN void TclBN_mp_clamp(mp_int *a);
/* 6 */
@@ -170,22 +178,24 @@ EXTERN int TclBN_mp_copy(const mp_int *a, mp_int *b);
/* 12 */
EXTERN int TclBN_mp_count_bits(const mp_int *a);
/* 13 */
-EXTERN int TclBN_mp_div(mp_int *a, mp_int *b, mp_int *q,
- mp_int *r);
+EXTERN int TclBN_mp_div(const mp_int *a, const mp_int *b,
+ mp_int *q, mp_int *r);
/* 14 */
-EXTERN int TclBN_mp_div_d(mp_int *a, mp_digit b, mp_int *q,
- mp_digit *r);
+EXTERN int TclBN_mp_div_d(const mp_int *a, mp_digit b,
+ mp_int *q, mp_digit *r);
/* 15 */
-EXTERN int TclBN_mp_div_2(mp_int *a, mp_int *q);
+EXTERN int TclBN_mp_div_2(const mp_int *a, mp_int *q);
/* 16 */
EXTERN int TclBN_mp_div_2d(const mp_int *a, int b, mp_int *q,
mp_int *r);
/* 17 */
-EXTERN int TclBN_mp_div_3(mp_int *a, mp_int *q, mp_digit *r);
+EXTERN int TclBN_mp_div_3(const mp_int *a, mp_int *q,
+ mp_digit *r);
/* 18 */
EXTERN void TclBN_mp_exch(mp_int *a, mp_int *b);
/* 19 */
-EXTERN int TclBN_mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
+EXTERN int TclBN_mp_expt_d(const mp_int *a, mp_digit b,
+ mp_int *c);
/* 20 */
EXTERN int TclBN_mp_grow(mp_int *a, int size);
/* 21 */
@@ -201,21 +211,25 @@ EXTERN int TclBN_mp_init_size(mp_int *a, int size);
/* 26 */
EXTERN int TclBN_mp_lshd(mp_int *a, int shift);
/* 27 */
-EXTERN int TclBN_mp_mod(mp_int *a, mp_int *b, mp_int *r);
+EXTERN int TclBN_mp_mod(const mp_int *a, const mp_int *b,
+ mp_int *r);
/* 28 */
EXTERN int TclBN_mp_mod_2d(const mp_int *a, int b, mp_int *r);
/* 29 */
-EXTERN int TclBN_mp_mul(mp_int *a, mp_int *b, mp_int *p);
+EXTERN int TclBN_mp_mul(const mp_int *a, const mp_int *b,
+ mp_int *p);
/* 30 */
-EXTERN int TclBN_mp_mul_d(mp_int *a, mp_digit b, mp_int *p);
+EXTERN int TclBN_mp_mul_d(const mp_int *a, mp_digit b,
+ mp_int *p);
/* 31 */
-EXTERN int TclBN_mp_mul_2(mp_int *a, mp_int *p);
+EXTERN int TclBN_mp_mul_2(const mp_int *a, mp_int *p);
/* 32 */
EXTERN int TclBN_mp_mul_2d(const mp_int *a, int d, mp_int *p);
/* 33 */
EXTERN int TclBN_mp_neg(const mp_int *a, mp_int *b);
/* 34 */
-EXTERN int TclBN_mp_or(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_or(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 35 */
EXTERN int TclBN_mp_radix_size(const mp_int *a, int radix,
int *size);
@@ -229,52 +243,59 @@ EXTERN int TclBN_mp_shrink(mp_int *a);
/* 39 */
EXTERN void TclBN_mp_set(mp_int *a, mp_digit b);
/* 40 */
-EXTERN int TclBN_mp_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_mp_sqr(const mp_int *a, mp_int *b);
/* 41 */
-EXTERN int TclBN_mp_sqrt(mp_int *a, mp_int *b);
+EXTERN int TclBN_mp_sqrt(const mp_int *a, mp_int *b);
/* 42 */
-EXTERN int TclBN_mp_sub(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_sub(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 43 */
-EXTERN int TclBN_mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
+EXTERN int TclBN_mp_sub_d(const mp_int *a, mp_digit b,
+ mp_int *c);
/* 44 */
-EXTERN int TclBN_mp_to_unsigned_bin(mp_int *a, unsigned char *b);
+EXTERN int TclBN_mp_to_unsigned_bin(const mp_int *a,
+ unsigned char *b);
/* 45 */
-EXTERN int TclBN_mp_to_unsigned_bin_n(mp_int *a,
+EXTERN int TclBN_mp_to_unsigned_bin_n(const mp_int *a,
unsigned char *b, unsigned long *outlen);
/* 46 */
-EXTERN int TclBN_mp_toradix_n(mp_int *a, char *str, int radix,
- int maxlen);
+EXTERN int TclBN_mp_toradix_n(const mp_int *a, char *str,
+ int radix, int maxlen);
/* 47 */
-EXTERN int TclBN_mp_unsigned_bin_size(mp_int *a);
+EXTERN int TclBN_mp_unsigned_bin_size(const mp_int *a);
/* 48 */
-EXTERN int TclBN_mp_xor(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_xor(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 49 */
EXTERN void TclBN_mp_zero(mp_int *a);
/* 50 */
EXTERN void TclBN_reverse(unsigned char *s, int len);
/* 51 */
-EXTERN int TclBN_fast_s_mp_mul_digs(mp_int *a, mp_int *b,
- mp_int *c, int digs);
+EXTERN int TclBN_fast_s_mp_mul_digs(const mp_int *a,
+ const mp_int *b, mp_int *c, int digs);
/* 52 */
-EXTERN int TclBN_fast_s_mp_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_fast_s_mp_sqr(const mp_int *a, mp_int *b);
/* 53 */
-EXTERN int TclBN_mp_karatsuba_mul(mp_int *a, mp_int *b,
- mp_int *c);
+EXTERN int TclBN_mp_karatsuba_mul(const mp_int *a,
+ const mp_int *b, mp_int *c);
/* 54 */
-EXTERN int TclBN_mp_karatsuba_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_mp_karatsuba_sqr(const mp_int *a, mp_int *b);
/* 55 */
-EXTERN int TclBN_mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_mp_toom_mul(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 56 */
-EXTERN int TclBN_mp_toom_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_mp_toom_sqr(const mp_int *a, mp_int *b);
/* 57 */
-EXTERN int TclBN_s_mp_add(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_s_mp_add(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 58 */
-EXTERN int TclBN_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c,
- int digs);
+EXTERN int TclBN_s_mp_mul_digs(const mp_int *a, const mp_int *b,
+ mp_int *c, int digs);
/* 59 */
-EXTERN int TclBN_s_mp_sqr(mp_int *a, mp_int *b);
+EXTERN int TclBN_s_mp_sqr(const mp_int *a, mp_int *b);
/* 60 */
-EXTERN int TclBN_s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
+EXTERN int TclBN_s_mp_sub(const mp_int *a, const mp_int *b,
+ mp_int *c);
/* 61 */
EXTERN int TclBN_mp_init_set_int(mp_int *a, unsigned long i);
/* 62 */
@@ -282,16 +303,27 @@ EXTERN int TclBN_mp_set_int(mp_int *a, unsigned long i);
/* 63 */
EXTERN int TclBN_mp_cnt_lsb(const mp_int *a);
/* 64 */
-EXTERN void TclBNInitBignumFromLong(mp_int *bignum, long initVal);
+TCL_DEPRECATED("Use mp_init() + mp_set_long_long()")
+void TclBNInitBignumFromLong(mp_int *bignum, long initVal);
/* 65 */
-EXTERN void TclBNInitBignumFromWideInt(mp_int *bignum,
+TCL_DEPRECATED("Use mp_init() + mp_set_long_long()")
+void TclBNInitBignumFromWideInt(mp_int *bignum,
Tcl_WideInt initVal);
/* 66 */
-EXTERN void TclBNInitBignumFromWideUInt(mp_int *bignum,
+TCL_DEPRECATED("Use mp_init() + mp_set_long_long()")
+void TclBNInitBignumFromWideUInt(mp_int *bignum,
Tcl_WideUInt initVal);
/* 67 */
-EXTERN int TclBN_mp_expt_d_ex(mp_int *a, mp_digit b, mp_int *c,
- int fast);
+EXTERN int TclBN_mp_expt_d_ex(const mp_int *a, mp_digit b,
+ mp_int *c, int fast);
+/* 68 */
+EXTERN int TclBN_mp_set_long_long(mp_int *a, Tcl_WideUInt i);
+/* 69 */
+EXTERN Tcl_WideUInt TclBN_mp_get_long_long(const mp_int *a);
+/* 70 */
+EXTERN int TclBN_mp_set_long(mp_int *a, unsigned long i);
+/* 71 */
+EXTERN unsigned long TclBN_mp_get_long(const mp_int *a);
typedef struct TclTomMathStubs {
int magic;
@@ -299,9 +331,9 @@ typedef struct TclTomMathStubs {
int (*tclBN_epoch) (void); /* 0 */
int (*tclBN_revision) (void); /* 1 */
- int (*tclBN_mp_add) (mp_int *a, mp_int *b, mp_int *c); /* 2 */
- int (*tclBN_mp_add_d) (mp_int *a, mp_digit b, mp_int *c); /* 3 */
- int (*tclBN_mp_and) (mp_int *a, mp_int *b, mp_int *c); /* 4 */
+ int (*tclBN_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 2 */
+ int (*tclBN_mp_add_d) (const mp_int *a, mp_digit b, mp_int *c); /* 3 */
+ int (*tclBN_mp_and) (const mp_int *a, const mp_int *b, mp_int *c); /* 4 */
void (*tclBN_mp_clamp) (mp_int *a); /* 5 */
void (*tclBN_mp_clear) (mp_int *a); /* 6 */
void (*tclBN_mp_clear_multi) (mp_int *a, ...); /* 7 */
@@ -310,13 +342,13 @@ typedef struct TclTomMathStubs {
int (*tclBN_mp_cmp_mag) (const mp_int *a, const mp_int *b); /* 10 */
int (*tclBN_mp_copy) (const mp_int *a, mp_int *b); /* 11 */
int (*tclBN_mp_count_bits) (const mp_int *a); /* 12 */
- int (*tclBN_mp_div) (mp_int *a, mp_int *b, mp_int *q, mp_int *r); /* 13 */
- int (*tclBN_mp_div_d) (mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 14 */
- int (*tclBN_mp_div_2) (mp_int *a, mp_int *q); /* 15 */
+ int (*tclBN_mp_div) (const mp_int *a, const mp_int *b, mp_int *q, mp_int *r); /* 13 */
+ int (*tclBN_mp_div_d) (const mp_int *a, mp_digit b, mp_int *q, mp_digit *r); /* 14 */
+ int (*tclBN_mp_div_2) (const mp_int *a, mp_int *q); /* 15 */
int (*tclBN_mp_div_2d) (const mp_int *a, int b, mp_int *q, mp_int *r); /* 16 */
- int (*tclBN_mp_div_3) (mp_int *a, mp_int *q, mp_digit *r); /* 17 */
+ int (*tclBN_mp_div_3) (const mp_int *a, mp_int *q, mp_digit *r); /* 17 */
void (*tclBN_mp_exch) (mp_int *a, mp_int *b); /* 18 */
- int (*tclBN_mp_expt_d) (mp_int *a, mp_digit b, mp_int *c); /* 19 */
+ int (*tclBN_mp_expt_d) (const mp_int *a, mp_digit b, mp_int *c); /* 19 */
int (*tclBN_mp_grow) (mp_int *a, int size); /* 20 */
int (*tclBN_mp_init) (mp_int *a); /* 21 */
int (*tclBN_mp_init_copy) (mp_int *a, const mp_int *b); /* 22 */
@@ -324,47 +356,51 @@ typedef struct TclTomMathStubs {
int (*tclBN_mp_init_set) (mp_int *a, mp_digit b); /* 24 */
int (*tclBN_mp_init_size) (mp_int *a, int size); /* 25 */
int (*tclBN_mp_lshd) (mp_int *a, int shift); /* 26 */
- int (*tclBN_mp_mod) (mp_int *a, mp_int *b, mp_int *r); /* 27 */
+ int (*tclBN_mp_mod) (const mp_int *a, const mp_int *b, mp_int *r); /* 27 */
int (*tclBN_mp_mod_2d) (const mp_int *a, int b, mp_int *r); /* 28 */
- int (*tclBN_mp_mul) (mp_int *a, mp_int *b, mp_int *p); /* 29 */
- int (*tclBN_mp_mul_d) (mp_int *a, mp_digit b, mp_int *p); /* 30 */
- int (*tclBN_mp_mul_2) (mp_int *a, mp_int *p); /* 31 */
+ int (*tclBN_mp_mul) (const mp_int *a, const mp_int *b, mp_int *p); /* 29 */
+ int (*tclBN_mp_mul_d) (const mp_int *a, mp_digit b, mp_int *p); /* 30 */
+ int (*tclBN_mp_mul_2) (const mp_int *a, mp_int *p); /* 31 */
int (*tclBN_mp_mul_2d) (const mp_int *a, int d, mp_int *p); /* 32 */
int (*tclBN_mp_neg) (const mp_int *a, mp_int *b); /* 33 */
- int (*tclBN_mp_or) (mp_int *a, mp_int *b, mp_int *c); /* 34 */
+ int (*tclBN_mp_or) (const mp_int *a, const mp_int *b, mp_int *c); /* 34 */
int (*tclBN_mp_radix_size) (const mp_int *a, int radix, int *size); /* 35 */
int (*tclBN_mp_read_radix) (mp_int *a, const char *str, int radix); /* 36 */
void (*tclBN_mp_rshd) (mp_int *a, int shift); /* 37 */
int (*tclBN_mp_shrink) (mp_int *a); /* 38 */
void (*tclBN_mp_set) (mp_int *a, mp_digit b); /* 39 */
- int (*tclBN_mp_sqr) (mp_int *a, mp_int *b); /* 40 */
- int (*tclBN_mp_sqrt) (mp_int *a, mp_int *b); /* 41 */
- int (*tclBN_mp_sub) (mp_int *a, mp_int *b, mp_int *c); /* 42 */
- int (*tclBN_mp_sub_d) (mp_int *a, mp_digit b, mp_int *c); /* 43 */
- int (*tclBN_mp_to_unsigned_bin) (mp_int *a, unsigned char *b); /* 44 */
- int (*tclBN_mp_to_unsigned_bin_n) (mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
- int (*tclBN_mp_toradix_n) (mp_int *a, char *str, int radix, int maxlen); /* 46 */
- int (*tclBN_mp_unsigned_bin_size) (mp_int *a); /* 47 */
- int (*tclBN_mp_xor) (mp_int *a, mp_int *b, mp_int *c); /* 48 */
+ int (*tclBN_mp_sqr) (const mp_int *a, mp_int *b); /* 40 */
+ int (*tclBN_mp_sqrt) (const mp_int *a, mp_int *b); /* 41 */
+ int (*tclBN_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 42 */
+ int (*tclBN_mp_sub_d) (const mp_int *a, mp_digit b, mp_int *c); /* 43 */
+ int (*tclBN_mp_to_unsigned_bin) (const mp_int *a, unsigned char *b); /* 44 */
+ int (*tclBN_mp_to_unsigned_bin_n) (const mp_int *a, unsigned char *b, unsigned long *outlen); /* 45 */
+ int (*tclBN_mp_toradix_n) (const mp_int *a, char *str, int radix, int maxlen); /* 46 */
+ int (*tclBN_mp_unsigned_bin_size) (const mp_int *a); /* 47 */
+ int (*tclBN_mp_xor) (const mp_int *a, const mp_int *b, mp_int *c); /* 48 */
void (*tclBN_mp_zero) (mp_int *a); /* 49 */
void (*tclBN_reverse) (unsigned char *s, int len); /* 50 */
- int (*tclBN_fast_s_mp_mul_digs) (mp_int *a, mp_int *b, mp_int *c, int digs); /* 51 */
- int (*tclBN_fast_s_mp_sqr) (mp_int *a, mp_int *b); /* 52 */
- int (*tclBN_mp_karatsuba_mul) (mp_int *a, mp_int *b, mp_int *c); /* 53 */
- int (*tclBN_mp_karatsuba_sqr) (mp_int *a, mp_int *b); /* 54 */
- int (*tclBN_mp_toom_mul) (mp_int *a, mp_int *b, mp_int *c); /* 55 */
- int (*tclBN_mp_toom_sqr) (mp_int *a, mp_int *b); /* 56 */
- int (*tclBN_s_mp_add) (mp_int *a, mp_int *b, mp_int *c); /* 57 */
- int (*tclBN_s_mp_mul_digs) (mp_int *a, mp_int *b, mp_int *c, int digs); /* 58 */
- int (*tclBN_s_mp_sqr) (mp_int *a, mp_int *b); /* 59 */
- int (*tclBN_s_mp_sub) (mp_int *a, mp_int *b, mp_int *c); /* 60 */
+ int (*tclBN_fast_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 51 */
+ int (*tclBN_fast_s_mp_sqr) (const mp_int *a, mp_int *b); /* 52 */
+ int (*tclBN_mp_karatsuba_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 53 */
+ int (*tclBN_mp_karatsuba_sqr) (const mp_int *a, mp_int *b); /* 54 */
+ int (*tclBN_mp_toom_mul) (const mp_int *a, const mp_int *b, mp_int *c); /* 55 */
+ int (*tclBN_mp_toom_sqr) (const mp_int *a, mp_int *b); /* 56 */
+ int (*tclBN_s_mp_add) (const mp_int *a, const mp_int *b, mp_int *c); /* 57 */
+ int (*tclBN_s_mp_mul_digs) (const mp_int *a, const mp_int *b, mp_int *c, int digs); /* 58 */
+ int (*tclBN_s_mp_sqr) (const mp_int *a, mp_int *b); /* 59 */
+ int (*tclBN_s_mp_sub) (const mp_int *a, const mp_int *b, mp_int *c); /* 60 */
int (*tclBN_mp_init_set_int) (mp_int *a, unsigned long i); /* 61 */
int (*tclBN_mp_set_int) (mp_int *a, unsigned long i); /* 62 */
int (*tclBN_mp_cnt_lsb) (const mp_int *a); /* 63 */
- void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
- void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
- void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
- int (*tclBN_mp_expt_d_ex) (mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
+ TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromLong) (mp_int *bignum, long initVal); /* 64 */
+ TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromWideInt) (mp_int *bignum, Tcl_WideInt initVal); /* 65 */
+ TCL_DEPRECATED_API("Use mp_init() + mp_set_long_long()") void (*tclBNInitBignumFromWideUInt) (mp_int *bignum, Tcl_WideUInt initVal); /* 66 */
+ int (*tclBN_mp_expt_d_ex) (const mp_int *a, mp_digit b, mp_int *c, int fast); /* 67 */
+ int (*tclBN_mp_set_long_long) (mp_int *a, Tcl_WideUInt i); /* 68 */
+ Tcl_WideUInt (*tclBN_mp_get_long_long) (const mp_int *a); /* 69 */
+ int (*tclBN_mp_set_long) (mp_int *a, unsigned long i); /* 70 */
+ unsigned long (*tclBN_mp_get_long) (const mp_int *a); /* 71 */
} TclTomMathStubs;
extern const TclTomMathStubs *tclTomMathStubsPtr;
@@ -515,6 +551,14 @@ extern const TclTomMathStubs *tclTomMathStubsPtr;
(tclTomMathStubsPtr->tclBNInitBignumFromWideUInt) /* 66 */
#define TclBN_mp_expt_d_ex \
(tclTomMathStubsPtr->tclBN_mp_expt_d_ex) /* 67 */
+#define TclBN_mp_set_long_long \
+ (tclTomMathStubsPtr->tclBN_mp_set_long_long) /* 68 */
+#define TclBN_mp_get_long_long \
+ (tclTomMathStubsPtr->tclBN_mp_get_long_long) /* 69 */
+#define TclBN_mp_set_long \
+ (tclTomMathStubsPtr->tclBN_mp_set_long) /* 70 */
+#define TclBN_mp_get_long \
+ (tclTomMathStubsPtr->tclBN_mp_get_long) /* 71 */
#endif /* defined(USE_TCL_STUBS) */
diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c
index 48db8c3..9e7bf4b 100644
--- a/generic/tclTomMathInterface.c
+++ b/generic/tclTomMathInterface.c
@@ -89,86 +89,11 @@ TclBN_revision(void)
{
return TCLTOMMATH_REVISION;
}
-#if 0
/*
*----------------------------------------------------------------------
*
- * TclBNAlloc --
- *
- * Allocate memory for libtommath.
- *
- * Results:
- * Returns a pointer to the allocated block.
- *
- * This procedure is a wrapper around Tcl_Alloc, needed because of a
- * mismatched type signature between Tcl_Alloc and malloc.
- *
- *----------------------------------------------------------------------
- */
-
-extern void *
-TclBNAlloc(
- size_t x)
-{
- return (void *) ckalloc((unsigned int) x);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TclBNRealloc --
- *
- * Change the size of an allocated block of memory in libtommath
- *
- * Results:
- * Returns a pointer to the allocated block.
- *
- * This procedure is a wrapper around Tcl_Realloc, needed because of a
- * mismatched type signature between Tcl_Realloc and realloc.
- *
- *----------------------------------------------------------------------
- */
-
-void *
-TclBNRealloc(
- void *p,
- size_t s)
-{
- return (void *) ckrealloc((char *) p, (unsigned int) s);
-}
-
-/*
- *----------------------------------------------------------------------
- *
- * TclBNFree --
- *
- * Free allocated memory in libtommath.
- *
- * Results:
- * None.
- *
- * Side effects:
- * Memory is freed.
- *
- * This function is simply a wrapper around Tcl_Free, needed in libtommath
- * because of a type mismatch between free and Tcl_Free.
- *
- *----------------------------------------------------------------------
- */
-
-extern void
-TclBNFree(
- void *p)
-{
- ckree((char *) p);
-}
-#endif
-
-/*
- *----------------------------------------------------------------------
- *
- * TclBNInitBignumFromLong --
+ * TclInitBignumFromLong --
*
* Allocate and initialize a 'bignum' from a native 'long'.
*
@@ -181,47 +106,20 @@ TclBNFree(
*----------------------------------------------------------------------
*/
-extern void
-TclBNInitBignumFromLong(
+void
+TclInitBignumFromLong(
mp_int *a,
- long initVal)
+ long v)
{
- int status;
- unsigned long v;
- mp_digit *p;
-
- /*
- * Allocate enough memory to hold the largest possible long
- */
-
- status = mp_init_size(a,
- (CHAR_BIT * sizeof(long) + DIGIT_BIT - 1) / DIGIT_BIT);
- if (status != MP_OKAY) {
- Tcl_Panic("initialization failure in TclBNInitBignumFromLong");
+ if (mp_init_size(a, (CHAR_BIT * sizeof(long) + DIGIT_BIT - 1) / DIGIT_BIT) != MP_OKAY) {
+ Tcl_Panic("initialization failure in TclInitBignumFromLong");
}
-
- /*
- * Convert arg to sign and magnitude.
- */
-
- if (initVal < 0) {
- a->sign = MP_NEG;
- v = -initVal;
+ if (v < (long)0) {
+ mp_set_long_long(a, (Tcl_WideUInt)(-(Tcl_WideInt)v));
+ mp_neg(a, a);
} else {
- a->sign = MP_ZPOS;
- v = initVal;
- }
-
- /*
- * Store the magnitude in the bignum.
- */
-
- p = a->dp;
- while (v) {
- *p++ = (mp_digit) (v & MP_MASK);
- v >>= MP_DIGIT_BIT;
+ mp_set_long_long(a, (Tcl_WideUInt)v);
}
- a->used = p - a->dp;
}
/*
@@ -240,16 +138,19 @@ TclBNInitBignumFromLong(
*----------------------------------------------------------------------
*/
-extern void
-TclBNInitBignumFromWideInt(
+void
+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) {
+ Tcl_Panic("initialization failure in TclInitBignumFromWideInt");
+ }
if (v < (Tcl_WideInt)0) {
- TclBNInitBignumFromWideUInt(a, (Tcl_WideUInt)(-v));
+ mp_set_long_long(a, (Tcl_WideUInt)(-v));
mp_neg(a, a);
} else {
- TclBNInitBignumFromWideUInt(a, (Tcl_WideUInt)v);
+ mp_set_long_long(a, (Tcl_WideUInt)v);
}
}
@@ -269,36 +170,15 @@ TclBNInitBignumFromWideInt(
*----------------------------------------------------------------------
*/
-extern void
-TclBNInitBignumFromWideUInt(
+void
+TclInitBignumFromWideUInt(
mp_int *a, /* Bignum to initialize */
Tcl_WideUInt v) /* Initial value */
{
- int status;
- mp_digit *p;
-
- /*
- * Allocate enough memory to hold the largest possible Tcl_WideUInt.
- */
-
- status = mp_init_size(a,
- (CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT);
- if (status != MP_OKAY) {
- Tcl_Panic("initialization failure in TclBNInitBignumFromWideUInt");
- }
-
- a->sign = MP_ZPOS;
-
- /*
- * Store the magnitude in the bignum.
- */
-
- p = a->dp;
- while (v) {
- *p++ = (mp_digit) (v & MP_MASK);
- v >>= MP_DIGIT_BIT;
- }
- a->used = p - a->dp;
+ if (mp_init_size(a, (CHAR_BIT * sizeof(Tcl_WideUInt) + DIGIT_BIT - 1) / DIGIT_BIT) != MP_OKAY) {
+ Tcl_Panic("initialization failure in TclInitBignumFromWideUInt");
+ }
+ mp_set_long_long(a, v);
}
/*