Tcl Library Source Code

Check-in [43401a27e1]
Login

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

Overview
Comment:aes - Moved tests fully to tcltest v2 format. Moved to require Tcl 8.5.
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 43401a27e1cf106438d7361dbc1d660322c7e8c3
User & Date: andreask 2014-09-23 00:09:55
Context
2014-09-23
00:18
aes - Ticket [358a88716e]. Applied patch improving performance by changing how the IV is stored. Version bumped to 1.2. Core dependency change! This version requires Tcl 8.5. check-in: 4b3d8bca51 user: andreask tags: trunk
00:09
aes - Moved tests fully to tcltest v2 format. Moved to require Tcl 8.5. check-in: 43401a27e1 user: andreask tags: trunk
2014-09-22
23:33
Created the constraints in the previous commit, and still forgot to apply it. Now applied. check-in: 17f2ede061 user: andreask tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/aes/aes.test.

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
162
163
164
165
166
167
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
194
195
196

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

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

testsNeedTcl     8.4
testsNeedTcltest 2

testing {
    useLocal aes.tcl aes
}

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

# data for variable key KAT

# Sample vectors from FIPS 197 specification document.
#
test aes-fips-C.1e {Test vector for AES-128 from FIPS-197 Appendix C.1} {
    list [catch {
        set txt [binary format H* 00112233445566778899aabbccddeeff]
        set key [binary format H* 000102030405060708090a0b0c0d0e0f]

        set enc [aes::aes -mode ecb -dir enc -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 69c4e0d86a7b0430d8cdb78070b4c55a}

test aes-fips-C.1d {Test vector for AES-128 from FIPS-197 Appendix C.1} {
    list [catch {
        set txt [binary format H* 69c4e0d86a7b0430d8cdb78070b4c55a]
        set key [binary format H* 000102030405060708090a0b0c0d0e0f]

        set enc [aes::aes -mode ecb -dir dec -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 00112233445566778899aabbccddeeff}

test aes-fips-C.2e {Test vector for AES-192 from FIPS-197 Appendix C.2} {
    list [catch {
        set txt [binary format H* 00112233445566778899aabbccddeeff]
        set key [binary format H* 000102030405060708090a0b0c0d0e0f1011121314151617]

        set enc [aes::aes -mode ecb -dir enc -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 dda97ca4864cdfe06eaf70a0ec0d7191}

test aes-fips-C.2d {Test vector for AES-192 from FIPS-197 Appendix C.2} {
    list [catch {
        set txt [binary format H* dda97ca4864cdfe06eaf70a0ec0d7191]
        set key [binary format H* 000102030405060708090a0b0c0d0e0f1011121314151617]

        set enc [aes::aes -mode ecb -dir dec -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 00112233445566778899aabbccddeeff}

test aes-fips-C.3e {Test vector for AES-256 from FIPS-197 Appendix C.3} {
    list [catch {
        set txt [binary format H* 00112233445566778899aabbccddeeff]
        set key [binary format H* 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f]

        set enc [aes::aes -mode ecb -dir enc -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 8ea2b7ca516745bfeafc49904b496089}

test aes-fips-C.3d {Test vector for AES-256 from FIPS-197 Appendix C.3} {
    list [catch {
        set txt [binary format H* 8ea2b7ca516745bfeafc49904b496089]
        set key [binary format H* 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f]

        set enc [aes::aes -mode ecb -dir dec -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 00112233445566778899aabbccddeeff}


test aes-kat-ecb-128e {Known answer tests - AES-128 ECB encryption} {
    list [catch {
        set txt [binary format H* 000102030405060708090a0b0c0d0e0f]
        set key [binary format H* 000102030405060708090a0b0c0d0e0f]

        set enc [aes::aes -mode ecb -dir enc -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 0a940bb5416ef045f1c39458c653ea5a}

test aes-kat-ecb-128d {Known answer tests - AES-128 ECB decryption} {
    list [catch {
        set txt [binary format H* 0a940bb5416ef045f1c39458c653ea5a]
        set key [binary format H* 000102030405060708090a0b0c0d0e0f]

        set enc [aes::aes -mode ecb -dir dec -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 000102030405060708090a0b0c0d0e0f}

test aes-kat-ecb-192e {Known answer tests - AES-192 ECB encryption} {
    list [catch {
        set txt [binary format H* 000102030405060708090a0b0c0d0e0f]
        set key [binary format H* 000102030405060708090A0B0C0D0E0F1011121314151617]

        set enc [aes::aes -mode ecb -dir enc -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 0060bffe46834bb8da5cf9a61ff220ae}

test aes-kat-ecb-192d {Known answer tests - AES-192 ECB decryption} {
    list [catch {
        set txt [binary format H* 0060bffe46834bb8da5cf9a61ff220ae]
        set key [binary format H* 000102030405060708090A0B0C0D0E0F1011121314151617]

        set enc [aes::aes -mode ecb -dir dec -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 000102030405060708090a0b0c0d0e0f}

test aes-kat-ecb-256e {Known answer tests - AES-256 ECB encryption} {
    list [catch {
        set txt [binary format H* 000102030405060708090a0b0c0d0e0f]
        set key [binary format H* 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F]

        set enc [aes::aes -mode ecb -dir enc -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 5a6e045708fb7196f02e553d02c3a692}

test aes-kat-ecb-256d {Known answer tests - AES-256 ECB decryption} {
    list [catch {
        set txt [binary format H* 5a6e045708fb7196f02e553d02c3a692]
        set key [binary format H* 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F]

        set enc [aes::aes -mode ecb -dir dec -key $key $txt]
        binary scan $enc H* r
        set r
    } msg] $msg

} {0 000102030405060708090a0b0c0d0e0f}


# N key ic plain cipher
set vectors {
    1 06a9214036b8a15b512e03d534120006 3dafba429d9eb430b422da802c9fac41
      53696e676c6520626c6f636b206d7367 e353779c1079aeb82708942dbe77181a
    2 c286696d887c9aa0611bbb3e2025a45a 562e17996d093d28ddb3ba695a2e6f58
      000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
      d296cd94c2cccf8a3a863028b5e1dc0a7586602d253cfff91b8266bea6d61ab1
    3 6c3ea0477630ce21a2ce334aa746c2cd c782dc4c098c66cbd9cd27d825682c81
      5468697320697320612034382d62797465206d657373616765202865786163746c7920332041455320626c6f636b7329
      d0a02b3836451753d493665d33f0e8862dea54cdb293abc7506939276772f8d5021c19216bad525c8579695d83ba2684    
    4 56e47a38c5598974bc46903dba290349 8ce82eefbea0da3c44699ed7db51b7d9
      a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedf
      c30e32ffedc0774e6aff6af0869f71aa0f3af07a9a31a9c684db207eb0ef8e4e35907aa632c3ffdf868bb7b29d3d46ad83ce9f9a102ee99d49a53e87f4c3da55
}

foreach {n key iv pt ct} $vectors {
    test aes-cbc-${n}e {RFC3602 AES-128 CBC mode encryption} {
        list [catch {
            set K [binary format H* $key]
            set I [binary format H* $iv]

            set aes [aes::aes -mode cbc -dir enc -key $K -iv $I [binary format H* $pt]]
            binary scan $aes H* r
            set r
        } msg] $msg

    } [list 0 $ct]
    
    test aes-cbc-${n}d {RFC3602 AES-128 CBC mode decryption} {
        list [catch {
            set K [binary format H* $key]
            set I [binary format H* $iv]

            set aes [aes::aes -mode cbc -dir dec -key $K -iv $I [binary format H* $ct]]
            binary scan $aes H* r
            set r
        } msg] $msg

    } [list 0 $pt]
}

# Known answer tests (CBC)
#    0 00000000000000000000000000000000 00000000000000000000000000000000 
#      00000000000000000000000000000000 8a05fc5e095af4848a08d328d3688e3d
#    1 8a05fc5e095af4848a08d328d3688e3d 8a05fc5e095af4848a08d328d3688e3d
#      204f17e2444381f6114ff53934c0bcd3 192d9b3aa10bb2f7846ccba0085c657a







|












|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|
<

|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|


















|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|







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
162
163
164
165
166
167
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

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209

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

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

testsNeedTcl     8.5
testsNeedTcltest 2

testing {
    useLocal aes.tcl aes
}

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

# data for variable key KAT

# Sample vectors from FIPS 197 specification document.
#
test aes-fips-C.1e {Test vector for AES-128 from FIPS-197 Appendix C.1} -setup {

    set txt [binary format H* 00112233445566778899aabbccddeeff]
    set key [binary format H* 000102030405060708090a0b0c0d0e0f]
} -body {
    set enc [aes::aes -mode ecb -dir enc -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 69c4e0d86a7b0430d8cdb78070b4c55a

test aes-fips-C.1d {Test vector for AES-128 from FIPS-197 Appendix C.1} -setup {

    set txt [binary format H* 69c4e0d86a7b0430d8cdb78070b4c55a]
    set key [binary format H* 000102030405060708090a0b0c0d0e0f]
} -body {
    set enc [aes::aes -mode ecb -dir dec -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 00112233445566778899aabbccddeeff

test aes-fips-C.2e {Test vector for AES-192 from FIPS-197 Appendix C.2} -setup {

    set txt [binary format H* 00112233445566778899aabbccddeeff]
    set key [binary format H* 000102030405060708090a0b0c0d0e0f1011121314151617]
} -body {
    set enc [aes::aes -mode ecb -dir enc -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result dda97ca4864cdfe06eaf70a0ec0d7191

test aes-fips-C.2d {Test vector for AES-192 from FIPS-197 Appendix C.2} -setup {

    set txt [binary format H* dda97ca4864cdfe06eaf70a0ec0d7191]
    set key [binary format H* 000102030405060708090a0b0c0d0e0f1011121314151617]
} -body {
    set enc [aes::aes -mode ecb -dir dec -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 00112233445566778899aabbccddeeff

test aes-fips-C.3e {Test vector for AES-256 from FIPS-197 Appendix C.3} -setup {

    set txt [binary format H* 00112233445566778899aabbccddeeff]
    set key [binary format H* 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f]
} -body {
    set enc [aes::aes -mode ecb -dir enc -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 8ea2b7ca516745bfeafc49904b496089

test aes-fips-C.3d {Test vector for AES-256 from FIPS-197 Appendix C.3} -setup {

    set txt [binary format H* 8ea2b7ca516745bfeafc49904b496089]
    set key [binary format H* 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f]
} -body {
    set enc [aes::aes -mode ecb -dir dec -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 00112233445566778899aabbccddeeff


test aes-kat-ecb-128e {Known answer tests - AES-128 ECB encryption} -setup {

    set txt [binary format H* 000102030405060708090a0b0c0d0e0f]
    set key [binary format H* 000102030405060708090a0b0c0d0e0f]
} -body {
    set enc [aes::aes -mode ecb -dir enc -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 0a940bb5416ef045f1c39458c653ea5a

test aes-kat-ecb-128d {Known answer tests - AES-128 ECB decryption} -setup {

    set txt [binary format H* 0a940bb5416ef045f1c39458c653ea5a]
    set key [binary format H* 000102030405060708090a0b0c0d0e0f]
} -body {
    set enc [aes::aes -mode ecb -dir dec -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 000102030405060708090a0b0c0d0e0f

test aes-kat-ecb-192e {Known answer tests - AES-192 ECB encryption} -setup {

    set txt [binary format H* 000102030405060708090a0b0c0d0e0f]
    set key [binary format H* 000102030405060708090A0B0C0D0E0F1011121314151617]
} -body {
    set enc [aes::aes -mode ecb -dir enc -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 0060bffe46834bb8da5cf9a61ff220ae

test aes-kat-ecb-192d {Known answer tests - AES-192 ECB decryption} -setup {

    set txt [binary format H* 0060bffe46834bb8da5cf9a61ff220ae]
    set key [binary format H* 000102030405060708090A0B0C0D0E0F1011121314151617]
} -body {
    set enc [aes::aes -mode ecb -dir dec -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 000102030405060708090a0b0c0d0e0f

test aes-kat-ecb-256e {Known answer tests - AES-256 ECB encryption} -setup {

    set txt [binary format H* 000102030405060708090a0b0c0d0e0f]
    set key [binary format H* 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F]
} -body {
    set enc [aes::aes -mode ecb -dir enc -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 5a6e045708fb7196f02e553d02c3a692

test aes-kat-ecb-256d {Known answer tests - AES-256 ECB decryption} -setup {

    set txt [binary format H* 5a6e045708fb7196f02e553d02c3a692]
    set key [binary format H* 000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F]
} -body {
    set enc [aes::aes -mode ecb -dir dec -key $key $txt]
    binary scan $enc H* r
    set r
} -cleanup {
    unset txt key enc r
} -result 000102030405060708090a0b0c0d0e0f


# N key ic plain cipher
set vectors {
    1 06a9214036b8a15b512e03d534120006 3dafba429d9eb430b422da802c9fac41
      53696e676c6520626c6f636b206d7367 e353779c1079aeb82708942dbe77181a
    2 c286696d887c9aa0611bbb3e2025a45a 562e17996d093d28ddb3ba695a2e6f58
      000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f
      d296cd94c2cccf8a3a863028b5e1dc0a7586602d253cfff91b8266bea6d61ab1
    3 6c3ea0477630ce21a2ce334aa746c2cd c782dc4c098c66cbd9cd27d825682c81
      5468697320697320612034382d62797465206d657373616765202865786163746c7920332041455320626c6f636b7329
      d0a02b3836451753d493665d33f0e8862dea54cdb293abc7506939276772f8d5021c19216bad525c8579695d83ba2684    
    4 56e47a38c5598974bc46903dba290349 8ce82eefbea0da3c44699ed7db51b7d9
      a0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedf
      c30e32ffedc0774e6aff6af0869f71aa0f3af07a9a31a9c684db207eb0ef8e4e35907aa632c3ffdf868bb7b29d3d46ad83ce9f9a102ee99d49a53e87f4c3da55
}

foreach {n key iv pt ct} $vectors {
    test aes-cbc-${n}e {RFC3602 AES-128 CBC mode encryption} -setup {

        set K [binary format H* $key]
        set I [binary format H* $iv]
    } -body {
        set aes [aes::aes -mode cbc -dir enc -key $K -iv $I [binary format H* $pt]]
        binary scan $aes H* r
        set r
    } -cleanup {
        unset r K I aes
    } -result $ct
    
    test aes-cbc-${n}d {RFC3602 AES-128 CBC mode decryption} -setup {

        set K [binary format H* $key]
        set I [binary format H* $iv]
    } -body {
        set aes [aes::aes -mode cbc -dir dec -key $K -iv $I [binary format H* $ct]]
        binary scan $aes H* r
        set r
    } -cleanup {
        unset r K I aes
    } -result $pt
}

# Known answer tests (CBC)
#    0 00000000000000000000000000000000 00000000000000000000000000000000 
#      00000000000000000000000000000000 8a05fc5e095af4848a08d328d3688e3d
#    1 8a05fc5e095af4848a08d328d3688e3d 8a05fc5e095af4848a08d328d3688e3d
#      204f17e2444381f6114ff53934c0bcd3 192d9b3aa10bb2f7846ccba0085c657a
207
208
209
210
211
212
213
214
215
216
217

218
219
220
221

222
223
224
225
226
227

228
229
230
231

232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
    3132333435363738393031323334353637383930313233343536373839303132
    c3f0929f353c2fc78b9c6705397f22c8
    005a0000003b00000000000000000000
    97d94ab5d6a6bf3e9a126b67b8b3bc12
}

foreach {n key iv pt ct} $vectors {
    test aes-cbc-x${n}e {RFC3602 AES-128 CBC mode encryption} {
        list [catch {
            set K [binary format H* $key]
            set I [binary format H* $iv]

            set aes [aes::aes -mode cbc -dir enc -key $K -iv $I [binary format H* $pt]]
            binary scan $aes H* r
            set r
        } msg] $msg

    } [list 0 $ct]
    
    test aes-cbc-x${n}d {RFC3602 AES-128 CBC mode decryption} {
        list [catch {
            set K [binary format H* $key]
            set I [binary format H* $iv]

            set aes [aes::aes -mode cbc -dir dec -key $K -iv $I [binary format H* $ct]]
            binary scan $aes H* r
            set r
        } msg] $msg

    } [list 0 $pt]
}

test aes-sf2993029 {aes decrypt, wide integer, sf bug 2993029} {

    aes::aes -hex -mode ecb -dir decrypt \
        -key [binary format H* FEDCBA98FEDCBA98FEDCBA98FEDCBA98] \
        [binary format H* 2a666624a86d4c29de37b520781c1069]

} {01000000000000003d5afbb584a29f57}

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

test aes-sf-3574004-a {aes use with data starting with a dash, auto-stop} {
    aes::aes -hex -mode cbc -dir encrypt -key [string repeat \\0 16] -[string repeat \\0 15]
} cc45117986e38ae95944f9eeaa7b700b240fdd169eacd2a20505ef4c6507c907

test aes-sf-3574004-b {aes use with data starting with a dash, double-dash} {
    aes::aes -hex -mode cbc -dir encrypt -key [string repeat \\0 16] -- -[string repeat \\0 15]
} cc45117986e38ae95944f9eeaa7b700b240fdd169eacd2a20505ef4c6507c907

# -------------------------------------------------------------------------
## TODO: Go through the various possible options and combinations.

test aes-sf-3612645-a0 {aes use of -in option, allura 1366} -setup {
    set key     [binary format a32 0123456789012345678901234567890123456789]
    set encfile [tcltest::makeFile {} aes.encrypt]







|
<
|
|
>
|
|
|
|
>
|

|
<
|
|
>
|
|
|
|
>
|


|
<



<
|



|

|

|

|







220
221
222
223
224
225
226
227

228
229
230
231
232
233
234
235
236
237
238

239
240
241
242
243
244
245
246
247
248
249
250

251
252
253

254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
    3132333435363738393031323334353637383930313233343536373839303132
    c3f0929f353c2fc78b9c6705397f22c8
    005a0000003b00000000000000000000
    97d94ab5d6a6bf3e9a126b67b8b3bc12
}

foreach {n key iv pt ct} $vectors {
    test aes-cbc-x${n}e {RFC3602 AES-128 CBC mode encryption} -setup {

        set K [binary format H* $key]
        set I [binary format H* $iv]
    } -body {
        set aes [aes::aes -mode cbc -dir enc -key $K -iv $I [binary format H* $pt]]
        binary scan $aes H* r
        set r
    } -cleanup {
        unset r K I aes
    } -result $ct
    
    test aes-cbc-x${n}d {RFC3602 AES-128 CBC mode decryption} -setup {

        set K [binary format H* $key]
        set I [binary format H* $iv]
    } -body {
        set aes [aes::aes -mode cbc -dir dec -key $K -iv $I [binary format H* $ct]]
        binary scan $aes H* r
        set r
    } -cleanup {
        unset r K I aes
    } -result $pt
}

test aes-sf2993029 {aes decrypt, wide integer, sf bug 2993029} -body {

    aes::aes -hex -mode ecb -dir decrypt \
        -key [binary format H* FEDCBA98FEDCBA98FEDCBA98FEDCBA98] \
        [binary format H* 2a666624a86d4c29de37b520781c1069]

} -result 01000000000000003d5afbb584a29f57

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

test aes-sf-3574004-a {aes use with data starting with a dash, auto-stop} -body {
    aes::aes -hex -mode cbc -dir encrypt -key [string repeat \\0 16] -[string repeat \\0 15]
} -result cc45117986e38ae95944f9eeaa7b700b240fdd169eacd2a20505ef4c6507c907

test aes-sf-3574004-b {aes use with data starting with a dash, double-dash} -body {
    aes::aes -hex -mode cbc -dir encrypt -key [string repeat \\0 16] -- -[string repeat \\0 15]
} -result cc45117986e38ae95944f9eeaa7b700b240fdd169eacd2a20505ef4c6507c907

# -------------------------------------------------------------------------
## TODO: Go through the various possible options and combinations.

test aes-sf-3612645-a0 {aes use of -in option, allura 1366} -setup {
    set key     [binary format a32 0123456789012345678901234567890123456789]
    set encfile [tcltest::makeFile {} aes.encrypt]