diff options
Diffstat (limited to 'src/lib/libc/crypt/crypt.3')
-rw-r--r-- | src/lib/libc/crypt/crypt.3 | 320 |
1 files changed, 320 insertions, 0 deletions
diff --git a/src/lib/libc/crypt/crypt.3 b/src/lib/libc/crypt/crypt.3 new file mode 100644 index 0000000000..32109dfac3 --- /dev/null +++ b/src/lib/libc/crypt/crypt.3 | |||
@@ -0,0 +1,320 @@ | |||
1 | .\" $OpenBSD: crypt.3,v 1.21 2003/08/07 00:32:12 deraadt Exp $ | ||
2 | .\" | ||
3 | .\" FreeSec: libcrypt | ||
4 | .\" | ||
5 | .\" Copyright (c) 1994 David Burren | ||
6 | .\" All rights reserved. | ||
7 | .\" | ||
8 | .\" Redistribution and use in source and binary forms, with or without | ||
9 | .\" modification, are permitted provided that the following conditions | ||
10 | .\" are met: | ||
11 | .\" 1. Redistributions of source code must retain the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer. | ||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer in the | ||
15 | .\" documentation and/or other materials provided with the distribution. | ||
16 | .\" 4. Neither the name of the author nor the names of other contributors | ||
17 | .\" may be used to endorse or promote products derived from this software | ||
18 | .\" without specific prior written permission. | ||
19 | .\" | ||
20 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | .\" SUCH DAMAGE. | ||
31 | .\" | ||
32 | .\" Manual page, using -mandoc macros | ||
33 | .\" | ||
34 | .Dd March 9, 1994 | ||
35 | .Dt CRYPT 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm crypt , | ||
39 | .Nm setkey , | ||
40 | .Nm encrypt , | ||
41 | .Nm des_setkey , | ||
42 | .Nm des_cipher | ||
43 | .Nd DES encryption | ||
44 | .Sh SYNOPSIS | ||
45 | .Fd #include <unistd.h> | ||
46 | .Ft char * | ||
47 | .Fn crypt "const char *key" "const char *setting" | ||
48 | .Ft int | ||
49 | .Fn setkey "char *key" | ||
50 | .Ft int | ||
51 | .Fn encrypt "char *block" "int flag" | ||
52 | .Ft int | ||
53 | .Fn des_setkey "const char *key" | ||
54 | .Ft int | ||
55 | .Fn des_cipher "const char *in" "char *out" "int32_t salt" "int count" | ||
56 | .Ft char * | ||
57 | .Fn bcrypt_gensalt "u_int8_t log_rounds" | ||
58 | .Ft char * | ||
59 | .Fn bcrypt "const char *key" "const char *salt" | ||
60 | .Ft char * | ||
61 | .Fn md5crypt "const char *key" "const char *salt" | ||
62 | .Sh DESCRIPTION | ||
63 | The | ||
64 | .Fn crypt | ||
65 | function performs password encryption based on the | ||
66 | .Tn NBS | ||
67 | Data Encryption Standard (DES). | ||
68 | Additional code has been added to deter key search attempts and to use | ||
69 | stronger hashing algorithms. | ||
70 | .Pp | ||
71 | The first argument to | ||
72 | .Fn crypt | ||
73 | is a | ||
74 | .Dv null Ns -terminated | ||
75 | string, typically a user's typed password. | ||
76 | The second is in one of three forms: | ||
77 | if it begins with an underscore | ||
78 | .Pq Ql _ | ||
79 | then an extended format is used | ||
80 | in interpreting both the key and the setting, as outlined below. | ||
81 | If it begins | ||
82 | with a string character | ||
83 | .Pq Ql $ | ||
84 | and a number then a different algorithm is used depending on the number. | ||
85 | At the moment a | ||
86 | .Ql $1 | ||
87 | chooses MD5 hashing and a | ||
88 | .Ql $2 | ||
89 | chooses Blowfish hashing; see below for more information. | ||
90 | .Ss Extended crypt | ||
91 | The | ||
92 | .Ar key | ||
93 | is divided into groups of 8 characters (the last group is null-padded) | ||
94 | and the low-order 7 bits of each character (56 bits per group) are | ||
95 | used to form the DES key as follows: | ||
96 | the first group of 56 bits becomes the initial DES key. | ||
97 | For each additional group, the XOR of the encryption of the current DES | ||
98 | key with itself and the group bits becomes the next DES key. | ||
99 | .Pp | ||
100 | The setting is a 9-character array consisting of an underscore followed | ||
101 | by 4 bytes of iteration count and 4 bytes of salt. | ||
102 | These are encoded as printable characters, 6 bits per character, | ||
103 | least significant character first. | ||
104 | The values 0 to 63 are encoded as | ||
105 | .Dq \&./0-9A-Za-z . | ||
106 | This allows 24 bits for both | ||
107 | .Fa count | ||
108 | and | ||
109 | .Fa salt . | ||
110 | .Ss "MD5" crypt | ||
111 | For | ||
112 | .Tn MD5 | ||
113 | crypt the version number, | ||
114 | .Fa salt | ||
115 | and the hashed password are separated by the | ||
116 | .Ql $ | ||
117 | character. | ||
118 | The maximum length of a password is limited by | ||
119 | the length counter of the MD5 context, which is about | ||
120 | 2**64. | ||
121 | A valid MD5 password entry looks like this: | ||
122 | .Pp | ||
123 | .Dq $1$caeiHQwX$hsKqOjrFRRN6K32OWkCBf1 . | ||
124 | .Pp | ||
125 | The whole MD5 password string is passed as | ||
126 | .Fa setting | ||
127 | for interpretation. | ||
128 | .Ss "Blowfish" crypt | ||
129 | The | ||
130 | .Tn Blowfish | ||
131 | version of crypt has 128 bits of | ||
132 | .Fa salt | ||
133 | in order to make building dictionaries of common passwords space consuming. | ||
134 | The initial state of the | ||
135 | .Tn Blowfish | ||
136 | cipher is expanded using the | ||
137 | .Fa salt | ||
138 | and the | ||
139 | .Fa password | ||
140 | repeating the process a variable number of rounds, which is encoded in | ||
141 | the password string. | ||
142 | The maximum password length is 72. | ||
143 | The final Blowfish password entry is created by encrypting the string | ||
144 | .Pp | ||
145 | .Dq OrpheanBeholderScryDoubt | ||
146 | .Pp | ||
147 | with the | ||
148 | .Tn Blowfish | ||
149 | state 64 times. | ||
150 | .Pp | ||
151 | The version number, the logarithm of the number of rounds and | ||
152 | the concatenation of salt and hashed password are separated by the | ||
153 | .Ql $ | ||
154 | character. | ||
155 | An encoded | ||
156 | .Sq 8 | ||
157 | would specify 256 rounds. | ||
158 | A valid Blowfish password looks like this: | ||
159 | .Pp | ||
160 | .Dq $2a$12$eIAq8PR8sIUnJ1HaohxX2O9x9Qlm2vK97LJ5dsXdmB.eXF42qjchC . | ||
161 | .Pp | ||
162 | The whole Blowfish password string is passed as | ||
163 | .Fa setting | ||
164 | for interpretation. | ||
165 | .Ss "Traditional" crypt | ||
166 | The first 8 bytes of the key are null-padded, and the low-order 7 bits of | ||
167 | each character is used to form the 56-bit | ||
168 | .Tn DES | ||
169 | key. | ||
170 | .Pp | ||
171 | The setting is a 2-character array of the ASCII-encoded salt. | ||
172 | Thus only 12 bits of | ||
173 | .Fa salt | ||
174 | are used. | ||
175 | .Fa count | ||
176 | is set to 25. | ||
177 | .Ss DES Algorithm | ||
178 | The | ||
179 | .Fa salt | ||
180 | introduces disorder in the | ||
181 | .Tn DES | ||
182 | algorithm in one of 16777216 or 4096 possible ways | ||
183 | (i.e., with 24 or 12 bits: if bit | ||
184 | .Em i | ||
185 | of the | ||
186 | .Ar salt | ||
187 | is set, then bits | ||
188 | .Em i | ||
189 | and | ||
190 | .Em i+24 | ||
191 | are swapped in the | ||
192 | .Tn DES | ||
193 | E-box output). | ||
194 | .Pp | ||
195 | The DES key is used to encrypt a 64-bit constant using | ||
196 | .Ar count | ||
197 | iterations of | ||
198 | .Tn DES . | ||
199 | The value returned is a | ||
200 | .Dv null Ns -terminated | ||
201 | string, 20 or 13 bytes (plus null) in length, consisting of the | ||
202 | .Ar setting | ||
203 | followed by the encoded 64-bit encryption. | ||
204 | .Pp | ||
205 | The functions | ||
206 | .Fn encrypt , | ||
207 | .Fn setkey , | ||
208 | .Fn des_setkey , | ||
209 | and | ||
210 | .Fn des_cipher | ||
211 | provide access to the | ||
212 | .Tn DES | ||
213 | algorithm itself. | ||
214 | .Fn setkey | ||
215 | is passed a 64-byte array of binary values (numeric 0 or 1). | ||
216 | A 56-bit key is extracted from this array by dividing the | ||
217 | array into groups of 8, and ignoring the last bit in each group. | ||
218 | That bit is reserved for a byte parity check by DES, but is ignored | ||
219 | by these functions. | ||
220 | .Pp | ||
221 | The | ||
222 | .Fa block | ||
223 | argument to | ||
224 | .Fn encrypt | ||
225 | is also a 64-byte array of binary values. | ||
226 | If the value of | ||
227 | .Fa flag | ||
228 | is 0, | ||
229 | .Fa block | ||
230 | is encrypted otherwise it is decrypted. | ||
231 | The result is returned in the original array | ||
232 | .Fa block | ||
233 | after using the key specified by | ||
234 | .Fn setkey | ||
235 | to process it. | ||
236 | .Pp | ||
237 | The argument to | ||
238 | .Fn des_setkey | ||
239 | is a character array of length 8. | ||
240 | The least significant bit (the parity bit) in each character is ignored, | ||
241 | and the remaining bits are concatenated to form a 56-bit key. | ||
242 | The function | ||
243 | .Fn des_cipher | ||
244 | encrypts (or decrypts if | ||
245 | .Fa count | ||
246 | is negative) the 64-bits stored in the 8 characters at | ||
247 | .Fa in | ||
248 | using | ||
249 | .Xr abs 3 | ||
250 | of | ||
251 | .Fa count | ||
252 | iterations of | ||
253 | .Tn DES | ||
254 | and stores the 64-bit result in the 8 characters at | ||
255 | .Fa out | ||
256 | (which may be the same as | ||
257 | .Fa in ) . | ||
258 | The | ||
259 | .Fa salt | ||
260 | specifies perturbations to the | ||
261 | .Tn DES | ||
262 | E-box output as described above. | ||
263 | .Pp | ||
264 | The function | ||
265 | .Fn crypt | ||
266 | returns a pointer to the encrypted value on success, and | ||
267 | .Dv NULL | ||
268 | on failure. | ||
269 | The functions | ||
270 | .Fn setkey , | ||
271 | .Fn encrypt , | ||
272 | .Fn des_setkey , | ||
273 | and | ||
274 | .Fn des_cipher | ||
275 | return 0 on success and 1 on failure. | ||
276 | .Pp | ||
277 | The | ||
278 | .Fn crypt , | ||
279 | .Fn setkey , | ||
280 | and | ||
281 | .Fn des_setkey | ||
282 | functions all manipulate the same key space. | ||
283 | .Sh SEE ALSO | ||
284 | .Xr login 1 , | ||
285 | .Xr passwd 1 , | ||
286 | .Xr blowfish 3 , | ||
287 | .Xr getpass 3 , | ||
288 | .Xr md5 3 , | ||
289 | .Xr passwd 5 | ||
290 | .Sh HISTORY | ||
291 | A rotor-based | ||
292 | .Fn crypt | ||
293 | function appeared in | ||
294 | .At v3 . | ||
295 | The current style | ||
296 | .Fn crypt | ||
297 | first appeared in | ||
298 | .At v7 . | ||
299 | .Pp | ||
300 | This library (FreeSec 1.0) was developed outside the United States of America | ||
301 | as an unencumbered replacement for the U.S.-only libcrypt encryption | ||
302 | library. | ||
303 | Programs linked against the | ||
304 | .Fn crypt | ||
305 | interface may be exported from the U.S.A. only if they use | ||
306 | .Fn crypt | ||
307 | solely for authentication purposes and avoid use of | ||
308 | the other programmer interfaces listed above. | ||
309 | Special care has been taken | ||
310 | in the library so that programs which only use the | ||
311 | .Fn crypt | ||
312 | interface do not pull in the other components. | ||
313 | .Sh AUTHORS | ||
314 | .An David Burren Aq davidb@werj.com.au | ||
315 | .Sh BUGS | ||
316 | The | ||
317 | .Fn crypt | ||
318 | function returns a pointer to static data, and subsequent calls to | ||
319 | .Fn crypt | ||
320 | will modify the same object. | ||