The md5pure Home Page

md5pure is a Tcl extension that computes an md5 message digest or hmac. md5pure uses only core Tcl commands and therefore requires no compilation.

How To Use

md5pure can be loaded using package require md5pure. Alternatively, it can be sourced or even inserted directly into another source file.

md5 message digests are computed using the md5pure::md5 command. It takes a single argument and returns the message digest. For example:

      % md5pure::md5 "hello world"

md5 hmacs are computed using the md5pure::hmac command. Its takes key and text arguments and returns the hmac. For example:

      % md5pure::hmac "our little secret" "hello world"


md5pure was not written for efficiency and is inappropriate for large arguments. Applications requiring high-performance should use Andreas Kupries' trf extension. trf implements several other message digests and contains many other conversion functions.

md5pure is appropriate for small arguments. Here are some timings. The numbers along the top of this chart indicate the message size (in bytes). So for example, to produce a digest of a 50-byte string on a Sparc 20 required 21ms (about 1/50 of a second).

Sun Sparc 20Solaris 5.6Tcl 8.3.2gcc 2.95.221ms21ms40ms151ms299ms1.48s3.05s
Sun Sparc Ultra 3000Solaris 5.6Tcl 8.3.2gcc 2.95.27ms7ms14ms54ms107ms0.53s1.07s
Sun Sparc Ultra 2Solaris 5.6Tcl 8.3.2gcc 2.95.26ms6ms12ms46ms92ms0.46s0.92s
Sun Sparc Ultra 60Solaris 5.6Tcl 8.3.2gcc 2.95.24ms4ms7ms29ms59ms0.29s0.59s
Mac PB 300Mhz G3MacOS 9.0.4Tcl 8.4a2CW Pro 5+2ms2ms5ms19ms38ms0.19s0.38s
Mac 450Mhz G4MacOS 9.0.4Tcl 8.3.2CW Pro 5+2ms1ms3ms12ms24ms0.1s0.25s
Intel 650Mhz PIIINT 4.0Tcl 8.2VC++ 5.01ms1ms2ms9ms18ms0.85s0.17s
Intel 650Mhz PIIINT 4.0 under VMware on SusE 2.2.14Tcl 8.4a2VC 6.01ms2ms3ms9ms17ms0.85s0.17s
Intel 650Mhz PIIISuSE 2.2.14Tcl 8.4a2gcc 2.951ms1ms2ms9ms18ms0.88s0.18s

The careful reader will note that the times for 10 and 50 are very close. In fact, the md5 algorithm pads all messages out to (roughly speaking) 64-byte boundaries so any difference in times is just system noise. The precise steps in the algorithm occur at 56 + 64n characters.

If you want to do your own timings, run: md5pure::time

I have optimized the code but only modestly because the performance is already acceptable for my own purposes. If you want to send me additional speedups, fine. However, I would prefer not to destroy the readability of the code or otherwise perturb it too much. The current implementation parallels the pseudocode in RFC 1321 very closely - in fact, most of the comments are direct quotes from the RFC. I'd hesitate to give that up.

Cross-language comparison

Jean-Claude Wippler has a chart showing the performance of MD5 in various languages.


D. J. Hagberg contributed the hmac-md5 implementation.

Other Caveats

md5pure has not been tested on machines with 64-bit integers. It is possible that it may not work on all 64-bit machines, due to integer layout although I haven't checked any. (I would be interested to hear feedback about this.)


md5pure includes a test suite. For simplicity, it is included in the md5pure package itself. To run the tests, load the package and run: md5pure::test


md5pure.tclThe source to md5pure. Note: if you've got the Tcl plugin loaded in your browser, you'll have to shift-click when fetching to avoid it being executed!
pkgIndex.tclOnly necessary if you want to load md5pure as a package.


There is no installation script since it is expected that most people will simply insert or include the md5pure.tcl file into their applications directly. However, a pkgIndex.tcl file is available so that md5pure can be installed as a package.

Generic Disclaimer

Although I can't promise anything in the way of support, I'd be interested to hear about your experiences using it (good or bad). I'm also interested in hearing bug reports and suggestions for improvement even though I can't promise to implement them.

If you send me a bug, fix, or question, include the version of md5pure, version of Tcl, and name and version of the OS that you are using. Before sending mail, it may be helpful to verify that your problem still exists in the latest version. You can check on the current release and whether it addresses your problems by retrieving the latest HISTORY.

Awards, love letters, and bug reports may be sent to:

Don Libes
National Institute of Standards and Technology
100 Bureau Dr, Stop 8260
Gaithersburg, MD 20899-8260
(301) 975-3535


Last edited: Thu Mar 18 12:35:15 EST 2004 by Don Libes