CRYPT(3)	       FreeBSD Library Functions Manual 	      CRYPT(3)

NAME
     crypt

SYNOPSIS
     char *cryptconschar *key, const char *setting)

DESCRIPTION:
     The crypt() function performs password encryption.  It is derived from
     the NBS Data Encryption Standard.	Additional code has been added to deter
     key search attempts.  The first argument to crypt is a NUL-terminated
     string (normally a password typed by a user).  The second is a character
     array, 9 bytes in length, consisting of an underscore (`_') followed by
     4 bytes of iteration count and 4 bytes of salt.  Both the iteration count
     and thsalt are encoded with 6 bits per character, least significant
     bits first.  The values 0 to 63 are encoded by the characters `./0-9A-
     Za-z', respectively.

     The salt is used to induce disorder in to the DES algorithm in one of
     16777216 possible ways (specifically, if bit i of the salt is set then
     bits i and 24 are swapped in the DES `E' box output). The key is di-
     vided into groups of 8 characters (a short final group is null-padded)
     and the low-order 7 bits of each character (56 bits per group) are used
     to form the DES key as follows: the first group of 56 bits becomes the
     initial DES key.  For each additional group, the XOR of the group bits
     and the encryption of the DES key with itself becomes the next DES key.
     Then the final DES key is used to perform count cumulative encryptions of
     a 64-bit constant.  The value returned is a NUL-terminated string, 20
     bytes in length, consisting of the setting followed by the encoded 64-bit
     encryption.

     For compatibility with historical versions of crypt(3),  the setting may
     consist of 2 bytes of salt, encoded as above, in which case an iteration
     count of 25 is used, fewer perturbations of DES are available, at most 8
     characters of key are used, and the returned value is a NUL-terminated
     string 13 bytes in length.


HISTORY:
     A rotor-based crypt() function appeared in Version 6 AT&T UNIX. The cur-
     rent style crypt() first appeared in Version 7 AT&T UNIX.
