1 .\" FreeSec: libcrypt for NetBSD
3 .\" Copyright (c) 1994 David Burren
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
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 .\" 3. 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.
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
37 .Nd Trapdoor encryption
43 .Fn crypt "const char *key" "const char *salt"
45 .Fn crypt_r "const char *key" "const char *salt" "struct crypt_data *data"
47 .Fn crypt_get_format "void"
49 .Fn crypt_set_format "const char *string"
53 function performs password hashing with additional code added to
54 deter key search attempts.
55 Different algorithms can be used to
59 .\" If you add more algorithms, make sure to update this list
60 .\" and the default used for the Traditional format, below.
62 Currently these include the
64 .Tn Data Encryption Standard (DES) ,
68 .Pq compatible with Microsoft's NT scheme
71 The algorithm used will depend upon the format of the Salt
74 the Modular Crypt Format
81 is installed or not, and whether
83 has been called to change the default.
88 .Pq usually a password ,
90 .Dv NUL Ns -terminated
92 The second is the salt, in one of three forms:
94 .Bl -tag -width Traditional -compact -offset indent
96 If it begins with an underscore
101 is used in interpreting both the key and the salt, as outlined below.
103 If it begins with the string
105 then the Modular Crypt Format is used, as outlined below.
107 If neither of the above is true, it assumes the Traditional Format,
108 using the entire string as the salt
109 .Pq or the first portion .
112 All routines are designed to be time-consuming.
113 .Ss DES Extended Format:
116 is divided into groups of 8 characters
117 .Pq the last group is NUL-padded
118 and the low-order 7 bits of each character
119 .Pq 56 bits per group
123 the first group of 56 bits becomes the initial
126 For each additional group, the XOR of the encryption of the current
128 key with itself and the group bits becomes the next
132 The salt is a 9-character array consisting of an underscore followed
133 by 4 bytes of iteration count and 4 bytes of salt.
134 These are encoded as printable characters, 6 bits per character,
135 least significant character first.
136 The values 0 to 63 are encoded as
138 This allows 24 bits for both
145 introduces disorder in the
147 algorithm in one of 16777216 or 4096 possible ways
149 i.e., with 24 or 12 bits: if bit
164 key is used to encrypt a 64-bit constant using
168 The value returned is a
169 .Dv NUL Ns -terminated
170 string, 20 or 13 bytes
172 in length, consisting of the
174 followed by the encoded 64-bit encryption.
176 If the salt begins with the string
178 then the Modular Crypt Format is used.
181 represents which algorithm is used in encryption.
182 Following the token is
183 the actual salt to use in the encryption.
184 The maximum length of the salt used depends upon the module.
185 The salt must be terminated with the end of the string character
188 Any characters after the dollar sign are ignored.
190 Currently supported algorithms are:
192 .Bl -enum -compact -offset indent
207 Other crypt formats may be easily added.
208 An example salt would be:
209 .Bl -tag -width 6n -offset indent
210 .It Cm "$4$thesalt$rest"
212 .Ss Traditional crypt:
213 The algorithm used will depend upon whether
215 has been called and whether a global default format has been specified.
216 Unless a global default has been specified or
218 has set the format to something else, the built-in default format is
222 .\" NOTICE: Also make sure to update this
225 if it is available, or SHA-512 if not.
227 How the salt is used will depend upon the algorithm for the hash.
229 best results, specify at least eight characters of salt.
233 function returns a constant string that represents the name of the
234 algorithm currently used.
237 .\" NOTICE: Also make sure to update this, too, as well
249 function sets the default encoding format according to the supplied
254 function behaves identically to
256 except that the resulting string is stored in
258 making it thread-safe.
264 functions return a pointer to the encrypted value on success, and NULL on
266 Note: this is not a standard behaviour, AT&T
268 will always return a pointer to a string.
272 function will return 1 if the supplied encoding format was valid.
273 Otherwise, a value of 0 is returned.
291 section of the code (FreeSec 1.0) was developed outside the United
292 States of America as an unencumbered replacement for the U.S.-only
294 libcrypt encryption library.
298 function was added in
302 Originally written by
303 .An David Burren Aq Mt davidb@werj.com.au ,
304 later additions and changes by
305 .An Poul-Henning Kamp ,
306 .An Mark R V Murray ,
307 .An Michael Bretterklieber ,
316 function returns a pointer to static data, and subsequent calls to
318 will modify the same data.
321 modifies static data.
323 The NT-hash scheme does not use a salt,
325 for a competent attacker
327 Its use is not recommended.