OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / 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 2014-02-26 "" "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 .br
43 .B #include <unistd.h>
44 .sp
45 .BI "char *crypt(const char *" key ", const char *" salt );
46 .sp
47 .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
48 .br
49 .B #include <crypt.h>
50 .sp
51 .BI "char *crypt_r(const char *" key ", const char *" salt ,
52 .BI "              struct crypt_data *" data );
53 .fi
54 .sp
55 Link with \fI\-lcrypt\fP.
56 .SH DESCRIPTION
57 .BR crypt ()
58 is the password encryption function.
59 It is based on the Data Encryption
60 Standard algorithm with variations intended (among other things) to
61 discourage use of hardware implementations of a key search.
62 .PP
63 .I key
64 is a user's typed password.
65 .PP
66 .I salt
67 is a two-character string chosen from the set
68 [\fBa\-zA\-Z0\-9./\fP].
69 This string is used to
70 perturb the algorithm in one of 4096 different ways.
71 .PP
72 By taking the lowest 7 bits of each of the first eight characters of the
73 .IR key ,
74 a 56-bit key is obtained.
75 This 56-bit key is used to encrypt repeatedly a
76 constant string (usually a string consisting of all zeros).
77 The returned
78 value points to the encrypted password, a series of 13 printable ASCII
79 characters (the first two characters represent the salt itself).
80 The return value points to static data whose content is
81 overwritten by each call.
82 .PP
83 Warning: The key space consists of
84 .if t 2\s-2\u56\s0\d
85 .if n 2**56
86 equal 7.2e16 possible values.
87 Exhaustive searches of this key space are
88 possible using massively parallel computers.
89 Software, such as
90 .BR crack (1),
91 is available which will search the portion of this key space that is
92 generally used by humans for passwords.
93 Hence, password selection should,
94 at minimum, avoid common words and names.
95 The use of a
96 .BR passwd (1)
97 program that checks for crackable passwords during the selection process is
98 recommended.
99 .PP
100 The DES algorithm itself has a few quirks which make the use of the
101 .BR crypt ()
102 interface a very poor choice for anything other than password
103 authentication.
104 If you are planning on using the
105 .BR crypt ()
106 interface for a cryptography project, don't do it: get a good book on
107 encryption and one of the widely available DES libraries.
108
109 .BR crypt_r ()
110 is a reentrant version of
111 .BR crypt ().
112 The structure pointed to by
113 .I data
114 is used to store result data and bookkeeping information.
115 Other than allocating it,
116 the only thing that the caller should do with this structure is to set
117 .I data->initialized
118 to zero before the first call to
119 .BR crypt_r ().
120 .SH RETURN VALUE
121 On success, a pointer to the encrypted password is returned.
122 On error, NULL is returned.
123 .SH ERRORS
124 .TP
125 .B EINVAL
126 .I salt
127 has the wrong format.
128 .TP
129 .B
130 .TP
131 .B ENOSYS
132 The
133 .BR crypt ()
134 function was not implemented, probably because of U.S.A. export restrictions.
135 .\" This level of detail is not necessary in this man page. . .
136 .\" .PP
137 .\" When encrypting a plain text P using DES with the key K results in the
138 .\" encrypted text C, then the complementary plain text P' being encrypted
139 .\" using the complementary key K' will result in the complementary encrypted
140 .\" text C'.
141 .\" .PP
142 .\" Weak keys are keys which stay invariant under the DES key transformation.
143 .\" The four known weak keys 0101010101010101, fefefefefefefefe,
144 .\" 1f1f1f1f0e0e0e0e and e0e0e0e0f1f1f1f1 must be avoided.
145 .\" .PP
146 .\" There are six known half weak key pairs, which keys lead to the same
147 .\" encrypted data.  Keys which are part of such key clusters should be
148 .\" avoided.
149 .\" Sorry, I could not find out what they are.
150 .\""
151 .\" .PP
152 .\" Heavily redundant data causes trouble with DES encryption, when used in the
153 .\" .I codebook
154 .\" mode that
155 .\" .BR crypt ()
156 .\" implements.  The
157 .\" .BR crypt ()
158 .\" interface should be used only for its intended purpose of password
159 .\" verification, and should not be used as part of a data encryption tool.
160 .\" .PP
161 .\" The first and last three output bits of the fourth S-box can be
162 .\" represented as function of their input bits.  Empiric studies have
163 .\" shown that S-boxes partially compute the same output for similar input.
164 .\" It is suspected that this may contain a back door which could allow the
165 .\" NSA to decrypt DES encrypted data.
166 .\" .PP
167 .\" Making encrypted data computed using crypt() publicly available has
168 .\" to be considered insecure for the given reasons.
169 .TP
170 .B EPERM
171 .I /proc/sys/crypto/fips_enabled
172 has a nonzero value,
173 and an attempt was made to use a weak encryption type, such as DES.
174 .SH ATTRIBUTES
175 .SS Multithreading (see pthreads(7))
176 The
177 .BR crypt ()
178 function is not thread-safe.
179 .LP
180 The
181 .BR crypt_r ()
182 function is thread-safe.
183 .SH CONFORMING TO
184 .BR crypt ():
185 SVr4, 4.3BSD, POSIX.1-2001.
186 .BR crypt_r ()
187 is a GNU extension.
188 .SH NOTES
189 .SS Glibc notes
190 The glibc2 version of this function supports additional
191 encryption algorithms.
192
193 If
194 .I salt
195 is a character string starting with the characters "$\fIid\fP$"
196 followed by a string terminated by "$":
197 .RS
198
199 $\fIid\fP$\fIsalt\fP$\fIencrypted\fP
200
201 .RE
202 then instead of using the DES machine,
203 .I id
204 identifies the encryption method used and this then determines how the rest
205 of the password string is interpreted.
206 The following values of
207 .I id
208 are supported:
209 .RS
210 .TS
211 l l.
212 ID  | Method
213 _
214 1   | MD5
215 2a  | Blowfish (not in mainline glibc; added in some
216     | Linux distributions)
217 .\" openSUSE has Blowfish, but AFAICS, this option is not supported
218 .\" natively by glibc -- mtk, Jul 08
219 .\"
220 .\" md5 | Sun MD5
221 .\" glibc doesn't appear to natively support Sun MD5; I don't know
222 .\" if any distros add the support.
223 5   | SHA-256 (since glibc 2.7)
224 6   | SHA-512 (since glibc 2.7)
225 .TE
226 .RE
227
228 So $5$\fIsalt\fP$\fIencrypted\fP is an SHA-256 encoded
229 password and $6$\fIsalt\fP$\fIencrypted\fP is an
230 SHA-512 encoded one.
231
232 "\fIsalt\fP" stands for the up to 16 characters
233 following "$\fIid\fP$" in the salt.
234 The encrypted part of the password string is the actual computed password.
235 The size of this string is fixed:
236 .TS
237 l l.
238 MD5     | 22 characters
239 SHA-256 | 43 characters
240 SHA-512 | 86 characters
241 .TE
242
243 The characters in "\fIsalt\fP" and "\fIencrypted\fP" are drawn from the set
244 [\fBa\-zA\-Z0\-9./\fP].
245 In the MD5 and SHA implementations the entire
246 .I key
247 is significant (instead of only the first
248 8 bytes in DES).
249 .SH SEE ALSO
250 .BR login (1),
251 .BR passwd (1),
252 .BR encrypt (3),
253 .BR getpass (3),
254 .BR passwd (5)
255 .SH COLOPHON
256 This page is part of release 3.68 of the Linux
257 .I man-pages
258 project.
259 A description of the project,
260 information about reporting bugs,
261 and the latest version of this page,
262 can be found at
263 \%http://www.kernel.org/doc/man\-pages/.