CRYPT_PREFERRED_METHOD(3)

πŸ“¦
version 4.5.2+20251210 Β· 2 versions
, in arch rolling, fedora 43, fedora 44, nixpkgs unstable, ubuntu resolute, ubuntu stonking

✨ CRYPT_PREFERRED_METHOD(3) ✨

okay bestie, welcome to the crypt_preferred_method page πŸ’– this is the CRYPT_PREFERRED_METHOD(3) manual page, living in the Library Functions Manual, and it's about to tell you how to find out which hash method your system is stanning rn. no cap, it's short, it's sweet, and it's lowkey iconic.


πŸŽ€ NAME πŸŽ€

crypt_preferred_method β€” get the prefix of the preferred hash method


πŸ“š LIBRARY πŸ“š

Crypt Library (libcrypt, -lcrypt)

like, that's the library you gotta link against, periodt 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <crypt.h>

const char*
crypt_preferred_method(void);

πŸ’… DESCRIPTION πŸ’…

so crypt_preferred_method is a little convenience function β€” a lil helper bestie, doing the most so you don't have to β€” that gets you the prefix of the preferred hash method ✨

and here's the tea: if a preferred method is available, it's literally the same one that the crypt_gensalt functions use too, whenever their given prefix parameter is NULL. same vibe, same method, no drama.


🌸 RETURN VALUES 🌸

the string that comes back at you equals the prefix of the preferred hash method πŸ’« and if there's no preferred hash method available, it's NULL. that's it, that's the whole return situation.

now for the part that's giving safety: it is safe to pass the string returned by crypt_preferred_method directly to crypt_gensalt β€” no prior string-sanitizing needed, no NULL-pointer checks needed. just hand it over. slay πŸ™Œ


πŸ”₯ FEATURE TEST MACROS πŸ”₯

<crypt.h> will define the macro CRYPT_PREFERRED_METHOD_AVAILABLE if crypt_preferred_method is available in the current version of libxcrypt.

so like, you can vibe-check whether the function even exists before you use it. iykyk πŸ’…


🌈 PORTABILITY NOTES 🌈

real talk: the function crypt_preferred_method is not part of any standard. nope, not a single one. it was added to libxcrypt in version 4.4.0, so if you're on something older, this function is simply not in the group chat 😭


πŸ‘‘ ATTRIBUTES πŸ‘‘

for an explanation of the terms used in this section, see attributes(7).

  • crypt_preferred_method β€” Thread safety: MT-Safe

that's the whole table bestie, and yes, MT-Safe means it's chill across threads 🧚


⭐ SEE ALSO ⭐


reminder boo: everything above is exactly as written in the original β€” i'm just the hype girl, not the source of truth πŸ’–

libxcrypt β€’ November 16, 2018 β€” ok that's the whole page, thanks for reading my lil manual-page era 🫢 go forth and get that preferred method prefix, you absolute main character πŸ’…βœ¨πŸŽ€

πŸ“¦ where this page comes from