md4(n) | MD4 Message-Digest Algorithm | md4(n) |
md4 - MD4 Message-Digest Algorithm
package require Tcl 8.2
package require md4 ?1.0?
::md4::md4 ?-hex? [ -channel channel | -file filename | string ]
::md4::hmac ?-hex? -key key [ -channel channel | -file filename | string ]
::md4::MD4Init
::md4::MD4Update token data
::md4::MD4Final token
::md4::HMACInit key
::md4::HMACUpdate token data
::md4::HMACFinal token
This package is an implementation in Tcl of the MD4 message-digest algorithm as described in RFC 1320 (1) and (2). This algorithm takes an arbitrary quantity of data and generates a 128-bit message digest from the input. The MD4 algorithm is faster but potentially weaker than the related MD5 algorithm (3).
If you have critcl and have built the tcllibc package then the implementation of the hashing function will be performed by compiled code. Alternatively if cryptkit is available this will be used. If no accelerator package can be found then the pure-tcl implementation is used. The programming interface remains the same in all cases.
The data to be hashed can be specified either as a string argument to the md4 command, or as a filename or a pre-opened channel. If the -filename argument is given then the file is opened, the data read and hashed and the file is closed. If the -channel argument is given then data is read from the channel until the end of file. The channel is not closed.
Only one of -file, -channel or string should be given.
For the programmer, the MD4 hash can be viewed as a bucket into which one pours data. When you have finished, you extract a value that is derived from the data that was poured into the bucket. The programming interface to the MD4 hash operates on a token (equivalent to the bucket). You call MD4Init to obtain a token and then call MD4Update as many times as required to add data to the hash. To release any resources and obtain the hash value, you then call MD4Final. An equivalent set of functions gives you a keyed digest (HMAC).
% md4::md4 -hex "Tcl does MD4" 858da9b31f57648a032230447bd15f25
% md4::hmac -hex -key Sekret "Tcl does MD4" c324088e5752872689caedf2a0464758
% set tok [md4::MD4Init] ::md4::1 % md4::MD4Update $tok "Tcl " % md4::MD4Update $tok "does " % md4::MD4Update $tok "MD4" % md4::Hex [md4::MD4Final $tok] 858da9b31f57648a032230447bd15f25
This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category md4 of the Tcllib SF Trackers [http://sourceforge.net/tracker/?group_id=12883]. Please also report any ideas for enhancements you may have for either package and/or documentation.
md5, sha1
hashing, md4, message-digest, rfc 1320, rfc 1321, rfc 2104, security
Hashes, checksums, and encryption
Copyright (c) 2003, Pat Thoyts <patthoyts@users.sourceforge.net>
1.0.5 | md4 |