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 .\" 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.
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
30 .\" $FreeBSD: src/lib/libcrypt/crypt.3,v 1.6.2.14 2002/12/29 16:35:35 schweikh Exp $
31 .\" $DragonFly: src/lib/libcrypt/crypt.3,v 1.5 2006/03/26 22:56:56 swildner Exp $
33 .\" Manual page, using -mandoc macros
40 .Nd Trapdoor encryption
46 .Fn crypt "const char *key" "const char *salt"
48 .Fn crypt_get_format "void"
50 .Fn crypt_set_format "const char *string"
54 function performs password hashing with additional code added to
55 deter key search attempts. 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) ,
70 The algorithm used will depend upon the format of the Salt (following
71 the Modular Crypt Format (MCF)), if
75 is installed or not, and whether
77 has been called to change the default.
81 is the data to hash (usually a password), in a
82 .Dv null Ns -terminated
84 The second is the salt, in one of three forms:
86 .Bl -tag -width Traditional -compact -offset indent
88 If it begins with an underscore
93 is used in interpreting both the key and the salt, as outlined below.
95 If it begins with the string
97 then the Modular Crypt Format is used, as outlined below.
99 If neither of the above is true, it assumes the Traditional Format,
100 using the entire string as the salt (or the first portion).
103 All routines are designed to be time-consuming. A brief test on a
107 crypt to do approximately 2640 crypts
108 a CPU second and MD5 to do about 62 crypts a CPU second.
109 .Ss DES Extended Format:
112 is divided into groups of 8 characters (the last group is null-padded)
113 and the low-order 7 bits of each character (56 bits per group) are
117 the first group of 56 bits becomes the initial
120 For each additional group, the XOR of the encryption of the current
122 key with itself and the group bits becomes the next
126 The salt is a 9-character array consisting of an underscore followed
127 by 4 bytes of iteration count and 4 bytes of salt.
128 These are encoded as printable characters, 6 bits per character,
129 least significant character first.
130 The values 0 to 63 are encoded as ``./0-9A-Za-z''.
131 This allows 24 bits for both
138 introduces disorder in the
140 algorithm in one of 16777216 or 4096 possible ways
141 (ie. with 24 or 12 bits: if bit
155 key is used to encrypt a 64-bit constant using
159 The value returned is a
160 .Dv null Ns -terminated
161 string, 20 or 13 bytes (plus null) in length, consisting of the
163 followed by the encoded 64-bit encryption.
165 If the salt begins with the string
167 then the Modular Crypt Format is used. The
169 represents which algorithm is used in encryption. Following the token is
170 the actual salt to use in the encryption. The length of the salt is limited
171 to 8 characters--because the length of the returned output is also limited
172 (_PASSWORD_LEN). The salt must be terminated with the end of the string
173 (NULL) or a dollar sign. Any characters after the dollar sign are ignored.
175 Currently supported algorithms are:
177 .Bl -enum -compact -offset indent
188 Other crypt formats may be easily added. An example salt would be:
189 .Bl -tag -offset indent
190 .It Cm "$3$thesalt$rest"
192 .Ss "Traditional" crypt:
193 The algorithm used will depend upon whether
195 has been called and whether a global default format has been specified.
196 Unless a global default has been specified or
198 has set the format to something else, the built-in default format is
202 .\" NOTICE: Also make sure to update this
205 if it is available, or MD5 if not.
207 How the salt is used will depend upon the algorithm for the hash. For
208 best results, specify at least two characters of salt.
212 function returns a constant string that represents the name of the
213 algorithm currently used.
216 .\" NOTICE: Also make sure to update this, too, as well
227 function sets the default encoding format according to the supplied
230 The global default format can be set using the
237 returns a pointer to the encrypted value on success, and NULL on failure.
238 Note: this is not a standard behaviour, AT&T
240 will always return a pointer to a string.
243 will return 1 if the supplied encoding format was valid.
244 Otherwise, a value of 0 is returned.
265 section of the code (FreeSec 1.0) was developed outside the United
266 States of America as an unencumbered replacement for the U.S.-only
268 libcrypt encryption library.
271 Originally written by
272 .An David Burren Aq davidb@werj.com.au ,
273 later additions and changes by
274 .An Poul-Henning Kamp ,
275 .An Mark R V Murray ,
284 function returns a pointer to static data, and subsequent calls to
286 will modify the same data. Likewise,
288 modifies static data.