OSDN Git Service

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