1CRYPT(3)                   Linux Programmer's Manual                  CRYPT(3)
2
3
4

NAME

6       crypt, crypt_r - password and data encryption
7

SYNOPSIS

9       #define _XOPEN_SOURCE       /* See feature_test_macros(7) */
10       #include <unistd.h>
11
12       char *crypt(const char *key, const char *salt);
13
14       #define _GNU_SOURCE         /* See feature_test_macros(7) */
15       #include <crypt.h>
16
17       char *crypt_r(const char *key, const char *salt,
18                     struct crypt_data *data);
19
20       Link with -lcrypt.
21

DESCRIPTION

23       crypt()  is  the password encryption function.  It is based on the Data
24       Encryption Standard algorithm with  variations  intended  (among  other
25       things) to discourage use of hardware implementations of a key search.
26
27       key is a user's typed password.
28
29       salt is a two-character string chosen from the set [azAZ09./].  This
30       string is used to perturb the algorithm in one of 4096 different ways.
31
32       By taking the lowest 7 bits of each of the first  eight  characters  of
33       the  key, a 56-bit key is obtained.  This 56-bit key is used to encrypt
34       repeatedly a constant  string  (usually  a  string  consisting  of  all
35       zeros).   The returned value points to the encrypted password, a series
36       of 13 printable ASCII characters (the first  two  characters  represent
37       the salt itself).  The return value points to static data whose content
38       is overwritten by each call.
39
40       Warning: The key space consists of 2**56 equal 7.2e16 possible  values.
41       Exhaustive searches of this key space are possible using massively par‐
42       allel computers.  Software, such as crack(1), is available  which  will
43       search  the  portion of this key space that is generally used by humans
44       for passwords.  Hence, password selection  should,  at  minimum,  avoid
45       common words and names.  The use of a passwd(1) program that checks for
46       crackable passwords during the selection process is recommended.
47
48       The DES algorithm itself has a few quirks which make  the  use  of  the
49       crypt()  interface  a very poor choice for anything other than password
50       authentication.  If you are planning on using the crypt() interface for
51       a  cryptography project, don't do it: get a good book on encryption and
52       one of the widely available DES libraries.
53
54       crypt_r() is a reentrant version of crypt().  The structure pointed  to
55       by  data  is  used  to  store  result data and bookkeeping information.
56       Other than allocating it, the only thing that the caller should do with
57       this  structure  is  to  set data->initialized to zero before the first
58       call to crypt_r().
59

RETURN VALUE

61       On success, a pointer to the encrypted password is returned.  On error,
62       NULL is returned.
63

ERRORS

65       ENOSYS The  crypt()  function  was not implemented, probably because of
66              U.S.A. export restrictions.
67

ATTRIBUTES

69   Multithreading (see pthreads(7))
70       The crypt() function is not thread-safe.
71
72       The crypt_r() function is thread-safe.
73

CONFORMING TO

75       crypt(): SVr4, 4.3BSD, POSIX.1-2001.  crypt_r() is a GNU extension.
76

NOTES

78   Glibc notes
79       The glibc2 version of  this  function  supports  additional  encryption
80       algorithms.
81
82       If  salt is a character string starting with the characters "$id$" fol‐
83       lowed by a string terminated by "$":
84
85              $id$salt$encrypted
86
87       then instead of using the DES machine,  id  identifies  the  encryption
88       method  used  and  this  then  determines  how the rest of the password
89       string is interpreted.  The following values of id are supported:
90
91              ID  | Method
92              ─────────────────────────────────────────────────────────
93              1   | MD5
94              2a  | Blowfish (not in mainline glibc; added in some
95                  | Linux distributions)
96              5   | SHA-256 (since glibc 2.7)
97              6   | SHA-512 (since glibc 2.7)
98
99       So   $5$salt$encrypted   is   an   SHA-256   encoded    password    and
100       $6$salt$encrypted is an SHA-512 encoded one.
101
102       "salt" stands for the up to 16 characters following "$id$" in the salt.
103       The encrypted part of the password string is the actual computed  pass‐
104       word.  The size of this string is fixed:
105
106       MD5     | 22 characters
107       SHA-256 | 43 characters
108       SHA-512 | 86 characters
109
110       The  characters  in  "salt"  and  "encrypted"  are  drawn  from the set
111       [azAZ09./].  In the MD5 and SHA implementations the  entire  key  is
112       significant (instead of only the first 8 bytes in DES).
113

SEE ALSO

115       login(1), passwd(1), encrypt(3), getpass(3), passwd(5)
116

COLOPHON

118       This  page  is  part of release 3.53 of the Linux man-pages project.  A
119       description of the project, and information about reporting  bugs,  can
120       be found at http://www.kernel.org/doc/man-pages/.
121
122
123
124                                  2013-06-21                          CRYPT(3)
Impressum