File: sha256.test

package info (click to toggle)
tcllib 1.10-dfsg-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 17,708 kB
  • ctags: 6,122
  • sloc: tcl: 106,354; ansic: 9,205; sh: 8,707; xml: 1,766; yacc: 753; makefile: 115; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (94 lines) | stat: -rw-r--r-- 3,055 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# -*- tcl -*-
# sha256.test:  tests for the sha256 commands
#
# This file contains a collection of tests for one or more of the Tcl
# built-in commands.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# RCS: @(#) $Id: sha256.test,v 1.6 2006/10/13 06:23:29 andreas_kupries Exp $

# -------------------------------------------------------------------------

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

testsNeedTcl     8.2
testsNeedTcltest 1.0

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

# -------------------------------------------------------------------------
# Now the package specific tests....
# -------------------------------------------------------------------------

test sha256-1.0 {sha256 usage} {
    catch {::sha2::sha256} result
    set result
} "wrong # args: should be \"::sha2::sha256 ?-hex|-bin? -filename file | -channel channel | string\""

test sha224-1.0 {sha224 usage} {
    catch {::sha2::sha224} result
    set result
} "wrong # args: should be \"::sha2::sha224 ?-hex|-bin? -filename file | -channel channel | string\""

# -------------------------------------------------------------------------
# Digest

# FIPS 180-2 test vectors SHA-256
set vectorsD \
    [list \
         "abc" \
         "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" \
         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" \
         "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" \
         [string repeat a 1000000] \
         "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" ]

# FIPS 180-2 test vectors SHA-224
set vectorsDT \
    [list \
         "abc" \
         "23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" \
         "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" \
         "75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" \
         [string repeat a 1000000] \
         "20794655980c91d8bbb4c1ea97618a4bf03f42581948b2ee4ee7ad67" ]

# -------------------------------------------------------------------------

TestAccelDo sha2 impl {
    set n 0
    foreach {msg hash} $vectorsD {
        test sha256-${impl}-2.$n {FIPS-180-2 test vectors for SHA-256} {
            list [catch {::sha2::sha256 $msg} r] $r
        } [list 0 $hash] ; # {}
        incr n
    }

    set n 0
    foreach {msg hash} $vectorsDT {
        test sha224-${impl}-2.$n {FIPS-180-2 test vectors for SHA-224} {
            list [catch {::sha2::sha224 $msg} r] $r
        } [list 0 $hash] ; # {}
        incr n
    }
}

# -------------------------------------------------------------------------

TestAccelExit sha2
testsuiteCleanup

# -------------------------------------------------------------------------
# Local Variables:
#   mode: tcl
#   indent-tabs-mode: nil
# End: