OSDN Git Service

(split) LDP_man-pages: update original to v3.34.
[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 .\" This is free documentation; you can redistribute it and/or
5 .\" modify it under the terms of the GNU General Public License as
6 .\" published by the Free Software Foundation; either version 2 of
7 .\" the License, or (at your option) any later version.
8 .\"
9 .\" The GNU General Public License's references to "object code"
10 .\" and "executables" are to be interpreted as the output of any
11 .\" document formatting or typesetting system, including
12 .\" intermediate and printed output.
13 .\"
14 .\" This manual is distributed in the hope that it will be useful,
15 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
16 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 .\" GNU General Public License for more details.
18 .\"
19 .\" You should have received a copy of the GNU General Public
20 .\" License along with this manual; if not, write to the Free
21 .\" Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111,
22 .\" USA.
23 .\"
24 .\" Sun Feb 19 21:32:25 1995, faith@cs.unc.edu edited details away
25 .\"
26 .\" TO DO: This manual page should go more into detail how DES is perturbed,
27 .\" which string will be encrypted, and what determines the repetition factor.
28 .\" Is a simple repetition using ECB used, or something more advanced?  I hope
29 .\" the presented explanations are at least better than nothing, but by no
30 .\" means enough.
31 .\"
32 .\" added _XOPEN_SOURCE, aeb, 970705
33 .\" added GNU MD5 stuff, aeb, 011223
34 .\"
35 .TH CRYPT 3 2011-09-15 "" "Linux Programmer's Manual"
36 .SH NAME
37 crypt, crypt_r \- password and data encryption
38 .SH SYNOPSIS
39 .nf
40 .BR "#define _XOPEN_SOURCE" "       /* See feature_test_macros(7) */"
41 .br
42 .B #include <unistd.h>
43 .sp
44 .BI "char *crypt(const char *" key ", const char *" salt );
45 .sp
46 .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
47 .br
48 .B #include <crypt.h>
49 .sp
50 .BI "char *crypt_r(const char *" key ", const char *" salt ,
51 .BI "              struct crypt_data *" data );
52 .fi
53 .sp
54 Link with \fI\-lcrypt\fP.
55 .SH DESCRIPTION
56 .BR crypt ()
57 is the password encryption function.
58 It is based on the Data Encryption
59 Standard algorithm with variations intended (among other things) to
60 discourage use of hardware implementations of a key search.
61 .PP
62 .I key
63 is a user's typed password.
64 .PP
65 .I salt
66 is a two-character string chosen from the set
67 [\fBa\fP\(en\fBzA\fP\(en\fBZ0\fP\(en\fB9./\fP].
68 This string is used to
69 perturb the algorithm in one of 4096 different ways.
70 .PP
71 By taking the lowest 7 bits of each of the first eight characters of the
72 .IR key ,
73 a 56-bit key is obtained.
74 This 56-bit key is used to encrypt repeatedly a
75 constant string (usually a string consisting of all zeros).
76 The returned
77 value points to the encrypted password, a series of 13 printable ASCII
78 characters (the first two characters represent the salt itself).
79 The return value points to static data whose content is
80 overwritten by each call.
81 .PP
82 Warning: The key space consists of
83 .if t 2\s-2\u56\s0\d
84 .if n 2**56
85 equal 7.2e16 possible values.
86 Exhaustive searches of this key space are
87 possible using massively parallel computers.
88 Software, such as
89 .BR crack (1),
90 is available which will search the portion of this key space that is
91 generally used by humans for passwords.
92 Hence, password selection should,
93 at minimum, avoid common words and names.
94 The use of a
95 .BR passwd (1)
96 program that checks for crackable passwords during the selection process is
97 recommended.
98 .PP
99 The DES algorithm itself has a few quirks which make the use of the
100 .BR crypt ()
101 interface a very poor choice for anything other than password
102 authentication.
103 If you are planning on using the
104 .BR crypt ()
105 interface for a cryptography project, don't do it: get a good book on
106 encryption and one of the widely available DES libraries.
107
108 .BR crypt_r ()
109 is a reentrant version of
110 .BR crypt ().
111 The structure pointed to by
112 .I data
113 is used to store result data and bookkeeping information.
114 Other than allocating it,
115 the only thing that the caller should do with this structure is to set
116 .I data->initialized
117 to zero before the first call to
118 .BR crypt_r ().
119 .SH "RETURN VALUE"
120 On success, a pointer to the encrypted password is returned.
121 On error, NULL is returned.
122 .SH ERRORS
123 .TP
124 .B ENOSYS
125 The
126 .BR crypt ()
127 function was not implemented, probably because of U.S.A. export restrictions.
128 .\" This level of detail is not necessary in this man page. . .
129 .\" .PP
130 .\" When encrypting a plain text P using DES with the key K results in the
131 .\" encrypted text C, then the complementary plain text P' being encrypted
132 .\" using the complementary key K' will result in the complementary encrypted
133 .\" text C'.
134 .\" .PP
135 .\" Weak keys are keys which stay invariant under the DES key transformation.
136 .\" The four known weak keys 0101010101010101, fefefefefefefefe,
137 .\" 1f1f1f1f0e0e0e0e and e0e0e0e0f1f1f1f1 must be avoided.
138 .\" .PP
139 .\" There are six known half weak key pairs, which keys lead to the same
140 .\" encrypted data.  Keys which are part of such key clusters should be
141 .\" avoided.
142 .\" Sorry, I could not find out what they are.
143 .\""
144 .\" .PP
145 .\" Heavily redundant data causes trouble with DES encryption, when used in the
146 .\" .I codebook
147 .\" mode that
148 .\" .BR crypt ()
149 .\" implements.  The
150 .\" .BR crypt ()
151 .\" interface should be used only for its intended purpose of password
152 .\" verification, and should not be used as part of a data encryption tool.
153 .\" .PP
154 .\" The first and last three output bits of the fourth S-box can be
155 .\" represented as function of their input bits.  Empiric studies have
156 .\" shown that S-boxes partially compute the same output for similar input.
157 .\" It is suspected that this may contain a back door which could allow the
158 .\" NSA to decrypt DES encrypted data.
159 .\" .PP
160 .\" Making encrypted data computed using crypt() publicly available has
161 .\" to be considered insecure for the given reasons.
162 .SH "CONFORMING TO"
163 .BR crypt ():
164 SVr4, 4.3BSD, POSIX.1-2001.
165 .BR crypt_r ()
166 is a GNU extension.
167 .SH NOTES
168 .SS Glibc Notes
169 The glibc2 version of this function supports additional
170 encryption algorithms.
171
172 If
173 .I salt
174 is a character string starting with the characters "$\fIid\fP$"
175 followed by a string terminated by "$":
176 .RS
177
178 $\fIid\fP$\fIsalt\fP$\fIencrypted\fP
179
180 .RE
181 then instead of using the DES machine,
182 .I id
183 identifies the encryption method used and this then determines how the rest
184 of the password string is interpreted.
185 The following values of
186 .I id
187 are supported:
188 .RS
189 .TS
190 l l.
191 ID  | Method
192 _
193 1   | MD5
194 2a  | Blowfish (not in mainline glibc; added in some
195     | Linux distributions)
196 .\" openSUSE has Blowfish, but AFAICS, this option is not supported
197 .\" natively by glibc -- mtk, Jul 08
198 .\"
199 .\" md5 | Sun MD5
200 .\" glibc doesn't appear to natively support Sun MD5; I don't know
201 .\" if any distros add the support.
202 5   | SHA-256 (since glibc 2.7)
203 6   | SHA-512 (since glibc 2.7)
204 .TE
205 .RE
206
207 So $5$\fIsalt\fP$\fIencrypted\fP is an SHA-256 encoded
208 password and $6$\fIsalt\fP$\fIencrypted\fP is an
209 SHA-512 encoded one.
210
211 "\fIsalt\fP" stands for the up to 16 characters
212 following "$\fIid\fP$" in the salt.
213 The encrypted part of the password string is the actual computed password.
214 The size of this string is fixed:
215 .TS
216 l l.
217 MD5     | 22 characters
218 SHA-256 | 43 characters
219 SHA-512 | 86 characters
220 .TE
221
222 The characters in "\fIsalt\fP" and "\fIencrypted\fP" are drawn from the set
223 [\fBa\fP\(en\fBzA\fP\(en\fBZ0\fP\(en\fB9./\fP].
224 In the MD5 and SHA implementations the entire
225 .I key
226 is significant (instead of only the first
227 8 bytes in DES).
228 .SH "SEE ALSO"
229 .BR login (1),
230 .BR passwd (1),
231 .BR encrypt (3),
232 .BR getpass (3),
233 .BR passwd (5)