1e9a56ad5SMark Murray.\" FreeSec: libcrypt for NetBSD 2e9a56ad5SMark Murray.\" 3e9a56ad5SMark Murray.\" Copyright (c) 1994 David Burren 4e9a56ad5SMark Murray.\" All rights reserved. 5e9a56ad5SMark Murray.\" 6e9a56ad5SMark Murray.\" Redistribution and use in source and binary forms, with or without 7e9a56ad5SMark Murray.\" modification, are permitted provided that the following conditions 8e9a56ad5SMark Murray.\" are met: 9e9a56ad5SMark Murray.\" 1. Redistributions of source code must retain the above copyright 10e9a56ad5SMark Murray.\" notice, this list of conditions and the following disclaimer. 11e9a56ad5SMark Murray.\" 2. Redistributions in binary form must reproduce the above copyright 12e9a56ad5SMark Murray.\" notice, this list of conditions and the following disclaimer in the 13e9a56ad5SMark Murray.\" documentation and/or other materials provided with the distribution. 14e9a56ad5SMark Murray.\" 4. Neither the name of the author nor the names of other contributors 15e9a56ad5SMark Murray.\" may be used to endorse or promote products derived from this software 16e9a56ad5SMark Murray.\" without specific prior written permission. 17e9a56ad5SMark Murray.\" 18e9a56ad5SMark Murray.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 19e9a56ad5SMark Murray.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20e9a56ad5SMark Murray.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21e9a56ad5SMark Murray.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 22e9a56ad5SMark Murray.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23e9a56ad5SMark Murray.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24e9a56ad5SMark Murray.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25e9a56ad5SMark Murray.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26e9a56ad5SMark Murray.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27e9a56ad5SMark Murray.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28e9a56ad5SMark Murray.\" SUCH DAMAGE. 29e9a56ad5SMark Murray.\" 30e9a56ad5SMark Murray.\" $FreeBSD$ 31e9a56ad5SMark Murray.\" 32e9a56ad5SMark Murray.\" Manual page, using -mandoc macros 33e9a56ad5SMark Murray.\" 34e9a56ad5SMark Murray.Dd January 19, 1997 35e9a56ad5SMark Murray.Dt CRYPT 3 36e9a56ad5SMark Murray.Os "FreeSec 1.0" 37e9a56ad5SMark Murray.Sh NAME 38e9a56ad5SMark Murray.Nm crypt 39e9a56ad5SMark Murray.Nd Trapdoor encryption 40e9a56ad5SMark Murray.Sh SYNOPSIS 41d3f0d184SBruce Evans.Ft char * 42d3f0d184SBruce Evans.Fn crypt "const char *key" "const char *salt" 43e9a56ad5SMark Murray.Sh DESCRIPTION 44e9a56ad5SMark MurrayThe 45e9a56ad5SMark Murray.Fn crypt 46e9a56ad5SMark Murrayfunction performs password hashing with additional code added to 47e9a56ad5SMark Murraydeter key search attempts. Different algorithms can be used to 48e9a56ad5SMark Murrayin the hash. 49e9a56ad5SMark Murray.\" 50e9a56ad5SMark Murray.\" NOTICE: 51e9a56ad5SMark Murray.\" If you add more algorithms, make sure to update this list 52e9a56ad5SMark Murray.\" and the default used for the Traditional format, below. 53e9a56ad5SMark Murray.\" 54e9a56ad5SMark MurrayCurrently these include the 55e9a56ad5SMark Murray.Tn NBS 56e9a56ad5SMark MurrayData Encryption Standard (DES), MD5 or SHS. The algorithm 57e9a56ad5SMark Murrayused will depend upon the format of the Salt--following the Modular 58e9a56ad5SMark MurrayCrypt Format (MCF)--and if DES is installed or not. 59e9a56ad5SMark Murray.Pp 60e9a56ad5SMark MurrayThe first argument to 61e9a56ad5SMark Murray.Nm crypt 62e9a56ad5SMark Murrayis the data to hash (usually a password), in a 63e9a56ad5SMark Murray.Dv null Ns -terminated 64e9a56ad5SMark Murraystring. 65e9a56ad5SMark MurrayThe second is the salt, in one of three forms: 66e9a56ad5SMark Murray.Pp 67e9a56ad5SMark Murray.Bl -tag -width Traditional -compact -offset indent 68e9a56ad5SMark Murray.It Extended 69e9a56ad5SMark MurrayIf it begins with an underscore (``_'') then the DES Extended Format 70e9a56ad5SMark Murrayis used in interpreting both the the key and the salt, as outlined below. 71e9a56ad5SMark Murray.It Modular 72e9a56ad5SMark MurrayIf it begins with the string ``$digit$'' then the Modular Crypt Format 73e9a56ad5SMark Murrayis used, as outlined below. 74e9a56ad5SMark Murray.It Traditional 75e9a56ad5SMark MurrayIf neither of the above is true, it assumes the Traditional Format, 76e9a56ad5SMark Murrayusing the entire string as the salt (or the first portion). 77e9a56ad5SMark Murray.El 78e9a56ad5SMark Murray.Pp 79e9a56ad5SMark MurrayAll routines are designed to be time-consuming. A brief test on a 80e9a56ad5SMark MurrayPentium 166/MMX shows the DES crypt to do approximately 2640 crypts 81e9a56ad5SMark Murraya CPU second, MD5 to do about 62 crypts a CPU second and SHA1 82e9a56ad5SMark Murrayto do about 18 crypts a CPU second. 83e9a56ad5SMark Murray.Ss DES Extended Format: 84e9a56ad5SMark Murray.Pp 85e9a56ad5SMark MurrayThe 86e9a56ad5SMark Murray.Ar key 87e9a56ad5SMark Murrayis divided into groups of 8 characters (the last group is null-padded) 88e9a56ad5SMark Murrayand the low-order 7 bits of each each character (56 bits per group) are 89e9a56ad5SMark Murrayused to form the DES key as follows: 90e9a56ad5SMark Murraythe first group of 56 bits becomes the initial DES key. 91e9a56ad5SMark MurrayFor each additional group, the XOR of the encryption of the current DES 92e9a56ad5SMark Murraykey with itself and the group bits becomes the next DES key. 93e9a56ad5SMark Murray.Pp 94e9a56ad5SMark MurrayThe salt is a 9-character array consisting of an underscore followed 95e9a56ad5SMark Murrayby 4 bytes of iteration count and 4 bytes of salt. 96e9a56ad5SMark MurrayThese are encoded as printable characters, 6 bits per character, 97e9a56ad5SMark Murrayleast significant character first. 98e9a56ad5SMark MurrayThe values 0 to 63 are encoded as ``./0-9A-Za-z''. 99e9a56ad5SMark MurrayThis allows 24 bits for both 100e9a56ad5SMark Murray.Fa count 101e9a56ad5SMark Murrayand 102e9a56ad5SMark Murray.Fa salt . 103e9a56ad5SMark Murray.Pp 104e9a56ad5SMark MurrayThe 105e9a56ad5SMark Murray.Fa salt 106e9a56ad5SMark Murrayintroduces disorder in the 107e9a56ad5SMark Murray.Tn DES 108e9a56ad5SMark Murrayalgorithm in one of 16777216 or 4096 possible ways 109e9a56ad5SMark Murray(ie. with 24 or 12 bits: if bit 110e9a56ad5SMark Murray.Em i 111e9a56ad5SMark Murrayof the 112e9a56ad5SMark Murray.Ar salt 113e9a56ad5SMark Murrayis set, then bits 114e9a56ad5SMark Murray.Em i 115e9a56ad5SMark Murrayand 116e9a56ad5SMark Murray.Em i+24 117e9a56ad5SMark Murrayare swapped in the 118e9a56ad5SMark Murray.Tn DES 119e9a56ad5SMark MurrayE-box output). 120e9a56ad5SMark Murray.Pp 121e9a56ad5SMark MurrayThe DES key is used to encrypt a 64-bit constant using 122e9a56ad5SMark Murray.Ar count 123e9a56ad5SMark Murrayiterations of 124e9a56ad5SMark Murray.Tn DES . 125e9a56ad5SMark MurrayThe value returned is a 126e9a56ad5SMark Murray.Dv null Ns -terminated 127e9a56ad5SMark Murraystring, 20 or 13 bytes (plus null) in length, consisting of the 128e9a56ad5SMark Murray.Ar salt 129e9a56ad5SMark Murrayfollowed by the encoded 64-bit encryption. 130e9a56ad5SMark Murray.Ss "Modular" crypt: 131e9a56ad5SMark Murray.Pp 132e9a56ad5SMark MurrayIf the salt begins with the string 133e9a56ad5SMark Murray.Fa $digit$ 134e9a56ad5SMark Murraythen the Modular Crypt Format is used. The 135e9a56ad5SMark Murray.Fa digit 136e9a56ad5SMark Murrayrepresents which algorithm is used in encryption. Following the token is 137e9a56ad5SMark Murraythe actual salt to use in the encryption. The length of the salt is limited 138e9a56ad5SMark Murrayto 16 characters--because the length of the returned output is also limited 139e9a56ad5SMark Murray(_PASSWORD_LEN). The salt must be terminated with the end of the string 140e9a56ad5SMark Murray(NULL) or a dollar sign. Any characters after the dollar sign are ignored. 141e9a56ad5SMark Murray.Pp 142e9a56ad5SMark MurrayCurrently supported algorithms are: 143e9a56ad5SMark Murray.Pp 144e9a56ad5SMark Murray.Bl -tag -width 012345678 -compact -offset indent 145e9a56ad5SMark Murray.It 1 146e9a56ad5SMark MurrayMD5 147e9a56ad5SMark Murray.It 3 148e9a56ad5SMark MurraySHA1 149e9a56ad5SMark Murray.El 150e9a56ad5SMark Murray.Pp 151e9a56ad5SMark MurrayOther crypt formats may be easilly added. An example salt would be: 152e9a56ad5SMark Murray.Bl -tag -offset indent 153e9a56ad5SMark Murray.It Cm "$3$thesalt$rest" 154e9a56ad5SMark Murray.El 155e9a56ad5SMark Murray.Pp 156e9a56ad5SMark Murray.Ss "Traditional" crypt: 157e9a56ad5SMark Murray.Pp 158e9a56ad5SMark MurrayThe algorithm used will depend upon whether DES is installed or not. If it is, 159e9a56ad5SMark MurrayDES will be used. Otherwise, the best algorithm is used, which is currently 160e9a56ad5SMark Murray.\" 161e9a56ad5SMark Murray.\" NOTICE: Also make sure to update this 162e9a56ad5SMark Murray.\" 163e9a56ad5SMark MurraySHA-1. 164e9a56ad5SMark Murray.Pp 165e9a56ad5SMark MurrayHow the salt is used will depend upon the algorithm for the hash. For 166e9a56ad5SMark Murraybest results, specify at least two characters of salt. 167e9a56ad5SMark Murray.Sh RETURN VALUES 168e9a56ad5SMark Murray.Pp 169e9a56ad5SMark Murray.Fn crypt 170e9a56ad5SMark Murrayreturns a pointer to the encrypted value on success, and NULL on failure. 171e9a56ad5SMark MurrayNote: this is not a standard behaviour, AT&T 172e9a56ad5SMark Murray.Fn crypt 173e9a56ad5SMark Murraywill always return a pointer to a string. 174e9a56ad5SMark Murray.Sh SEE ALSO 175e9a56ad5SMark Murray.Xr login 1 , 176e9a56ad5SMark Murray.Xr passwd 1 , 177e9a56ad5SMark Murray.Xr getpass 3 , 178e9a56ad5SMark Murray.Xr passwd 5 , 179e9a56ad5SMark Murray.Xr shs 3 , 180e9a56ad5SMark Murray.Sh BUGS 181e9a56ad5SMark MurrayThe 182e9a56ad5SMark Murray.Fn crypt 183e9a56ad5SMark Murrayfunction returns a pointer to static data, and subsequent calls to 184e9a56ad5SMark Murray.Fn crypt 185e9a56ad5SMark Murraywill modify the same data. 186e9a56ad5SMark Murray.Sh HISTORY 187e9a56ad5SMark MurrayA rotor-based 188e9a56ad5SMark Murray.Fn crypt 189e9a56ad5SMark Murrayfunction appeared in 190e9a56ad5SMark Murray.At v6 . 191e9a56ad5SMark MurrayThe current style 192e9a56ad5SMark Murray.Fn crypt 193e9a56ad5SMark Murrayfirst appeared in 194e9a56ad5SMark Murray.At v7 . 195e9a56ad5SMark Murray.Pp 196e9a56ad5SMark MurrayThe DES section of the code (FreeSec 1.0) was developed outside the United 197e9a56ad5SMark MurrayStates of America as an unencumbered replacement for the U.S.-only NetBSD 198e9a56ad5SMark Murraylibcrypt encryption library. 199e9a56ad5SMark MurrayUsers should be aware that this code (and programs staticly linked with it) 200e9a56ad5SMark Murraymay not be exported from the U.S., although it apparently can be imported. 201e9a56ad5SMark Murray.Sh AUTHORS 202e9a56ad5SMark MurrayOriginally written by David Burren <davidb@werj.com.au>, later additions 203e9a56ad5SMark Murrayand changes by Brandon Gillespie, Poul-henning Kamp and Mark R V Murray. 204