MD5(3ossl)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

πŸ’– MD5(3ossl) β€” the MD2, MD4 & MD5 hash functions, explained by your favorite Unix goblin πŸ’–

okay so bestie, buckle up πŸŽ€ this one's an OpenSSL page about three hashing legends: MD2, MD4 and MD5 β€” plus all their _Init/_Update/_Final besties. It's from the OpenSSL manual (section 3ossl, iykyk), and tbh it's giving "vintage, deprecated, still kinda iconic" energy. Let's get into it πŸ’…


✨ SYNOPSIS ✨

so here's the thing: all three families are deprecated since OpenSSL 3.0, and you can hide them entirely by defining OPENSSL_API_COMPAT with a suitable version value β€” peep openssl_user_macros(7) for the deets. Three separate deprecation notices in the original, three separate vibes, three separate headers, so let's do them one by one 🫢

πŸ“ MD2 β€” <openssl/md2.h>

same deprecation warning as above (deprecated since OpenSSL 3.0, hideable via OPENSSL_API_COMPAT, see openssl_user_macros(7)), and here's the code, verbatim, no cap:

#include <openssl/md2.h>

unsigned char *MD2(const unsigned char *d, unsigned long n, unsigned char *md);

int MD2_Init(MD2_CTX *c);
int MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len);
int MD2_Final(unsigned char *md, MD2_CTX *c);

πŸ¦‹ MD4 β€” <openssl/md4.h>

again, deprecated since OpenSSL 3.0, hideable with OPENSSL_API_COMPAT and a suitable version value, see openssl_user_macros(7):

#include <openssl/md4.h>

unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md);

int MD4_Init(MD4_CTX *c);
int MD4_Update(MD4_CTX *c, const void *data, unsigned long len);
int MD4_Final(unsigned char *md, MD4_CTX *c);

🧚 MD5 β€” <openssl/md5.h>

yep, same deal, deprecated since OpenSSL 3.0, hideable via OPENSSL_API_COMPAT with a suitable version value, see openssl_user_macros(7):

#include <openssl/md5.h>

unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md);

int MD5_Init(MD5_CTX *c);
int MD5_Update(MD5_CTX *c, const void *data, unsigned long len);
int MD5_Final(unsigned char *md, MD5_CTX *c);

(lowkey notice how MD2_Update and MD5_Update take const unsigned char *data, but MD4_Update takes const void *data? not me clocking that πŸ‘€ β€” copy them exactly, bestie, don't "fix" it.)


🌸 DESCRIPTION 🌸

heads up, the big one: every single function on this page is deprecated. like, all of them. Applications should instead use EVP_DigestInit_ex(3), EVP_DigestUpdate(3) and EVP_DigestFinal_ex(3). periodt.

so what are they? MD2, MD4 and MD5 are cryptographic hash functions with a 128 bit output. cute little 128-bit babies 🌈

  • MD2(), MD4(), MD5() β€” these compute the MD2, MD4 and MD5 message digest of the n bytes at d and place it in md. and md must have space for MD2_DIGEST_LENGTH == MD4_DIGEST_LENGTH == MD5_DIGEST_LENGTH == 16 bytes of output. if md is NULL, the digest gets placed in a static array (which, ngl, is a whole vibe β€” careful with that).
  • The one-shot functions only work if your message is fully sittin' in memory. If not, use the incremental trio, which is literally what they're for:

πŸŽ€ the incremental flow (MD2 version, but they all match)

  • MD2_Init() β€” initializes a MD2_CTX structure.
  • MD2_Update() β€” can be called repeatedly with chunks of the message to be hashed (len bytes at data).
  • MD2_Final() β€” places the message digest in md, which must have space for MD2_DIGEST_LENGTH == 16 bytes of output, and erases the MD2_CTX.

πŸ’œ and the rest

MD4_Init(), MD4_Update(), MD4_Final(), MD5_Init(), MD5_Update(), and MD5_Final() are all analogous, using an MD4_CTX and MD5_CTX structure instead. and listen β€” the parameter MUST NOT be NULL. that's not a suggestion, bestie, that's an all-caps requirement 😭

😭 and fr fr: applications should use the higher level functions EVP_DigestInit(3) etc. instead of calling the hash functions directly.

⭐ NOTE ⭐

MD2, MD4 and MD5 are recommended only for compatibility with existing applications β€” like, legacy-support main character energy, not new-project energy. in new applications, hashes from the SHA-2 or SHA-3 family should be preferred. slay, move on, upgrade πŸ¦‹


πŸ”₯ RETURN VALUES πŸ”₯

  • MD2(), MD4(), MD5() β€” return pointers to the hash value.
  • MD2_Init(), MD2_Update(), MD2_Final(), MD4_Init(), MD4_Update(), MD4_Final(), MD5_Init(), MD5_Update(), and MD5_Final() β€” return 1 for success, 0 otherwise.

that's it, that's the whole return contract, no surprises πŸ’…


πŸ‘‘ CONFORMING TO πŸ‘‘

RFC 1319, RFC 1320, RFC 1321 β€” the holy trinity of MD specs πŸ“œβœ¨


πŸ’€ SEE ALSO πŸ’€

go read those instead, bestie, that's literally the whole point 🫢


🌈 HISTORY 🌈

All of these functions were deprecated in OpenSSL 3.0. that's the entire history section, and honestly it ate.


Copyright 2000-2024 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


okay diva, that's the page πŸŽ€ β€” this was OpenSSL 3.5.6, dated 2026-04-07, page MD5(3ossl). now go use EVP_DigestInit_ex(3) like the icon you are. mwah πŸ’œβœ¨

πŸ“¦ where this page comes from