md4(3tcl)
π md4 β MD4 Message-Digest Algorithm π
okay bestie, so this is md4(3tcl), the MD4 message-digest page from the tcllib fam, and we are gonna get you so comfy with it. grab a boba, sit down, let's go π«Ά
β¨ NAME β¨
md4 β the MD4 Message-Digest Algorithm, no cap π
π SYNOPSIS π
package require Tcl 8.5 9
package require md4 ?1.0.8?
::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
πΈ DESCRIPTION πΈ
So this package is a Tcl implementation of the MD4 message-digest algorithm, exactly as it's described in RFC 1320 (1) and (2). The vibe: you feed it literally any amount of data, and it hands you back a 128-bit message digest of that input. And yes, MD4 is faster than its cousin MD5 (3), but it's also potentially weaker β that's just the tradeoff, iykyk.
Now, the backend situation π§: if you've got critcl and you've built the tcllibc package, then the hashing gets done by compiled code. Alternatively, if cryptkit is available, that'll get used instead. And if no accelerator package can be found at all, it falls back to the pure-tcl implementation. The good news? The programming interface stays exactly the same in all three cases. slay β¨
β οΈ BEWARE β the commands in this package expect binary data as their input, fr fr. When you pass a-file, the commands handle that for you, because they open the referenced file in binary mode themselves. But when you're passing literal data, or a-channel, then your caller ass is responsible for making sure it's binary. The conversion command you want is:
encoding convertto utf-8 $string
π¨ ATTENTION, there is a Tcl 9 COMPATIBILITY ISSUE here and it is not cute. Tcl 8.x silently mishandles non-binary input by cutting it internally to size β meaning it only uses the low byte of a higher unicode point. No error gets thrown. The result is just simply wrong. π Tcl 9 throws an error instead, like this: expected byte sequence but character <location> was ...
π COMMANDS π
::md4::md4 ?-hex? [ -channel channel | -file filename | string ]β calculates the MD4 digest of the data you hand it in string. By default it comes back as a binary string. Toss in the-hexoption and you get a hexadecimal encoded version of that digest instead. π
The data being hashed can be given as a string argument to the md4 command, or as a filename, or as a pre-opened channel. If you give the -filename argument, then the file gets opened, the data read and hashed, and the file closed. If you give the -channel argument, data is read from the channel until end of file β and the channel is not closed. π
Only one of -file, -channel or string should be given. pick one bestie, don't be greedy π
::md4::hmac ?-hex? -key key [ -channel channel | -file filename | string ]β calculates a Hashed Message Authentication digest (HMAC) using the MD4 digest algorithm. HMACs are described in RFC 2104 (4), and they give you an MD4 digest that includes a key. Every option other than-keyworks exactly like it does for the::md4::md4command. π₯
π¦ PROGRAMMING INTERFACE π¦
For the programmer girlies: think of the MD4 hash as a bucket πͺ£ that you pour data into. When you're done pouring, you extract a value that's derived from everything you poured in. The programming interface to the MD4 hash works on a token β and yeah, that token is basically the bucket. You call MD4Init to get a token, then you call MD4Update as many times as you need to add data to the hash. To release any resources and grab the hash value, you call MD4Final. And there's an equivalent set of functions that gives you a keyed digest (HMAC). obsessed. β¨
::md4::MD4Initβ begins a brand new MD4 hash. Returns a token ID that you must use for all the remaining functions. π::md4::MD4Update token dataβ adds data to the hash identified by token. CallingMD4Update $token "abcd"is equivalent to callingMD4Update $token "ab"followed byMD4Update $token "cb". See EXAMPLES below, bestie. πΈ::md4::MD4Final tokenβ returns the hash value and releases any resources held by this token. Once this command completes, the token is invalid. The result is a binary string of 16 bytes representing the 128 bit MD4 digest value. π::md4::HMACInit keyβ this is equivalent to the::md4::MD4Initcommand, except it requires the key that will be included in the HMAC. π::md4::HMACUpdate token dataβ (no extra description, it's just chillin')::md4::HMACFinal tokenβ these commands are identical to the MD4 equivalent commands. periodt. π
π EXAMPLES π
% 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
look at that hash match up on the first and last one. iconic behavior β
π REFERENCES π
- Rivest, R., "The MD4 Message Digest Algorithm", RFC 1320, MIT, April 1992. (http://www.rfc-editor.org/rfc/rfc1320.txt)
- 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.
- Rivest, R., "The MD5 Message-Digest Algorithm", RFC 1321, MIT and RSA Data Security, Inc, April 1992. (http://www.rfc-editor.org/rfc/rfc1321.txt)
- Krawczyk, H., Bellare, M. and Canetti, R. "HMAC: Keyed-Hashing for Message Authentication", RFC 2104, February 1997. (http://www.rfc-editor.org/rfc/rfc2104.txt)
π BUGS, IDEAS, FEEDBACK π
ngl, 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 [http://core.tcl.tk/tcllib/reportlist]. And please also report any ideas for enhancements you may have for either the package and/or the documentation β we want the feedback, fr fr. π«Ά
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. iykyk π
π SEE ALSO π
md5, sha1
π KEYWORDS π
hashing, md4, message-digest, rfc 1320, rfc 1321, rfc 2104, security
π CATEGORY π
Hashes, checksums, and encryption
π COPYRIGHT π
Copyright (c) 2003, Pat Thoyts <patthoyts@users.sourceforge.net>
and that's the whole page bestie!! this one's from the tcllib girlies, version 1.0.8, and it's the md4(3tcl) manual page β go forth and hash responsibly, mwah πβ¨ππ¦πΈπ
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2003, Pat Thoyts <patthoyts@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms