From the wiki, i.e. http://wiki.tcl.tk/14648
Larry Virden wrote _________
LV 2008 June 27.
Here's what I get using ActiveTcl 8.5.2 (and teacup update):
$ tclsh8.5
% package require aes
set key [string repeat - 16]
set fullData {MalletData 9 q q q2 22}
set encryptedData [aes::aes -dir encrypt -key $key $fullData]
aes::aes -dir decrypt -key $key $encryptedData
puts $errorInfo
1.0.1
% ----------------
% MalletData 9 q q q2 22
% I9â3òÌH£í<¯CUÜËÚ¤N|úÙdÜp
% MalletData 9 q q q2 22
%
Vale adds _________
It's a bug in aes.tcl. After calling "binary scan binary-array I var", the numbers in var should be converted to unsigned 32-bit integers. You can define a procedure to do this.
proc ::aes::to_unsigned {data} {
upvar $data d
set i 0
foreach num $d {
lset d $i [expr { $num & 0xffffffff }]
incr i
}
}
There are 5 places to do the convertion, 2 in ::aes::EncryptBlock, 2 in ::aes::DecryptBlock and 1 in ::aes::ExpandKey. You should call to_unsigned after calling of binary scan, like this:
# original code
if {[binary scan $block I4 data] != 1} {
return -code error "invalid block size: blocks must be 16 bytes"
}
# bug-fix add here
to_unsigned data
AK, not from the wiki _________
Note also the ChangeLog entry ...
2008-05-12 Andreas Kupries <andreask@activestate.com>
* aes.tcl (DecryptBlock, EncryptBlock): Added code limiting the
* aes.man: values to int32 range, to prevent going out of range
* aes.test: when run by Tcl 8.5 and its bignums. Extended
* pkgIndex.tcl: testsuite to catch a problematic case which fails
without the change. Bumped version to 1.0.1.
It may be that this is the same bug, that the fix made was not enough.
Or a similar one.