Tcl Library Source Code

Changes On Branch sha1-debugging
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch sha1-debugging Excluding Merge-Ins

This is equivalent to a diff from 325182e9f0 to ae3535e446

2013-10-29
06:09
Ticket [a3dd326ec8c21f1b]. Updated valtype::iban for IBAN Registry Release 46 compatibility. Provided by Max Jarek. check-in: 1027eca073 user: aku tags: trunk
06:04
Extended sha1 binding code with debug help. Closed-Leaf check-in: ae3535e446 user: aku tags: sha1-debugging
2013-10-24
06:40
Fix the opt_def mistake in the manpage as found by Andreas check-in: 325182e9f0 user: markus tags: trunk
2013-10-21
19:20
[_columnwidth]: Recognize ANSI color control sequences and exclude them from the calculation. They are logically of no width and thus their characters must not be counted when determining a column's width. check-in: 1596620b2e user: andreask tags: trunk

Changes to modules/sha1/sha1c.tcl.

20
21
22
23
24
25
26
27


28
29



























30
31
32
33
34
35
36

namespace eval ::sha1 {

    critcl::ccode {
        #include "sha1.h"
        #include <stdlib.h>
        #include <assert.h>
        


        static
        Tcl_ObjType sha1_type; /* fast internal access representation */



























        
        static void 
        sha1_free_rep(Tcl_Obj* obj)
        {
            SHA1_CTX* mp = (SHA1_CTX*) obj->internalRep.otherValuePtr;
            Tcl_Free(mp);
        }







|
>
>


>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

namespace eval ::sha1 {

    critcl::ccode {
        #include "sha1.h"
        #include <stdlib.h>
        #include <assert.h>

#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;
            Tcl_Free(mp);
        }
47
48
49
50
51
52
53
54


55
56
57
58
59
60
61
        static void
        sha1_string_rep(Tcl_Obj* obj)
        {
            unsigned char buf[20];
            Tcl_Obj* temp;
            char* str;
            SHA1_CTX dup = *(SHA1_CTX*) obj->internalRep.otherValuePtr;
            


            SHA1Final(buf, &dup);
            
            /* convert via a byte array to properly handle null bytes */
            temp = Tcl_NewByteArrayObj(buf, sizeof buf);
            Tcl_IncrRefCount(temp);
            
            str = Tcl_GetStringFromObj(temp, &obj->length);







|
>
>







76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
        static void
        sha1_string_rep(Tcl_Obj* obj)
        {
            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);
            
            str = Tcl_GetStringFromObj(temp, &obj->length);
99
100
101
102
103
104
105
106


107
108
109
110
111
112
113
114
115
116
117
118
119


120
121
122
123
124
            if (Tcl_IsShared(obj)) {
                obj = Tcl_DuplicateObj(obj);
            }
        } else {
            obj = Tcl_NewObj();
            mp = (SHA1_CTX*) Tcl_Alloc(sizeof *mp);
            SHA1Init(mp);
            


            if (obj->typePtr != NULL && obj->typePtr->freeIntRepProc != NULL) {
                obj->typePtr->freeIntRepProc(obj);
            }
            
            obj->internalRep.otherValuePtr = mp;
            obj->typePtr = &sha1_type;
        }
        
        Tcl_InvalidateStringRep(obj);

        mp = (SHA1_CTX*) obj->internalRep.otherValuePtr;
        data = Tcl_GetByteArrayFromObj(objv[1], &size);
        SHA1Update(mp, data, size);



        Tcl_SetObjResult(ip, obj);
        return TCL_OK;
    }
}







|
>
>













>
>





130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
            if (Tcl_IsShared(obj)) {
                obj = Tcl_DuplicateObj(obj);
            }
        } 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;
            obj->typePtr = &sha1_type;
        }
        
        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;
    }
}