Index: modules/sha1/sha1c.tcl ================================================================== --- modules/sha1/sha1c.tcl +++ modules/sha1/sha1c.tcl @@ -22,13 +22,42 @@ critcl::ccode { #include "sha1.h" #include #include + +#define DEBUG static Tcl_ObjType sha1_type; /* fast internal access representation */ + + /* = = == === Debug Helper Function */ + static void + HexDumpContext (SHA1_CTX* mp, const char* label) + { + int i; + fprintf(stdout,"%p %s = {\n",mp, label);fflush(stdout); + for (i=0;i<5;i++) { + fprintf(stdout,"%p state[%d] = %08lx\n",mp,i,mp->state[i]);fflush(stdout); + } + for (i=0;i<2;i++) { + fprintf(stdout,"%p count[%d] = %08lx\n",mp,i,mp->count[i]);fflush(stdout); + } +#if 0 + for (i=0;i<64;i++) { + fprintf(stdout,"%p buffr[%02d] = %d\n",mp,i,mp->buffer[i]);fflush(stdout); + } +#endif + fprintf(stdout,"}\n");fflush(stdout); + } + +#ifndef DEBUG +#define HDC(m,s) +#else +#define HDC(m,s) HexDumpContext (m,s) +#endif + /* = = == === ===== ======== ============= */ static void sha1_free_rep(Tcl_Obj* obj) { SHA1_CTX* mp = (SHA1_CTX*) obj->internalRep.otherValuePtr; @@ -49,11 +78,13 @@ { unsigned char buf[20]; Tcl_Obj* temp; char* str; SHA1_CTX dup = *(SHA1_CTX*) obj->internalRep.otherValuePtr; - + + HDC ((SHA1_CTX*) obj->internalRep.otherValuePtr,"pre-final"); + SHA1Final(buf, &dup); /* convert via a byte array to properly handle null bytes */ temp = Tcl_NewByteArrayObj(buf, sizeof buf); Tcl_IncrRefCount(temp); @@ -101,11 +132,13 @@ } } else { obj = Tcl_NewObj(); mp = (SHA1_CTX*) Tcl_Alloc(sizeof *mp); SHA1Init(mp); - + + HDC (mp,"post-init"); + if (obj->typePtr != NULL && obj->typePtr->freeIntRepProc != NULL) { obj->typePtr->freeIntRepProc(obj); } obj->internalRep.otherValuePtr = mp; @@ -115,10 +148,12 @@ Tcl_InvalidateStringRep(obj); mp = (SHA1_CTX*) obj->internalRep.otherValuePtr; data = Tcl_GetByteArrayFromObj(objv[1], &size); SHA1Update(mp, data, size); + + HDC (mp, "post-update"); Tcl_SetObjResult(ip, obj); return TCL_OK; } }