diff options
author | cvs2svn <admin@example.com> | 1998-10-19 21:47:13 +0000 |
---|---|---|
committer | cvs2svn <admin@example.com> | 1998-10-19 21:47:13 +0000 |
commit | f954a53a9a7dced3fb4c80b1e8dd267981ae025d (patch) | |
tree | c667406046ddb1efca5ed4316b02e43494241660 /src/lib/libc/crypt/crypt.3 | |
parent | 536c76cbb863bab152f19842ab88772c01e922c7 (diff) | |
download | openbsd-OPENBSD_2_4.tar.gz openbsd-OPENBSD_2_4.tar.bz2 openbsd-OPENBSD_2_4.zip |
This commit was manufactured by cvs2git to create branch 'OPENBSD_2_4'.OPENBSD_2_4
Diffstat (limited to 'src/lib/libc/crypt/crypt.3')
-rw-r--r-- | src/lib/libc/crypt/crypt.3 | 298 |
1 files changed, 298 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..524645de55 --- /dev/null +++ b/src/lib/libc/crypt/crypt.3 | |||
@@ -0,0 +1,298 @@ | |||
1 | .\" $OpenBSD: crypt.3,v 1.11 1998/02/27 12:17:45 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 | .Sh DESCRIPTION | ||
57 | The | ||
58 | .Fn crypt | ||
59 | function performs password encryption, based on the | ||
60 | .Tn NBS | ||
61 | Data Encryption Standard (DES). | ||
62 | Additional code has been added to deter key search attempts and to use | ||
63 | stronger hashing algorithms. | ||
64 | The first argument to | ||
65 | .Fn crypt | ||
66 | is a | ||
67 | .Dv null Ns -terminated | ||
68 | string, typically a user's typed password. | ||
69 | The second is in one of three forms: | ||
70 | if it begins with an underscore (``_'') then an extended format is used | ||
71 | in interpreting both the key and the setting, as outlined below. If it begins | ||
72 | with an string character (``$'') and a number then a different algorithm | ||
73 | is used depending on the number. At the moment a ``$1'' chooses MD5 hashing | ||
74 | and a ``$2'' chooses Blowfish hashing, see below for more information. | ||
75 | .Ss Extended crypt: | ||
76 | .Pp | ||
77 | The | ||
78 | .Ar key | ||
79 | is divided into groups of 8 characters (the last group is null-padded) | ||
80 | and the low-order 7 bits of each each character (56 bits per group) are | ||
81 | used to form the DES key as follows: | ||
82 | the first group of 56 bits becomes the initial DES key. | ||
83 | For each additional group, the XOR of the encryption of the current DES | ||
84 | key with itself and the group bits becomes the next DES key. | ||
85 | .Pp | ||
86 | The setting is a 9-character array consisting of an underscore followed | ||
87 | by 4 bytes of iteration count and 4 bytes of salt. | ||
88 | These are encoded as printable characters, 6 bits per character, | ||
89 | least significant character first. | ||
90 | The values 0 to 63 are encoded as ``./0-9A-Za-z''. | ||
91 | This allows 24 bits for both | ||
92 | .Fa count | ||
93 | and | ||
94 | .Fa salt . | ||
95 | .Ss "MD5" crypt: | ||
96 | .Pp | ||
97 | For | ||
98 | .Tn MD5 | ||
99 | crypt the version number, | ||
100 | .Fa salt | ||
101 | and the hashed password are separated | ||
102 | by the ``$'' character. The maximum length of a password is limited by | ||
103 | the length counter of the MD5 context, which is about | ||
104 | 2**64. A valid MD5 password entry looks like this: | ||
105 | .Pp | ||
106 | ``$1$caeiHQwX$hsKqOjrFRRN6K32OWkCBf1''. | ||
107 | .Pp | ||
108 | The whole MD5 password string is passed as | ||
109 | .Fa setting | ||
110 | for interpretation. | ||
111 | .Ss "Blowfish" crypt: | ||
112 | .Pp | ||
113 | The | ||
114 | .Tn Blowfish | ||
115 | version of crypt has 128 bits of | ||
116 | .Fa salt | ||
117 | in order to make building | ||
118 | dictionaries of common passwords space consuming. The initial state | ||
119 | of the | ||
120 | .Tn Blowfish | ||
121 | cipher is expanded using the | ||
122 | .Fa salt | ||
123 | and the | ||
124 | .Fa password | ||
125 | repeating the process a variable number of rounds, which is encoded in | ||
126 | the password string. The maximum password length is 72. The final Blowfish | ||
127 | password entry is created by encrypting | ||
128 | the string ``OrpheanBeholderScryDoubt'' with the | ||
129 | .Tn Blowfish | ||
130 | state 64 times. | ||
131 | .Pp | ||
132 | The version number, the logarithm of the number of rounds and | ||
133 | the concatenation of salt and | ||
134 | hashed password are separated by the ``$'' character. An encoded ``8'' | ||
135 | would specify 256 rounds. | ||
136 | A valid Blowfish password looks like this: | ||
137 | .Pp | ||
138 | ``$2a$12$eIAq8PR8sIUnJ1HaohxX2O9x9Qlm2vK97LJ5dsXdmB.eXF42qjchC''. | ||
139 | .Pp | ||
140 | The whole Blowfish password string is passed as | ||
141 | .Fa setting | ||
142 | for interpretation. | ||
143 | .Ss "Traditional" crypt: | ||
144 | .Pp | ||
145 | The first 8 bytes of the key are null-padded, and the low-order 7 bits of | ||
146 | each character is used to form the 56-bit | ||
147 | .Tn DES | ||
148 | key. | ||
149 | .Pp | ||
150 | The setting is a 2-character array of the ASCII-encoded salt. | ||
151 | Thus only 12 bits of | ||
152 | .Fa salt | ||
153 | are used. | ||
154 | .Fa count | ||
155 | is set to 25. | ||
156 | .Ss DES Algorithm: | ||
157 | .Pp | ||
158 | The | ||
159 | .Fa salt | ||
160 | introduces disorder in the | ||
161 | .Tn DES | ||
162 | algorithm in one of 16777216 or 4096 possible ways | ||
163 | (ie. with 24 or 12 bits: if bit | ||
164 | .Em i | ||
165 | of the | ||
166 | .Ar salt | ||
167 | is set, then bits | ||
168 | .Em i | ||
169 | and | ||
170 | .Em i+24 | ||
171 | are swapped in the | ||
172 | .Tn DES | ||
173 | E-box output). | ||
174 | .Pp | ||
175 | The DES key is used to encrypt a 64-bit constant using | ||
176 | .Ar count | ||
177 | iterations of | ||
178 | .Tn DES . | ||
179 | The value returned is a | ||
180 | .Dv null Ns -terminated | ||
181 | string, 20 or 13 bytes (plus null) in length, consisting of the | ||
182 | .Ar setting | ||
183 | followed by the encoded 64-bit encryption. | ||
184 | .Pp | ||
185 | The functions, | ||
186 | .Fn encrypt , | ||
187 | .Fn setkey , | ||
188 | .Fn des_setkey | ||
189 | and | ||
190 | .Fn des_cipher | ||
191 | provide access to the | ||
192 | .Tn DES | ||
193 | algorithm itself. | ||
194 | .Fn setkey | ||
195 | is passed a 64-byte array of binary values (numeric 0 or 1). | ||
196 | A 56-bit key is extracted from this array by dividing the | ||
197 | array into groups of 8, and ignoring the last bit in each group. | ||
198 | That bit is reserved for a byte parity check by DES, but is ignored | ||
199 | by these functions. | ||
200 | .Pp | ||
201 | The | ||
202 | .Fa block | ||
203 | argument to | ||
204 | .Fn encrypt | ||
205 | is also a 64-byte array of binary values. | ||
206 | If the value of | ||
207 | .Fa flag | ||
208 | is 0, | ||
209 | .Fa block | ||
210 | is encrypted otherwise it is decrypted. | ||
211 | The result is returned in the original array | ||
212 | .Fa block | ||
213 | after using the key specified by | ||
214 | .Fn setkey | ||
215 | to process it. | ||
216 | .Pp | ||
217 | The argument to | ||
218 | .Fn des_setkey | ||
219 | is a character array of length 8. | ||
220 | The least significant bit (the parity bit) in each character is ignored, | ||
221 | and the remaining bits are concatenated to form a 56-bit key. | ||
222 | The function | ||
223 | .Fn des_cipher | ||
224 | encrypts (or decrypts if | ||
225 | .Fa count | ||
226 | is negative) the 64-bits stored in the 8 characters at | ||
227 | .Fa in | ||
228 | using | ||
229 | .Xr abs 3 | ||
230 | of | ||
231 | .Fa count | ||
232 | iterations of | ||
233 | .Tn DES | ||
234 | and stores the 64-bit result in the 8 characters at | ||
235 | .Fa out | ||
236 | (which may be the same as | ||
237 | .Fa in | ||
238 | ). | ||
239 | The | ||
240 | .Fa salt | ||
241 | specifies perturbations to the | ||
242 | .Tn DES | ||
243 | E-box output as described above. | ||
244 | .Pp | ||
245 | The function | ||
246 | .Fn crypt | ||
247 | returns a pointer to the encrypted value on success, and NULL on failure. | ||
248 | The functions | ||
249 | .Fn setkey , | ||
250 | .Fn encrypt , | ||
251 | .Fn des_setkey , | ||
252 | and | ||
253 | .Fn des_cipher | ||
254 | return 0 on success and 1 on failure. | ||
255 | .Pp | ||
256 | The | ||
257 | .Fn crypt , | ||
258 | .Fn setkey | ||
259 | and | ||
260 | .Fn des_setkey | ||
261 | functions all manipulate the same key space. | ||
262 | .Sh SEE ALSO | ||
263 | .Xr login 1 , | ||
264 | .Xr passwd 1 , | ||
265 | .Xr blowfish 3 , | ||
266 | .Xr getpass 3 , | ||
267 | .Xr md5 3 , | ||
268 | .Xr passwd 5 | ||
269 | .Sh BUGS | ||
270 | The | ||
271 | .Fn crypt | ||
272 | function returns a pointer to static data, and subsequent calls to | ||
273 | .Fn crypt | ||
274 | will modify the same object. | ||
275 | .Sh HISTORY | ||
276 | A rotor-based | ||
277 | .Fn crypt | ||
278 | function appeared in | ||
279 | .At v6 . | ||
280 | The current style | ||
281 | .Fn crypt | ||
282 | first appeared in | ||
283 | .At v7 . | ||
284 | .Pp | ||
285 | This library (FreeSec 1.0) was developed outside the United States of America | ||
286 | as an unencumbered replacement for the U.S.-only libcrypt encryption | ||
287 | library. | ||
288 | Programs linked against the | ||
289 | .Fn crypt | ||
290 | interface may be exported from the U.S.A. only if they use | ||
291 | .Fn crypt | ||
292 | solely for authentication purposes and avoid use of | ||
293 | the other programmer interfaces listed above. Special care has been taken | ||
294 | in the library so that programs which only use the | ||
295 | .Fn crypt | ||
296 | interface do not pull in the other components. | ||
297 | .Sh AUTHOR | ||
298 | David Burren <davidb@werj.com.au> | ||