]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/crypt.3
encrypt.3: srcfix: rewrap source lines
[thirdparty/man-pages.git] / man3 / crypt.3
1 .\" Michael Haardt (michael@cantor.informatik.rwth.aachen.de)
2 .\" Sat Sep 3 22:00:30 MET DST 1994
3 .\"
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
9 .\"
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
14 .\"
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 .\" GNU General Public License for more details.
19 .\"
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Sun Feb 19 21:32:25 1995, faith@cs.unc.edu edited details away
26 .\"
27 .\" TO DO: This manual page should go more into detail how DES is perturbed,
28 .\" which string will be encrypted, and what determines the repetition factor.
29 .\" Is a simple repetition using ECB used, or something more advanced? I hope
30 .\" the presented explanations are at least better than nothing, but by no
31 .\" means enough.
32 .\"
33 .\" added _XOPEN_SOURCE, aeb, 970705
34 .\" added GNU MD5 stuff, aeb, 011223
35 .\"
36 .TH CRYPT 3 2017-09-15 "" "Linux Programmer's Manual"
37 .SH NAME
38 crypt, crypt_r \- password and data encryption
39 .SH SYNOPSIS
40 .nf
41 .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
42 .B #include <unistd.h>
43 .PP
44 .BI "char *crypt(const char *" key ", const char *" salt );
45
46 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
47 .B #include <crypt.h>
48 .PP
49 .BI "char *crypt_r(const char *" key ", const char *" salt ,
50 .BI " struct crypt_data *" data );
51 .fi
52 .PP
53 Link with \fI\-lcrypt\fP.
54 .SH DESCRIPTION
55 .BR crypt ()
56 is the password encryption function.
57 It is based on the Data Encryption
58 Standard algorithm with variations intended (among other things) to
59 discourage use of hardware implementations of a key search.
60 .PP
61 .I key
62 is a user's typed password.
63 .PP
64 .I salt
65 is a two-character string chosen from the set
66 [\fBa\-zA\-Z0\-9./\fP].
67 This string is used to
68 perturb the algorithm in one of 4096 different ways.
69 .PP
70 By taking the lowest 7 bits of each of the first eight characters of the
71 .IR key ,
72 a 56-bit key is obtained.
73 This 56-bit key is used to encrypt repeatedly a
74 constant string (usually a string consisting of all zeros).
75 The returned
76 value points to the encrypted password, a series of 13 printable ASCII
77 characters (the first two characters represent the salt itself).
78 The return value points to static data whose content is
79 overwritten by each call.
80 .PP
81 Warning: the key space consists of
82 .if t 2\s-2\u56\s0\d
83 .if n 2**56
84 equal 7.2e16 possible values.
85 Exhaustive searches of this key space are
86 possible using massively parallel computers.
87 Software, such as
88 .BR crack (1),
89 is available which will search the portion of this key space that is
90 generally used by humans for passwords.
91 Hence, password selection should,
92 at minimum, avoid common words and names.
93 The use of a
94 .BR passwd (1)
95 program that checks for crackable passwords during the selection process is
96 recommended.
97 .PP
98 The DES algorithm itself has a few quirks which make the use of the
99 .BR crypt ()
100 interface a very poor choice for anything other than password
101 authentication.
102 If you are planning on using the
103 .BR crypt ()
104 interface for a cryptography project, don't do it: get a good book on
105 encryption and one of the widely available DES libraries.
106 .PP
107 .BR crypt_r ()
108 is a reentrant version of
109 .BR crypt ().
110 The structure pointed to by
111 .I data
112 is used to store result data and bookkeeping information.
113 Other than allocating it,
114 the only thing that the caller should do with this structure is to set
115 .I data->initialized
116 to zero before the first call to
117 .BR crypt_r ().
118 .SH RETURN VALUE
119 On success, a pointer to the encrypted password is returned.
120 On error, NULL is returned.
121 .SH ERRORS
122 .TP
123 .B EINVAL
124 .I salt
125 has the wrong format.
126 .TP
127 .B ENOSYS
128 The
129 .BR crypt ()
130 function was not implemented, probably because of U.S.A. export restrictions.
131 .\" This level of detail is not necessary in this man page. . .
132 .\" .PP
133 .\" When encrypting a plain text P using DES with the key K results in the
134 .\" encrypted text C, then the complementary plain text P' being encrypted
135 .\" using the complementary key K' will result in the complementary encrypted
136 .\" text C'.
137 .\" .PP
138 .\" Weak keys are keys which stay invariant under the DES key transformation.
139 .\" The four known weak keys 0101010101010101, fefefefefefefefe,
140 .\" 1f1f1f1f0e0e0e0e and e0e0e0e0f1f1f1f1 must be avoided.
141 .\" .PP
142 .\" There are six known half weak key pairs, which keys lead to the same
143 .\" encrypted data. Keys which are part of such key clusters should be
144 .\" avoided.
145 .\" Sorry, I could not find out what they are.
146 .\""
147 .\" .PP
148 .\" Heavily redundant data causes trouble with DES encryption, when used in the
149 .\" .I codebook
150 .\" mode that
151 .\" .BR crypt ()
152 .\" implements. The
153 .\" .BR crypt ()
154 .\" interface should be used only for its intended purpose of password
155 .\" verification, and should not be used as part of a data encryption tool.
156 .\" .PP
157 .\" The first and last three output bits of the fourth S-box can be
158 .\" represented as function of their input bits. Empiric studies have
159 .\" shown that S-boxes partially compute the same output for similar input.
160 .\" It is suspected that this may contain a back door which could allow the
161 .\" NSA to decrypt DES encrypted data.
162 .\" .PP
163 .\" Making encrypted data computed using crypt() publicly available has
164 .\" to be considered insecure for the given reasons.
165 .TP
166 .B EPERM
167 .I /proc/sys/crypto/fips_enabled
168 has a nonzero value,
169 and an attempt was made to use a weak encryption type, such as DES.
170 .SH ATTRIBUTES
171 For an explanation of the terms used in this section, see
172 .BR attributes (7).
173 .TS
174 allbox;
175 lb lb lb
176 l l l.
177 Interface Attribute Value
178 T{
179 .BR crypt ()
180 T} Thread safety MT-Unsafe race:crypt
181 T{
182 .BR crypt_r ()
183 T} Thread safety MT-Safe
184 .TE
185 .SH CONFORMING TO
186 .BR crypt ():
187 POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
188 .BR crypt_r ()
189 is a GNU extension.
190 .SH NOTES
191 .SS Availability in glibc
192 The
193 .BR crypt (),
194 .BR encrypt (),
195 and
196 .BR setkey ()
197 functions are part of the POSIX.1-2008 XSI Options Group for Encryption
198 and are optional.
199 If the interfaces are not available then the symbolic constant
200 .BR _XOPEN_CRYPT
201 is either not defined or defined to -1, and can be checked at runtime with
202 .BR sysconf ().
203 This may be the case if the downstream distribution has switched from glibc
204 crypt to libxcrypt.
205 When recompiling applications in such distributions the
206 user must detect if
207 .BR _XOPEN_CRPYT
208 is not available and include crypt.h for the function prototypes;
209 otherwise
210 libxcrypt is a ABI compatible drop-in replacement.
211 .SS Features in glibc
212 The glibc version of this function supports additional
213 encryption algorithms.
214 .PP
215 If
216 .I salt
217 is a character string starting with the characters "$\fIid\fP$"
218 followed by a string optionally terminated by "$",
219 then the result has the form:
220 .RS
221 .PP
222 $\fIid\fP$\fIsalt\fP$\fIencrypted\fP
223 .PP
224 .RE
225 .I id
226 identifies the encryption method used instead of DES and this
227 then determines how the rest of the password string is interpreted.
228 The following values of
229 .I id
230 are supported:
231 .RS
232 .TS
233 l l.
234 ID | Method
235 _
236 1 | MD5
237 2a | Blowfish (not in mainline glibc; added in some
238 | Linux distributions)
239 .\" openSUSE has Blowfish, but AFAICS, this option is not supported
240 .\" natively by glibc -- mtk, Jul 08
241 .\"
242 .\" md5 | Sun MD5
243 .\" glibc doesn't appear to natively support Sun MD5; I don't know
244 .\" if any distros add the support.
245 5 | SHA-256 (since glibc 2.7)
246 6 | SHA-512 (since glibc 2.7)
247 .TE
248 .RE
249 .PP
250 Thus, $5$\fIsalt\fP$\fIencrypted\fP and $6$\fIsalt\fP$\fIencrypted\fP
251 contain the password encrypted with, respectively, functions
252 based on SHA-256 and SHA-512.
253 .PP
254 "\fIsalt\fP" stands for the up to 16 characters
255 following "$\fIid\fP$" in the salt.
256 The "\fIencrypted\fP"
257 part of the password string is the actual computed password.
258 The size of this string is fixed:
259 .TS
260 l l.
261 MD5 | 22 characters
262 SHA-256 | 43 characters
263 SHA-512 | 86 characters
264 .TE
265 .sp 1
266 The characters in "\fIsalt\fP" and "\fIencrypted\fP" are drawn from the set
267 [\fBa\-zA\-Z0\-9./\fP].
268 In the MD5 and SHA implementations the entire
269 .I key
270 is significant (instead of only the first
271 8 bytes in DES).
272 .PP
273 Since glibc 2.7,
274 .\" glibc commit 9425cb9eea6a62fc21d99aafe8a60f752b934b05
275 the SHA-256 and SHA-512 implementations support a user-supplied number of
276 hashing rounds, defaulting to 5000.
277 If the "$\fIid\fP$" characters in the salt are
278 followed by "rounds=\fIxxx\fP$", where \fIxxx\fP is an integer, then the
279 result has the form
280 .RS
281 .PP
282 $\fIid\fP$\fIrounds=yyy\fP$\fIsalt\fP$\fIencrypted\fP
283 .PP
284 .RE
285 where \fIyyy\fP is the number of hashing rounds actually used.
286 The number of rounds actually used is 1000 if
287 .I xxx
288 is less than
289 1000, 999999999 if
290 .I xxx
291 is greater than 999999999, and
292 is equal to
293 .I xxx
294 otherwise.
295 .SH SEE ALSO
296 .BR login (1),
297 .BR passwd (1),
298 .BR encrypt (3),
299 .BR getpass (3),
300 .BR passwd (5)