File: rc4.test

package info (click to toggle)
tcllib 1.8-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 13,628 kB
  • ctags: 4,897
  • sloc: tcl: 88,012; sh: 7,856; ansic: 4,174; xml: 1,765; yacc: 753; perl: 84; f90: 84; makefile: 60; python: 33; ruby: 13; php: 11
file content (161 lines) | stat: -rw-r--r-- 5,982 bytes parent folder | download
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
95
96
97
98
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
125
126
127
128
129
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
160
161
# rc4.test - Copyright (C) 2004 Pat Thoyts <patthoyts@users.sourceforge.net>
#
# $Id: rc4.test,v 1.6 2005/02/20 01:56:20 patthoyts Exp $

# -------------------------------------------------------------------------
# Initialize the test package
#
if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest
    namespace import ::tcltest::*
}

# -------------------------------------------------------------------------
# Ensure we test _this_ local copy and one installed somewhere else.
#
package forget rc4
catch {namespace delete ::rc4}
if {[catch {source [file join [file dirname [info script]] rc4.tcl]} msg]} {
    puts "skipped [file tail [info script]]: $msg"
}

# -------------------------------------------------------------------------
# Setup any constraints
#

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

if {[info command ::rc4::rc4c] != {}} {
    puts "- rc4 [package present rc4] (critcl)"
}

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

test rc4-1.0 {rc4 basic command options} {
    list [catch {::rc4::rc4} msg] $msg
} {1 {wrong # args: should be "rc4 ?-hex? -key key -in channel | string"}}

test rc4-1.1 {rc4 basic command options} {
    list [catch {::rc4::rc4 -key secret} msg] $msg
} {1 {wrong # args: should be "rc4 ?-hex? -key key -in channel | string"}}

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

# Test vectors
set tests {
    "\x01\x23\x45\x67\x89\xab\xcd\xef"
    "\x01\x23\x45\x67\x89\xab\xcd\xef" 
    "\x75\xb7\x87\x80\x99\xe0\xc5\x96"

    "\x01\x23\x45\x67\x89\xab\xcd\xef"
    "\x00\x00\x00\x00\x00\x00\x00\x00"
    "\x74\x94\xc2\xe7\x10\x4b\x08\x79"

    "\x00\x00\x00\x00\x00\x00\x00\x00"
    "\x00\x00\x00\x00\x00\x00\x00\x00"
    "\xde\x18\x89\x41\xa3\x37\x5d\x3a"

    "\xef\x01\x23\x45"
    "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
    "\xd6\xa1\x41\xa7\xec\x3c\x38\xdf\xbd\x61"
}

lappend tests \
    "\x01\x23\x45\x67\x89\xab\xcd\xef" \
    [string repeat \x01 512] \
    [binary format H* \
         [join \
              "75 95 c3 e6 11 4a 09 78 0c 4a d4 52 33 8e 1f fd 9a 1b e9 49\
               8f 81 3d 76 53 34 49 b6 77 8d ca d8 c7 8a 8d 2b a9 ac 66 08\
               5d 0e 53 d5 9c 26 c2 d1 c4 90 c1 eb be 0c e6 6d 1b 6b 1b 13\
               b6 b9 19 b8 47 c2 5a 91 44 7a 95 e7 5e 4e f1 67 79 cd e8 bf\
               0a 95 85 0e 32 af 96 89 44 4f d3 77 10 8f 98 fd cb d4 e7 26\
               56 75 00 99 0b cc 7e 0c a3 c4 aa a3 04 a3 87 d2 0f 3b 8f bb\
               cd 42 a1 bd 31 1d 7a 43 03 dd a5 ab 07 88 96 ae 80 c1 8b 0a\
               f6 6d ff 31 96 16 eb 78 4e 49 5a d2 ce 90 d7 f7 72 a8 17 47\
               b6 5f 62 09 3b 1e 0d b9 e5 ba 53 2f af ec 47 50 83 23 e6 71\
               32 7d f9 44 44 32 cb 73 67 ce c8 2f 5d 44 c0 d0 0b 67 d6 50\
               a0 75 cd 4b 70 de dd 77 eb 9b 10 23 1b 6b 5b 74 13 47 39 6d\
               62 89 74 21 d4 3d f9 b4 2e 44 6e 35 8e 9c 11 a9 b2 18 4e cb\
               ef 0c d8 e7 a8 77 ef 96 8f 13 90 ec 9b 3d 35 a5 58 5c b0 09\
               29 0e 2f cd e7 b5 ec 66 d9 08 4b e4 40 55 a6 19 d9 dd 7f c3\
               16 6f 94 87 f7 cb 27 29 12 42 64 45 99 85 14 c1 5d 53 a1 8c\
               86 4c e3 a2 b7 55 57 93 98 81 26 52 0e ac f2 e3 06 6e 23 0c\
               91 be e4 dd 53 04 f5 fd 04 05 b3 5b d9 9c 73 13 5d 3d 9b c3\
               35 ee 04 9e f6 9b 38 67 bf 2d 7b d1 ea a5 95 d8 bf c0 06 6f\
               f8 d3 15 09 eb 0c 6c aa 00 6c 80 7a 62 3e f8 4c 3d 33 c1 95\
               d2 3e e3 20 c4 0d e0 55 81 57 c8 22 d4 b8 c5 69 d8 49 ae d5\
               9d 4e 0f d7 f3 79 58 6b 4b 7f f6 84 ed 6a 18 9f 74 86 d4 9b\
               9c 4b ad 9b a2 4b 96 ab f9 24 37 2c 8a 8f ff b1 0d 55 35 49\
               00 a7 7a 3d b5 f2 05 e1 b9 9f cd 86 60 86 3a 15 9a d4 ab e4\
               0f a4 89 34 16 3d dd e5 42 a6 58 55 40 fd 68 3c bf d8 c0 0f\
               12 12 9a 28 4d ea cc 4c de fe 58 be 71 37 54 1c 04 71 26 c8\
               d4 9e 27 55 ab 18 1a b7 e9 40 b0 c0" {}]]

if {[llength [info command ::rc4::rc4c]] != 0} {
    set n 0
    foreach {key input output} $tests {
        test rc4-critcl-2.$n {rc4 test vectors (critcl based)} {
            list [catch {::rc4::rc4 -key $key $input} msg] $msg
        } [list 0 $output]
        incr n
    }
}

puts "- rc4 [package present rc4] (pure Tcl - array based)"
set n 0
interp alias {} ::rc4::RC4Init {} ::rc4::RC4Init_Array
interp alias {} ::rc4::RC4     {} ::rc4::RC4_Array
foreach {key input output} $tests {
    test rc4-array-2.$n {rc4 test vectors (pure tcl array based)} {
        list [catch {::rc4::rc4 -key $key $input} msg] $msg
    } [list 0 $output]
    incr n
}

puts "- rc4 [package present rc4] (pure Tcl - list based)"
set n 0
interp alias {} ::rc4::RC4Init {} ::rc4::RC4Init_List
interp alias {} ::rc4::RC4     {} ::rc4::RC4_List
foreach {key input output} $tests {
    test rc4-list-2.$n {rc4 test vectors (pure tcl list based)} {
        list [catch {::rc4::rc4 -key $key $input} msg] $msg
    } [list 0 $output]
    incr n
}

test rc4-3.0 {rc4 check hyphen handling} {
    list [catch {rc4::rc4 -hex -key - \0} msg] $msg
} {0 9d}

test rc4-3.1 {rc4 check hyphen handling} {
    list [catch {rc4::rc4 -hex -key -- \0} msg] $msg
} {0 9d}

test rc4-3.2 {rc4 check hyphen handling} {
    list [catch {rc4::rc4 -hex -key - -} msg] $msg
} {0 b0}

test rc4-3.3 {rc4 check hyphen handling} {
    list [catch {rc4::rc4 -hex -key - --} msg] $msg
} {0 b046}

test rc4-3.4 {rc4 check hyphen handling} {
    list [catch {rc4::rc4 -hex -key - -- -} msg] $msg
} {0 b0}

test rc4-3.5 {rc4 check hyphen handling} {
    list [catch {rc4::rc4 -hex -key - -- --} msg] $msg
} {0 b046}


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

::tcltest::cleanupTests

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