summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog38
-rw-r--r--generic/tcl.decls9
-rw-r--r--generic/tclBasic.c6
-rw-r--r--generic/tclClock.c4
-rw-r--r--generic/tclDecls.h14
-rw-r--r--generic/tclIO.c4
-rw-r--r--generic/tclIORChan.c6
-rw-r--r--generic/tclInt.decls23
-rw-r--r--generic/tclInt.h7
-rw-r--r--generic/tclIntDecls.h70
-rw-r--r--generic/tclIntPlatDecls.h10
-rw-r--r--generic/tclLink.c6
-rw-r--r--generic/tclListObj.c4
-rw-r--r--generic/tclObj.c4
-rw-r--r--generic/tclParseExpr.c4
-rw-r--r--generic/tclProc.c4
-rw-r--r--generic/tclStubInit.c81
-rw-r--r--generic/tclStubLib.c64
-rw-r--r--generic/tclTimer.c4
-rw-r--r--generic/tclTomMath.decls214
-rw-r--r--generic/tclTomMath.h938
-rw-r--r--generic/tclTomMathDecls.h810
-rw-r--r--generic/tclTomMathInterface.c79
-rw-r--r--generic/tommath.h612
-rwxr-xr-xtools/fix_tommath_h.tcl99
-rw-r--r--unix/Makefile.in15
-rw-r--r--win/Makefile.in13
-rw-r--r--win/makefile.vc50
-rw-r--r--win/tclWinChan.c13
-rw-r--r--win/tclWinConsole.c12
-rw-r--r--win/tclWinDde.c15
-rw-r--r--win/tclWinFCmd.c8
-rw-r--r--win/tclWinFile.c13
-rw-r--r--win/tclWinReg.c27
-rw-r--r--win/tclWinSock.c18
35 files changed, 2347 insertions, 951 deletions
diff --git a/ChangeLog b/ChangeLog
index 325c773..9e71367 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,41 @@
+2005-12-13 Kevin B. Kenny <kennykb@acm.org>
+
+ * generic/tcl.decls: Added changes to export an additional
+ * generic/tclBasic.c: Stubs table to represent the 'libtommath'
+ * generic/tclDecls.h: routines that Tcl uses and export them
+ * generic/tclInt.decls: to callers. Reran 'genstubs'
+ * generic/tclInt.h:
+ * generic/tclIntDecls.h:
+ * generic/tclIntPlatDecls.h:
+ * generic/tclStubInit.c:
+ * generic/tclStubLib.c:
+ * generic/tclTomMath.decls:
+ * generic/tclTomMath.h:
+ * generic/tclTomMathDecls.h:
+ * generic/tclTomMathInterface.c:
+ * generic/tommath.h:
+ * tools/fix_tommath_h.tcl:
+ * unix/Makefile.in:
+ * win/Makefile.in:
+ * win/makefile.vc:
+
+ * generic/tclClock.c: Made changes to silence a number of
+ * generic/tclIO.c: compiler warnings when building with
+ * generic/tclIORChan.c: mingw.
+ * generic/tclLink.c:
+ * generic/tclListObj.c:
+ * generic/tclObj.c:
+ * generic/tclParseExpr.c:
+ * generic/tclProc.c:
+ * generic/tclTimer.c:
+ * win/tclWinChan.c:
+ * win/tclWinConsole.c:
+ * win/tclWinDde.c:
+ * win/tclWinFCmd.c:
+ * win/tclWinFile.c:
+ * win/tclWinReg.c:
+ * win/tclWinSock.c:
+
2005-12-13 Donal K. Fellows <donal.k.fellows@manchester.ac.uk>
* generic/tclExecute.c (TEBC:DICT_FIRST,DICT_DONE): Only decrease the
diff --git a/generic/tcl.decls b/generic/tcl.decls
index 49d0d33..e5a51cd 100644
--- a/generic/tcl.decls
+++ b/generic/tcl.decls
@@ -11,7 +11,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: tcl.decls,v 1.115 2005/11/27 02:33:48 das Exp $
+# RCS: @(#) $Id: tcl.decls,v 1.116 2005/12/13 22:43:16 kennykb Exp $
library tcl
@@ -2031,6 +2031,13 @@ declare 565 generic {
void Tcl_GetChannelError (Tcl_Channel chan, Tcl_Obj** msg)
}
+declare 566 generic {
+ const char* TclTomMathInitializeStubs(Tcl_Interp* interp,
+ CONST char* version, int epoch, int revision)
+}
+
+
+
##############################################################################
# Define the platform specific public Tcl interface. These functions are
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 6bd2627..589892d 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclBasic.c,v 1.183 2005/11/29 22:50:56 kennykb Exp $
+ * RCS: @(#) $Id: tclBasic.c,v 1.184 2005/12/13 22:43:17 kennykb Exp $
*/
#include "tclInt.h"
@@ -582,6 +582,10 @@ Tcl_CreateInterp(void)
#endif
Tcl_InitStubs(interp, TCL_VERSION, 1);
+ if (TclTommath_Init(interp) != TCL_OK) {
+ panic(Tcl_GetString(Tcl_GetObjResult(interp)));
+ }
+
return interp;
}
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 69abb95..6189a5a 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclClock.c,v 1.49 2005/12/02 22:13:41 kennykb Exp $
+ * RCS: @(#) $Id: tclClock.c,v 1.50 2005/12/13 22:43:17 kennykb Exp $
*/
#include "tclInt.h"
@@ -422,7 +422,7 @@ ClockGetdatefieldsObjCmd(
Tcl_DictObjPut((Tcl_Interp*) NULL, dict, literals[LIT_TZOFFSET],
Tcl_NewIntObj(fields.tzOffset));
Tcl_DictObjPut((Tcl_Interp*) NULL, dict, literals[LIT_JULIANDAY],
- Tcl_NewWideIntObj(fields.julianDay));
+ Tcl_NewIntObj(fields.julianDay));
Tcl_DictObjPut((Tcl_Interp*) NULL, dict, literals[LIT_GREGORIAN],
Tcl_NewIntObj(fields.gregorian));
Tcl_DictObjPut((Tcl_Interp*) NULL, dict, literals[LIT_ERA],
diff --git a/generic/tclDecls.h b/generic/tclDecls.h
index f01f3ca..6851457 100644
--- a/generic/tclDecls.h
+++ b/generic/tclDecls.h
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclDecls.h,v 1.117 2005/10/08 14:42:45 dgp Exp $
+ * RCS: @(#) $Id: tclDecls.h,v 1.118 2005/12/13 22:43:17 kennykb Exp $
*/
#ifndef _TCLDECLS
@@ -3527,6 +3527,13 @@ EXTERN void Tcl_SetChannelError _ANSI_ARGS_((Tcl_Channel chan,
EXTERN void Tcl_GetChannelError _ANSI_ARGS_((Tcl_Channel chan,
Tcl_Obj** msg));
#endif
+#ifndef TclTomMathInitializeStubs_TCL_DECLARED
+#define TclTomMathInitializeStubs_TCL_DECLARED
+/* 566 */
+EXTERN const char* TclTomMathInitializeStubs _ANSI_ARGS_((
+ Tcl_Interp* interp, CONST char* version,
+ int epoch, int revision));
+#endif
typedef struct TclStubHooks {
struct TclPlatStubs *tclPlatStubs;
@@ -4134,6 +4141,7 @@ typedef struct TclStubs {
void (*tcl_GetChannelErrorInterp) _ANSI_ARGS_((Tcl_Interp* interp, Tcl_Obj** msg)); /* 563 */
void (*tcl_SetChannelError) _ANSI_ARGS_((Tcl_Channel chan, Tcl_Obj* msg)); /* 564 */
void (*tcl_GetChannelError) _ANSI_ARGS_((Tcl_Channel chan, Tcl_Obj** msg)); /* 565 */
+ const char* (*tclTomMathInitializeStubs) _ANSI_ARGS_((Tcl_Interp* interp, CONST char* version, int epoch, int revision)); /* 566 */
} TclStubs;
#ifdef __cplusplus
@@ -6438,6 +6446,10 @@ extern TclStubs *tclStubsPtr;
#define Tcl_GetChannelError \
(tclStubsPtr->tcl_GetChannelError) /* 565 */
#endif
+#ifndef TclTomMathInitializeStubs
+#define TclTomMathInitializeStubs \
+ (tclStubsPtr->tclTomMathInitializeStubs) /* 566 */
+#endif
#endif /* defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) */
diff --git a/generic/tclIO.c b/generic/tclIO.c
index f77a1a4..86a25f6 100644
--- a/generic/tclIO.c
+++ b/generic/tclIO.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclIO.c,v 1.102 2005/11/18 19:38:38 hobbs Exp $
+ * RCS: @(#) $Id: tclIO.c,v 1.103 2005/12/13 22:43:17 kennykb Exp $
*/
#include "tclInt.h"
@@ -6023,7 +6023,7 @@ Tcl_TruncateChannel(
* pre-read input data.
*/
- if (Tcl_Seek(chan, 0, SEEK_CUR) == Tcl_LongAsWide(-1)) {
+ if (Tcl_Seek(chan, (Tcl_WideInt)0, SEEK_CUR) == Tcl_LongAsWide(-1)) {
return TCL_ERROR;
}
diff --git a/generic/tclIORChan.c b/generic/tclIORChan.c
index 2e4b192..faaaca1 100644
--- a/generic/tclIORChan.c
+++ b/generic/tclIORChan.c
@@ -15,7 +15,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclIORChan.c,v 1.11 2005/10/19 21:26:19 dkf Exp $
+ * RCS: @(#) $Id: tclIORChan.c,v 1.12 2005/12/13 22:43:17 kennykb Exp $
*/
#include <tclInt.h>
@@ -1116,7 +1116,7 @@ ReflectInput(
*errorCodePtr = EOK;
if (bytec > 0) {
- memcpy(buf, bytev, bytec);
+ memcpy(buf, bytev, (size_t)bytec);
}
Tcl_DecrRefCount(resObj); /* Remove reference held from invoke */
@@ -2248,7 +2248,7 @@ ForwardProc(
paramPtr->input.toRead = -1;
} else {
if (bytec > 0) {
- memcpy(paramPtr->input.buf, bytev, bytec);
+ memcpy(paramPtr->input.buf, bytev, (size_t)bytec);
}
paramPtr->input.toRead = bytec;
}
diff --git a/generic/tclInt.decls b/generic/tclInt.decls
index 9a07c73..02eeaf5 100644
--- a/generic/tclInt.decls
+++ b/generic/tclInt.decls
@@ -12,7 +12,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: tclInt.decls,v 1.93 2005/10/08 14:42:45 dgp Exp $
+# RCS: @(#) $Id: tclInt.decls,v 1.94 2005/12/13 22:43:17 kennykb Exp $
library tcl
@@ -878,23 +878,6 @@ declare 218 generic {
void TclPopStackFrame(Tcl_Interp *interp)
}
-# Entries in tommath needed only by tcltest
-
-declare 219 generic {
- int TclBN_mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d)
-}
-declare 220 generic {
- int TclBN_mp_mul_d(mp_int *a, mp_digit b, mp_int *c)
-}
-declare 221 generic {
- void TclBN_mp_clear(mp_int *a)
-}
-declare 222 generic {
- int TclBN_mp_init(mp_int *a)
-}
-declare 223 generic {
- int TclBN_mp_read_radix(mp_int *a, const char *str, int radix)
-}
# for use in tclTest.c
declare 224 generic {
TclPlatformType *TclGetPlatform(void)
@@ -927,7 +910,7 @@ declare 2 win {
CONST char *proto)
}
declare 3 win {
- int TclWinGetSockOpt(SOCKET s, int level, int optname,
+ int TclWinGetSockOpt(int s, int level, int optname,
char FAR *optval, int FAR *optlen)
}
declare 4 win {
@@ -941,7 +924,7 @@ declare 6 win {
u_short TclWinNToHS(u_short ns)
}
declare 7 win {
- int TclWinSetSockOpt(SOCKET s, int level, int optname,
+ int TclWinSetSockOpt(int s, int level, int optname,
CONST char FAR *optval, int optlen)
}
declare 8 win {
diff --git a/generic/tclInt.h b/generic/tclInt.h
index 4978151..b183bca 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclInt.h,v 1.261 2005/12/01 11:03:55 dkf Exp $
+ * RCS: @(#) $Id: tclInt.h,v 1.262 2005/12/13 22:43:17 kennykb Exp $
*/
#ifndef _TCLINT
@@ -2864,9 +2864,7 @@ MODULE_SCOPE void TclDbInitNewObj(Tcl_Obj *objPtr);
*----------------------------------------------------------------------
*/
-MODULE_SCOPE void * TclBNAlloc(size_t nBytes);
-MODULE_SCOPE void * TclBNRealloc(void *oldBlock, size_t newNBytes);
-MODULE_SCOPE void TclBNFree(void *block);
+MODULE_SCOPE int TclTommath_Init(Tcl_Interp*);
MODULE_SCOPE void TclBNInitBignumFromLong(mp_int *bignum, long initVal);
MODULE_SCOPE void TclBNInitBignumFromWideInt(mp_int* bignum,
Tcl_WideInt initVal);
@@ -3027,6 +3025,7 @@ MODULE_SCOPE void TclBNInitBignumFromWideUInt(mp_int* bignum,
#include "tclPort.h"
#include "tclIntDecls.h"
#include "tclIntPlatDecls.h"
+#include "tclTomMathDecls.h"
#endif /* _TCLINT */
diff --git a/generic/tclIntDecls.h b/generic/tclIntDecls.h
index 4b19ca6..5df62d5 100644
--- a/generic/tclIntDecls.h
+++ b/generic/tclIntDecls.h
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclIntDecls.h,v 1.84 2005/10/08 14:42:45 dgp Exp $
+ * RCS: @(#) $Id: tclIntDecls.h,v 1.85 2005/12/13 22:43:18 kennykb Exp $
*/
#ifndef _TCLINTDECLS
@@ -1045,34 +1045,11 @@ EXTERN int TclPushStackFrame _ANSI_ARGS_((Tcl_Interp * interp,
/* 218 */
EXTERN void TclPopStackFrame _ANSI_ARGS_((Tcl_Interp * interp));
#endif
-#ifndef TclBN_mp_div_d_TCL_DECLARED
-#define TclBN_mp_div_d_TCL_DECLARED
-/* 219 */
-EXTERN int TclBN_mp_div_d _ANSI_ARGS_((mp_int * a, mp_digit b,
- mp_int * c, mp_digit * d));
-#endif
-#ifndef TclBN_mp_mul_d_TCL_DECLARED
-#define TclBN_mp_mul_d_TCL_DECLARED
-/* 220 */
-EXTERN int TclBN_mp_mul_d _ANSI_ARGS_((mp_int * a, mp_digit b,
- mp_int * c));
-#endif
-#ifndef TclBN_mp_clear_TCL_DECLARED
-#define TclBN_mp_clear_TCL_DECLARED
-/* 221 */
-EXTERN void TclBN_mp_clear _ANSI_ARGS_((mp_int * a));
-#endif
-#ifndef TclBN_mp_init_TCL_DECLARED
-#define TclBN_mp_init_TCL_DECLARED
-/* 222 */
-EXTERN int TclBN_mp_init _ANSI_ARGS_((mp_int * a));
-#endif
-#ifndef TclBN_mp_read_radix_TCL_DECLARED
-#define TclBN_mp_read_radix_TCL_DECLARED
-/* 223 */
-EXTERN int TclBN_mp_read_radix _ANSI_ARGS_((mp_int * a,
- const char * str, int radix));
-#endif
+/* Slot 219 is reserved */
+/* Slot 220 is reserved */
+/* Slot 221 is reserved */
+/* Slot 222 is reserved */
+/* Slot 223 is reserved */
#ifndef TclGetPlatform_TCL_DECLARED
#define TclGetPlatform_TCL_DECLARED
/* 224 */
@@ -1324,11 +1301,11 @@ typedef struct TclIntStubs {
void (*tclStackFree) _ANSI_ARGS_((Tcl_Interp * interp)); /* 216 */
int (*tclPushStackFrame) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_CallFrame ** framePtrPtr, Tcl_Namespace * namespacePtr, int isProcCallFrame)); /* 217 */
void (*tclPopStackFrame) _ANSI_ARGS_((Tcl_Interp * interp)); /* 218 */
- int (*tclBN_mp_div_d) _ANSI_ARGS_((mp_int * a, mp_digit b, mp_int * c, mp_digit * d)); /* 219 */
- int (*tclBN_mp_mul_d) _ANSI_ARGS_((mp_int * a, mp_digit b, mp_int * c)); /* 220 */
- void (*tclBN_mp_clear) _ANSI_ARGS_((mp_int * a)); /* 221 */
- int (*tclBN_mp_init) _ANSI_ARGS_((mp_int * a)); /* 222 */
- int (*tclBN_mp_read_radix) _ANSI_ARGS_((mp_int * a, const char * str, int radix)); /* 223 */
+ void *reserved219;
+ void *reserved220;
+ void *reserved221;
+ void *reserved222;
+ void *reserved223;
TclPlatformType * (*tclGetPlatform) _ANSI_ARGS_((void)); /* 224 */
Tcl_Obj * (*tclTraceDictPath) _ANSI_ARGS_((Tcl_Interp * interp, Tcl_Obj * rootPtr, int keyc, Tcl_Obj *CONST keyv[], int flags)); /* 225 */
} TclIntStubs;
@@ -2034,26 +2011,11 @@ extern TclIntStubs *tclIntStubsPtr;
#define TclPopStackFrame \
(tclIntStubsPtr->tclPopStackFrame) /* 218 */
#endif
-#ifndef TclBN_mp_div_d
-#define TclBN_mp_div_d \
- (tclIntStubsPtr->tclBN_mp_div_d) /* 219 */
-#endif
-#ifndef TclBN_mp_mul_d
-#define TclBN_mp_mul_d \
- (tclIntStubsPtr->tclBN_mp_mul_d) /* 220 */
-#endif
-#ifndef TclBN_mp_clear
-#define TclBN_mp_clear \
- (tclIntStubsPtr->tclBN_mp_clear) /* 221 */
-#endif
-#ifndef TclBN_mp_init
-#define TclBN_mp_init \
- (tclIntStubsPtr->tclBN_mp_init) /* 222 */
-#endif
-#ifndef TclBN_mp_read_radix
-#define TclBN_mp_read_radix \
- (tclIntStubsPtr->tclBN_mp_read_radix) /* 223 */
-#endif
+/* Slot 219 is reserved */
+/* Slot 220 is reserved */
+/* Slot 221 is reserved */
+/* Slot 222 is reserved */
+/* Slot 223 is reserved */
#ifndef TclGetPlatform
#define TclGetPlatform \
(tclIntStubsPtr->tclGetPlatform) /* 224 */
diff --git a/generic/tclIntPlatDecls.h b/generic/tclIntPlatDecls.h
index e9c1184..c05b3a5 100644
--- a/generic/tclIntPlatDecls.h
+++ b/generic/tclIntPlatDecls.h
@@ -9,7 +9,7 @@
* Copyright (c) 1998-1999 by Scriptics Corporation.
* All rights reserved.
*
- * RCS: @(#) $Id: tclIntPlatDecls.h,v 1.27 2005/05/14 20:46:45 das Exp $
+ * RCS: @(#) $Id: tclIntPlatDecls.h,v 1.28 2005/12/13 22:43:18 kennykb Exp $
*/
#ifndef _TCLINTPLATDECLS
@@ -146,7 +146,7 @@ EXTERN struct servent * TclWinGetServByName _ANSI_ARGS_((CONST char * nm,
#ifndef TclWinGetSockOpt_TCL_DECLARED
#define TclWinGetSockOpt_TCL_DECLARED
/* 3 */
-EXTERN int TclWinGetSockOpt _ANSI_ARGS_((SOCKET s, int level,
+EXTERN int TclWinGetSockOpt _ANSI_ARGS_((int s, int level,
int optname, char FAR * optval,
int FAR * optlen));
#endif
@@ -164,7 +164,7 @@ EXTERN u_short TclWinNToHS _ANSI_ARGS_((u_short ns));
#ifndef TclWinSetSockOpt_TCL_DECLARED
#define TclWinSetSockOpt_TCL_DECLARED
/* 7 */
-EXTERN int TclWinSetSockOpt _ANSI_ARGS_((SOCKET s, int level,
+EXTERN int TclWinSetSockOpt _ANSI_ARGS_((int s, int level,
int optname, CONST char FAR * optval,
int optlen));
#endif
@@ -322,11 +322,11 @@ typedef struct TclIntPlatStubs {
void (*tclWinConvertError) _ANSI_ARGS_((DWORD errCode)); /* 0 */
void (*tclWinConvertWSAError) _ANSI_ARGS_((DWORD errCode)); /* 1 */
struct servent * (*tclWinGetServByName) _ANSI_ARGS_((CONST char * nm, CONST char * proto)); /* 2 */
- int (*tclWinGetSockOpt) _ANSI_ARGS_((SOCKET s, int level, int optname, char FAR * optval, int FAR * optlen)); /* 3 */
+ int (*tclWinGetSockOpt) _ANSI_ARGS_((int s, int level, int optname, char FAR * optval, int FAR * optlen)); /* 3 */
HINSTANCE (*tclWinGetTclInstance) _ANSI_ARGS_((void)); /* 4 */
void *reserved5;
u_short (*tclWinNToHS) _ANSI_ARGS_((u_short ns)); /* 6 */
- int (*tclWinSetSockOpt) _ANSI_ARGS_((SOCKET s, int level, int optname, CONST char FAR * optval, int optlen)); /* 7 */
+ int (*tclWinSetSockOpt) _ANSI_ARGS_((int s, int level, int optname, CONST char FAR * optval, int optlen)); /* 7 */
unsigned long (*tclpGetPid) _ANSI_ARGS_((Tcl_Pid pid)); /* 8 */
int (*tclWinGetPlatformId) _ANSI_ARGS_((void)); /* 9 */
void *reserved10;
diff --git a/generic/tclLink.c b/generic/tclLink.c
index 9a1f53f..6a4e49e 100644
--- a/generic/tclLink.c
+++ b/generic/tclLink.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLink.c,v 1.15 2005/11/09 13:52:42 dkf Exp $
+ * RCS: @(#) $Id: tclLink.c,v 1.16 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
@@ -575,13 +575,13 @@ ObjValue(
return Tcl_NewIntObj(linkPtr->lastValue.us);
case TCL_LINK_UINT:
linkPtr->lastValue.ui = *(unsigned int *)(linkPtr->addr);
- return Tcl_NewWideIntObj(linkPtr->lastValue.ui);
+ return Tcl_NewWideIntObj((Tcl_WideInt)(linkPtr->lastValue.ui));
case TCL_LINK_LONG:
linkPtr->lastValue.l = *(long *)(linkPtr->addr);
return Tcl_NewWideIntObj(linkPtr->lastValue.l);
case TCL_LINK_ULONG:
linkPtr->lastValue.ul = *(unsigned long *)(linkPtr->addr);
- return Tcl_NewWideIntObj(linkPtr->lastValue.ul);
+ return Tcl_NewWideIntObj((Tcl_WideInt)(linkPtr->lastValue.ul));
case TCL_LINK_FLOAT:
linkPtr->lastValue.f = *(float *)(linkPtr->addr);
return Tcl_NewDoubleObj(linkPtr->lastValue.f);
diff --git a/generic/tclListObj.c b/generic/tclListObj.c
index e750809..1bc0344 100644
--- a/generic/tclListObj.c
+++ b/generic/tclListObj.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclListObj.c,v 1.30 2005/11/18 15:58:18 dgp Exp $
+ * RCS: @(#) $Id: tclListObj.c,v 1.31 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
@@ -554,7 +554,7 @@ Tcl_ListObjAppendElement(
oldListRepPtr->refCount--;
listPtr->internalRep.twoPtrValue.ptr1 = (VOID *) listRepPtr;
} else if (newSize) {
- listRepPtr = (List *) ckrealloc((char *)listRepPtr, newSize);
+ listRepPtr = (List *) ckrealloc((char *)listRepPtr, (size_t)newSize);
listRepPtr->maxElemCount = newMax;
listPtr->internalRep.twoPtrValue.ptr1 = (VOID *) listRepPtr;
}
diff --git a/generic/tclObj.c b/generic/tclObj.c
index 54b84c8..5237cd4 100644
--- a/generic/tclObj.c
+++ b/generic/tclObj.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclObj.c,v 1.102 2005/11/27 02:33:49 das Exp $
+ * RCS: @(#) $Id: tclObj.c,v 1.103 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
@@ -149,7 +149,7 @@ static Tcl_ThreadDataKey pendingObjDataKey;
mp_int *temp = (void *) ckalloc((unsigned) sizeof(mp_int)); \
*temp = bignum; \
(objPtr)->internalRep.ptrAndLongRep.ptr = (void*) temp; \
- (objPtr)->internalRep.ptrAndLongRep.value = -1; \
+ (objPtr)->internalRep.ptrAndLongRep.value = (unsigned long)(-1); \
} else { \
if ((bignum).alloc > 0x7fff) { \
mp_shrink(&(bignum)); \
diff --git a/generic/tclParseExpr.c b/generic/tclParseExpr.c
index 27d980e..ae1e2b2 100644
--- a/generic/tclParseExpr.c
+++ b/generic/tclParseExpr.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclParseExpr.c,v 1.30 2005/10/31 15:59:41 dkf Exp $
+ * RCS: @(#) $Id: tclParseExpr.c,v 1.31 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
@@ -1615,7 +1615,7 @@ GetLexeme(
if ((c != '+') && (c != '-')) {
CONST char *end = infoPtr->lastChar;
CONST char* end2;
- int code = TclParseNumber(NULL, NULL, NULL, src, (unsigned)(end-src),
+ int code = TclParseNumber(NULL, NULL, NULL, src, (int)(end-src),
&end2, 0);
if (code == TCL_OK) {
diff --git a/generic/tclProc.c b/generic/tclProc.c
index 126d73b..cab0788 100644
--- a/generic/tclProc.c
+++ b/generic/tclProc.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclProc.c,v 1.82 2005/11/02 00:55:06 dkf Exp $
+ * RCS: @(#) $Id: tclProc.c,v 1.83 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
@@ -1171,7 +1171,7 @@ TclObjInterpProc(
*/
localCt = procPtr->numCompiledLocals;
- compiledLocals = (Var *) TclStackAlloc(interp, localCt*sizeof(Var));
+ compiledLocals = (Var *) TclStackAlloc(interp, (int)(localCt*sizeof(Var)));
framePtr->numCompiledLocals = localCt;
framePtr->compiledLocals = compiledLocals;
diff --git a/generic/tclStubInit.c b/generic/tclStubInit.c
index bb1d018..3d7ecef 100644
--- a/generic/tclStubInit.c
+++ b/generic/tclStubInit.c
@@ -8,10 +8,11 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStubInit.c,v 1.124 2005/11/27 02:33:49 das Exp $
+ * RCS: @(#) $Id: tclStubInit.c,v 1.125 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
+#include "tommath.h"
/*
* Remove macros that will interfere with the definitions below.
@@ -62,6 +63,7 @@ MODULE_SCOPE TclIntStubs tclIntStubs;
MODULE_SCOPE TclIntPlatStubs tclIntPlatStubs;
MODULE_SCOPE TclPlatStubs tclPlatStubs;
MODULE_SCOPE TclStubs tclStubs;
+MODULE_SCOPE TclTomMathStubs tclTomMathStubs;
/*
* WARNING: The contents of this file is automatically generated by the
@@ -308,11 +310,11 @@ TclIntStubs tclIntStubs = {
TclStackFree, /* 216 */
TclPushStackFrame, /* 217 */
TclPopStackFrame, /* 218 */
- TclBN_mp_div_d, /* 219 */
- TclBN_mp_mul_d, /* 220 */
- TclBN_mp_clear, /* 221 */
- TclBN_mp_init, /* 222 */
- TclBN_mp_read_radix, /* 223 */
+ NULL, /* 219 */
+ NULL, /* 220 */
+ NULL, /* 221 */
+ NULL, /* 222 */
+ NULL, /* 223 */
TclGetPlatform, /* 224 */
TclTraceDictPath, /* 225 */
};
@@ -389,6 +391,72 @@ TclPlatStubs tclPlatStubs = {
#endif /* MAC_OSX_TCL */
};
+TclTomMathStubs tclTomMathStubs = {
+ TCL_STUB_MAGIC,
+ NULL,
+ TclBN_epoch, /* 0 */
+ TclBN_revision, /* 1 */
+ TclBN_mp_add, /* 2 */
+ TclBN_mp_add_d, /* 3 */
+ TclBN_mp_and, /* 4 */
+ TclBN_mp_clamp, /* 5 */
+ TclBN_mp_clear, /* 6 */
+ TclBN_mp_clear_multi, /* 7 */
+ TclBN_mp_cmp, /* 8 */
+ TclBN_mp_cmp_d, /* 9 */
+ TclBN_mp_cmp_mag, /* 10 */
+ TclBN_mp_copy, /* 11 */
+ TclBN_mp_count_bits, /* 12 */
+ TclBN_mp_div, /* 13 */
+ TclBN_mp_div_d, /* 14 */
+ TclBN_mp_div_2, /* 15 */
+ TclBN_mp_div_2d, /* 16 */
+ TclBN_mp_div_3, /* 17 */
+ TclBN_mp_exch, /* 18 */
+ TclBN_mp_expt_d, /* 19 */
+ TclBN_mp_grow, /* 20 */
+ TclBN_mp_init, /* 21 */
+ TclBN_mp_init_copy, /* 22 */
+ TclBN_mp_init_multi, /* 23 */
+ TclBN_mp_init_set, /* 24 */
+ TclBN_mp_init_size, /* 25 */
+ TclBN_mp_lshd, /* 26 */
+ TclBN_mp_mod, /* 27 */
+ TclBN_mp_mod_2d, /* 28 */
+ TclBN_mp_mul, /* 29 */
+ TclBN_mp_mul_d, /* 30 */
+ TclBN_mp_mul_2, /* 31 */
+ TclBN_mp_mul_2d, /* 32 */
+ TclBN_mp_neg, /* 33 */
+ TclBN_mp_or, /* 34 */
+ TclBN_mp_radix_size, /* 35 */
+ TclBN_mp_read_radix, /* 36 */
+ TclBN_mp_rshd, /* 37 */
+ TclBN_mp_shrink, /* 38 */
+ TclBN_mp_set, /* 39 */
+ TclBN_mp_sqr, /* 40 */
+ TclBN_mp_sqrt, /* 41 */
+ TclBN_mp_sub, /* 42 */
+ TclBN_mp_sub_d, /* 43 */
+ TclBN_mp_to_unsigned_bin, /* 44 */
+ TclBN_mp_to_unsigned_bin_n, /* 45 */
+ TclBN_mp_toradix_n, /* 46 */
+ TclBN_mp_unsigned_bin_size, /* 47 */
+ TclBN_mp_xor, /* 48 */
+ TclBN_mp_zero, /* 49 */
+ TclBN_reverse, /* 50 */
+ TclBN_fast_s_mp_mul_digs, /* 51 */
+ TclBN_fast_s_mp_sqr, /* 52 */
+ TclBN_mp_karatsuba_mul, /* 53 */
+ TclBN_mp_karatsuba_sqr, /* 54 */
+ TclBN_mp_toom_mul, /* 55 */
+ TclBN_mp_toom_sqr, /* 56 */
+ TclBN_s_mp_add, /* 57 */
+ TclBN_s_mp_mul_digs, /* 58 */
+ TclBN_s_mp_sqr, /* 59 */
+ TclBN_s_mp_sub, /* 60 */
+};
+
static TclStubHooks tclStubHooks = {
&tclPlatStubs,
&tclIntStubs,
@@ -994,6 +1062,7 @@ TclStubs tclStubs = {
Tcl_GetChannelErrorInterp, /* 563 */
Tcl_SetChannelError, /* 564 */
Tcl_GetChannelError, /* 565 */
+ TclTomMathInitializeStubs, /* 566 */
};
/* !END!: Do not edit above this line. */
diff --git a/generic/tclStubLib.c b/generic/tclStubLib.c
index 3b44f98..133de97 100644
--- a/generic/tclStubLib.c
+++ b/generic/tclStubLib.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclStubLib.c,v 1.11 2005/11/27 02:33:49 das Exp $
+ * RCS: @(#) $Id: tclStubLib.c,v 1.12 2005/12/13 22:43:18 kennykb Exp $
*/
/*
@@ -36,11 +36,13 @@ MODULE_SCOPE TclStubs *tclStubsPtr;
MODULE_SCOPE TclPlatStubs *tclPlatStubsPtr;
MODULE_SCOPE TclIntStubs *tclIntStubsPtr;
MODULE_SCOPE TclIntPlatStubs *tclIntPlatStubsPtr;
+MODULE_SCOPE TclTomMathStubs *tclTomMathStubsPtr;
TclStubs *tclStubsPtr = NULL;
TclPlatStubs *tclPlatStubsPtr = NULL;
TclIntStubs *tclIntStubsPtr = NULL;
TclIntPlatStubs *tclIntPlatStubsPtr = NULL;
+TclTomMathStubs* tclTomMathStubsPtr = NULL;
static TclStubs *
HasStubSupport(
@@ -118,3 +120,63 @@ Tcl_InitStubs(
return actualVersion;
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclTomMathInitStubs --
+ *
+ * Initializes the Stubs table for Tcl's subset of libtommath
+ *
+ * Results:
+ * Returns a standard Tcl result.
+ *
+ * This procedure should not be called directly, but rather through
+ * the TclTomMath_InitStubs macro, to insure that the Stubs table
+ * matches the header files used in compilation.
+ *
+ * This procedure assumes that Tcl_InitStubs has been called first.
+ * Hence, it appears in Tcl's internal Stubs table.
+ *
+ *----------------------------------------------------------------------
+ */
+
+#ifdef TclTomMathInitializeStubs
+#undef TclTomMathInitializeStubs
+#endif
+
+const char*
+TclTomMathInitializeStubs(
+ Tcl_Interp* interp, /* Tcl interpreter */
+ CONST char* version, /* Tcl version needed */
+ int epoch, /* Stubs table epoch from the header files */
+ int revision /* Stubs table revision number from the
+ * header files */
+) {
+ int exact = 0;
+ const char* packageName = "tcl::tommath";
+ const char* errMsg = NULL;
+ ClientData pkgClientData = NULL;
+ const char* actualVersion =
+ Tcl_PkgRequireEx(interp, packageName, version, exact, &pkgClientData);
+ TclTomMathStubs* stubsPtr = (TclTomMathStubs*) pkgClientData;
+ if (actualVersion == NULL) {
+ return NULL;
+ }
+ if (pkgClientData == NULL) {
+ errMsg = "missing stub täble pointer";
+ } else if ((stubsPtr->tclBN_epoch)() != epoch) {
+ errMsg = "epoch number mismatch";
+ } else if ((stubsPtr->tclBN_revision)() != revision) {
+ errMsg = "requires a later revision";
+ } else {
+ tclTomMathStubsPtr = stubsPtr;
+ return actualVersion;
+ }
+ Tcl_ResetResult(interp);
+ Tcl_AppendResult(interp, "error loading ", packageName,
+ " (requested version ", version,
+ ", actual version ", actualVersion,
+ "): ", errMsg, NULL);
+ return NULL;
+}
diff --git a/generic/tclTimer.c b/generic/tclTimer.c
index 6c07717..b867287 100644
--- a/generic/tclTimer.c
+++ b/generic/tclTimer.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclTimer.c,v 1.21 2005/11/09 21:28:36 kennykb Exp $
+ * RCS: @(#) $Id: tclTimer.c,v 1.22 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
@@ -830,7 +830,7 @@ Tcl_AfterObjCmd(
* to wait, or else index is the index of a subcommand.
*/
- switch ((enum afterSubCmds) index) {
+ switch (index) {
case -1: {
if (ms < 0) {
ms = 0;
diff --git a/generic/tclTomMath.decls b/generic/tclTomMath.decls
new file mode 100644
index 0000000..d68f512
--- /dev/null
+++ b/generic/tclTomMath.decls
@@ -0,0 +1,214 @@
+# tclTomMath.decls --
+#
+# This file contains the declarations for the functions in
+# 'libtommath' that are contained within the Tcl library.
+# This file is used to generate the 'tclTomMathDecls.h' and
+# 'tclTomMathStub.c' files.
+#
+# If you edit this file, advance the revision number (and the epoch
+# if the new stubs are not backward compatible) in tclTomMathDecls.h
+#
+# Copyright (c) 2005 by Kevin B. Kenny. All rights reserved.
+#
+# See the file "license.terms" for information on usage and redistribution
+# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+#
+# RCS: @(#) $Id: tclTomMath.decls,v 1.1 2005/12/13 22:43:18 kennykb Exp $
+
+library tcl
+
+# Define the unsupported generic interfaces.
+
+interface tclTomMath
+# hooks {tclTomMathInt}
+
+# Declare each of the functions in the Tcl tommath interface
+
+declare 0 generic {
+ int TclBN_epoch(void)
+}
+declare 1 generic {
+ int TclBN_revision(void)
+}
+
+declare 2 generic {
+ int TclBN_mp_add(mp_int* a, mp_int* b, mp_int* c)
+}
+declare 3 generic {
+ int TclBN_mp_add_d(mp_int* a, mp_digit b, mp_int* c)
+}
+declare 4 generic {
+ int TclBN_mp_and(mp_int* a, mp_int* b, mp_int* c)
+}
+declare 5 generic {
+ void TclBN_mp_clamp(mp_int* a)
+}
+declare 6 generic {
+ void TclBN_mp_clear(mp_int* a)
+}
+declare 7 generic {
+ void TclBN_mp_clear_multi(mp_int* a, ...)
+}
+declare 8 generic {
+ int TclBN_mp_cmp(mp_int* a, mp_int* b)
+}
+declare 9 generic {
+ int TclBN_mp_cmp_d(mp_int* a, mp_digit b)
+}
+declare 10 generic {
+ int TclBN_mp_cmp_mag(mp_int* a, mp_int* b)
+}
+declare 11 generic {
+ int TclBN_mp_copy(mp_int* a, mp_int* b)
+}
+declare 12 generic {
+ int TclBN_mp_count_bits(mp_int* a)
+}
+declare 13 generic {
+ int TclBN_mp_div(mp_int* a, mp_int* b, mp_int* q, mp_int* r)
+}
+declare 14 generic {
+ int TclBN_mp_div_d(mp_int* a, mp_digit b, mp_int* q, mp_digit* r)
+}
+declare 15 generic {
+ int TclBN_mp_div_2(mp_int* a, mp_int* q)
+}
+declare 16 generic {
+ int TclBN_mp_div_2d(mp_int* a, int b, mp_int* q, mp_int* r)
+}
+declare 17 generic {
+ int TclBN_mp_div_3(mp_int* a, mp_int* q, mp_digit* r)
+}
+declare 18 generic {
+ void TclBN_mp_exch(mp_int* a, mp_int* b)
+}
+declare 19 generic {
+ int TclBN_mp_expt_d(mp_int* a, mp_digit b, mp_int* c)
+}
+declare 20 generic {
+ int TclBN_mp_grow(mp_int* a, int size)
+}
+declare 21 generic {
+ int TclBN_mp_init(mp_int* a)
+}
+declare 22 generic {
+ int TclBN_mp_init_copy(mp_int * a, mp_int* b)
+}
+declare 23 generic {
+ int TclBN_mp_init_multi(mp_int* a, ...)
+}
+declare 24 generic {
+ int TclBN_mp_init_set(mp_int* a, mp_digit b)
+}
+declare 25 generic {
+ int TclBN_mp_init_size(mp_int* a, int size)
+}
+declare 26 generic {
+ int TclBN_mp_lshd(mp_int* a, int shift)
+}
+declare 27 generic {
+ int TclBN_mp_mod(mp_int* a, mp_int* b, mp_int* r)
+}
+declare 28 generic {
+ int TclBN_mp_mod_2d(mp_int* a, int b, mp_int* r)
+}
+declare 29 generic {
+ int TclBN_mp_mul(mp_int* a, mp_int* b, mp_int* p)
+}
+declare 30 generic {
+ int TclBN_mp_mul_d(mp_int* a, mp_digit b, mp_int* p)
+}
+declare 31 generic {
+ int TclBN_mp_mul_2(mp_int* a, mp_int* p)
+}
+declare 32 generic {
+ int TclBN_mp_mul_2d(mp_int* a, int d, mp_int* p)
+}
+declare 33 generic {
+ int TclBN_mp_neg(mp_int* a, mp_int* b)
+}
+declare 34 generic {
+ int TclBN_mp_or(mp_int* a, mp_int* b, mp_int* c)
+}
+declare 35 generic {
+ int TclBN_mp_radix_size(mp_int* a, int radix, int* size)
+}
+declare 36 generic {
+ int TclBN_mp_read_radix(mp_int* a, const char* str, int radix)
+}
+declare 37 generic {
+ void TclBN_mp_rshd(mp_int * a, int shift)
+}
+declare 38 generic {
+ int TclBN_mp_shrink(mp_int* a)
+}
+declare 39 generic {
+ void TclBN_mp_set(mp_int* a, mp_digit b)
+}
+declare 40 generic {
+ int TclBN_mp_sqr(mp_int* a, mp_int* b)
+}
+declare 41 generic {
+ int TclBN_mp_sqrt(mp_int* a, mp_int* b)
+}
+declare 42 generic {
+ int TclBN_mp_sub(mp_int* a, mp_int* b, mp_int* c)
+}
+declare 43 generic {
+ int TclBN_mp_sub_d(mp_int* a, mp_digit b, mp_int* c)
+}
+declare 44 generic {
+ int TclBN_mp_to_unsigned_bin(mp_int* a, unsigned char* b)
+}
+declare 45 generic {
+ int TclBN_mp_to_unsigned_bin_n(mp_int* a, unsigned char* b, unsigned long* outlen)
+}
+declare 46 generic {
+ int TclBN_mp_toradix_n(mp_int* a, char* str, int radix, int maxlen)
+}
+declare 47 generic {
+ int TclBN_mp_unsigned_bin_size(mp_int* a)
+}
+declare 48 generic {
+ int TclBN_mp_xor(mp_int* a, mp_int* b, mp_int* c)
+}
+declare 49 generic {
+ void TclBN_mp_zero(mp_int* a)
+}
+
+# internal routines to libtommath - should not be called but must be
+# exported to accommodate the "tommath" extension
+
+declare 50 generic {
+ void TclBN_reverse(unsigned char* s, int len)
+}
+declare 51 generic {
+ int TclBN_fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs)
+}
+declare 52 generic {
+ int TclBN_fast_s_mp_sqr(mp_int* a, mp_int* b)
+}
+declare 53 generic {
+ int TclBN_mp_karatsuba_mul(mp_int* a, mp_int* b, mp_int* c)
+}
+declare 54 generic {
+ int TclBN_mp_karatsuba_sqr(mp_int* a, mp_int* b)
+}
+declare 55 generic {
+ int TclBN_mp_toom_mul(mp_int* a, mp_int* b, mp_int* c)
+}
+declare 56 generic {
+ int TclBN_mp_toom_sqr(mp_int* a, mp_int* b)
+}
+declare 57 generic {
+ int TclBN_s_mp_add(mp_int* a, mp_int* b, mp_int* c)
+}
+declare 58 generic {
+ int TclBN_s_mp_mul_digs(mp_int* a, mp_int* b, mp_int* c, int digs)
+}
+declare 59 generic {
+ int TclBN_s_mp_sqr(mp_int* a, mp_int* b)
+}
+declare 60 generic {
+ int TclBN_s_mp_sub(mp_int* a, mp_int* b, mp_int* c)
+}
diff --git a/generic/tclTomMath.h b/generic/tclTomMath.h
index a807e10..2ecc3c5 100644
--- a/generic/tclTomMath.h
+++ b/generic/tclTomMath.h
@@ -1,130 +1,844 @@
-/*
- * tclTomMath.h --
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
*
- * Interface information that comes in at the head of
- * <tommath.h> to adapt the API to Tcl's linkage conventions.
+ * LibTomMath is a library that provides multiple-precision
+ * integer arithmetic as well as number theoretic functionality.
*
- * Copyright (c) 2005 by Kevin B. Kenny. All rights reserved.
+ * The library was designed directly after the MPI library by
+ * Michael Fromberger but has been written from scratch with
+ * additional optimizations in place.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * The library is free for all purposes without any express
+ * guarantee it works.
*
- * RCS: @(#) $Id: tclTomMath.h,v 1.4 2005/10/08 14:42:45 dgp Exp $
+ * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
*/
+#ifndef BN_H_
+#define BN_H_
-#ifndef TCLTOMMATH_H
-#define TCLTOMMATH_H 1
+#include <tclTomMathDecls.h>
+#ifndef MODULE_SCOPE
+#define MODULE_SCOPE extern
+#endif
-#include <tcl.h>
+#include <stdio.h>
+#include <string.h>
#include <stdlib.h>
+#include <ctype.h>
+#include <limits.h>
+
+#include <tommath_class.h>
+
+#ifndef MIN
+ #define MIN(x,y) ((x)<(y)?(x):(y))
+#endif
+#ifndef MAX
+ #define MAX(x,y) ((x)>(y)?(x):(y))
+#endif
+
+#ifdef __cplusplus
+extern "C" {
-/* Define TOMMATH_DLLIMPORT and TOMMATH_DLLEXPORT to suit the compiler */
+/* C++ compilers don't like assigning void * to mp_digit * */
+#define OPT_CAST(x) (x *)
-#ifdef STATIC_BUILD
-# define TOMMATH_DLLIMPORT
-# define TOMMATH_DLLEXPORT
#else
-# if (defined(__WIN32__) && (defined(_MSC_VER) || (__BORLANDC__ >= 0x0550) || defined(__LCC__) || defined(__WATCOMC__) || (defined(__GNUC__) && defined(__declspec))))
-# define TOMMATH_DLLIMPORT __declspec(dllimport)
-# define TOMMATH_DLLEXPORT __declspec(dllexport)
-# else
-# define TOMMATH_DLLIMPORT
-# define TOMMATH_DLLEXPORT
-# endif
+
+/* C on the other hand doesn't care */
+#define OPT_CAST(x)
+
#endif
-/* Define TOMMATH_STORAGE_CLASS according to the build options. */
-#undef TOMMATH_STORAGE_CLASS
-#ifdef BUILD_tcl
-# define TOMMATH_STORAGE_CLASS TOMMATH_DLLEXPORT
+/* detect 64-bit mode if possible */
+#if defined(__x86_64__)
+ #if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
+ #define MP_64BIT
+ #endif
+#endif
+
+/* some default configurations.
+ *
+ * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
+ * A "mp_word" must be able to hold 2*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
+#ifndef MP_DIGIT_DECLARED
+ typedef unsigned char mp_digit;
+#define MP_DIGIT_DECLARED
+#endif
+ typedef unsigned short mp_word;
+#elif defined(MP_16BIT)
+#ifndef MP_DIGIT_DECLARED
+ typedef unsigned short mp_digit;
+#define MP_DIGIT_DECLARED
+#endif
+ typedef unsigned long mp_word;
+#elif defined(MP_64BIT)
+ /* for GCC only on supported platforms */
+#ifndef CRYPT
+ typedef unsigned long long ulong64;
+ typedef signed long long long64;
+#endif
+
+#ifndef MP_DIGIT_DECLARED
+ typedef unsigned long mp_digit;
+#define MP_DIGIT_DECLARED
+#endif
+ typedef unsigned long mp_word __attribute__ ((mode(TI)));
+
+ #define DIGIT_BIT 60
#else
-# ifdef USE_TCL_STUBS
-# define TOMMATH_STORAGE_CLASS
-# else
-# define TOMMATH_STORAGE_CLASS TOMMATH_DLLIMPORT
-# endif
-#endif
-
-/* Define custom memory allocation for libtommath */
-
-#define XMALLOC(x) TclBNAlloc(x)
-#define XFREE(x) TclBNFree(x)
-#define XREALLOC(x,n) TclBNRealloc(x,n)
-#define XCALLOC(n,x) TclBNCalloc(n,x)
-void* TclBNAlloc( size_t );
-void* TclBNRealloc( void*, size_t );
-void TclBNFree( void* );
-void* TclBNCalloc( size_t, size_t );
-
-/* Rename all global symboles in libtommath to avoid linkage conflicts */
-
-#define KARATSUBA_MUL_CUTOFF TclBNKaratsubaMulCutoff
-#define KARATSUBA_SQR_CUTOFF TclBNKaratsubaSqrCutoff
-#define TOOM_MUL_CUTOFF TclBNToomMulCutoff
-#define TOOM_SQR_CUTOFF TclBNToomSqrCutoff
-
-#define mp_s_rmap TclBNMpSRmap
-
-#define bn_reverse TclBN_reverse
-#define fast_s_mp_mul_digs TclBN_fast_s_mp_mul_digs
-#define fast_s_mp_sqr TclBN_fast_s_mp_sqr
-#define mp_add TclBN_mp_add
-#define mp_add_d TclBN_mp_add_d
-#define mp_and TclBN_mp_and
-#define mp_clamp TclBN_mp_clamp
-#define mp_clear TclBN_mp_clear
-#define mp_clear_multi TclBN_mp_clear_multi
-#define mp_cmp TclBN_mp_cmp
-#define mp_cmp_d TclBN_mp_cmp_d
-#define mp_cmp_mag TclBN_mp_cmp_mag
-#define mp_copy TclBN_mp_copy
-#define mp_count_bits TclBN_mp_count_bits
-#define mp_div TclBN_mp_div
-#define mp_div_d TclBN_mp_div_d
-#define mp_div_2 TclBN_mp_div_2
-#define mp_div_2d TclBN_mp_div_2d
-#define mp_div_3 TclBN_mp_div_3
-#define mp_exch TclBN_mp_exch
-#define mp_expt_d TclBN_mp_expt_d
-#define mp_grow TclBN_mp_grow
-#define mp_init TclBN_mp_init
-#define mp_init_copy TclBN_mp_init_copy
-#define mp_init_multi TclBN_mp_init_multi
-#define mp_init_set TclBN_mp_init_set
-#define mp_init_size TclBN_mp_init_size
-#define mp_karatsuba_mul TclBN_mp_karatsuba_mul
-#define mp_karatsuba_sqr TclBN_mp_karatsuba_sqr
-#define mp_lshd TclBN_mp_lshd
-#define mp_mod TclBN_mp_mod
-#define mp_mod_2d TclBN_mp_mod_2d
-#define mp_mul TclBN_mp_mul
-#define mp_mul_2 TclBN_mp_mul_2
-#define mp_mul_2d TclBN_mp_mul_2d
-#define mp_mul_d TclBN_mp_mul_d
-#define mp_neg TclBN_mp_neg
-#define mp_or TclBN_mp_or
-#define mp_radix_size TclBN_mp_radix_size
-#define mp_read_radix TclBN_mp_read_radix
-#define mp_rshd TclBN_mp_rshd
-#define mp_shrink TclBN_mp_shrink
-#define mp_set TclBN_mp_set
-#define mp_sqr TclBN_mp_sqr
-#define mp_sqrt TclBN_mp_sqrt
-#define mp_sub TclBN_mp_sub
-#define mp_sub_d TclBN_mp_sub_d
-#define mp_to_unsigned_bin TclBN_mp_to_unsigned_bin
-#define mp_to_unsigned_bin_n TclBN_mp_to_unsigned_bin_n
-#define mp_toom_mul TclBN_mp_toom_mul
-#define mp_toom_sqr TclBN_mp_toom_sqr
-#define mp_toradix_n TclBN_mp_toradix_n
-#define mp_unsigned_bin_size TclBN_mp_unsigned_bin_size
-#define mp_xor TclBN_mp_xor
-#define mp_zero TclBN_mp_zero
-#define s_mp_add TclBN_s_mp_add
-#define s_mp_mul_digs TclBN_s_mp_mul_digs
-#define s_mp_sqr TclBN_s_mp_sqr
-#define s_mp_sub TclBN_s_mp_sub
+ /* this is the default case, 28-bit digits */
+
+ /* this is to make porting into LibTomCrypt easier :-) */
+#ifndef CRYPT
+ #if defined(_MSC_VER) || defined(__BORLANDC__)
+ typedef unsigned __int64 ulong64;
+ typedef signed __int64 long64;
+ #else
+ typedef unsigned long long ulong64;
+ typedef signed long long long64;
+ #endif
+#endif
+
+#ifndef MP_DIGIT_DECLARED
+ typedef unsigned long mp_digit;
+#define MP_DIGIT_DECLARED
+#endif
+ typedef ulong64 mp_word;
+
+#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
+
+/* define heap macros */
+#if 0 /* these are macros in tclTomMathDecls.h */
+#ifndef CRYPT
+ /* default to libc stuff */
+ #ifndef XMALLOC
+ #define XMALLOC malloc
+ #define XFREE free
+ #define XREALLOC realloc
+ #define XCALLOC calloc
+ #else
+ /* 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
+#endif
+#endif
+
+
+/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
+#ifndef DIGIT_BIT
+ #define DIGIT_BIT ((int)((CHAR_BIT * sizeof(mp_digit) - 1))) /* bits per digit */
+#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 */
+#define MP_EQ 0 /* equal to */
+#define MP_GT 1 /* greater than */
+
+#define MP_ZPOS 0 /* positive integer */
+#define MP_NEG 1 /* negative */
+
+#define MP_OKAY 0 /* ok result */
+#define MP_MEM -2 /* out of mem */
+#define MP_VAL -3 /* invalid input */
+#define MP_RANGE MP_VAL
+
+#define MP_YES 1 /* yes response */
+#define MP_NO 0 /* no response */
+/* Primality generation flags */
+#define LTM_PRIME_BBS 0x0001 /* BBS style prime */
+#define LTM_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
+#define LTM_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
+
+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;
+#endif
+
+/* define this to use lower memory usage routines (exptmods mostly) */
+/* #define MP_LOW_MEM */
+
+/* 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
#endif
+
+/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
+#define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
+
+/* the infamous mp_int structure */
+#ifndef MP_INT_DECLARED
+#define MP_INT_DECLARED
+typedef struct mp_int mp_int;
+#endif
+struct mp_int {
+ 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)
+
+/* error code to char* string */
+/*
+char *mp_error_to_string(int code);
+*/
+
+/* ---> init and deinit bignum functions <--- */
+/* init a bignum */
+/*
+int mp_init(mp_int *a);
+*/
+
+/* free a bignum */
+/*
+void mp_clear(mp_int *a);
+*/
+
+/* init a null terminated series of arguments */
+/*
+int mp_init_multi(mp_int *mp, ...);
+*/
+
+/* clear a null terminated series of arguments */
+/*
+void mp_clear_multi(mp_int *mp, ...);
+*/
+
+/* exchange two ints */
+/*
+void mp_exch(mp_int *a, mp_int *b);
+*/
+
+/* shrink ram required for a bignum */
+/*
+int mp_shrink(mp_int *a);
+*/
+
+/* grow an int to a given size */
+/*
+int mp_grow(mp_int *a, int size);
+*/
+
+/* init to a given number of digits */
+/*
+int mp_init_size(mp_int *a, int size);
+*/
+
+/* ---> Basic Manipulations <--- */
+#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
+#define mp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
+#define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
+
+/* set to zero */
+/*
+void mp_zero(mp_int *a);
+*/
+
+/* set to a digit */
+/*
+void mp_set(mp_int *a, mp_digit b);
+*/
+
+/* set a 32-bit const */
+/*
+int mp_set_int(mp_int *a, unsigned long b);
+*/
+
+/* get a 32-bit value */
+unsigned long mp_get_int(mp_int * a);
+
+/* initialize and set a digit */
+/*
+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);
+*/
+
+/* copy, b = a */
+/*
+int mp_copy(mp_int *a, mp_int *b);
+*/
+
+/* inits and copies, a = b */
+/*
+int mp_init_copy(mp_int *a, mp_int *b);
+*/
+
+/* trim unused digits */
+/*
+void mp_clamp(mp_int *a);
+*/
+
+/* ---> digit manipulation <--- */
+
+/* right shift by "b" digits */
+/*
+void mp_rshd(mp_int *a, int b);
+*/
+
+/* left shift by "b" digits */
+/*
+int mp_lshd(mp_int *a, int b);
+*/
+
+/* c = a / 2**b */
+/*
+int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d);
+*/
+
+/* b = a/2 */
+/*
+int mp_div_2(mp_int *a, mp_int *b);
+*/
+
+/* c = a * 2**b */
+/*
+int mp_mul_2d(mp_int *a, int b, mp_int *c);
+*/
+
+/* b = a*2 */
+/*
+int mp_mul_2(mp_int *a, mp_int *b);
+*/
+
+/* c = a mod 2**d */
+/*
+int mp_mod_2d(mp_int *a, int b, mp_int *c);
+*/
+
+/* computes a = 2**b */
+/*
+int mp_2expt(mp_int *a, int b);
+*/
+
+/* Counts the number of lsbs which are zero before the first zero bit */
+/*
+int mp_cnt_lsb(mp_int *a);
+*/
+
+/* I Love Earth! */
+
+/* makes a pseudo-random int of a given size */
+/*
+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);
+*/
+
+/* c = a OR b */
+/*
+int mp_or(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* c = a AND b */
+/*
+int mp_and(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* ---> Basic arithmetic <--- */
+
+/* b = -a */
+/*
+int mp_neg(mp_int *a, mp_int *b);
+*/
+
+/* b = |a| */
+/*
+int mp_abs(mp_int *a, mp_int *b);
+*/
+
+/* compare a to b */
+/*
+int mp_cmp(mp_int *a, mp_int *b);
+*/
+
+/* compare |a| to |b| */
+/*
+int mp_cmp_mag(mp_int *a, mp_int *b);
+*/
+
+/* c = a + b */
+/*
+int mp_add(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* c = a - b */
+/*
+int mp_sub(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* c = a * b */
+/*
+int mp_mul(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* b = a*a */
+/*
+int mp_sqr(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);
+*/
+
+/* c = a mod b, 0 <= c < b */
+/*
+int mp_mod(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* ---> single digit functions <--- */
+
+/* compare against a single digit */
+/*
+int mp_cmp_d(mp_int *a, mp_digit b);
+*/
+
+/* c = a + b */
+/*
+int mp_add_d(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);
+*/
+
+/* c = a * b */
+/*
+int mp_mul_d(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);
+*/
+
+/* a/3 => 3c + d == a */
+/*
+int mp_div_3(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);
+*/
+
+/* c = a mod b, 0 <= c < b */
+/*
+int mp_mod_d(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);
+*/
+
+/* d = a - b (mod c) */
+/*
+int mp_submod(mp_int *a, mp_int *b, 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);
+*/
+
+/* c = a * a (mod b) */
+/*
+int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* c = 1/a (mod b) */
+/*
+int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* c = (a, b) */
+/*
+int mp_gcd(mp_int *a, 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);
+*/
+
+/* c = [a, b] or (a*b)/(a, b) */
+/*
+int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* finds one of the b'th root of a, such that |c|**b <= |a|
+ *
+ * returns error if a < 0 and b is even
+ */
+/*
+int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
+*/
+
+/* special sqrt algo */
+/*
+int mp_sqrt(mp_int *arg, mp_int *ret);
+*/
+
+/* is number a square? */
+/*
+int mp_is_square(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);
+*/
+
+/* used to setup the Barrett reduction for a given modulus b */
+/*
+int mp_reduce_setup(mp_int *a, mp_int *b);
+*/
+
+/* Barrett Reduction, computes a (mod b) with a precomputed value c
+ *
+ * Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely
+ * compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
+ */
+/*
+int mp_reduce(mp_int *a, mp_int *b, mp_int *c);
+*/
+
+/* setups the montgomery reduction */
+/*
+int mp_montgomery_setup(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);
+*/
+
+/* computes x/R == x (mod N) via Montgomery Reduction */
+/*
+int mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
+*/
+
+/* returns 1 if a is a valid DR modulus */
+/*
+int mp_dr_is_modulus(mp_int *a);
+*/
+
+/* sets the value of "d" required for mp_dr_reduce */
+/*
+void mp_dr_setup(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);
+*/
+
+/* returns true if a can be reduced with mp_reduce_2k */
+/*
+int mp_reduce_is_2k(mp_int *a);
+*/
+
+/* determines k value for 2k reduction */
+/*
+int mp_reduce_2k_setup(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);
+*/
+
+/* returns true if a can be reduced with mp_reduce_2k_l */
+/*
+int mp_reduce_is_2k_l(mp_int *a);
+*/
+
+/* determines k value for 2k reduction */
+/*
+int mp_reduce_2k_setup_l(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);
+*/
+
+/* d = a**b (mod c) */
+/*
+int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
+*/
+
+/* ---> Primes <--- */
+
+/* number of primes */
+#ifdef MP_8BIT
+ #define PRIME_SIZE 31
+#else
+ #define PRIME_SIZE 256
+#endif
+
+/* table of first PRIME_SIZE primes */
+#if defined(BUILD_tcl) || !defined(_WIN32)
+MODULE_SCOPE const mp_digit ltm_prime_tab[];
+#endif
+
+/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
+/*
+int mp_prime_is_divisible(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);
+*/
+
+/* 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);
+*/
+
+/* This gives [for a given bit size] the number of trials required
+ * such that Miller-Rabin gives a prob of failure lower than 2^-96
+ */
+/*
+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
+ * division. Determines if "a" is prime with probability
+ * of error no more than (1/4)**t.
+ *
+ * Sets result to 1 if probably prime, 0 otherwise
+ */
+/*
+int mp_prime_is_prime(mp_int *a, int t, int *result);
+*/
+
+/* finds the next prime after the number "a" using "t" trials
+ * of Miller-Rabin.
+ *
+ * bbs_style = 1 means the prime must be congruent to 3 mod 4
+ */
+/*
+int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
+*/
+
+/* 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_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
+
+/* makes a truly random prime of a given size (bits),
+ *
+ * Flags are as follows:
+ *
+ * LTM_PRIME_BBS - make prime congruent to 3 mod 4
+ * LTM_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
+ * LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
+ * LTM_PRIME_2MSB_ON - make the 2nd highest bit one
+ *
+ * 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
+ *
+ */
+/*
+int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
+*/
+
+/* ---> radix conversion <--- */
+/*
+int mp_count_bits(mp_int *a);
+*/
+
+/*
+int mp_unsigned_bin_size(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_n (mp_int * a, unsigned char *b, unsigned long *outlen);
+*/
+
+/*
+int mp_signed_bin_size(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_n (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_n(mp_int * a, char *str, int radix, int maxlen);
+*/
+/*
+int mp_radix_size(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);
+*/
+
+#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
+#define mp_raw_size(mp) mp_signed_bin_size(mp)
+#define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
+#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
+#define mp_mag_size(mp) mp_unsigned_bin_size(mp)
+#define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
+
+#define mp_tobinary(M, S) mp_toradix((M), (S), 2)
+#define mp_tooctal(M, S) mp_toradix((M), (S), 8)
+#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
+#define mp_tohex(M, S) mp_toradix((M), (S), 16)
+
+/* lowlevel functions, do not call! */
+/*
+int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
+*/
+/*
+int s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
+*/
+#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
+/*
+int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
+*/
+/*
+int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
+*/
+/*
+int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
+*/
+/*
+int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
+*/
+/*
+int fast_s_mp_sqr(mp_int *a, mp_int *b);
+*/
+/*
+int s_mp_sqr(mp_int *a, mp_int *b);
+*/
+/*
+int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
+*/
+/*
+int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
+*/
+/*
+int mp_karatsuba_sqr(mp_int *a, mp_int *b);
+*/
+/*
+int mp_toom_sqr(mp_int *a, mp_int *b);
+*/
+/*
+int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
+*/
+/*
+int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
+*/
+/*
+int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
+*/
+/*
+int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
+*/
+/*
+int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int mode);
+*/
+/*
+void bn_reverse(unsigned char *s, int len);
+*/
+
+#if defined(BUILD_tcl) || !defined(_WIN32)
+MODULE_SCOPE const char *mp_s_rmap;
+#endif
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif
+
+
+/* $Source: /root/tcl/repos-to-convert/tcl/generic/tclTomMath.h,v $ */
+/* $Revision: 1.5 $ */
+/* $Date: 2005/12/13 22:43:18 $ */
+
diff --git a/generic/tclTomMathDecls.h b/generic/tclTomMathDecls.h
new file mode 100644
index 0000000..598f3f7
--- /dev/null
+++ b/generic/tclTomMathDecls.h
@@ -0,0 +1,810 @@
+/*
+ *----------------------------------------------------------------------
+ *
+ * tclTomMathDecls.h --
+ *
+ * This file contains the declarations for the 'libtommath'
+ * functions that are exported by the Tcl library.
+ *
+ * Copyright (c) 2005 by Kevin B. Kenny. All rights reserved.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ *
+ * RCS: @(#) $Id: tclTomMathDecls.h,v 1.1 2005/12/13 22:43:18 kennykb Exp $
+ */
+
+#ifndef _TCLTOMMATHDECLS
+#define _TCLTOMMATHDECLS
+
+#include "tcl.h"
+
+/*
+ * Define the version of the Stubs table that's exported for tommath
+ */
+
+#define TCLTOMMATH_EPOCH 0
+#define TCLTOMMATH_REVISION 0
+
+#define Tcl_TomMath_InitStubs(interp,version) \
+ (TclTomMathInitializeStubs((interp),(version),\
+ TCLTOMMATH_EPOCH,TCLTOMMATH_REVISION))
+
+/* Define custom memory allocation for libtommath */
+
+/* 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)))
+/* MODULE_SCOPE void* TclBNCalloc( size_t, size_t ); */
+/* unused - no macro */
+
+#define XMALLOC(x) TclBNAlloc(x)
+#define XFREE(x) TclBNFree(x)
+#define XREALLOC(x,n) TclBNRealloc(x,n)
+#define XCALLOC(n,x) TclBNCalloc(n,x)
+
+/* Rename the global symbols in libtommath to avoid linkage conflicts */
+
+#define KARATSUBA_MUL_CUTOFF TclBNKaratsubaMulCutoff
+#define KARATSUBA_SQR_CUTOFF TclBNKaratsubaSqrCutoff
+#define TOOM_MUL_CUTOFF TclBNToomMulCutoff
+#define TOOM_SQR_CUTOFF TclBNToomSqrCutoff
+
+#define bn_reverse TclBN_reverse
+#define fast_s_mp_mul_digs TclBN_fast_s_mp_mul_digs
+#define fast_s_mp_sqr TclBN_fast_s_mp_sqr
+#define mp_add TclBN_mp_add
+#define mp_add_d TclBN_mp_add_d
+#define mp_and TclBN_mp_and
+#define mp_clamp TclBN_mp_clamp
+#define mp_clear TclBN_mp_clear
+#define mp_clear_multi TclBN_mp_clear_multi
+#define mp_cmp TclBN_mp_cmp
+#define mp_cmp_d TclBN_mp_cmp_d
+#define mp_cmp_mag TclBN_mp_cmp_mag
+#define mp_copy TclBN_mp_copy
+#define mp_count_bits TclBN_mp_count_bits
+#define mp_div TclBN_mp_div
+#define mp_div_2 TclBN_mp_div_2
+#define mp_div_2d TclBN_mp_div_2d
+#define mp_div_3 TclBN_mp_div_3
+#define mp_div_d TclBN_mp_div_d
+#define mp_exch TclBN_mp_exch
+#define mp_expt_d TclBN_mp_expt_d
+#define mp_grow TclBN_mp_grow
+#define mp_init TclBN_mp_init
+#define mp_init_copy TclBN_mp_init_copy
+#define mp_init_multi TclBN_mp_init_multi
+#define mp_init_set TclBN_mp_init_set
+#define mp_init_size TclBN_mp_init_size
+#define mp_karatsuba_mul TclBN_mp_karatsuba_mul
+#define mp_karatsuba_sqr TclBN_mp_karatsuba_sqr
+#define mp_lshd TclBN_mp_lshd
+#define mp_mod TclBN_mp_mod
+#define mp_mod_2d TclBN_mp_mod_2d
+#define mp_mul TclBN_mp_mul
+#define mp_mul_2 TclBN_mp_mul_2
+#define mp_mul_2d TclBN_mp_mul_2d
+#define mp_mul_d TclBN_mp_mul_d
+#define mp_neg TclBN_mp_neg
+#define mp_or TclBN_mp_or
+#define mp_radix_size TclBN_mp_radix_size
+#define mp_read_radix TclBN_mp_read_radix
+#define mp_rshd TclBN_mp_rshd
+#define mp_s_rmap TclBNMpSRmap
+#define mp_set TclBN_mp_set
+#define mp_shrink TclBN_mp_shrink
+#define mp_sqr TclBN_mp_sqr
+#define mp_sqrt TclBN_mp_sqrt
+#define mp_sub TclBN_mp_sub
+#define mp_sub_d TclBN_mp_sub_d
+#define mp_to_unsigned_bin TclBN_mp_to_unsigned_bin
+#define mp_to_unsigned_bin_n TclBN_mp_to_unsigned_bin_n
+#define mp_toom_mul TclBN_mp_toom_mul
+#define mp_toom_sqr TclBN_mp_toom_sqr
+#define mp_toradix_n TclBN_mp_toradix_n
+#define mp_unsigned_bin_size TclBN_mp_unsigned_bin_size
+#define mp_xor TclBN_mp_xor
+#define mp_zero TclBN_mp_zero
+#define s_mp_add TclBN_s_mp_add
+#define s_mp_mul_digs TclBN_s_mp_mul_digs
+#define s_mp_sqr TclBN_s_mp_sqr
+#define s_mp_sub TclBN_s_mp_sub
+
+#undef TCL_STORAGE_CLASS
+#ifdef BUILD_tcl
+# define TCL_STORAGE_CLASS DLLEXPORT
+#else
+# ifdef USE_TCL_STUBS
+# define TCL_STORAGE_CLASS
+# else
+# define TCL_STORAGE_CLASS DLLIMPORT
+# endif
+#endif
+
+/*
+ * WARNING: This file is automatically generated by the tools/genStubs.tcl
+ * script. Any modifications to the function declarations below should be made
+ * in the generic/tclInt.decls script.
+ */
+
+/* !BEGIN!: Do not edit below this line. */
+
+/*
+ * Exported function declarations:
+ */
+
+#ifndef TclBN_epoch_TCL_DECLARED
+#define TclBN_epoch_TCL_DECLARED
+/* 0 */
+EXTERN int TclBN_epoch _ANSI_ARGS_((void));
+#endif
+#ifndef TclBN_revision_TCL_DECLARED
+#define TclBN_revision_TCL_DECLARED
+/* 1 */
+EXTERN int TclBN_revision _ANSI_ARGS_((void));
+#endif
+#ifndef TclBN_mp_add_TCL_DECLARED
+#define TclBN_mp_add_TCL_DECLARED
+/* 2 */
+EXTERN int TclBN_mp_add _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* c));
+#endif
+#ifndef TclBN_mp_add_d_TCL_DECLARED
+#define TclBN_mp_add_d_TCL_DECLARED
+/* 3 */
+EXTERN int TclBN_mp_add_d _ANSI_ARGS_((mp_int* a, mp_digit b,
+ mp_int* c));
+#endif
+#ifndef TclBN_mp_and_TCL_DECLARED
+#define TclBN_mp_and_TCL_DECLARED
+/* 4 */
+EXTERN int TclBN_mp_and _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* c));
+#endif
+#ifndef TclBN_mp_clamp_TCL_DECLARED
+#define TclBN_mp_clamp_TCL_DECLARED
+/* 5 */
+EXTERN void TclBN_mp_clamp _ANSI_ARGS_((mp_int* a));
+#endif
+#ifndef TclBN_mp_clear_TCL_DECLARED
+#define TclBN_mp_clear_TCL_DECLARED
+/* 6 */
+EXTERN void TclBN_mp_clear _ANSI_ARGS_((mp_int* a));
+#endif
+#ifndef TclBN_mp_clear_multi_TCL_DECLARED
+#define TclBN_mp_clear_multi_TCL_DECLARED
+/* 7 */
+EXTERN void TclBN_mp_clear_multi _ANSI_ARGS_((mp_int*a, ...));
+#endif
+#ifndef TclBN_mp_cmp_TCL_DECLARED
+#define TclBN_mp_cmp_TCL_DECLARED
+/* 8 */
+EXTERN int TclBN_mp_cmp _ANSI_ARGS_((mp_int* a, mp_int* b));
+#endif
+#ifndef TclBN_mp_cmp_d_TCL_DECLARED
+#define TclBN_mp_cmp_d_TCL_DECLARED
+/* 9 */
+EXTERN int TclBN_mp_cmp_d _ANSI_ARGS_((mp_int* a, mp_digit b));
+#endif
+#ifndef TclBN_mp_cmp_mag_TCL_DECLARED
+#define TclBN_mp_cmp_mag_TCL_DECLARED
+/* 10 */
+EXTERN int TclBN_mp_cmp_mag _ANSI_ARGS_((mp_int* a, mp_int* b));
+#endif
+#ifndef TclBN_mp_copy_TCL_DECLARED
+#define TclBN_mp_copy_TCL_DECLARED
+/* 11 */
+EXTERN int TclBN_mp_copy _ANSI_ARGS_((mp_int* a, mp_int* b));
+#endif
+#ifndef TclBN_mp_count_bits_TCL_DECLARED
+#define TclBN_mp_count_bits_TCL_DECLARED
+/* 12 */
+EXTERN int TclBN_mp_count_bits _ANSI_ARGS_((mp_int* a));
+#endif
+#ifndef TclBN_mp_div_TCL_DECLARED
+#define TclBN_mp_div_TCL_DECLARED
+/* 13 */
+EXTERN int TclBN_mp_div _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* q, mp_int* r));
+#endif
+#ifndef TclBN_mp_div_d_TCL_DECLARED
+#define TclBN_mp_div_d_TCL_DECLARED
+/* 14 */
+EXTERN int TclBN_mp_div_d _ANSI_ARGS_((mp_int* a, mp_digit b,
+ mp_int* q, mp_digit* r));
+#endif
+#ifndef TclBN_mp_div_2_TCL_DECLARED
+#define TclBN_mp_div_2_TCL_DECLARED
+/* 15 */
+EXTERN int TclBN_mp_div_2 _ANSI_ARGS_((mp_int* a, mp_int* q));
+#endif
+#ifndef TclBN_mp_div_2d_TCL_DECLARED
+#define TclBN_mp_div_2d_TCL_DECLARED
+/* 16 */
+EXTERN int TclBN_mp_div_2d _ANSI_ARGS_((mp_int* a, int b,
+ mp_int* q, mp_int* r));
+#endif
+#ifndef TclBN_mp_div_3_TCL_DECLARED
+#define TclBN_mp_div_3_TCL_DECLARED
+/* 17 */
+EXTERN int TclBN_mp_div_3 _ANSI_ARGS_((mp_int* a, mp_int* q,
+ mp_digit* r));
+#endif
+#ifndef TclBN_mp_exch_TCL_DECLARED
+#define TclBN_mp_exch_TCL_DECLARED
+/* 18 */
+EXTERN void TclBN_mp_exch _ANSI_ARGS_((mp_int* a, mp_int* b));
+#endif
+#ifndef TclBN_mp_expt_d_TCL_DECLARED
+#define TclBN_mp_expt_d_TCL_DECLARED
+/* 19 */
+EXTERN int TclBN_mp_expt_d _ANSI_ARGS_((mp_int* a, mp_digit b,
+ mp_int* c));
+#endif
+#ifndef TclBN_mp_grow_TCL_DECLARED
+#define TclBN_mp_grow_TCL_DECLARED
+/* 20 */
+EXTERN int TclBN_mp_grow _ANSI_ARGS_((mp_int* a, int size));
+#endif
+#ifndef TclBN_mp_init_TCL_DECLARED
+#define TclBN_mp_init_TCL_DECLARED
+/* 21 */
+EXTERN int TclBN_mp_init _ANSI_ARGS_((mp_int* a));
+#endif
+#ifndef TclBN_mp_init_copy_TCL_DECLARED
+#define TclBN_mp_init_copy_TCL_DECLARED
+/* 22 */
+EXTERN int TclBN_mp_init_copy _ANSI_ARGS_((mp_int * a,
+ mp_int* b));
+#endif
+#ifndef TclBN_mp_init_multi_TCL_DECLARED
+#define TclBN_mp_init_multi_TCL_DECLARED
+/* 23 */
+EXTERN int TclBN_mp_init_multi _ANSI_ARGS_((mp_int*a, ...));
+#endif
+#ifndef TclBN_mp_init_set_TCL_DECLARED
+#define TclBN_mp_init_set_TCL_DECLARED
+/* 24 */
+EXTERN int TclBN_mp_init_set _ANSI_ARGS_((mp_int* a, mp_digit b));
+#endif
+#ifndef TclBN_mp_init_size_TCL_DECLARED
+#define TclBN_mp_init_size_TCL_DECLARED
+/* 25 */
+EXTERN int TclBN_mp_init_size _ANSI_ARGS_((mp_int* a, int size));
+#endif
+#ifndef TclBN_mp_lshd_TCL_DECLARED
+#define TclBN_mp_lshd_TCL_DECLARED
+/* 26 */
+EXTERN int TclBN_mp_lshd _ANSI_ARGS_((mp_int* a, int shift));
+#endif
+#ifndef TclBN_mp_mod_TCL_DECLARED
+#define TclBN_mp_mod_TCL_DECLARED
+/* 27 */
+EXTERN int TclBN_mp_mod _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* r));
+#endif
+#ifndef TclBN_mp_mod_2d_TCL_DECLARED
+#define TclBN_mp_mod_2d_TCL_DECLARED
+/* 28 */
+EXTERN int TclBN_mp_mod_2d _ANSI_ARGS_((mp_int* a, int b,
+ mp_int* r));
+#endif
+#ifndef TclBN_mp_mul_TCL_DECLARED
+#define TclBN_mp_mul_TCL_DECLARED
+/* 29 */
+EXTERN int TclBN_mp_mul _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* p));
+#endif
+#ifndef TclBN_mp_mul_d_TCL_DECLARED
+#define TclBN_mp_mul_d_TCL_DECLARED
+/* 30 */
+EXTERN int TclBN_mp_mul_d _ANSI_ARGS_((mp_int* a, mp_digit b,
+ mp_int* p));
+#endif
+#ifndef TclBN_mp_mul_2_TCL_DECLARED
+#define TclBN_mp_mul_2_TCL_DECLARED
+/* 31 */
+EXTERN int TclBN_mp_mul_2 _ANSI_ARGS_((mp_int* a, mp_int* p));
+#endif
+#ifndef TclBN_mp_mul_2d_TCL_DECLARED
+#define TclBN_mp_mul_2d_TCL_DECLARED
+/* 32 */
+EXTERN int TclBN_mp_mul_2d _ANSI_ARGS_((mp_int* a, int d,
+ mp_int* p));
+#endif
+#ifndef TclBN_mp_neg_TCL_DECLARED
+#define TclBN_mp_neg_TCL_DECLARED
+/* 33 */
+EXTERN int TclBN_mp_neg _ANSI_ARGS_((mp_int* a, mp_int* b));
+#endif
+#ifndef TclBN_mp_or_TCL_DECLARED
+#define TclBN_mp_or_TCL_DECLARED
+/* 34 */
+EXTERN int TclBN_mp_or _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* c));
+#endif
+#ifndef TclBN_mp_radix_size_TCL_DECLARED
+#define TclBN_mp_radix_size_TCL_DECLARED
+/* 35 */
+EXTERN int TclBN_mp_radix_size _ANSI_ARGS_((mp_int* a,
+ int radix, int* size));
+#endif
+#ifndef TclBN_mp_read_radix_TCL_DECLARED
+#define TclBN_mp_read_radix_TCL_DECLARED
+/* 36 */
+EXTERN int TclBN_mp_read_radix _ANSI_ARGS_((mp_int* a,
+ const char* str, int radix));
+#endif
+#ifndef TclBN_mp_rshd_TCL_DECLARED
+#define TclBN_mp_rshd_TCL_DECLARED
+/* 37 */
+EXTERN void TclBN_mp_rshd _ANSI_ARGS_((mp_int * a, int shift));
+#endif
+#ifndef TclBN_mp_shrink_TCL_DECLARED
+#define TclBN_mp_shrink_TCL_DECLARED
+/* 38 */
+EXTERN int TclBN_mp_shrink _ANSI_ARGS_((mp_int* a));
+#endif
+#ifndef TclBN_mp_set_TCL_DECLARED
+#define TclBN_mp_set_TCL_DECLARED
+/* 39 */
+EXTERN void TclBN_mp_set _ANSI_ARGS_((mp_int* a, mp_digit b));
+#endif
+#ifndef TclBN_mp_sqr_TCL_DECLARED
+#define TclBN_mp_sqr_TCL_DECLARED
+/* 40 */
+EXTERN int TclBN_mp_sqr _ANSI_ARGS_((mp_int* a, mp_int* b));
+#endif
+#ifndef TclBN_mp_sqrt_TCL_DECLARED
+#define TclBN_mp_sqrt_TCL_DECLARED
+/* 41 */
+EXTERN int TclBN_mp_sqrt _ANSI_ARGS_((mp_int* a, mp_int* b));
+#endif
+#ifndef TclBN_mp_sub_TCL_DECLARED
+#define TclBN_mp_sub_TCL_DECLARED
+/* 42 */
+EXTERN int TclBN_mp_sub _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* c));
+#endif
+#ifndef TclBN_mp_sub_d_TCL_DECLARED
+#define TclBN_mp_sub_d_TCL_DECLARED
+/* 43 */
+EXTERN int TclBN_mp_sub_d _ANSI_ARGS_((mp_int* a, mp_digit b,
+ mp_int* c));
+#endif
+#ifndef TclBN_mp_to_unsigned_bin_TCL_DECLARED
+#define TclBN_mp_to_unsigned_bin_TCL_DECLARED
+/* 44 */
+EXTERN int TclBN_mp_to_unsigned_bin _ANSI_ARGS_((mp_int* a,
+ unsigned char* b));
+#endif
+#ifndef TclBN_mp_to_unsigned_bin_n_TCL_DECLARED
+#define TclBN_mp_to_unsigned_bin_n_TCL_DECLARED
+/* 45 */
+EXTERN int TclBN_mp_to_unsigned_bin_n _ANSI_ARGS_((mp_int* a,
+ unsigned char* b, unsigned long* outlen));
+#endif
+#ifndef TclBN_mp_toradix_n_TCL_DECLARED
+#define TclBN_mp_toradix_n_TCL_DECLARED
+/* 46 */
+EXTERN int TclBN_mp_toradix_n _ANSI_ARGS_((mp_int* a, char* str,
+ int radix, int maxlen));
+#endif
+#ifndef TclBN_mp_unsigned_bin_size_TCL_DECLARED
+#define TclBN_mp_unsigned_bin_size_TCL_DECLARED
+/* 47 */
+EXTERN int TclBN_mp_unsigned_bin_size _ANSI_ARGS_((mp_int* a));
+#endif
+#ifndef TclBN_mp_xor_TCL_DECLARED
+#define TclBN_mp_xor_TCL_DECLARED
+/* 48 */
+EXTERN int TclBN_mp_xor _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* c));
+#endif
+#ifndef TclBN_mp_zero_TCL_DECLARED
+#define TclBN_mp_zero_TCL_DECLARED
+/* 49 */
+EXTERN void TclBN_mp_zero _ANSI_ARGS_((mp_int* a));
+#endif
+#ifndef TclBN_reverse_TCL_DECLARED
+#define TclBN_reverse_TCL_DECLARED
+/* 50 */
+EXTERN void TclBN_reverse _ANSI_ARGS_((unsigned char* s, int len));
+#endif
+#ifndef TclBN_fast_s_mp_mul_digs_TCL_DECLARED
+#define TclBN_fast_s_mp_mul_digs_TCL_DECLARED
+/* 51 */
+EXTERN int TclBN_fast_s_mp_mul_digs _ANSI_ARGS_((mp_int * a,
+ mp_int * b, mp_int * c, int digs));
+#endif
+#ifndef TclBN_fast_s_mp_sqr_TCL_DECLARED
+#define TclBN_fast_s_mp_sqr_TCL_DECLARED
+/* 52 */
+EXTERN int TclBN_fast_s_mp_sqr _ANSI_ARGS_((mp_int* a,
+ mp_int* b));
+#endif
+#ifndef TclBN_mp_karatsuba_mul_TCL_DECLARED
+#define TclBN_mp_karatsuba_mul_TCL_DECLARED
+/* 53 */
+EXTERN int TclBN_mp_karatsuba_mul _ANSI_ARGS_((mp_int* a,
+ mp_int* b, mp_int* c));
+#endif
+#ifndef TclBN_mp_karatsuba_sqr_TCL_DECLARED
+#define TclBN_mp_karatsuba_sqr_TCL_DECLARED
+/* 54 */
+EXTERN int TclBN_mp_karatsuba_sqr _ANSI_ARGS_((mp_int* a,
+ mp_int* b));
+#endif
+#ifndef TclBN_mp_toom_mul_TCL_DECLARED
+#define TclBN_mp_toom_mul_TCL_DECLARED
+/* 55 */
+EXTERN int TclBN_mp_toom_mul _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* c));
+#endif
+#ifndef TclBN_mp_toom_sqr_TCL_DECLARED
+#define TclBN_mp_toom_sqr_TCL_DECLARED
+/* 56 */
+EXTERN int TclBN_mp_toom_sqr _ANSI_ARGS_((mp_int* a, mp_int* b));
+#endif
+#ifndef TclBN_s_mp_add_TCL_DECLARED
+#define TclBN_s_mp_add_TCL_DECLARED
+/* 57 */
+EXTERN int TclBN_s_mp_add _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* c));
+#endif
+#ifndef TclBN_s_mp_mul_digs_TCL_DECLARED
+#define TclBN_s_mp_mul_digs_TCL_DECLARED
+/* 58 */
+EXTERN int TclBN_s_mp_mul_digs _ANSI_ARGS_((mp_int* a,
+ mp_int* b, mp_int* c, int digs));
+#endif
+#ifndef TclBN_s_mp_sqr_TCL_DECLARED
+#define TclBN_s_mp_sqr_TCL_DECLARED
+/* 59 */
+EXTERN int TclBN_s_mp_sqr _ANSI_ARGS_((mp_int* a, mp_int* b));
+#endif
+#ifndef TclBN_s_mp_sub_TCL_DECLARED
+#define TclBN_s_mp_sub_TCL_DECLARED
+/* 60 */
+EXTERN int TclBN_s_mp_sub _ANSI_ARGS_((mp_int* a, mp_int* b,
+ mp_int* c));
+#endif
+
+typedef struct TclTomMathStubs {
+ int magic;
+ struct TclTomMathStubHooks *hooks;
+
+ int (*tclBN_epoch) _ANSI_ARGS_((void)); /* 0 */
+ int (*tclBN_revision) _ANSI_ARGS_((void)); /* 1 */
+ int (*tclBN_mp_add) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c)); /* 2 */
+ int (*tclBN_mp_add_d) _ANSI_ARGS_((mp_int* a, mp_digit b, mp_int* c)); /* 3 */
+ int (*tclBN_mp_and) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c)); /* 4 */
+ void (*tclBN_mp_clamp) _ANSI_ARGS_((mp_int* a)); /* 5 */
+ void (*tclBN_mp_clear) _ANSI_ARGS_((mp_int* a)); /* 6 */
+ void (*tclBN_mp_clear_multi) _ANSI_ARGS_((mp_int*a, ...)); /* 7 */
+ int (*tclBN_mp_cmp) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 8 */
+ int (*tclBN_mp_cmp_d) _ANSI_ARGS_((mp_int* a, mp_digit b)); /* 9 */
+ int (*tclBN_mp_cmp_mag) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 10 */
+ int (*tclBN_mp_copy) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 11 */
+ int (*tclBN_mp_count_bits) _ANSI_ARGS_((mp_int* a)); /* 12 */
+ int (*tclBN_mp_div) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* q, mp_int* r)); /* 13 */
+ int (*tclBN_mp_div_d) _ANSI_ARGS_((mp_int* a, mp_digit b, mp_int* q, mp_digit* r)); /* 14 */
+ int (*tclBN_mp_div_2) _ANSI_ARGS_((mp_int* a, mp_int* q)); /* 15 */
+ int (*tclBN_mp_div_2d) _ANSI_ARGS_((mp_int* a, int b, mp_int* q, mp_int* r)); /* 16 */
+ int (*tclBN_mp_div_3) _ANSI_ARGS_((mp_int* a, mp_int* q, mp_digit* r)); /* 17 */
+ void (*tclBN_mp_exch) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 18 */
+ int (*tclBN_mp_expt_d) _ANSI_ARGS_((mp_int* a, mp_digit b, mp_int* c)); /* 19 */
+ int (*tclBN_mp_grow) _ANSI_ARGS_((mp_int* a, int size)); /* 20 */
+ int (*tclBN_mp_init) _ANSI_ARGS_((mp_int* a)); /* 21 */
+ int (*tclBN_mp_init_copy) _ANSI_ARGS_((mp_int * a, mp_int* b)); /* 22 */
+ int (*tclBN_mp_init_multi) _ANSI_ARGS_((mp_int*a, ...)); /* 23 */
+ int (*tclBN_mp_init_set) _ANSI_ARGS_((mp_int* a, mp_digit b)); /* 24 */
+ int (*tclBN_mp_init_size) _ANSI_ARGS_((mp_int* a, int size)); /* 25 */
+ int (*tclBN_mp_lshd) _ANSI_ARGS_((mp_int* a, int shift)); /* 26 */
+ int (*tclBN_mp_mod) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* r)); /* 27 */
+ int (*tclBN_mp_mod_2d) _ANSI_ARGS_((mp_int* a, int b, mp_int* r)); /* 28 */
+ int (*tclBN_mp_mul) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* p)); /* 29 */
+ int (*tclBN_mp_mul_d) _ANSI_ARGS_((mp_int* a, mp_digit b, mp_int* p)); /* 30 */
+ int (*tclBN_mp_mul_2) _ANSI_ARGS_((mp_int* a, mp_int* p)); /* 31 */
+ int (*tclBN_mp_mul_2d) _ANSI_ARGS_((mp_int* a, int d, mp_int* p)); /* 32 */
+ int (*tclBN_mp_neg) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 33 */
+ int (*tclBN_mp_or) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c)); /* 34 */
+ int (*tclBN_mp_radix_size) _ANSI_ARGS_((mp_int* a, int radix, int* size)); /* 35 */
+ int (*tclBN_mp_read_radix) _ANSI_ARGS_((mp_int* a, const char* str, int radix)); /* 36 */
+ void (*tclBN_mp_rshd) _ANSI_ARGS_((mp_int * a, int shift)); /* 37 */
+ int (*tclBN_mp_shrink) _ANSI_ARGS_((mp_int* a)); /* 38 */
+ void (*tclBN_mp_set) _ANSI_ARGS_((mp_int* a, mp_digit b)); /* 39 */
+ int (*tclBN_mp_sqr) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 40 */
+ int (*tclBN_mp_sqrt) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 41 */
+ int (*tclBN_mp_sub) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c)); /* 42 */
+ int (*tclBN_mp_sub_d) _ANSI_ARGS_((mp_int* a, mp_digit b, mp_int* c)); /* 43 */
+ int (*tclBN_mp_to_unsigned_bin) _ANSI_ARGS_((mp_int* a, unsigned char* b)); /* 44 */
+ int (*tclBN_mp_to_unsigned_bin_n) _ANSI_ARGS_((mp_int* a, unsigned char* b, unsigned long* outlen)); /* 45 */
+ int (*tclBN_mp_toradix_n) _ANSI_ARGS_((mp_int* a, char* str, int radix, int maxlen)); /* 46 */
+ int (*tclBN_mp_unsigned_bin_size) _ANSI_ARGS_((mp_int* a)); /* 47 */
+ int (*tclBN_mp_xor) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c)); /* 48 */
+ void (*tclBN_mp_zero) _ANSI_ARGS_((mp_int* a)); /* 49 */
+ void (*tclBN_reverse) _ANSI_ARGS_((unsigned char* s, int len)); /* 50 */
+ int (*tclBN_fast_s_mp_mul_digs) _ANSI_ARGS_((mp_int * a, mp_int * b, mp_int * c, int digs)); /* 51 */
+ int (*tclBN_fast_s_mp_sqr) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 52 */
+ int (*tclBN_mp_karatsuba_mul) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c)); /* 53 */
+ int (*tclBN_mp_karatsuba_sqr) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 54 */
+ int (*tclBN_mp_toom_mul) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c)); /* 55 */
+ int (*tclBN_mp_toom_sqr) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 56 */
+ int (*tclBN_s_mp_add) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c)); /* 57 */
+ int (*tclBN_s_mp_mul_digs) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c, int digs)); /* 58 */
+ int (*tclBN_s_mp_sqr) _ANSI_ARGS_((mp_int* a, mp_int* b)); /* 59 */
+ int (*tclBN_s_mp_sub) _ANSI_ARGS_((mp_int* a, mp_int* b, mp_int* c)); /* 60 */
+} TclTomMathStubs;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+extern TclTomMathStubs *tclTomMathStubsPtr;
+#ifdef __cplusplus
+}
+#endif
+
+#if defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS)
+
+/*
+ * Inline function declarations:
+ */
+
+#ifndef TclBN_epoch
+#define TclBN_epoch \
+ (tclTomMathStubsPtr->tclBN_epoch) /* 0 */
+#endif
+#ifndef TclBN_revision
+#define TclBN_revision \
+ (tclTomMathStubsPtr->tclBN_revision) /* 1 */
+#endif
+#ifndef TclBN_mp_add
+#define TclBN_mp_add \
+ (tclTomMathStubsPtr->tclBN_mp_add) /* 2 */
+#endif
+#ifndef TclBN_mp_add_d
+#define TclBN_mp_add_d \
+ (tclTomMathStubsPtr->tclBN_mp_add_d) /* 3 */
+#endif
+#ifndef TclBN_mp_and
+#define TclBN_mp_and \
+ (tclTomMathStubsPtr->tclBN_mp_and) /* 4 */
+#endif
+#ifndef TclBN_mp_clamp
+#define TclBN_mp_clamp \
+ (tclTomMathStubsPtr->tclBN_mp_clamp) /* 5 */
+#endif
+#ifndef TclBN_mp_clear
+#define TclBN_mp_clear \
+ (tclTomMathStubsPtr->tclBN_mp_clear) /* 6 */
+#endif
+#ifndef TclBN_mp_clear_multi
+#define TclBN_mp_clear_multi \
+ (tclTomMathStubsPtr->tclBN_mp_clear_multi) /* 7 */
+#endif
+#ifndef TclBN_mp_cmp
+#define TclBN_mp_cmp \
+ (tclTomMathStubsPtr->tclBN_mp_cmp) /* 8 */
+#endif
+#ifndef TclBN_mp_cmp_d
+#define TclBN_mp_cmp_d \
+ (tclTomMathStubsPtr->tclBN_mp_cmp_d) /* 9 */
+#endif
+#ifndef TclBN_mp_cmp_mag
+#define TclBN_mp_cmp_mag \
+ (tclTomMathStubsPtr->tclBN_mp_cmp_mag) /* 10 */
+#endif
+#ifndef TclBN_mp_copy
+#define TclBN_mp_copy \
+ (tclTomMathStubsPtr->tclBN_mp_copy) /* 11 */
+#endif
+#ifndef TclBN_mp_count_bits
+#define TclBN_mp_count_bits \
+ (tclTomMathStubsPtr->tclBN_mp_count_bits) /* 12 */
+#endif
+#ifndef TclBN_mp_div
+#define TclBN_mp_div \
+ (tclTomMathStubsPtr->tclBN_mp_div) /* 13 */
+#endif
+#ifndef TclBN_mp_div_d
+#define TclBN_mp_div_d \
+ (tclTomMathStubsPtr->tclBN_mp_div_d) /* 14 */
+#endif
+#ifndef TclBN_mp_div_2
+#define TclBN_mp_div_2 \
+ (tclTomMathStubsPtr->tclBN_mp_div_2) /* 15 */
+#endif
+#ifndef TclBN_mp_div_2d
+#define TclBN_mp_div_2d \
+ (tclTomMathStubsPtr->tclBN_mp_div_2d) /* 16 */
+#endif
+#ifndef TclBN_mp_div_3
+#define TclBN_mp_div_3 \
+ (tclTomMathStubsPtr->tclBN_mp_div_3) /* 17 */
+#endif
+#ifndef TclBN_mp_exch
+#define TclBN_mp_exch \
+ (tclTomMathStubsPtr->tclBN_mp_exch) /* 18 */
+#endif
+#ifndef TclBN_mp_expt_d
+#define TclBN_mp_expt_d \
+ (tclTomMathStubsPtr->tclBN_mp_expt_d) /* 19 */
+#endif
+#ifndef TclBN_mp_grow
+#define TclBN_mp_grow \
+ (tclTomMathStubsPtr->tclBN_mp_grow) /* 20 */
+#endif
+#ifndef TclBN_mp_init
+#define TclBN_mp_init \
+ (tclTomMathStubsPtr->tclBN_mp_init) /* 21 */
+#endif
+#ifndef TclBN_mp_init_copy
+#define TclBN_mp_init_copy \
+ (tclTomMathStubsPtr->tclBN_mp_init_copy) /* 22 */
+#endif
+#ifndef TclBN_mp_init_multi
+#define TclBN_mp_init_multi \
+ (tclTomMathStubsPtr->tclBN_mp_init_multi) /* 23 */
+#endif
+#ifndef TclBN_mp_init_set
+#define TclBN_mp_init_set \
+ (tclTomMathStubsPtr->tclBN_mp_init_set) /* 24 */
+#endif
+#ifndef TclBN_mp_init_size
+#define TclBN_mp_init_size \
+ (tclTomMathStubsPtr->tclBN_mp_init_size) /* 25 */
+#endif
+#ifndef TclBN_mp_lshd
+#define TclBN_mp_lshd \
+ (tclTomMathStubsPtr->tclBN_mp_lshd) /* 26 */
+#endif
+#ifndef TclBN_mp_mod
+#define TclBN_mp_mod \
+ (tclTomMathStubsPtr->tclBN_mp_mod) /* 27 */
+#endif
+#ifndef TclBN_mp_mod_2d
+#define TclBN_mp_mod_2d \
+ (tclTomMathStubsPtr->tclBN_mp_mod_2d) /* 28 */
+#endif
+#ifndef TclBN_mp_mul
+#define TclBN_mp_mul \
+ (tclTomMathStubsPtr->tclBN_mp_mul) /* 29 */
+#endif
+#ifndef TclBN_mp_mul_d
+#define TclBN_mp_mul_d \
+ (tclTomMathStubsPtr->tclBN_mp_mul_d) /* 30 */
+#endif
+#ifndef TclBN_mp_mul_2
+#define TclBN_mp_mul_2 \
+ (tclTomMathStubsPtr->tclBN_mp_mul_2) /* 31 */
+#endif
+#ifndef TclBN_mp_mul_2d
+#define TclBN_mp_mul_2d \
+ (tclTomMathStubsPtr->tclBN_mp_mul_2d) /* 32 */
+#endif
+#ifndef TclBN_mp_neg
+#define TclBN_mp_neg \
+ (tclTomMathStubsPtr->tclBN_mp_neg) /* 33 */
+#endif
+#ifndef TclBN_mp_or
+#define TclBN_mp_or \
+ (tclTomMathStubsPtr->tclBN_mp_or) /* 34 */
+#endif
+#ifndef TclBN_mp_radix_size
+#define TclBN_mp_radix_size \
+ (tclTomMathStubsPtr->tclBN_mp_radix_size) /* 35 */
+#endif
+#ifndef TclBN_mp_read_radix
+#define TclBN_mp_read_radix \
+ (tclTomMathStubsPtr->tclBN_mp_read_radix) /* 36 */
+#endif
+#ifndef TclBN_mp_rshd
+#define TclBN_mp_rshd \
+ (tclTomMathStubsPtr->tclBN_mp_rshd) /* 37 */
+#endif
+#ifndef TclBN_mp_shrink
+#define TclBN_mp_shrink \
+ (tclTomMathStubsPtr->tclBN_mp_shrink) /* 38 */
+#endif
+#ifndef TclBN_mp_set
+#define TclBN_mp_set \
+ (tclTomMathStubsPtr->tclBN_mp_set) /* 39 */
+#endif
+#ifndef TclBN_mp_sqr
+#define TclBN_mp_sqr \
+ (tclTomMathStubsPtr->tclBN_mp_sqr) /* 40 */
+#endif
+#ifndef TclBN_mp_sqrt
+#define TclBN_mp_sqrt \
+ (tclTomMathStubsPtr->tclBN_mp_sqrt) /* 41 */
+#endif
+#ifndef TclBN_mp_sub
+#define TclBN_mp_sub \
+ (tclTomMathStubsPtr->tclBN_mp_sub) /* 42 */
+#endif
+#ifndef TclBN_mp_sub_d
+#define TclBN_mp_sub_d \
+ (tclTomMathStubsPtr->tclBN_mp_sub_d) /* 43 */
+#endif
+#ifndef TclBN_mp_to_unsigned_bin
+#define TclBN_mp_to_unsigned_bin \
+ (tclTomMathStubsPtr->tclBN_mp_to_unsigned_bin) /* 44 */
+#endif
+#ifndef TclBN_mp_to_unsigned_bin_n
+#define TclBN_mp_to_unsigned_bin_n \
+ (tclTomMathStubsPtr->tclBN_mp_to_unsigned_bin_n) /* 45 */
+#endif
+#ifndef TclBN_mp_toradix_n
+#define TclBN_mp_toradix_n \
+ (tclTomMathStubsPtr->tclBN_mp_toradix_n) /* 46 */
+#endif
+#ifndef TclBN_mp_unsigned_bin_size
+#define TclBN_mp_unsigned_bin_size \
+ (tclTomMathStubsPtr->tclBN_mp_unsigned_bin_size) /* 47 */
+#endif
+#ifndef TclBN_mp_xor
+#define TclBN_mp_xor \
+ (tclTomMathStubsPtr->tclBN_mp_xor) /* 48 */
+#endif
+#ifndef TclBN_mp_zero
+#define TclBN_mp_zero \
+ (tclTomMathStubsPtr->tclBN_mp_zero) /* 49 */
+#endif
+#ifndef TclBN_reverse
+#define TclBN_reverse \
+ (tclTomMathStubsPtr->tclBN_reverse) /* 50 */
+#endif
+#ifndef TclBN_fast_s_mp_mul_digs
+#define TclBN_fast_s_mp_mul_digs \
+ (tclTomMathStubsPtr->tclBN_fast_s_mp_mul_digs) /* 51 */
+#endif
+#ifndef TclBN_fast_s_mp_sqr
+#define TclBN_fast_s_mp_sqr \
+ (tclTomMathStubsPtr->tclBN_fast_s_mp_sqr) /* 52 */
+#endif
+#ifndef TclBN_mp_karatsuba_mul
+#define TclBN_mp_karatsuba_mul \
+ (tclTomMathStubsPtr->tclBN_mp_karatsuba_mul) /* 53 */
+#endif
+#ifndef TclBN_mp_karatsuba_sqr
+#define TclBN_mp_karatsuba_sqr \
+ (tclTomMathStubsPtr->tclBN_mp_karatsuba_sqr) /* 54 */
+#endif
+#ifndef TclBN_mp_toom_mul
+#define TclBN_mp_toom_mul \
+ (tclTomMathStubsPtr->tclBN_mp_toom_mul) /* 55 */
+#endif
+#ifndef TclBN_mp_toom_sqr
+#define TclBN_mp_toom_sqr \
+ (tclTomMathStubsPtr->tclBN_mp_toom_sqr) /* 56 */
+#endif
+#ifndef TclBN_s_mp_add
+#define TclBN_s_mp_add \
+ (tclTomMathStubsPtr->tclBN_s_mp_add) /* 57 */
+#endif
+#ifndef TclBN_s_mp_mul_digs
+#define TclBN_s_mp_mul_digs \
+ (tclTomMathStubsPtr->tclBN_s_mp_mul_digs) /* 58 */
+#endif
+#ifndef TclBN_s_mp_sqr
+#define TclBN_s_mp_sqr \
+ (tclTomMathStubsPtr->tclBN_s_mp_sqr) /* 59 */
+#endif
+#ifndef TclBN_s_mp_sub
+#define TclBN_s_mp_sub \
+ (tclTomMathStubsPtr->tclBN_s_mp_sub) /* 60 */
+#endif
+
+#endif /* defined(USE_TCL_STUBS) && !defined(USE_TCL_STUB_PROCS) */
+
+/* !END!: Do not edit above this line. */
+
+#undef TCL_STORAGE_CLASS
+#define TCL_STORAGE_CLASS DLLIMPORT
+
+#endif /* _TCLINTDECLS */
diff --git a/generic/tclTomMathInterface.c b/generic/tclTomMathInterface.c
index bf62963..65eddcf 100644
--- a/generic/tclTomMathInterface.c
+++ b/generic/tclTomMathInterface.c
@@ -11,12 +11,86 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclTomMathInterface.c,v 1.5 2005/10/13 00:14:38 dgp Exp $
+ * RCS: @(#) $Id: tclTomMathInterface.c,v 1.6 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
#include "tommath.h"
#include <limits.h>
+
+extern TclTomMathStubs tclTomMathStubs;
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclTommath_Init --
+ *
+ * Initializes the TclTomMath 'package', which exists as a
+ * placeholder so that the package data can be used to hold
+ * a stub table pointer.
+ *
+ * Results:
+ * Returns a standard Tcl result.
+ *
+ * Side effects:
+ * Installs the stub table for tommath.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclTommath_Init(
+ Tcl_Interp* interp /* Tcl interpreter */
+) {
+ if (Tcl_PkgProvideEx(interp, "tcl::tommath", TCL_VERSION,
+ (ClientData)&tclTomMathStubs) != TCL_OK) {
+ return TCL_ERROR;
+ }
+ return TCL_OK;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclBN_epoch --
+ *
+ * Return the epoch number of the TclTomMath stubs table
+ *
+ * Results:
+ * Returns an arbitrary integer that does not decrease with
+ * release. Stubs tables with different epochs are incompatible.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclBN_epoch()
+{
+ return TCLTOMMATH_EPOCH;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * TclBN_revision --
+ *
+ * Returns the revision level of the TclTomMath stubs table
+ *
+ * Results:
+ * Returns an arbitrary integer that increases with revisions.
+ * If a client requires a given epoch and revision, any Stubs table
+ * with the same epoch and an equal or higher revision satisfies
+ * the request.
+ *
+ *----------------------------------------------------------------------
+ */
+
+int
+TclBN_revision()
+{
+ return TCLTOMMATH_REVISION;
+}
+#if 0
/*
*----------------------------------------------------------------------
@@ -57,7 +131,7 @@ TclBNAlloc(
*----------------------------------------------------------------------
*/
-extern void *
+void *
TclBNRealloc(
void *p,
size_t s)
@@ -90,6 +164,7 @@ TclBNFree(
{
Tcl_Free((char *) p);
}
+#endif
/*
*----------------------------------------------------------------------
diff --git a/generic/tommath.h b/generic/tommath.h
index 8bb3675..4ce3e43 100644
--- a/generic/tommath.h
+++ b/generic/tommath.h
@@ -1,611 +1 @@
-/* LibTomMath, multiple-precision integer library -- Tom St Denis
- *
- * LibTomMath is a library that provides multiple-precision
- * integer arithmetic as well as number theoretic functionality.
- *
- * The library was designed directly after the MPI library by
- * 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.
- *
- * Tom St Denis, tomstdenis@iahu.ca, http://math.libtomcrypt.org
- */
-#ifndef BN_H_
-#define BN_H_
-
-#ifdef TCL_TOMMATH
-#include <tclTomMath.h>
-#endif
-#ifndef TOMMATH_STORAGE_CLASS
-#define TOMMATH_STORAGE_CLASS extern
-#endif
-#ifndef MODULE_SCOPE
-#define MODULE_SCOPE extern
-#endif
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include <tommath_class.h>
-
-#ifndef MIN
- #define MIN(x,y) ((x)<(y)?(x):(y))
-#endif
-
-#ifndef MAX
- #define MAX(x,y) ((x)>(y)?(x):(y))
-#endif
-
-#ifdef __cplusplus
-extern "C" {
-
-/* C++ compilers don't like assigning void * to mp_digit * */
-#define OPT_CAST(x) (x *)
-
-#else
-
-/* C on the other hand doesn't care */
-#define OPT_CAST(x)
-
-#endif
-
-
-/* detect 64-bit mode if possible */
-#if defined(__x86_64__)
- #if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
- #define MP_64BIT
- #endif
-#endif
-
-/* some default configurations.
- *
- * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
- * A "mp_word" must be able to hold 2*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
-#ifndef MP_DIGIT_DECLARED
- typedef unsigned char mp_digit;
-#define MP_DIGIT_DECLARED
-#endif
- typedef unsigned short mp_word;
-#elif defined(MP_16BIT)
-#ifndef MP_DIGIT_DECLARED
- typedef unsigned short mp_digit;
-#define MP_DIGIT_DECLARED
-#endif
- typedef unsigned long mp_word;
-#elif defined(MP_64BIT)
- /* for GCC only on supported platforms */
-#ifndef CRYPT
- typedef unsigned long long ulong64;
- typedef signed long long long64;
-#endif
-
-#ifndef MP_DIGIT_DECLARED
- typedef unsigned long mp_digit;
-#define MP_DIGIT_DECLARED
-#endif
- typedef unsigned long mp_word __attribute__ ((mode(TI)));
-
- #define DIGIT_BIT 60
-#else
- /* this is the default case, 28-bit digits */
-
- /* this is to make porting into LibTomCrypt easier :-) */
-#ifndef CRYPT
- #if defined(_MSC_VER) || defined(__BORLANDC__)
- typedef unsigned __int64 ulong64;
- typedef signed __int64 long64;
- #else
- typedef unsigned long long ulong64;
- typedef signed long long long64;
- #endif
-#endif
-
-#ifndef MP_DIGIT_DECLARED
- typedef unsigned long mp_digit;
-#define MP_DIGIT_DECLARED
-#endif
- typedef ulong64 mp_word;
-
-#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
-
-/* define heap macros */
-#ifndef CRYPT
- /* default to libc stuff */
- #ifndef XMALLOC
- #define XMALLOC malloc
- #define XFREE free
- #define XREALLOC realloc
- #define XCALLOC calloc
- #else
- /* 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
-#endif
-
-
-/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
-#ifndef DIGIT_BIT
- #define DIGIT_BIT ((int)((CHAR_BIT * sizeof(mp_digit) - 1))) /* bits per digit */
-#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 */
-#define MP_EQ 0 /* equal to */
-#define MP_GT 1 /* greater than */
-
-#define MP_ZPOS 0 /* positive integer */
-#define MP_NEG 1 /* negative */
-
-#define MP_OKAY 0 /* ok result */
-#define MP_MEM -2 /* out of mem */
-#define MP_VAL -3 /* invalid input */
-#define MP_RANGE MP_VAL
-
-#define MP_YES 1 /* yes response */
-#define MP_NO 0 /* no response */
-
-/* Primality generation flags */
-#define LTM_PRIME_BBS 0x0001 /* BBS style prime */
-#define LTM_PRIME_SAFE 0x0002 /* Safe prime (p-1)/2 == prime */
-#define LTM_PRIME_2MSB_ON 0x0008 /* force 2nd MSB to 1 */
-
-typedef int mp_err;
-
-/* you'll have to tune these... */
-MODULE_SCOPE 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 */
-
-/* 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
-#endif
-
-/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
-#define MP_WARRAY (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
-
-/* the infamous mp_int structure */
-#ifndef MP_INT_DECLARED
-#define MP_INT_DECLARED
-typedef struct mp_int mp_int;
-#endif
-struct mp_int {
- 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)
-
-/* error code to char* string */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE char *mp_error_to_string(int code);
-
-/* ---> init and deinit bignum functions <--- */
-/* init a bignum */
-TOMMATH_STORAGE_CLASS int mp_init(mp_int *a);
-
-/* free a bignum */
-TOMMATH_STORAGE_CLASS void mp_clear(mp_int *a);
-
-/* init a null terminated series of arguments */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_init_multi(mp_int *mp, ...);
-
-/* clear a null terminated series of arguments */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE void mp_clear_multi(mp_int *mp, ...);
-
-/* exchange two ints */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE void mp_exch(mp_int *a, mp_int *b);
-
-/* shrink ram required for a bignum */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_shrink(mp_int *a);
-
-/* grow an int to a given size */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_grow(mp_int *a, int size);
-
-/* init to a given number of digits */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_init_size(mp_int *a, int size);
-
-/* ---> Basic Manipulations <--- */
-#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
-#define mp_iseven(a) (((a)->used == 0 || (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
-#define mp_isodd(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
-
-/* set to zero */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE void mp_zero(mp_int *a);
-
-/* set to a digit */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE void mp_set(mp_int *a, mp_digit b);
-
-/* set a 32-bit const */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_set_int(mp_int *a, unsigned long b);
-
-/* get a 32-bit value */
-unsigned long mp_get_int(mp_int * a);
-
-/* initialize and set a digit */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_init_set (mp_int * a, mp_digit b);
-
-/* initialize and set 32-bit value */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_init_set_int (mp_int * a, unsigned long b);
-
-/* copy, b = a */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_copy(mp_int *a, mp_int *b);
-
-/* inits and copies, a = b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_init_copy(mp_int *a, mp_int *b);
-
-/* trim unused digits */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE void mp_clamp(mp_int *a);
-
-/* ---> digit manipulation <--- */
-
-/* right shift by "b" digits */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE void mp_rshd(mp_int *a, int b);
-
-/* left shift by "b" digits */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_lshd(mp_int *a, int b);
-
-/* c = a / 2**b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d);
-
-/* b = a/2 */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_div_2(mp_int *a, mp_int *b);
-
-/* c = a * 2**b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_mul_2d(mp_int *a, int b, mp_int *c);
-
-/* b = a*2 */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_mul_2(mp_int *a, mp_int *b);
-
-/* c = a mod 2**d */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_mod_2d(mp_int *a, int b, mp_int *c);
-
-/* computes a = 2**b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_2expt(mp_int *a, int b);
-
-/* Counts the number of lsbs which are zero before the first zero bit */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_cnt_lsb(mp_int *a);
-
-/* I Love Earth! */
-
-/* makes a pseudo-random int of a given size */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_rand(mp_int *a, int digits);
-
-/* ---> binary operations <--- */
-/* c = a XOR b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_xor(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = a OR b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_or(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = a AND b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_and(mp_int *a, mp_int *b, mp_int *c);
-
-/* ---> Basic arithmetic <--- */
-
-/* b = -a */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_neg(mp_int *a, mp_int *b);
-
-/* b = |a| */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_abs(mp_int *a, mp_int *b);
-
-/* compare a to b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_cmp(mp_int *a, mp_int *b);
-
-/* compare |a| to |b| */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_cmp_mag(mp_int *a, mp_int *b);
-
-/* c = a + b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_add(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = a - b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_sub(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = a * b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_mul(mp_int *a, mp_int *b, mp_int *c);
-
-/* b = a*a */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_sqr(mp_int *a, mp_int *b);
-
-/* a/b => cb + d == a */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* c = a mod b, 0 <= c < b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_mod(mp_int *a, mp_int *b, mp_int *c);
-
-/* ---> single digit functions <--- */
-
-/* compare against a single digit */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_cmp_d(mp_int *a, mp_digit b);
-
-/* c = a + b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_add_d(mp_int *a, mp_digit b, mp_int *c);
-
-/* c = a - b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
-
-/* c = a * b */
-TOMMATH_STORAGE_CLASS int mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
-
-/* a/b => cb + d == a */
-TOMMATH_STORAGE_CLASS int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
-
-/* a/3 => 3c + d == a */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
-
-/* c = a**b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
-
-/* c = a mod b, 0 <= c < b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
-
-/* ---> number theory <--- */
-
-/* d = a + b (mod c) */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* d = a - b (mod c) */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_submod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* d = a * b (mod c) */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* c = a * a (mod b) */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = 1/a (mod b) */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
-
-/* c = (a, b) */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_gcd(mp_int *a, mp_int *b, mp_int *c);
-
-/* produces value such that U1*a + U2*b = U3 */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3);
-
-/* c = [a, b] or (a*b)/(a, b) */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
-
-/* finds one of the b'th root of a, such that |c|**b <= |a|
- *
- * returns error if a < 0 and b is even
- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
-
-/* special sqrt algo */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_sqrt(mp_int *arg, mp_int *ret);
-
-/* is number a square? */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_is_square(mp_int *arg, int *ret);
-
-/* computes the jacobi c = (a | n) (or Legendre if b is prime) */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_jacobi(mp_int *a, mp_int *n, int *c);
-
-/* used to setup the Barrett reduction for a given modulus b */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_reduce_setup(mp_int *a, mp_int *b);
-
-/* Barrett Reduction, computes a (mod b) with a precomputed value c
- *
- * Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely
- * compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_reduce(mp_int *a, mp_int *b, mp_int *c);
-
-/* setups the montgomery reduction */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_montgomery_setup(mp_int *a, mp_digit *mp);
-
-/* computes a = B**n mod b without division or multiplication useful for
- * normalizing numbers in a Montgomery system.
- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
-
-/* computes x/R == x (mod N) via Montgomery Reduction */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
-
-/* returns 1 if a is a valid DR modulus */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_dr_is_modulus(mp_int *a);
-
-/* sets the value of "d" required for mp_dr_reduce */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE void mp_dr_setup(mp_int *a, mp_digit *d);
-
-/* reduces a modulo b using the Diminished Radix method */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_dr_reduce(mp_int *a, mp_int *b, mp_digit mp);
-
-/* returns true if a can be reduced with mp_reduce_2k */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_reduce_is_2k(mp_int *a);
-
-/* determines k value for 2k reduction */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
-
-/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
-
-/* returns true if a can be reduced with mp_reduce_2k_l */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_reduce_is_2k_l(mp_int *a);
-
-/* determines k value for 2k reduction */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_reduce_2k_setup_l(mp_int *a, mp_int *d);
-
-/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d);
-
-/* d = a**b (mod c) */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
-
-/* ---> Primes <--- */
-
-/* number of primes */
-#ifdef MP_8BIT
- #define PRIME_SIZE 31
-#else
- #define PRIME_SIZE 256
-#endif
-
-/* table of first PRIME_SIZE primes */
-MODULE_SCOPE const mp_digit ltm_prime_tab[];
-
-/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_prime_is_divisible(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
- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_prime_fermat(mp_int *a, 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
- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
-
-/* This gives [for a given bit size] the number of trials required
- * such that Miller-Rabin gives a prob of failure lower than 2^-96
- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE 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
- * division. Determines if "a" is prime with probability
- * of error no more than (1/4)**t.
- *
- * Sets result to 1 if probably prime, 0 otherwise
- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_prime_is_prime(mp_int *a, int t, int *result);
-
-/* finds the next prime after the number "a" using "t" trials
- * of Miller-Rabin.
- *
- * bbs_style = 1 means the prime must be congruent to 3 mod 4
- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
-
-/* 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_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
-
-/* makes a truly random prime of a given size (bits),
- *
- * Flags are as follows:
- *
- * LTM_PRIME_BBS - make prime congruent to 3 mod 4
- * LTM_PRIME_SAFE - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
- * LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
- * LTM_PRIME_2MSB_ON - make the 2nd highest bit one
- *
- * 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
- *
- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
-
-/* ---> radix conversion <--- */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_count_bits(mp_int *a);
-
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_unsigned_bin_size(mp_int *a);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
-
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_signed_bin_size(mp_int *a);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_to_signed_bin(mp_int *a, unsigned char *b);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
-
-TOMMATH_STORAGE_CLASS int mp_read_radix(mp_int *a, const char *str, int radix);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_toradix(mp_int *a, char *str, int radix);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_radix_size(mp_int *a, int radix, int *size);
-
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_fread(mp_int *a, int radix, FILE *stream);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_fwrite(mp_int *a, int radix, FILE *stream);
-
-#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
-#define mp_raw_size(mp) mp_signed_bin_size(mp)
-#define mp_toraw(mp, str) mp_to_signed_bin((mp), (str))
-#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
-#define mp_mag_size(mp) mp_unsigned_bin_size(mp)
-#define mp_tomag(mp, str) mp_to_unsigned_bin((mp), (str))
-
-#define mp_tobinary(M, S) mp_toradix((M), (S), 2)
-#define mp_tooctal(M, S) mp_toradix((M), (S), 8)
-#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
-#define mp_tohex(M, S) mp_toradix((M), (S), 16)
-
-/* lowlevel functions, do not call! */
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
-#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int fast_s_mp_sqr(mp_int *a, mp_int *b);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int s_mp_sqr(mp_int *a, mp_int *b);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_karatsuba_sqr(mp_int *a, mp_int *b);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_toom_sqr(mp_int *a, mp_int *b);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int mode);
-TOMMATH_STORAGE_CLASS MODULE_SCOPE void bn_reverse(unsigned char *s, int len);
-
-MODULE_SCOPE const char *mp_s_rmap;
-
-#ifdef __cplusplus
- }
-#endif
-
-#endif
-
-
-/* $Source: /root/tcl/repos-to-convert/tcl/generic/tommath.h,v $ */
-/* $Revision: 1.5 $ */
-/* $Date: 2005/11/27 02:33:49 $ */
-
+#include "tclTomMath.h"
diff --git a/tools/fix_tommath_h.tcl b/tools/fix_tommath_h.tcl
index bf52ce6..adad734 100755
--- a/tools/fix_tommath_h.tcl
+++ b/tools/fix_tommath_h.tcl
@@ -8,7 +8,7 @@
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#
-# RCS: @(#) $Id: fix_tommath_h.tcl,v 1.3 2005/11/27 02:33:50 das Exp $
+# RCS: @(#) $Id: fix_tommath_h.tcl,v 1.4 2005/12/13 22:43:18 kennykb Exp $
#
#----------------------------------------------------------------------
@@ -16,48 +16,69 @@ set f [open [lindex $argv 0] r]
set data [read $f]
close $f
+set eat_endif 0
+set eat_semi 0
foreach line [split $data \n] {
- switch -regexp -- $line {
- {#define BN_H_} {
- puts $line
- puts {}
- puts "\#ifdef TCL_TOMMATH"
- puts "\#include <tclTomMath.h>"
- puts "\#endif"
- puts "\#ifndef TOMMATH_STORAGE_CLASS"
- puts "\#define TOMMATH_STORAGE_CLASS extern"
- puts "\#endif"
- puts "\#ifndef MODULE_SCOPE"
- puts "\#define MODULE_SCOPE extern"
- puts "\#endif"
+ if { !$eat_semi && !$eat_endif } {
+ switch -regexp -- $line {
+ {#define BN_H_} {
+ puts $line
+ puts {}
+ puts "\#include <tclTomMathDecls.h>"
+ puts "\#ifndef MODULE_SCOPE"
+ puts "\#define MODULE_SCOPE extern"
+ puts "\#endif"
+ }
+ {typedef.*mp_digit;} {
+ puts "\#ifndef MP_DIGIT_DECLARED"
+ puts $line
+ puts "\#define MP_DIGIT_DECLARED"
+ puts "\#endif"
+ }
+ {typedef struct} {
+ puts "\#ifndef MP_INT_DECLARED"
+ puts "\#define MP_INT_DECLARED"
+ puts "typedef struct mp_int mp_int;"
+ puts "\#endif"
+ puts "struct mp_int \{"
+ }
+ \}\ mp_int\; {
+ puts "\};"
+ }
+ {^(char|int|void)} {
+ puts "/*"
+ puts $line
+ set eat_semi 1
+ set after_semi "*/"
+ }
+ {^extern (int|const)} {
+ puts "\#if defined(BUILD_tcl) || !defined(_WIN32)"
+ puts [regsub {^extern} $line "MODULE_SCOPE"]
+ set eat_semi 1
+ set after_semi "\#endif"
+ }
+ {define heap macros} {
+ puts $line
+ puts "\#if 0 /* these are macros in tclTomMathDecls.h */"
+ set eat_endif 1
+ }
+ default {
+ puts $line
+ }
}
- {typedef.*mp_digit;} {
- puts "\#ifndef MP_DIGIT_DECLARED"
- puts $line
- puts "\#define MP_DIGIT_DECLARED"
- puts "\#endif"
+ } else {
+ puts $line
+ }
+ if {$eat_semi} {
+ if {[regexp {; *$} $line]} {
+ puts $after_semi
+ set eat_semi 0
}
- {typedef struct} {
- puts "\#ifndef MP_INT_DECLARED"
- puts "\#define MP_INT_DECLARED"
- puts "typedef struct mp_int mp_int;"
+ }
+ if {$eat_endif} {
+ if {[regexp {^\#endif} $line]} {
puts "\#endif"
- puts "struct mp_int \{"
- }
- \}\ mp_int\; {
- puts "\};"
- }
- {^(char|int|void) mp_(div_d|mul_d|clear|init|read_radix)\(} {
- puts "TOMMATH_STORAGE_CLASS $line"
- }
- {^(char|int|void)} {
- puts "TOMMATH_STORAGE_CLASS MODULE_SCOPE $line"
- }
- {^extern (int|const)} {
- puts [regsub {^extern} $line "MODULE_SCOPE"]
- }
- default {
- puts $line
+ set eat_endif 0
}
}
}
diff --git a/unix/Makefile.in b/unix/Makefile.in
index e84e109..5930d1f 100644
--- a/unix/Makefile.in
+++ b/unix/Makefile.in
@@ -5,7 +5,7 @@
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.
#
-# RCS: @(#) $Id: Makefile.in,v 1.181 2005/12/02 16:58:14 kennykb Exp $
+# RCS: @(#) $Id: Makefile.in,v 1.182 2005/12/13 22:43:18 kennykb Exp $
VERSION = @TCL_VERSION@
MAJOR_VERSION = @TCL_MAJOR_VERSION@
@@ -351,6 +351,8 @@ GENERIC_HDRS = \
$(GENERIC_DIR)/tclInt.h \
$(GENERIC_DIR)/tclIntDecls.h \
$(GENERIC_DIR)/tclIntPlatDecls.h \
+ $(GENERIC_DIR)/tclTomMath.h \
+ $(GENERIC_DIR)/tclTomMathDecls.h \
$(GENERIC_DIR)/tclPatch.h \
$(GENERIC_DIR)/tclPlatDecls.h \
$(GENERIC_DIR)/tclPort.h \
@@ -676,14 +678,14 @@ gendate:
# <y.tab.c >$(GENERIC_DIR)/tclDate.c
# rm y.tab.c
-# The following target generates the file generic/tommath.h.
+# The following target generates the file generic/tclTomMath.h.
# It needs to be run (and the results checked) after updating
# to a new release of libtommath.
gentommath_h:
$(TCL_EXE) "$(TOP_DIR)/tools/fix_tommath_h.tcl" \
"$(TOMMATH_DIR)/tommath.h" \
- > "$(GENERIC_DIR)/tommath.h"
+ > "$(GENERIC_DIR)/tclTomMath.h"
# The following target generates the shared libraries in dltest/ that
# are used for testing; they are included as part of the "tcltest"
@@ -762,7 +764,9 @@ install-libraries: libraries install-tzdata install-msgs
fi
@echo "Installing header files";
@for i in $(GENERIC_DIR)/tcl.h $(GENERIC_DIR)/tclDecls.h \
- $(GENERIC_DIR)/tclPlatDecls.h; \
+ $(GENERIC_DIR)/tclPlatDecls.h \
+ $(GENERIC_DIR)/tclTomMath.h \
+ $(GENERIC_DIR)/tclTomMathDecls.h ; \
do \
$(INSTALL_DATA) $$i $(INCLUDE_INSTALL_DIR); \
done;
@@ -1516,7 +1520,8 @@ $(GENERIC_DIR)/tclStubInit.c: $(GENERIC_DIR)/tcl.decls \
genstubs:
$(TCL_EXE) $(TOOL_DIR)/genStubs.tcl $(GENERIC_DIR) \
- $(GENERIC_DIR)/tcl.decls $(GENERIC_DIR)/tclInt.decls
+ $(GENERIC_DIR)/tcl.decls $(GENERIC_DIR)/tclInt.decls \
+ $(GENERIC_DIR)/tclTomMath.decls
#
# Target to check that all exported functions have an entry in the stubs
diff --git a/win/Makefile.in b/win/Makefile.in
index 7e6efc6..5967b9f 100644
--- a/win/Makefile.in
+++ b/win/Makefile.in
@@ -5,7 +5,7 @@
# "autoconf" program (constructs like "@foo@" will get replaced in the
# actual Makefile.
#
-# RCS: @(#) $Id: Makefile.in,v 1.94 2005/12/08 20:20:36 hobbs Exp $
+# RCS: @(#) $Id: Makefile.in,v 1.95 2005/12/13 22:43:18 kennykb Exp $
VERSION = @TCL_VERSION@
@@ -542,14 +542,14 @@ gendate:
--no-lines \
$(GENERIC_DIR)/tclGetDate.y
-# The following target generates the file generic/tommath.h.
+# The following target generates the file generic/tclTomMath.h.
# It needs to be run (and the results checked) after updating
# to a new release of libtommath.
gentommath_h:
$(TCL_EXE) "$(ROOT_DIR_NATIVE)\tools\fix_tommath_h.tcl" \
"$(TOMMATH_DIR_NATIVE)\tommath.h" \
- > "$(GENERIC_DIR_NATIVE)\tommath.h"
+ > "$(GENERIC_DIR_NATIVE)\tclTomMath.h"
install: all install-binaries install-libraries install-doc
@@ -626,7 +626,9 @@ install-libraries: libraries install-tzdata install-msgs
done;
@echo "Installing header files";
@for i in "$(GENERIC_DIR)/tcl.h" "$(GENERIC_DIR)/tclDecls.h" \
- "$(GENERIC_DIR)/tclPlatDecls.h" ; \
+ "$(GENERIC_DIR)/tclPlatDecls.h" \
+ "$(GENERIC_DIR)/tclTomMath.h" \
+ "$(GENERIC_DIR)/tclTomMathDecls.h" ; \
do \
$(COPY) "$$i" "$(INCLUDE_INSTALL_DIR)"; \
done;
@@ -747,4 +749,5 @@ genstubs:
$(TCL_EXE) "$(ROOT_DIR_NATIVE)\tools\genStubs.tcl" \
"$(GENERIC_DIR_NATIVE)" \
"$(GENERIC_DIR_NATIVE)\tcl.decls" \
- "$(GENERIC_DIR_NATIVE)\tclInt.decls"
+ "$(GENERIC_DIR_NATIVE)\tclInt.decls" \
+ "$(GENERIC_DIR_NATIVE)\tclTomMath.decls"
diff --git a/win/makefile.vc b/win/makefile.vc
index c5763ad..d238937 100644
--- a/win/makefile.vc
+++ b/win/makefile.vc
@@ -12,7 +12,7 @@
# Copyright (c) 2001-2004 David Gravereaux.
#
#------------------------------------------------------------------------------
-# RCS: @(#) $Id: makefile.vc,v 1.142 2005/12/08 20:20:37 hobbs Exp $
+# RCS: @(#) $Id: makefile.vc,v 1.143 2005/12/13 22:43:18 kennykb Exp $
#------------------------------------------------------------------------------
# Check to see we are configured to build with MSVC (MSDEVDIR or MSVCDIR)
@@ -637,11 +637,27 @@ genstubs:
!if !exist($(TCLSH))
@echo Build tclsh first!
!else
- $(TCLSH) $(TOOLSDIR:\=/)\genStubs.tcl $(GENERICDIR:\=/) \
- $(GENERICDIR:\=/)/tcl.decls $(GENERICDIR:\=/)/tclInt.decls
+ $(TCLSH) $(TOOLSDIR:\=/)/genStubs.tcl $(GENERICDIR:\=/) \
+ $(GENERICDIR:\=/)/tcl.decls $(GENERICDIR:\=/)/tclInt.decls \
+ $(GENERICDIR:\=/)/tclTomMath.decls
!endif
+#----------------------------------------------------------------------
+# The following target generates the file generic/tclTomMath.h.
+# It needs to be run (and the results checked) after updating
+# to a new release of libtommath.
+#----------------------------------------------------------------------
+
+gentommath_h:
+!if !exist($(TCLSH))
+ @echo Build tclsh first!
+!else
+ $(TCLSH) "$(TOOLSDIR:\=/)/fix_tommath_h.tcl" \
+ "$(TOMMATHDIR:\=/)/tommath.h" \
+ > "$(GENERICDIR)\tclTomMath.h"
+!endif
+
#---------------------------------------------------------------------
# Generate the makefile depedancies.
#---------------------------------------------------------------------
@@ -1003,19 +1019,21 @@ install-libraries: tclConfig install-msgs install-tzdata
@$(CPY) "$(ROOT)\library\encoding\*.enc" \
"$(SCRIPT_INSTALL_DIR)\encoding\"
@echo installing library files
- @$(CPY) "$(GENERICDIR)\tcl.h" "$(INCLUDE_INSTALL_DIR)\"
- @$(CPY) "$(GENERICDIR)\tclDecls.h" "$(INCLUDE_INSTALL_DIR)\"
- @$(CPY) "$(GENERICDIR)\tclPlatDecls.h" "$(INCLUDE_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\history.tcl" "$(SCRIPT_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\init.tcl" "$(SCRIPT_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\clock.tcl" "$(SCRIPT_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\tm.tcl" "$(SCRIPT_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\parray.tcl" "$(SCRIPT_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\safe.tcl" "$(SCRIPT_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\tclIndex" "$(SCRIPT_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\package.tcl" "$(SCRIPT_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\word.tcl" "$(SCRIPT_INSTALL_DIR)\"
- @$(CPY) "$(ROOT)\library\auto.tcl" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(GENERICDIR)\tcl.h" "$(INCLUDE_INSTALL_DIR)\"
+ @$(CPY) "$(GENERICDIR)\tclDecls.h" "$(INCLUDE_INSTALL_DIR)\"
+ @$(CPY) "$(GENERICDIR)\tclPlatDecls.h" "$(INCLUDE_INSTALL_DIR)\"
+ @$(CPY) "$(GENERICDIR)\tclTomMath.h" "$(INCLUDE_INSTALL_DIR)\"
+ @$(CPY) "$(GENERICDIR)\tclTomMathDecls.h" "$(INCLUDE_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\history.tcl" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\init.tcl" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\clock.tcl" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\tm.tcl" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\parray.tcl" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\safe.tcl" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\tclIndex" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\package.tcl" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\word.tcl" "$(SCRIPT_INSTALL_DIR)\"
+ @$(CPY) "$(ROOT)\library\auto.tcl" "$(SCRIPT_INSTALL_DIR)\"
install-tzdata:
@echo "Installing time zone data"
diff --git a/win/tclWinChan.c b/win/tclWinChan.c
index bf5301a..94efd2f 100644
--- a/win/tclWinChan.c
+++ b/win/tclWinChan.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinChan.c,v 1.45 2005/11/04 00:06:50 dkf Exp $
+ * RCS: @(#) $Id: tclWinChan.c,v 1.46 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclWinInt.h"
@@ -849,8 +849,8 @@ TclpOpenFileChannel(
* what modes to create it? */
{
Tcl_Channel channel = 0;
- int channelPermissions;
- DWORD accessMode, createMode, shareMode, flags, consoleParams, type;
+ int channelPermissions = 0;
+ DWORD accessMode = 0, createMode, shareMode, flags, consoleParams, type;
CONST TCHAR *nativeName;
HANDLE handle;
char channelName[16 + TCL_INTEGER_SPACE];
@@ -1267,9 +1267,10 @@ TclpGetDefaultStdChannel(
{
Tcl_Channel channel;
HANDLE handle;
- int mode;
- char *bufMode;
- DWORD handleId; /* Standard handle to retrieve. */
+ int mode = -1;
+ char *bufMode = NULL;
+ DWORD handleId = (DWORD)INVALID_HANDLE_VALUE;
+ /* Standard handle to retrieve. */
switch (type) {
case TCL_STDIN:
diff --git a/win/tclWinConsole.c b/win/tclWinConsole.c
index 615e87d..f859593 100644
--- a/win/tclWinConsole.c
+++ b/win/tclWinConsole.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinConsole.c,v 1.17 2005/11/04 00:06:50 dkf Exp $
+ * RCS: @(#) $Id: tclWinConsole.c,v 1.18 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclWinInt.h"
@@ -815,9 +815,9 @@ ConsoleOutputProc(
ckfree(infoPtr->writeBuf);
}
infoPtr->writeBufLen = toWrite;
- infoPtr->writeBuf = ckalloc(toWrite);
+ infoPtr->writeBuf = ckalloc((size_t)toWrite);
}
- memcpy(infoPtr->writeBuf, buf, toWrite);
+ memcpy(infoPtr->writeBuf, buf, (size_t)toWrite);
infoPtr->toWrite = toWrite;
ResetEvent(infoPtr->writable);
SetEvent(infoPtr->startWriter);
@@ -828,7 +828,8 @@ ConsoleOutputProc(
* avoids an unnecessary copy.
*/
- if (writeConsoleBytes(infoPtr->handle, buf, toWrite, &bytesWritten)
+ if (writeConsoleBytes(infoPtr->handle, buf, (DWORD)toWrite,
+ &bytesWritten)
== FALSE) {
TclWinConvertError(GetLastError());
goto error;
@@ -1275,7 +1276,8 @@ ConsoleWriterThread(
*/
while (toWrite > 0) {
- if (writeConsoleBytes(handle, buf, toWrite, &count) == FALSE) {
+ if (writeConsoleBytes(handle, buf, (DWORD)toWrite,
+ &count) == FALSE) {
infoPtr->writeError = GetLastError();
break;
} else {
diff --git a/win/tclWinDde.c b/win/tclWinDde.c
index 913a361..0171810 100644
--- a/win/tclWinDde.c
+++ b/win/tclWinDde.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinDde.c,v 1.28 2005/11/04 00:06:50 dkf Exp $
+ * RCS: @(#) $Id: tclWinDde.c,v 1.29 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
@@ -59,7 +59,7 @@ typedef struct DdeEnumServices {
ATOM service;
ATOM topic;
HWND hwnd;
-};
+} DdeEnumServices;
typedef struct ThreadSpecificData {
Conversation *currentConversations;
@@ -953,7 +953,6 @@ DdeClientWindowProc(
WPARAM wParam,
LPARAM lParam) /* (Potentially) our local handle */
{
- LRESULT lr = 0L;
switch (uMsg) {
case WM_CREATE: {
@@ -999,7 +998,7 @@ DdeServicesOnAck(
Tcl_Obj *matchPtr = Tcl_NewListObj(0, NULL);
Tcl_Obj *resultPtr = Tcl_GetObjResult(es->interp);
- GlobalGetAtomName((ATOM)service, sz, 255);
+ GlobalGetAtomName(service, sz, 255);
Tcl_ListObjAppendElement(NULL, matchPtr, Tcl_NewStringObj(sz, -1));
GlobalGetAtomName(topic, sz, 255);
Tcl_ListObjAppendElement(NULL, matchPtr, Tcl_NewStringObj(sz, -1));
@@ -1140,7 +1139,7 @@ Tcl_DdeObjCmd(
ClientData clientData, /* Used only for deletion */
Tcl_Interp *interp, /* The interp we are sending from */
int objc, /* Number of arguments */
- Tcl_Obj *CONST objv[]) /* The arguments */
+ Tcl_Obj *CONST * objv) /* The arguments */
{
static CONST char *ddeCommands[] = {
"servername", "execute", "poke", "request", "services", "eval",
@@ -1190,9 +1189,9 @@ Tcl_DdeObjCmd(
switch ((enum DdeSubcommands) index) {
case DDE_SERVERNAME:
for (i = 2; i < objc; i++) {
- enum DdeSrvOptions argIndex;
+ int argIndex;
if (Tcl_GetIndexFromObj(interp, objv[i], ddeSrvOptions,
- "option", 0, (int *) &argIndex) != TCL_OK) {
+ "option", 0, &argIndex) != TCL_OK) {
/*
* If it is the last argument, it might be a server name
* instead of a bad argument.
@@ -1486,7 +1485,7 @@ Tcl_DdeObjCmd(
}
objc -= (async + 3);
- ((Tcl_Obj **) objv) += (async + 3);
+ objv += (async + 3);
/*
* See if the target interpreter is local. If so, execute the command
diff --git a/win/tclWinFCmd.c b/win/tclWinFCmd.c
index 2aa5f0c..3d95de9 100644
--- a/win/tclWinFCmd.c
+++ b/win/tclWinFCmd.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinFCmd.c,v 1.50 2005/11/04 00:06:50 dkf Exp $
+ * RCS: @(#) $Id: tclWinFCmd.c,v 1.51 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclWinInt.h"
@@ -1233,7 +1233,7 @@ TraverseWinTree(
{
DWORD sourceAttr;
TCHAR *nativeSource, *nativeTarget, *nativeErrfile;
- int result, found, sourceLen, targetLen, oldSourceLen, oldTargetLen;
+ int result, found, sourceLen, targetLen = 0, oldSourceLen, oldTargetLen;
HANDLE handle;
WIN32_FIND_DATAT data;
@@ -1448,9 +1448,9 @@ TraversalCopy(
break;
case DOTREE_PRED:
if (DoCreateDirectory(nativeDst) == TCL_OK) {
- DWORD attr = (*tclWinProcs->getFileAttributesProc)(nativeSrc);
+ DWORD attr = (tclWinProcs->getFileAttributesProc)(nativeSrc);
- if ((*tclWinProcs->setFileAttributesProc)(nativeDst,
+ if ((tclWinProcs->setFileAttributesProc)(nativeDst,
attr) != FALSE) {
return TCL_OK;
}
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index eb88bb1..f7fc5a4 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinFile.c,v 1.80 2005/11/04 00:06:50 dkf Exp $
+ * RCS: @(#) $Id: tclWinFile.c,v 1.81 2005/12/13 22:43:18 kennykb Exp $
*/
/* #define _WIN32_WINNT 0x0500 */
@@ -28,7 +28,8 @@
* on the proleptic Gregorian calendar) and the Posix epoch (1970-01-01).
*/
-#define POSIX_EPOCH_AS_FILETIME 116444736000000000
+#define POSIX_EPOCH_AS_FILETIME ((Tcl_WideInt)116444736 \
+ * (Tcl_WideInt) 1000000000)
/*
* Declarations for 'link' related information. This information should come
@@ -1445,7 +1446,7 @@ TclpGetUserHome(
if (domain != NULL) {
Tcl_DStringInit(&ds);
wName = Tcl_UtfToUniCharDString(domain + 1, -1, &ds);
- badDomain = (*netGetDCNameProc)(NULL, wName,
+ badDomain = (netGetDCNameProc)(NULL, wName,
(LPBYTE *) &wDomain);
Tcl_DStringFree(&ds);
nameLen = domain - name;
@@ -1453,7 +1454,7 @@ TclpGetUserHome(
if (badDomain == 0) {
Tcl_DStringInit(&ds);
wName = Tcl_UtfToUniCharDString(name, nameLen, &ds);
- if ((*netUserGetInfoProc)(wDomain, wName, 1,
+ if ((netUserGetInfoProc)(wDomain, wName, 1,
(LPBYTE *) &uiPtr) == 0) {
wHomeDir = uiPtr->usri1_home_dir;
if ((wHomeDir != NULL) && (wHomeDir[0] != L'\0')) {
@@ -1609,7 +1610,7 @@ NativeAccess(
* to EACCES - just what we want!
*/
- TclWinConvertError(error);
+ TclWinConvertError((DWORD)error);
return -1;
}
@@ -2799,7 +2800,7 @@ TclpObjNormalizePath(
}
}
Tcl_DStringAppend(&dsNorm, nativePath,
- sizeof(WCHAR)*len);
+ (int)(sizeof(WCHAR)*len));
lastValidPathEnd = currentPathEndPosition;
}
}
diff --git a/win/tclWinReg.c b/win/tclWinReg.c
index cebb97c..d7d442a 100644
--- a/win/tclWinReg.c
+++ b/win/tclWinReg.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinReg.c,v 1.34 2005/11/04 00:06:51 dkf Exp $
+ * RCS: @(#) $Id: tclWinReg.c,v 1.35 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclInt.h"
@@ -818,7 +818,9 @@ GetValue(
Tcl_NewStringObj(Tcl_DStringValue(&buf),
Tcl_DStringLength(&buf)));
if (regWinProcs->useWide) {
- while (*((Tcl_UniChar *)p)++ != 0) {}
+ Tcl_UniChar* up = (Tcl_UniChar*) p;
+ while (*up++ != 0) {}
+ p = (char*) up;
} else {
while (*p++ != '\0') {}
}
@@ -1256,7 +1258,8 @@ SetValue(
Tcl_Obj *dataObj, /* Data to be written. */
Tcl_Obj *typeObj) /* Type of data to be written. */
{
- DWORD type, result;
+ int type;
+ DWORD result;
HKEY key;
int length;
char *valueName;
@@ -1279,15 +1282,16 @@ SetValue(
valueName = (char *) Tcl_WinUtfToTChar(valueName, length, &nameBuf);
if (type == REG_DWORD || type == REG_DWORD_BIG_ENDIAN) {
- DWORD value;
- if (Tcl_GetIntFromObj(interp, dataObj, (int*) &value) != TCL_OK) {
+ int value;
+ if (Tcl_GetIntFromObj(interp, dataObj, &value) != TCL_OK) {
RegCloseKey(key);
Tcl_DStringFree(&nameBuf);
return TCL_ERROR;
}
- value = ConvertDWORD(type, value);
- result = (*regWinProcs->regSetValueExProc)(key, valueName, 0, type,
+ value = ConvertDWORD((DWORD)type, (DWORD)value);
+ result = (*regWinProcs->regSetValueExProc)(key, valueName, 0,
+ (DWORD)type,
(BYTE*) &value, sizeof(DWORD));
} else if (type == REG_MULTI_SZ) {
Tcl_DString data, buf;
@@ -1322,7 +1326,8 @@ SetValue(
Tcl_WinUtfToTChar(Tcl_DStringValue(&data), Tcl_DStringLength(&data)+1,
&buf);
- result = (*regWinProcs->regSetValueExProc)(key, valueName, 0, type,
+ result = (*regWinProcs->regSetValueExProc)(key, valueName, 0,
+ (DWORD)type,
(BYTE *) Tcl_DStringValue(&buf),
(DWORD) Tcl_DStringLength(&buf));
Tcl_DStringFree(&data);
@@ -1342,7 +1347,8 @@ SetValue(
}
length = Tcl_DStringLength(&buf) + 1;
- result = (*regWinProcs->regSetValueExProc)(key, valueName, 0, type,
+ result = (*regWinProcs->regSetValueExProc)(key, valueName, 0,
+ (DWORD)type,
(BYTE*)data, (DWORD) length);
Tcl_DStringFree(&buf);
} else {
@@ -1353,7 +1359,8 @@ SetValue(
*/
data = Tcl_GetByteArrayFromObj(dataObj, &length);
- result = (*regWinProcs->regSetValueExProc)(key, valueName, 0, type,
+ result = (*regWinProcs->regSetValueExProc)(key, valueName, 0,
+ (DWORD)type,
(BYTE *)data, (DWORD) length);
}
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index cd26f98..509df69 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -8,7 +8,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclWinSock.c,v 1.50 2005/11/04 00:06:51 dkf Exp $
+ * RCS: @(#) $Id: tclWinSock.c,v 1.51 2005/12/13 22:43:18 kennykb Exp $
*/
#include "tclWinInt.h"
@@ -447,7 +447,7 @@ InitSockets(void)
#define WSA_VERSION_MINOR 1
#define WSA_VERSION_REQD MAKEWORD(WSA_VERSION_MAJOR, WSA_VERSION_MINOR)
- if ((err = winSock.WSAStartup(WSA_VERSION_REQD, &wsaData)) != 0) {
+ if ((err = winSock.WSAStartup((WORD)WSA_VERSION_REQD, &wsaData)) != 0) {
TclWinConvertWSAError(err);
goto unloadLibrary;
}
@@ -966,7 +966,7 @@ TcpCloseProc(
SocketInfo *infoPtr = (SocketInfo *) instanceData;
/* TIP #218 */
int errorCode = 0;
- ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+ /* ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); */
/*
* Check that WinSock is initialized; do not call it if not, to prevent
@@ -1019,7 +1019,7 @@ NewSocketInfo(
SOCKET socket)
{
SocketInfo *infoPtr;
- ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+ /* ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey); */
infoPtr = (SocketInfo *) ckalloc((unsigned) sizeof(SocketInfo));
infoPtr->channel = 0;
@@ -2050,7 +2050,7 @@ TcpGetOptionProc(
int ret;
optlen = sizeof(int);
- ret = TclWinGetSockOpt(sock, SOL_SOCKET, SO_ERROR,
+ ret = TclWinGetSockOpt((int)sock, SOL_SOCKET, SO_ERROR,
(char *)&err, &optlen);
if (ret == SOCKET_ERROR) {
err = winSock.WSAGetLastError();
@@ -2582,7 +2582,7 @@ InitializeHostName(
int
TclWinGetSockOpt(
- SOCKET s,
+ int s,
int level,
int optname,
char * optval,
@@ -2598,12 +2598,12 @@ TclWinGetSockOpt(
return SOCKET_ERROR;
}
- return winSock.getsockopt(s, level, optname, optval, optlen);
+ return winSock.getsockopt((SOCKET)s, level, optname, optval, optlen);
}
int
TclWinSetSockOpt(
- SOCKET s,
+ int s,
int level,
int optname,
const char * optval,
@@ -2619,7 +2619,7 @@ TclWinSetSockOpt(
return SOCKET_ERROR;
}
- return winSock.setsockopt(s, level, optname, optval, optlen);
+ return winSock.setsockopt((SOCKET)s, level, optname, optval, optlen);
}
u_short