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