diff options
Diffstat (limited to 'src/lib/libc/crypt/crypt.3')
-rw-r--r-- | src/lib/libc/crypt/crypt.3 | 237 |
1 files changed, 237 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..78a54b18a2 --- /dev/null +++ b/src/lib/libc/crypt/crypt.3 | |||
@@ -0,0 +1,237 @@ | |||
1 | .\" FreeSec: libcrypt | ||
2 | .\" | ||
3 | .\" Copyright (c) 1994 David Burren | ||
4 | .\" All rights reserved. | ||
5 | .\" | ||
6 | .\" Redistribution and use in source and binary forms, with or without | ||
7 | .\" modification, are permitted provided that the following conditions | ||
8 | .\" are met: | ||
9 | .\" 1. Redistributions of source code must retain the above copyright | ||
10 | .\" notice, this list of conditions and the following disclaimer. | ||
11 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer in the | ||
13 | .\" documentation and/or other materials provided with the distribution. | ||
14 | .\" 4. Neither the name of the author nor the names of other contributors | ||
15 | .\" may be used to endorse or promote products derived from this software | ||
16 | .\" without specific prior written permission. | ||
17 | .\" | ||
18 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
19 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
20 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
21 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
22 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
23 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
24 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
25 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
26 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
28 | .\" SUCH DAMAGE. | ||
29 | .\" | ||
30 | .\" $Id: crypt.3,v 1.1 1995/12/16 12:55:29 deraadt Exp $ | ||
31 | .\" | ||
32 | .\" Manual page, using -mandoc macros | ||
33 | .\" | ||
34 | .Dd March 9, 1994 | ||
35 | .Dt CRYPT 3 | ||
36 | .Os "FreeSec 1.0" | ||
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 | .Ft char | ||
46 | .Fn *crypt "const char *key" "const char *setting" | ||
47 | .Ft int | ||
48 | .Fn setkey "char *key" | ||
49 | .Ft int | ||
50 | .Fn encrypt "char *block" "int flag" | ||
51 | .Ft int | ||
52 | .Fn des_setkey "const char *key" | ||
53 | .Ft int | ||
54 | .Fn des_cipher "const char *in" "char *out" "long salt" "int count" | ||
55 | .Sh DESCRIPTION | ||
56 | The | ||
57 | .Fn crypt | ||
58 | function performs password encryption, based on the | ||
59 | .Tn NBS | ||
60 | Data Encryption Standard (DES). | ||
61 | Additional code has been added to deter key search attempts. | ||
62 | The first argument to | ||
63 | .Nm crypt | ||
64 | is a | ||
65 | .Dv null Ns -terminated | ||
66 | string, typically a user's typed password. | ||
67 | The second is in one of two forms: | ||
68 | if it begins with an underscore (``_'') then an extended format is used | ||
69 | in interpreting both the the key and the setting, as outlined below. | ||
70 | .Ss Extended crypt: | ||
71 | .Pp | ||
72 | The | ||
73 | .Ar key | ||
74 | is divided into groups of 8 characters (the last group is null-padded) | ||
75 | and the low-order 7 bits of each each character (56 bits per group) are | ||
76 | used to form the DES key as follows: | ||
77 | the first group of 56 bits becomes the initial DES key. | ||
78 | For each additional group, the XOR of the encryption of the current DES | ||
79 | key with itself and the group bits becomes the next DES key. | ||
80 | .Pp | ||
81 | The setting is a 9-character array consisting of an underscore followed | ||
82 | by 4 bytes of iteration count and 4 bytes of salt. | ||
83 | These are encoded as printable characters, 6 bits per character, | ||
84 | least significant character first. | ||
85 | The values 0 to 63 are encoded as ``./0-9A-Za-z''. | ||
86 | This allows 24 bits for both | ||
87 | .Fa count | ||
88 | and | ||
89 | .Fa salt . | ||
90 | .Ss "Traditional" crypt: | ||
91 | .Pp | ||
92 | The first 8 bytes of the key are null-padded, and the low-order 7 bits of | ||
93 | each character is used to form the 56-bit | ||
94 | .Tn DES | ||
95 | key. | ||
96 | .Pp | ||
97 | The setting is a 2-character array of the ASCII-encoded salt. | ||
98 | Thus only 12 bits of | ||
99 | .Fa salt | ||
100 | are used. | ||
101 | .Fa count | ||
102 | is set to 25. | ||
103 | .Ss Algorithm: | ||
104 | .Pp | ||
105 | The | ||
106 | .Fa salt | ||
107 | introduces disorder in the | ||
108 | .Tn DES | ||
109 | algorithm in one of 16777216 or 4096 possible ways | ||
110 | (ie. with 24 or 12 bits: if bit | ||
111 | .Em i | ||
112 | of the | ||
113 | .Ar salt | ||
114 | is set, then bits | ||
115 | .Em i | ||
116 | and | ||
117 | .Em i+24 | ||
118 | are swapped in the | ||
119 | .Tn DES | ||
120 | E-box output). | ||
121 | .Pp | ||
122 | The DES key is used to encrypt a 64-bit constant using | ||
123 | .Ar count | ||
124 | iterations of | ||
125 | .Tn DES . | ||
126 | The value returned is a | ||
127 | .Dv null Ns -terminated | ||
128 | string, 20 or 13 bytes (plus null) in length, consisting of the | ||
129 | .Ar setting | ||
130 | followed by the encoded 64-bit encryption. | ||
131 | .Pp | ||
132 | The functions, | ||
133 | .Fn encrypt , | ||
134 | .Fn setkey , | ||
135 | .Fn des_setkey | ||
136 | and | ||
137 | .Fn des_cipher | ||
138 | provide access to the | ||
139 | .Tn DES | ||
140 | algorithm itself. | ||
141 | .Fn setkey | ||
142 | is passed a 64-byte array of binary values (numeric 0 or 1). | ||
143 | A 56-bit key is extracted from this array by dividing the | ||
144 | array into groups of 8, and ignoring the last bit in each group. | ||
145 | That bit is reserved for a byte parity check by DES, but is ignored | ||
146 | by these functions. | ||
147 | .Pp | ||
148 | The | ||
149 | .Fa block | ||
150 | argument to | ||
151 | .Fn encrypt | ||
152 | is also a 64-byte array of binary values. | ||
153 | If the value of | ||
154 | .Fa flag | ||
155 | is 0, | ||
156 | .Fa block | ||
157 | is encrypted otherwise it is decrypted. | ||
158 | The result is returned in the original array | ||
159 | .Fa block | ||
160 | after using the key specified by | ||
161 | .Fn setkey | ||
162 | to process it. | ||
163 | .Pp | ||
164 | The argument to | ||
165 | .Fn des_setkey | ||
166 | is a character array of length 8. | ||
167 | The least significant bit (the parity bit) in each character is ignored, | ||
168 | and the remaining bits are concatenated to form a 56-bit key. | ||
169 | The function | ||
170 | .Fn des_cipher | ||
171 | encrypts (or decrypts if | ||
172 | .Fa count | ||
173 | is negative) the 64-bits stored in the 8 characters at | ||
174 | .Fa in | ||
175 | using | ||
176 | .Xr abs 3 | ||
177 | of | ||
178 | .Fa count | ||
179 | iterations of | ||
180 | .Tn DES | ||
181 | and stores the 64-bit result in the 8 characters at | ||
182 | .Fa out | ||
183 | (which may be the same as | ||
184 | .Fa in | ||
185 | ). | ||
186 | The | ||
187 | .Fa salt | ||
188 | specifies perturbations to the | ||
189 | .Tn DES | ||
190 | E-box output as described above. | ||
191 | .Pp | ||
192 | The function | ||
193 | .Fn crypt | ||
194 | returns a pointer to the encrypted value on success, and NULL on failure. | ||
195 | The functions | ||
196 | .Fn setkey , | ||
197 | .Fn encrypt , | ||
198 | .Fn des_setkey , | ||
199 | and | ||
200 | .Fn des_cipher | ||
201 | return 0 on success and 1 on failure. | ||
202 | .Pp | ||
203 | The | ||
204 | .Fn crypt , | ||
205 | .Fn setkey | ||
206 | and | ||
207 | .Fn des_setkey | ||
208 | functions all manipulate the same key space. | ||
209 | .Sh SEE ALSO | ||
210 | .Xr login 1 , | ||
211 | .Xr passwd 1 , | ||
212 | .Xr getpass 3 , | ||
213 | .Xr passwd 5 | ||
214 | .Sh BUGS | ||
215 | The | ||
216 | .Fn crypt | ||
217 | function returns a pointer to static data, and subsequent calls to | ||
218 | .Fn crypt | ||
219 | will modify the same object. | ||
220 | .Sh HISTORY | ||
221 | A rotor-based | ||
222 | .Fn crypt | ||
223 | function appeared in | ||
224 | .At v6 . | ||
225 | The current style | ||
226 | .Fn crypt | ||
227 | first appeared in | ||
228 | .At v7 . | ||
229 | .Pp | ||
230 | This library (FreeSec 1.0) was developed outside the United States of America | ||
231 | as an unencumbered replacement for the U.S.-only libcrypt encryption | ||
232 | library. | ||
233 | Programs linked against the crypt() interface may be exported from the U.S.A. | ||
234 | only if they use crypt() solely for authentication purposes and avoid use of | ||
235 | the other programmer interfaces listed above. | ||
236 | .Sh AUTHOR | ||
237 | David Burren <davidb@werj.com.au> | ||