Tcl Library Source Code


[ Main Table Of Contents | Table Of Contents | Keyword Index | Categories | Modules | Applications ]


md4 - MD4 Message-Digest Algorithm

Table Of Contents


package require Tcl 8.5 9
package require md4 ?1.0.7?

::md4::md4 ?-hex? [ -channel channel | -file filename | string ]
::md4::hmac ?-hex? -key key [ -channel channel | -file filename | string ]
::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.



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"

% md4::hmac -hex -key Sekret "Tcl does MD4"

% set tok [md4::MD4Init]
% md4::MD4Update $tok "Tcl "
% md4::MD4Update $tok "does "
% md4::MD4Update $tok "MD4"
% md4::Hex [md4::MD4Final $tok]


  1. Rivest, R., "The MD4 Message Digest Algorithm", RFC 1320, MIT, April 1992. (

  2. Rivest, R., "The MD4 message digest algorithm", in A.J. Menezes and S.A. Vanstone, editors, Advances in Cryptology - CRYPTO '90 Proceedings, pages 303-311, Springer-Verlag, 1991.

  3. Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, MIT and RSA Data Security, Inc, April 1992. (

  4. Krawczyk, H., Bellare, M. and Canetti, R. "HMAC: Keyed-Hashing for Message Authentication", RFC 2104, February 1997. (

Bugs, Ideas, Feedback

This document, and the package it describes, will undoubtedly contain bugs and other problems. Please report such in the category md4 of the Tcllib Trackers. Please also report any ideas for enhancements you may have for either package and/or documentation.

When proposing code changes, please provide unified diffs, i.e the output of diff -u.

Note further that attachments are strongly preferred over inlined patches. Attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar.


md5, sha1


hashing, md4, message-digest, rfc 1320, rfc 1321, rfc 2104, security


Hashes, checksums, and encryption


Copyright © 2003, Pat Thoyts