# crypt_gensalt_rn(3) - man - phpMan

[CRYPT_GENSALT(3)](https://www.chedong.com/phpMan.php/man/CRYPTGENSALT/3/markdown)         BSD Library Functions Manual         [CRYPT_GENSALT(3)](https://www.chedong.com/phpMan.php/man/CRYPTGENSALT/3/markdown)

## NAME
     **crypt**___**gensalt**, **crypt**___**gensalt**___**rn**, **crypt**___**gensalt**___**ra** — encode settings for passphrase hashing

## LIBRARY
     Crypt Library (libcrypt, -lcrypt)

## SYNOPSIS
### #include <crypt.h>

     _char_ _*_
     **crypt**___**gensalt**(_const_ _char_ _*prefix_, _unsigned_ _long_ _count_, _const_ _char_ _*rbytes_, _int_ _nrbytes_);

     _char_ _*_
     **crypt**___**gensalt**___**rn**(_const_ _char_ _*_ _prefix_, _unsigned_ _long_ _count_, _const_ _char_ _*rbytes_, _int_ _nrbytes_,
         _char_ _*_ _output_, _int_ _output_size_);

     _char_ _*_
     **crypt**___**gensalt**___**ra**(_const_ _char_ _*prefix_, _unsigned_ _long_ _count_, _const_ _char_ _*rbytes_, _int_ _nrbytes_);

## DESCRIPTION
     The **crypt**___**gensalt**, **crypt**___**gensalt**___**rn**, and **crypt**___**gensalt**___**ra** functions compile a string for use as
     the _setting_ argument to **crypt**, **crypt**___**r**, **crypt**___**rn**, and **crypt**___**ra**.  _prefix_ selects the hashing
     method to use.  _count_ controls the CPU time cost of the hash; the valid range for _count_ and the
     exact meaning of “CPU time cost” depends on the hashing method, but larger numbers correspond
     to more costly hashes.  _rbytes_ should point to _nrbytes_ cryptographically random bytes for use
     as “salt.”

     If _prefix_ is a null pointer, the best available hashing method will be selected.  (**CAUTION**: if
     _prefix_ is an empty string, the “traditional” DES-based hashing method will be selected; this
     method is unacceptably weak by modern standards.)  If _count_ is 0, a low default cost will be
     selected.  If _rbytes_ is a null pointer, an appropriate number of random bytes will be obtained
     from the operating system, and _nrbytes_ is ignored.

     See [crypt(5)](https://www.chedong.com/phpMan.php/man/crypt/5/markdown) for other strings that can be used as _prefix_, and valid values of _count_ for each.

## RETURN VALUES
     **crypt**___**gensalt**, **crypt**___**gensalt**___**rn**, and **crypt**___**gensalt**___**ra** return a pointer to an encoded setting
     string.  This string will be entirely printable ASCII, and will not contain whitespace or the
     characters ‘:’, ‘;’, ‘*’, ‘!’, or ‘\’.  See [crypt(5)](https://www.chedong.com/phpMan.php/man/crypt/5/markdown) for more detail on the format of this
     string.  Upon error, they return a null pointer and set _errno_ to an appropriate error code.

     **crypt**___**gensalt** places its result in a static storage area, which will be overwritten by subse‐
     quent calls to **crypt**___**gensalt**.  It is not safe to call **crypt**___**gensalt** from multiple threads si‐
     multaneously.  However, it _is_ safe to pass the string returned by **crypt**___**gensalt** directly to
     **crypt** without copying it; each function has its own static storage area.

     **crypt**___**gensalt**___**rn** places its result in the supplied _output_ buffer, which has _output_size_ bytes
     of storage available.  _output_size_ should be greater than or equal to
     CRYPT_GENSALT_OUTPUT_SIZE.

     **crypt**___**gensalt**___**ra** allocates memory for its result using [malloc(3)](https://www.chedong.com/phpMan.php/man/malloc/3/markdown).  It should be freed with
     [free(3)](https://www.chedong.com/phpMan.php/man/free/3/markdown) after use.

     Upon error, in addition to returning a null pointer, **crypt**___**gensalt** and **crypt**___**gensalt**___**rn** will
     write an invalid setting string to their output buffer, if there is enough space; this string
     will begin with a ‘*’ and will not be equal to _prefix_.

## ERRORS
     EINVAL             _prefix_ is invalid or not supported by this implementation; _count_ is invalid
                        for the requested _prefix_; the input _nrbytes_ is insufficient for the smallest
                        valid salt with the requested _prefix_.

     ERANGE             **crypt**___**gensalt**___**rn** only: _output_size_ is too small to hold the compiled _setting_
                        string.

     ENOMEM             Failed to allocate internal scratch memory.
                        **crypt**___**gensalt**___**ra** only: failed to allocate memory for the compiled _setting_
                        string.

     ENOSYS, EACCES, EIO, etc.
                        Obtaining random bytes from the operating system failed.  This can only hap‐
                        pen when _rbytes_ is a null pointer.

## FEATURE TEST MACROS
     The following macros are defined by <_crypt.h_>:

     CRYPT_GENSALT_IMPLEMENTS_DEFAULT_PREFIX
             A null pointer can be specified as the _prefix_ argument.

     CRYPT_GENSALT_IMPLEMENTS_AUTO_ENTROPY
             A null pointer can be specified as the _rbytes_ argument.

## PORTABILITY NOTES
     The functions **crypt**___**gensalt**, **crypt**___**gensalt**___**rn**, and **crypt**___**gensalt**___**ra** are not part of any stan‐
     dard.  They originate with the Openwall project.  A function with the name **crypt**___**gensalt** also
     exists on Solaris 10 and newer, but its prototype and semantics differ.

     The default prefix and auto entropy features are available since libxcrypt version 4.0.0.  Por‐
     table software can use feature test macros to find out whether null pointers can be used for
     the _prefix_ and _rbytes_ arguments.

     The set of supported hashing methods varies considerably from system to system.

## ATTRIBUTES
     For an explanation of the terms used in this section, see [attributes(7)](https://www.chedong.com/phpMan.php/man/attributes/7/markdown).
     ┌──────────────────┬───────────────┬──────────────────────────────┐
     │**Interface**         │ **Attribute**     │ **Value**                        │
     ├──────────────────┼───────────────┼──────────────────────────────┤
     │**crypt**___**gensalt**     │ Thread safety │ MT-Unsafe race:crypt_gensalt │
     ├──────────────────┼───────────────┼──────────────────────────────┤
     │**crypt**___**gensalt**___**rn**, │ Thread safety │ MT-Safe                      │
     │**crypt**___**gensalt**___**ra**  │               │                              │
     └──────────────────┴───────────────┴──────────────────────────────┘

## SEE ALSO
     [crypt(3)](https://www.chedong.com/phpMan.php/man/crypt/3/markdown), [getpass(3)](https://www.chedong.com/phpMan.php/man/getpass/3/markdown), [getpwent(3)](https://www.chedong.com/phpMan.php/man/getpwent/3/markdown), [shadow(3)](https://www.chedong.com/phpMan.php/man/shadow/3/markdown), [login(1)](https://www.chedong.com/phpMan.php/man/login/1/markdown), [passwd(1)](https://www.chedong.com/phpMan.php/man/passwd/1/markdown), [crypt(5)](https://www.chedong.com/phpMan.php/man/crypt/5/markdown), [passwd(5)](https://www.chedong.com/phpMan.php/man/passwd/5/markdown),
     [shadow(5)](https://www.chedong.com/phpMan.php/man/shadow/5/markdown), [pam(8)](https://www.chedong.com/phpMan.php/man/pam/8/markdown)

## Openwall Project               October 11, 2017               Openwall Project
