CRYPT\_PREFERRED\_METHOD(3) Library Functions Manual CRYPT\_PREFERRED\_METHOD(3)

# [NAME](#NAME)

`crypt_preferred_method` — get the prefix of the preferred hash method

# [LIBRARY](#LIBRARY)

Crypt Library (libcrypt, -lcrypt)

# [SYNOPSIS](#SYNOPSIS)

`#include <crypt.h>`

`const char*`  
`crypt_preferred_method`(`void`);

# [DESCRIPTION](#DESCRIPTION)

`crypt_preferred_method` is a convenience function to get the prefix of the preferred hash method. If a preferred method is available, it is the same as the one also used by the `crypt_gensalt functions`, if their given `prefix` parameter is NULL.

# [RETURN VALUES](#RETURN_VALUES)

The string returned equals the prefix of the preferred hash method. If no preferred hash method is available it is NULL. It [*is*](#is) safe to pass the string returned by `crypt_preferred_method` directly to `crypt_gensalt` without prior string-sanitizing nor NULL-pointer checks.

# [FEATURE TEST MACROS](#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.

# [PORTABILITY NOTES](#PORTABILITY_NOTES)

The function `crypt_preferred_method` is not part of any standard. It was added to libxcrypt in version 4.4.0.

# [ATTRIBUTES](#ATTRIBUTES)

For an explanation of the terms used in this section, see [attributes(7)](/man/os/libxcrypt/attributes.7).

**Interface** **Attribute** **Value** Thread safety MT-Safe

# [SEE ALSO](#SEE_ALSO)

[crypt\_gensalt(3)](/man/os/libxcrypt/crypt_gensalt.3)

November 16, 2018 libxcrypt

---

Document: crypt_preferred_method(3) from libxcrypt 4.5.2-r5 (Chainguard OS)
Source: https://github.com/besser82/libxcrypt
