Tcl Library Source Code

EuroTcl/OpenACS 11 - 12 JULY 2024, VIENNA

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


ripemd128 - RIPEMD-128 Message-Digest Algorithm

Table Of Contents


package require Tcl 8.5 9
package require ripemd128 ?1.0.6?

::ripemd::ripemd128 ?-hex? [ -channel channel | -file filename | string ]
::ripemd::hmac128 ?-hex? -key key [ -channel channel | -file filename | string ]
::ripemd::RIPEMD128Update token data
::ripemd::RIPEMD128Final token
::ripemd::RIPEHMAC128Init key
::ripemd::RIPEHMAC128Update token data
::ripemd::RIPEHMAC128Final token


This package is an implementation in Tcl of the RIPEMD-128 message-digest algorithm (1). This algorithm takes an arbitrary quantity of data and generates a 128-bit message digest from the input. The RIPEMD-128 algorithm is based upon the MD4 algorithm (2, 4) but has been cryptographically strengthened against weaknesses that have been found in MD4 (4). RIPEMD-128 has been designed to be a drop-in replacement for MD4 and MD5 (5). If security is the major consideration, then RIPEMD-160 or SHA1 should be considered.

This package will use Trf to accelerate the digest computation if available. In the absence of an accelerator package the pure-Tcl implementation will be used.



For the programmer, hash functions can be viewed as a bucket into which one pours data. When you have finished, you extract a value that is uniquely derived from the data that was poured into the bucket. The programming interface to the hash operates on a token (equivalent to the bucket). You call RIPEMD128Init to obtain a token and then call RIPEMD128Update as many times as required to add data to the hash. To release any resources and obtain the hash value, you then call RIPEMD128Final. An equivalent set of functions gives you a keyed digest (HMAC).

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 both the Trf and Memchan extensions are available then these will be used. Finally the package will revert to a pure-Tcl implementation. The programming interface remains the same, however.


% ripemd::ripemd128 -hex "Tcl does RIPEMD-128"

% ripemd::hmac128 -hex -key Sekret "Tcl does RIPEMD-128"

% set tok [ripemd::RIPEMD128Init]
% ripemd::RIPEMD128Update $tok "Tcl "
% ripemd::RIPEMD128Update $tok "does "
% ripemd::RIPEMD128Update $tok "RIPEMD-128"
% ripemd::Hex [ripemd::RIPEMD128Final $tok]


  1. H. Dobbertin, A. Bosselaers, B. Preneel, "RIPEMD-160, a strengthened version of RIPEMD"

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

  3. 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.

  4. Dobbertin, H., "Cryptanalysis of MD4", Journal of Cryptology vol 11 (4), pp. 253-271 (1998)

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

  6. 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 ripemd 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.


md4, md5, ripemd160, sha1


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


Hashes, checksums, and encryption


Copyright © 2004, Pat Thoyts