MD5(3)

πŸ“¦
version 1.3.0 Β· 3 versions
  • 1.3.0 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 14.5 Β· freebsd 14.5
  • 15.1 Β· freebsd 15.1
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian bookworm, debian trixie, epel 10, epel 9, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– MD5(3) β€” Library Functions Manual πŸ’–

okay bestie, sit down, hydrate, and let me tell you about the MD5 crew from the Library Functions Manual. this is the MD5(3) page, and yes it's giving "cryptography but make it vintage" energy. πŸŽ€


✨ NAME ✨

MD5Init, MD5Update, MD5Pad, MD5Final, MD5Transform, MD5End, MD5File, MD5FileChunk, MD5Data β€” these lil icons calculate the RSA Data Security, Inc. β€œMD5” message digest. periodt. πŸ’…


πŸ“š LIBRARY πŸ“š

Message Digest (MD4, MD5, etc.) Support Library β€” that's libmd, link it with -lmd. no cap.


🌈 SYNOPSIS 🌈

#include <sys/types.h>
#include <md5.h>

void
MD5Init(MD5_CTX *context);

void
MD5Update(MD5_CTX *context, const uint8_t *data, size_t len);

void
MD5Pad(MD5_CTX *context);

void
MD5Final(uint8_t digest[MD5_DIGEST_LENGTH], MD5_CTX *context);

void
MD5Transform(uint32_t state[4], uint8_t block[MD5_BLOCK_LENGTH]);

char *
MD5End(MD5_CTX *context, char *buf);

char *
MD5File(const char *filename, char *buf);

char *
MD5FileChunk(const char *filename, char *buf, off_t offset,
    off_t length);

char *
MD5Data(const uint8_t *data, size_t len, char *buf);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the MD5 functions calculate a 128-bit cryptographic checksum (aka a digest) for literally any number of input bytes. a cryptographic checksum is a one-way hash-function, meaning you cannot find (except by exhaustive search, which is a whole nightmare) the input that corresponds to a particular output. the net result is a β€œfingerprint” of the input-data that doesn't spill the actual input. it's giving secretive queen. πŸ‘‘

now for the family drama: MD2 is the slowest, MD4 is the fastest, and MD5 is somewhere in the middle, main character in the middle of the sibling sandwich. MD2 can only be used for Privacy-Enhanced Mail. MD4 got criticized for being too weak, so MD5 was developed in response as β€œMD4 with safety-belts”. πŸ’€ and here's the tea: MD4 and MD5 have been broken β€” they should only be used where necessary for backward compatibility. the attacks on both are in the nature of finding β€œcollisions”, i.e. multiple inputs which hash to the same value. still, it's unlikely for an attacker to be able to determine the exact original input given a hash value. so like… bad but not that bad. πŸ™ˆ

MD5Init(), MD5Update(), and MD5Final() are the core functions, the holy trinity fr fr. allocate an MD5_CTX, initialize it with MD5Init(), run over the data with MD5Update(), and finally extract the result using MD5Final(). iconic workflow.

MD5Pad() can be used to apply padding to the message digest as in MD5Final(), but the current context can still be used with MD5Update(). versatile. we love that.

MD5Transform() is used by MD5Update() to hash 512-bit blocks and forms the core of the algorithm. but most programs should use the interface provided by MD5Init(), MD5Update() and MD5Final() instead of calling MD5Transform() directly. like, don't go poking the engine, bestie. πŸš—

MD5End() is a wrapper for MD5Final() which converts the return value to an MD5_DIGEST_STRING_LENGTH-character (including the terminating '\0') ASCII string which represents the 128 bits in hexadecimal. slay formatting. ✨

MD5File() calculates the digest of a file, and uses MD5End() to return the result. if the file cannot be opened, a null pointer is returned. rip.

MD5FileChunk() behaves like MD5File() but calculates the digest only for that portion of the file starting at offset and continuing for length bytes or until end of file is reached, whichever comes first. a zero length can be specified to read until end of file. a negative length or offset will be ignored. MD5Data() calculates the digest of a chunk of data in memory, and uses MD5End() to return the result. lowkey flexible, highkey useful.

when using MD5End(), MD5File(), MD5FileChunk(), or MD5Data(), the buf argument can be a null pointer, in which case the returned string is allocated with malloc(3) and subsequently must be explicitly deallocated using free(3) after use. πŸ‘€ do not forget the free(3), that's a memory leak and we don't do those here. if the buf argument is non-null it must point to at least MD5_DIGEST_STRING_LENGTH characters of buffer space.


πŸ‘€ SEE ALSO πŸ‘€

  • md2(3), md4(3), md5(3), rmd160(3), sha1(3), sha2(3)
  • B. Kaliski, The MD2 Message-Digest Algorithm, RFC 1319.
  • R. Rivest, The MD4 Message-Digest Algorithm, RFC 1186.
  • R. Rivest, The MD5 Message-Digest Algorithm, RFC 1321.
  • RSA Laboratories, Frequently Asked Questions About today's Cryptography, <http://www.rsa.com/rsalabs/faq/>.
  • H. Dobbertin, β€œAlf Swindles Ann”, CryptoBytes, 1(3):5, 1995.
  • MJ. B. Robshaw, β€œOn Recent Results for MD4 and MD5”, RSA Laboratories Bulletin, 4, November 12, 1996.
  • Hans Dobbertin, Cryptanalysis of MD5 Compress.

πŸ•°οΈ HISTORY πŸ•°οΈ

these functions appeared in OpenBSD 2.0 and NetBSD 1.3. vintage babies. truly old money. πŸ’œ


🫢 AUTHORS 🫢

the original MD5 routines were developed by RSA Data Security, Inc., and published in the above references. this code is derived from a public domain implementation written by Colin Plumb. legends only.

the MD5End(), MD5File(), MD5FileChunk(), and MD5Data() helper functions are derived from code written by Poul-Henning Kamp. the helpers ate and left no crumbs. πŸ”₯


πŸ’€ BUGS πŸ’€

collisions have been found for the full versions of both MD4 and MD5. the use of sha2(3) is recommended instead.

bestie if you're picking a hash for something new, do NOT pick MD5. this is not a drill, this is not a vibe, this is a real warning. use sha2(3). 🚨

and that's the whole page, mwah πŸ’…

this was brought to you by Debian, dated July 13, 2010, filed under MD5(3) β€” go forth and hash responsibly, bestie. πŸŽ€βœ¨πŸ¦‹

πŸ“¦ where this page comes from