Tcl Library Source Code

Check-in [75a5d29cd5]
Login

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

Overview
Comment:Add critcl api for sha256. Remove obsolete parts in sha256.h
Timelines: family | ancestors | descendants | both | pooryorick
Files: files | file ages | folders
SHA3-256:75a5d29cd57dbff3d95c9a6f943832b210eb4fa5fead72e33b4b00f1a5c473d7
User & Date: pooryorick 2018-12-17 12:59:07
Context
2019-02-18
06:42
drop ego Leaf check-in: d7bcf888d9 user: pooryorick tags: pooryorick
2018-12-17
12:59
Add critcl api for sha256. Remove obsolete parts in sha256.h check-in: 75a5d29cd5 user: pooryorick tags: pooryorick
2018-12-11
07:50
Re-adding smtp.test check-in: 5f84b5353b user: hypnotoad tags: pooryorick
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/sha1/pkgIndex.tcl.

6
7
8
9
10
11
12

13
14
# information so that packages will be loaded automatically
# in response to "package require" commands.  When this
# script is sourced, the variable $dir must contain the
# full path name of this file's directory.

if {![package vsatisfies [package provide Tcl] 8.2]} {return}
package ifneeded sha256 1.0.3 [list source [file join $dir sha256.tcl]]

package ifneeded sha1   2.0.3 [list source [file join $dir sha1.tcl]]
package ifneeded sha1   1.1.1 [list source [file join $dir sha1v1.tcl]]







>


6
7
8
9
10
11
12
13
14
15
# information so that packages will be loaded automatically
# in response to "package require" commands.  When this
# script is sourced, the variable $dir must contain the
# full path name of this file's directory.

if {![package vsatisfies [package provide Tcl] 8.2]} {return}
package ifneeded sha256 1.0.3 [list source [file join $dir sha256.tcl]]
package ifneeded sha256c 1.0.2 [list source [file join $dir sha256c.tcl]]
package ifneeded sha1   2.0.3 [list source [file join $dir sha1.tcl]]
package ifneeded sha1   1.1.1 [list source [file join $dir sha1v1.tcl]]

Changes to modules/sha1/sha256.h.

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
 *
 *	$Id: sha256.h,v 1.4 2011/04/21 17:51:55 andreas_kupries Exp $
 */

#ifndef _SHA256_H
#define _SHA256_H

#if HAVE_INTTYPES_H
# include <inttypes.h>
#else
# if HAVE_STDINT_H
#  include <stdint.h>
# endif
#endif

#define SHA256_HASH_SIZE 32

/* Hash size in 32-bit words */
#define SHA256_HASH_WORDS 8

#ifdef _MSC_VER
typedef unsigned __int64    uint64_t;
#elif !(defined(__hpux) || defined(_AIX))
typedef unsigned long long  uint64_t;
#endif

#if !(defined(__hpux))
typedef unsigned int        uint32_t;
typedef unsigned char       uint8_t;
#endif

struct _SHA256Context {
  uint64_t totalLength;
  uint32_t hash[SHA256_HASH_WORDS];
  uint32_t bufferLength;
  union {
    uint32_t words[16];
    uint8_t bytes[64];







<
<
<
<
|
<
<






<
<
<
<
<
<
<
<
<
<
<







25
26
27
28
29
30
31




32


33
34
35
36
37
38











39
40
41
42
43
44
45
 *
 *	$Id: sha256.h,v 1.4 2011/04/21 17:51:55 andreas_kupries Exp $
 */

#ifndef _SHA256_H
#define _SHA256_H





#include <stdint.h>



#define SHA256_HASH_SIZE 32

/* Hash size in 32-bit words */
#define SHA256_HASH_WORDS 8












struct _SHA256Context {
  uint64_t totalLength;
  uint32_t hash[SHA256_HASH_WORDS];
  uint32_t bufferLength;
  union {
    uint32_t words[16];
    uint8_t bytes[64];

Changes to modules/sha1/sha256.tcl.

27
28
29
30
31
32
33

34
35
36
37
38
39
40
...
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
namespace eval ::sha2 {
    variable  accel
    array set accel {tcl 0 critcl 0}
    variable  loaded {}

    namespace export sha256 hmac \
            SHA256Init SHA256Update SHA256Final


    variable uid
    if {![info exists uid]} {
        set uid 0
    }

    variable K
................................................................................

    if {![string equal $key ""]} {
        foreach c {
            SHA256Init   SHA224Init
            SHA256Final  SHA224Final
            SHA256Update
        } {
            rename ::sha2::${c}-${key} ::sha2::$c
        }
    }

    # Remember the active implementation, for deactivation by future
    # switches.

    set loaded $key







>







 







|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
namespace eval ::sha2 {
    variable  accel
    array set accel {tcl 0 critcl 0}
    variable  loaded {}

    namespace export sha256 hmac \
            SHA256Init SHA256Update SHA256Final


    variable uid
    if {![info exists uid]} {
        set uid 0
    }

    variable K
................................................................................

    if {![string equal $key ""]} {
        foreach c {
            SHA256Init   SHA224Init
            SHA256Final  SHA224Final
            SHA256Update
        } {
	    interp alias {} ::sha2::$c {} ::sha2::${c}-${key}
        }
    }

    # Remember the active implementation, for deactivation by future
    # switches.

    set loaded $key

Changes to modules/sha1/sha256.test.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.5
testsNeedTcltest 1.0

testing {
    if {[useTcllibC]} {
        useLocalKeep sha256.tcl sha256 ::sha2
    } else {
        useLocal     sha256.tcl sha256 ::sha2
    }







|







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.5
testsNeedTcltest 1.0-

testing {
    if {[useTcllibC]} {
        useLocalKeep sha256.tcl sha256 ::sha2
    } else {
        useLocal     sha256.tcl sha256 ::sha2
    }

Changes to modules/sha1/sha256c.tcl.

168
169
170
171
172
173
174



















        data = Tcl_GetByteArrayFromObj(objv[1], &size);
        SHA256Update(mp, data, size);
        
        Tcl_SetObjResult(ip, obj);
        return TCL_OK;
    }
}


























>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
        data = Tcl_GetByteArrayFromObj(objv[1], &size);
        SHA256Update(mp, data, size);
        
        Tcl_SetObjResult(ip, obj);
        return TCL_OK;
    }
}

critcl::api header sha256.h
::critcl::api function void SHA256Init {
	SHA256Context *sc
}

::critcl::api function void SHA256Update {
	SHA256Context *sc
	{const void} *data
	uint32_t len
}
::critcl::api function void SHA256Final {
	SHA256Context *sc
	uint8_t *hash
}

::critcl::debug symbols
::critcl::load