diff options
author | Kevin B Kenny <kennykb@acm.org> | 2005-12-13 22:43:15 (GMT) |
---|---|---|
committer | Kevin B Kenny <kennykb@acm.org> | 2005-12-13 22:43:15 (GMT) |
commit | 47ed8302270238b3263e8c7e6fb103e6c12e4d9c (patch) | |
tree | f5971ca2525b7271645c996adc428790015b1fe6 /generic | |
parent | 0def411fa61fa15627a6b3b0cad45918f27ca675 (diff) | |
download | tcl-47ed8302270238b3263e8c7e6fb103e6c12e4d9c.zip tcl-47ed8302270238b3263e8c7e6fb103e6c12e4d9c.tar.gz tcl-47ed8302270238b3263e8c7e6fb103e6c12e4d9c.tar.bz2 |
Export stubs for libtommath; fix mingw compiler warnings
Diffstat (limited to 'generic')
-rw-r--r-- | generic/tcl.decls | 9 | ||||
-rw-r--r-- | generic/tclBasic.c | 6 | ||||
-rw-r--r-- | generic/tclClock.c | 4 | ||||
-rw-r--r-- | generic/tclDecls.h | 14 | ||||
-rw-r--r-- | generic/tclIO.c | 4 | ||||
-rw-r--r-- | generic/tclIORChan.c | 6 | ||||
-rw-r--r-- | generic/tclInt.decls | 23 | ||||
-rw-r--r-- | generic/tclInt.h | 7 | ||||
-rw-r--r-- | generic/tclIntDecls.h | 70 | ||||
-rw-r--r-- | generic/tclIntPlatDecls.h | 10 | ||||
-rw-r--r-- | generic/tclLink.c | 6 | ||||
-rw-r--r-- | generic/tclListObj.c | 4 | ||||
-rw-r--r-- | generic/tclObj.c | 4 | ||||
-rw-r--r-- | generic/tclParseExpr.c | 4 | ||||
-rw-r--r-- | generic/tclProc.c | 4 | ||||
-rw-r--r-- | generic/tclStubInit.c | 81 | ||||
-rw-r--r-- | generic/tclStubLib.c | 64 | ||||
-rw-r--r-- | generic/tclTimer.c | 4 | ||||
-rw-r--r-- | generic/tclTomMath.decls | 214 | ||||
-rw-r--r-- | generic/tclTomMath.h | 938 | ||||
-rw-r--r-- | generic/tclTomMathDecls.h | 810 | ||||
-rw-r--r-- | generic/tclTomMathInterface.c | 79 | ||||
-rw-r--r-- | generic/tommath.h | 612 |
23 files changed, 2139 insertions, 838 deletions
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" |