md4(n)

πŸ“¦
version 2.0 Β· 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

md4(n) β€” MD4 Message-Digest Algorithm πŸ’–

okay bestie, gather round, we're doing the MD4 Message-Digest Algorithm and honestly? it's giving vintage, it's giving iconic, it's giving "yes this is in Tcl." no cap. let's go ✨


✨ 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

like look at all those little commands. they're a whole squad 🫢


🌸 DESCRIPTION 🌸

so this package is an implementation in Tcl of the MD4 message-digest algorithm, exactly as described in RFC 1320 (1) and (2). what does that mean? it 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). slay, but like, in a historical way.

if you have critcl and you've built the tcllibc package, then the implementation of the hashing function will be performed by compiled code. alternatively, if cryptkit is available, that gets used instead. and if no accelerator package can be found at all? then the pure-tcl implementation is used. and the best part β€” the programming interface stays the same in all cases. consistent queen behavior πŸ‘‘

BEWARE 🚨 the commands in this package expect binary data as their input. when a -file is provided, the commands themselves ensure this, because they open the referenced file in binary mode. but when literal data, or a -channel, are provided instead, then the command's caller is responsible for ensuring this fact. the necessary conversion command is encoding convertto utf-8 $string. do not skip this bestie, i'm begging 😭
ATTENTION, there is a Tcl 9 COMPATIBILITY ISSUE here. πŸ‘€ Tcl 8.x silently mishandles non-binary input by cutting it internally to size. i.e. by only using the low byte of a higher unicode point. no error is thrown β€” the result is simply wrong. πŸ’€ Tcl 9 throws an error instead, i.e. expected byte sequence but character <location> was ...

πŸ’… COMMANDS πŸ’…

  • ::md4::md4 ?-hex? [ -channel channel | -file filename | string ] β€” calculate the MD4 digest of the data given in string. this gets returned as a binary string by default. giving the -hex option will return a hexadecimal encoded version of the digest instead. the data to be hashed can be specified either as a string argument to the md4 command, or as a filename, or as a pre-opened channel. if the -filename argument is given then the file is opened, the data is read and hashed, and the file is closed. if the -channel argument is given then data is read from the channel until the end of file, and the channel is not closed. only one of -file, -channel or string should be given β€” pick one, babe, not all three πŸ™ˆ
  • ::md4::hmac ?-hex? -key key [ -channel channel | -file filename | string ] β€” calculate 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. all options other than -key are exactly as for the ::md4::md4 command. same vibe, extra key πŸ”‘

πŸŽ€ PROGRAMMING INTERFACE πŸŽ€

for the programmer, the MD4 hash can be viewed as a bucket into which you pour data πŸͺ£. when you're done pouring, you extract a value that's derived from everything that went in. the programming interface to the MD4 hash operates on a token (which is basically the bucket). you call MD4Init to obtain a token, then you call MD4Update as many times as you need to add data to the hash. to release any resources and obtain the hash value, you then call MD4Final. and there's an equivalent set of functions that gives you a keyed digest (HMAC). it's the same energy, but with a key. periodt.

  • ::md4::MD4Init β€” begins a new MD4 hash. returns a token ID that must be used for the remaining functions.
  • ::md4::MD4Update token data β€” add data to the hash identified by token. calling MD4Update $token "abcd" is equivalent to calling MD4Update $token "ab" followed by MD4Update $token "cb". see EXAMPLES below, i promise it makes sense πŸ’–
  • ::md4::MD4Final token β€” returns the hash value and releases any resources held by this token. once this command completes, the token will be 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::MD4Init command except that it requires the key that will be included in the HMAC.
  • ::md4::HMACUpdate token data β€” (no extra description, it's just vibing here)
  • ::md4::HMACFinal token β€” these commands are identical to the MD4 equivalent commands. twins fr fr πŸ‘―

🌈 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

see how the last one matches the first one?? that's the bucket working exactly how it should πŸ”₯ ate and left no crumbs.


πŸ¦‹ REFERENCES πŸ¦‹

  1. Rivest, R., "The MD4 Message Digest Algorithm", RFC 1320, MIT, April 1992. (http://www.rfc-editor.org/rfc/rfc1320.txt)
  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. (http://www.rfc-editor.org/rfc/rfc1321.txt)
  4. 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. it's giving "we know, we know." please report such in the category md4 of the Tcllib Trackers [http://core.tcl.tk/tcllib/reportlist]. please also report any ideas for enhancements you may have for either the package and/or the documentation. we love a glow-up suggestion ✨

when proposing code changes, please provide unified diffs, i.e. the output of diff -u. that's the language they speak.

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 (c) 2003, Pat Thoyts <patthoyts@users.sourceforge.net>


and that's the whole page bestie!! this one came from tcllib, version 1.0.8, and it's the md4(n) manual page πŸ’– thanks for reading all the way to the bottom, you're a real one 🫢✨

πŸ“¦ where this page comes from