md5pure is a Tcl extension that computes an md5 message digest or hmac. md5pure uses only core Tcl commands and therefore requires no compilation.
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" 5eb63bbbe01eeed093cb22bb8f5acdc3
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" 61a922114c8aaf5050098be6d3a7daf0
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).
10 | 50 | 100 | 500 | 1000 | 5000 | 10000 | ||||
Sun Sparc 20 | Solaris 5.6 | Tcl 8.3.2 | gcc 2.95.2 | 21ms | 21ms | 40ms | 151ms | 299ms | 1.48s | 3.05s |
Sun Sparc Ultra 3000 | Solaris 5.6 | Tcl 8.3.2 | gcc 2.95.2 | 7ms | 7ms | 14ms | 54ms | 107ms | 0.53s | 1.07s |
Sun Sparc Ultra 2 | Solaris 5.6 | Tcl 8.3.2 | gcc 2.95.2 | 6ms | 6ms | 12ms | 46ms | 92ms | 0.46s | 0.92s |
Sun Sparc Ultra 60 | Solaris 5.6 | Tcl 8.3.2 | gcc 2.95.2 | 4ms | 4ms | 7ms | 29ms | 59ms | 0.29s | 0.59s |
Mac PB 300Mhz G3 | MacOS 9.0.4 | Tcl 8.4a2 | CW Pro 5+ | 2ms | 2ms | 5ms | 19ms | 38ms | 0.19s | 0.38s |
Mac 450Mhz G4 | MacOS 9.0.4 | Tcl 8.3.2 | CW Pro 5+ | 2ms | 1ms | 3ms | 12ms | 24ms | 0.1s | 0.25s |
Intel 650Mhz PIII | NT 4.0 | Tcl 8.2 | VC++ 5.0 | 1ms | 1ms | 2ms | 9ms | 18ms | 0.85s | 0.17s |
Intel 650Mhz PIII | NT 4.0 under VMware on SusE 2.2.14 | Tcl 8.4a2 | VC 6.0 | 1ms | 2ms | 3ms | 9ms | 17ms | 0.85s | 0.17s |
Intel 650Mhz PIII | SuSE 2.2.14 | Tcl 8.4a2 | gcc 2.95 | 1ms | 1ms | 2ms | 9ms | 18ms | 0.88s | 0.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.
Jean-Claude Wippler has a chart showing the performance of MD5 in various languages.
D. J. Hagberg contributed the hmac-md5 implementation.
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.tcl | The 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.tcl | Only 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.
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 LibesLast edited: Thu Mar 18 12:35:15 EST 2004 by Don Libes