1999-09-20 12:45:49 +00:00
|
|
|
.\" FreeSec: libcrypt for NetBSD
|
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 1994 David Burren
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
2017-02-28 23:42:47 +00:00
|
|
|
.\" 3. Neither the name of the author nor the names of other contributors
|
1999-09-20 12:45:49 +00:00
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
2005-02-09 18:07:17 +00:00
|
|
|
.\" $FreeBSD$
|
1999-09-20 12:45:49 +00:00
|
|
|
.\"
|
2019-05-27 06:37:23 +00:00
|
|
|
.Dd May 26, 2019
|
1999-09-20 12:45:49 +00:00
|
|
|
.Dt CRYPT 3
|
2001-07-10 13:41:46 +00:00
|
|
|
.Os
|
1999-09-20 12:45:49 +00:00
|
|
|
.Sh NAME
|
|
|
|
.Nm crypt
|
|
|
|
.Nd Trapdoor encryption
|
2000-04-22 15:56:59 +00:00
|
|
|
.Sh LIBRARY
|
|
|
|
.Lb libcrypt
|
1999-09-20 12:45:49 +00:00
|
|
|
.Sh SYNOPSIS
|
2001-10-01 16:09:29 +00:00
|
|
|
.In unistd.h
|
1999-12-23 16:53:18 +00:00
|
|
|
.Ft char *
|
|
|
|
.Fn crypt "const char *key" "const char *salt"
|
2016-08-10 15:16:28 +00:00
|
|
|
.Ft char *
|
|
|
|
.Fn crypt_r "const char *key" "const char *salt" "struct crypt_data *data"
|
2000-08-22 02:15:54 +00:00
|
|
|
.Ft const char *
|
|
|
|
.Fn crypt_get_format "void"
|
|
|
|
.Ft int
|
|
|
|
.Fn crypt_set_format "const char *string"
|
1999-09-20 12:45:49 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Fn crypt
|
|
|
|
function performs password hashing with additional code added to
|
2004-07-02 23:52:20 +00:00
|
|
|
deter key search attempts.
|
|
|
|
Different algorithms can be used to
|
1999-09-20 12:45:49 +00:00
|
|
|
in the hash.
|
|
|
|
.\"
|
|
|
|
.\" NOTICE:
|
|
|
|
.\" If you add more algorithms, make sure to update this list
|
|
|
|
.\" and the default used for the Traditional format, below.
|
|
|
|
.\"
|
|
|
|
Currently these include the
|
|
|
|
.Tn NBS
|
2000-04-22 15:56:59 +00:00
|
|
|
.Tn Data Encryption Standard (DES) ,
|
2001-03-11 16:05:43 +00:00
|
|
|
.Tn MD5
|
2003-06-02 19:29:27 +00:00
|
|
|
hash,
|
|
|
|
.Tn NT-Hash
|
2014-03-09 07:45:59 +00:00
|
|
|
.Pq compatible with Microsoft's NT scheme
|
2000-04-22 20:43:21 +00:00
|
|
|
and
|
2001-03-11 16:05:43 +00:00
|
|
|
.Tn Blowfish .
|
2014-03-09 07:45:59 +00:00
|
|
|
The algorithm used will depend upon the format of the Salt
|
|
|
|
.Po
|
|
|
|
following
|
|
|
|
the Modular Crypt Format
|
|
|
|
.Pq MCF
|
|
|
|
.Pc ,
|
|
|
|
if
|
2000-04-22 15:56:59 +00:00
|
|
|
.Tn DES
|
2001-03-11 16:05:43 +00:00
|
|
|
and/or
|
|
|
|
.Tn Blowfish
|
2000-08-22 02:15:54 +00:00
|
|
|
is installed or not, and whether
|
|
|
|
.Fn crypt_set_format
|
|
|
|
has been called to change the default.
|
1999-09-20 12:45:49 +00:00
|
|
|
.Pp
|
|
|
|
The first argument to
|
2000-04-22 15:56:59 +00:00
|
|
|
.Nm
|
2014-03-09 07:45:59 +00:00
|
|
|
is the data to hash
|
|
|
|
.Pq usually a password ,
|
|
|
|
in a
|
|
|
|
.Dv NUL Ns -terminated
|
1999-09-20 12:45:49 +00:00
|
|
|
string.
|
|
|
|
The second is the salt, in one of three forms:
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -width Traditional -compact -offset indent
|
|
|
|
.It Extended
|
2000-04-22 15:56:59 +00:00
|
|
|
If it begins with an underscore
|
|
|
|
.Pq Dq _
|
|
|
|
then the
|
|
|
|
.Tn DES
|
|
|
|
Extended Format
|
2001-06-24 01:34:38 +00:00
|
|
|
is used in interpreting both the key and the salt, as outlined below.
|
1999-09-20 12:45:49 +00:00
|
|
|
.It Modular
|
2000-04-22 15:56:59 +00:00
|
|
|
If it begins with the string
|
|
|
|
.Dq $digit$
|
|
|
|
then the Modular Crypt Format is used, as outlined below.
|
1999-09-20 12:45:49 +00:00
|
|
|
.It Traditional
|
|
|
|
If neither of the above is true, it assumes the Traditional Format,
|
2014-03-09 07:45:59 +00:00
|
|
|
using the entire string as the salt
|
|
|
|
.Pq or the first portion .
|
1999-09-20 12:45:49 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
2004-07-02 23:52:20 +00:00
|
|
|
All routines are designed to be time-consuming.
|
1999-09-20 12:45:49 +00:00
|
|
|
.Ss DES Extended Format:
|
|
|
|
The
|
|
|
|
.Ar key
|
2014-03-09 07:45:59 +00:00
|
|
|
is divided into groups of 8 characters
|
|
|
|
.Pq the last group is NUL-padded
|
|
|
|
and the low-order 7 bits of each character
|
|
|
|
.Pq 56 bits per group
|
|
|
|
are used to form the
|
2000-04-22 15:56:59 +00:00
|
|
|
.Tn DES
|
|
|
|
key as follows:
|
|
|
|
the first group of 56 bits becomes the initial
|
|
|
|
.Tn DES
|
|
|
|
key.
|
|
|
|
For each additional group, the XOR of the encryption of the current
|
|
|
|
.Tn DES
|
|
|
|
key with itself and the group bits becomes the next
|
|
|
|
.Tn DES
|
|
|
|
key.
|
1999-09-20 12:45:49 +00:00
|
|
|
.Pp
|
|
|
|
The salt is a 9-character array consisting of an underscore followed
|
|
|
|
by 4 bytes of iteration count and 4 bytes of salt.
|
|
|
|
These are encoded as printable characters, 6 bits per character,
|
|
|
|
least significant character first.
|
2014-03-09 07:45:59 +00:00
|
|
|
The values 0 to 63 are encoded as
|
|
|
|
.Dq ./0-9A-Za-z .
|
1999-09-20 12:45:49 +00:00
|
|
|
This allows 24 bits for both
|
|
|
|
.Fa count
|
|
|
|
and
|
|
|
|
.Fa salt .
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fa salt
|
|
|
|
introduces disorder in the
|
|
|
|
.Tn DES
|
|
|
|
algorithm in one of 16777216 or 4096 possible ways
|
2014-03-09 07:45:59 +00:00
|
|
|
.Po
|
|
|
|
i.e., with 24 or 12 bits: if bit
|
1999-09-20 12:45:49 +00:00
|
|
|
.Em i
|
|
|
|
of the
|
|
|
|
.Ar salt
|
|
|
|
is set, then bits
|
|
|
|
.Em i
|
|
|
|
and
|
|
|
|
.Em i+24
|
|
|
|
are swapped in the
|
|
|
|
.Tn DES
|
2014-03-09 07:45:59 +00:00
|
|
|
E-box output
|
|
|
|
.Pc .
|
1999-09-20 12:45:49 +00:00
|
|
|
.Pp
|
2000-04-22 15:56:59 +00:00
|
|
|
The
|
|
|
|
.Tn DES
|
|
|
|
key is used to encrypt a 64-bit constant using
|
1999-09-20 12:45:49 +00:00
|
|
|
.Ar count
|
|
|
|
iterations of
|
|
|
|
.Tn DES .
|
|
|
|
The value returned is a
|
2014-03-09 07:45:59 +00:00
|
|
|
.Dv NUL Ns -terminated
|
|
|
|
string, 20 or 13 bytes
|
|
|
|
.Pq plus NUL
|
|
|
|
in length, consisting of the
|
1999-09-20 12:45:49 +00:00
|
|
|
.Ar salt
|
|
|
|
followed by the encoded 64-bit encryption.
|
2014-03-09 07:45:59 +00:00
|
|
|
.Ss Modular crypt:
|
2001-07-15 07:53:42 +00:00
|
|
|
If the salt begins with the string
|
1999-09-20 12:45:49 +00:00
|
|
|
.Fa $digit$
|
2004-07-02 23:52:20 +00:00
|
|
|
then the Modular Crypt Format is used.
|
|
|
|
The
|
1999-09-20 12:45:49 +00:00
|
|
|
.Fa digit
|
2004-07-02 23:52:20 +00:00
|
|
|
represents which algorithm is used in encryption.
|
|
|
|
Following the token is
|
|
|
|
the actual salt to use in the encryption.
|
2014-03-09 07:45:59 +00:00
|
|
|
The maximum length of the salt used depends upon the module.
|
|
|
|
The salt must be terminated with the end of the string character
|
|
|
|
.Pq NUL
|
|
|
|
or a dollar sign.
|
2004-07-02 23:52:20 +00:00
|
|
|
Any characters after the dollar sign are ignored.
|
1999-09-20 12:45:49 +00:00
|
|
|
.Pp
|
|
|
|
Currently supported algorithms are:
|
|
|
|
.Pp
|
2000-12-29 14:08:20 +00:00
|
|
|
.Bl -enum -compact -offset indent
|
2001-03-16 12:06:26 +00:00
|
|
|
.It
|
1999-09-20 12:45:49 +00:00
|
|
|
MD5
|
2001-03-16 12:06:26 +00:00
|
|
|
.It
|
2001-03-11 16:05:43 +00:00
|
|
|
Blowfish
|
2003-06-02 19:29:27 +00:00
|
|
|
.It
|
|
|
|
NT-Hash
|
2011-04-09 14:09:46 +00:00
|
|
|
.It
|
2012-04-11 14:12:28 +00:00
|
|
|
(unused)
|
|
|
|
.It
|
2011-04-09 14:09:46 +00:00
|
|
|
SHA-256
|
|
|
|
.It
|
|
|
|
SHA-512
|
1999-09-20 12:45:49 +00:00
|
|
|
.El
|
|
|
|
.Pp
|
2004-07-02 23:52:20 +00:00
|
|
|
Other crypt formats may be easily added.
|
|
|
|
An example salt would be:
|
2012-06-02 08:47:26 +00:00
|
|
|
.Bl -tag -width 6n -offset indent
|
2003-06-02 19:29:27 +00:00
|
|
|
.It Cm "$4$thesalt$rest"
|
1999-09-20 12:45:49 +00:00
|
|
|
.El
|
2014-03-09 07:45:59 +00:00
|
|
|
.Ss Traditional crypt:
|
2000-04-22 15:56:59 +00:00
|
|
|
The algorithm used will depend upon whether
|
2000-08-22 02:15:54 +00:00
|
|
|
.Fn crypt_set_format
|
2000-12-28 10:32:02 +00:00
|
|
|
has been called and whether a global default format has been specified.
|
|
|
|
Unless a global default has been specified or
|
2000-08-22 02:15:54 +00:00
|
|
|
.Fn crypt_set_format
|
2000-12-28 11:56:45 +00:00
|
|
|
has set the format to something else, the built-in default format is
|
|
|
|
used.
|
|
|
|
This is currently
|
1999-09-20 12:45:49 +00:00
|
|
|
.\"
|
|
|
|
.\" NOTICE: Also make sure to update this
|
|
|
|
.\"
|
2000-12-28 11:56:45 +00:00
|
|
|
DES
|
2019-05-27 06:37:23 +00:00
|
|
|
if it is available, or SHA-512 if not.
|
1999-09-20 12:45:49 +00:00
|
|
|
.Pp
|
2004-07-02 23:52:20 +00:00
|
|
|
How the salt is used will depend upon the algorithm for the hash.
|
|
|
|
For
|
2014-03-09 07:45:59 +00:00
|
|
|
best results, specify at least eight characters of salt.
|
2000-08-22 02:15:54 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn crypt_get_format
|
|
|
|
function returns a constant string that represents the name of the
|
|
|
|
algorithm currently used.
|
|
|
|
Valid values are
|
|
|
|
.\"
|
|
|
|
.\" NOTICE: Also make sure to update this, too, as well
|
|
|
|
.\"
|
2001-03-11 16:05:43 +00:00
|
|
|
.Ql des ,
|
2003-06-02 19:29:27 +00:00
|
|
|
.Ql blf ,
|
2011-04-09 14:09:46 +00:00
|
|
|
.Ql md5 ,
|
|
|
|
.Ql sha256 ,
|
|
|
|
.Ql sha512
|
2000-08-22 02:15:54 +00:00
|
|
|
and
|
2003-06-02 19:29:27 +00:00
|
|
|
.Ql nth .
|
2000-08-22 02:15:54 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn crypt_set_format
|
|
|
|
function sets the default encoding format according to the supplied
|
|
|
|
.Fa string .
|
2016-08-10 15:16:28 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn crypt_r
|
|
|
|
function behaves identically to
|
|
|
|
.Fn crypt ,
|
|
|
|
except that the resulting string is stored in
|
|
|
|
.Fa data ,
|
|
|
|
making it thread-safe.
|
1999-09-20 12:45:49 +00:00
|
|
|
.Sh RETURN VALUES
|
2003-06-08 10:20:32 +00:00
|
|
|
The
|
1999-09-20 12:45:49 +00:00
|
|
|
.Fn crypt
|
2016-08-10 15:16:28 +00:00
|
|
|
and
|
|
|
|
.Fn crypt_r
|
|
|
|
functions return a pointer to the encrypted value on success, and NULL on
|
2003-06-08 10:20:32 +00:00
|
|
|
failure.
|
1999-09-20 12:45:49 +00:00
|
|
|
Note: this is not a standard behaviour, AT&T
|
|
|
|
.Fn crypt
|
|
|
|
will always return a pointer to a string.
|
2000-08-22 02:15:54 +00:00
|
|
|
.Pp
|
2003-06-08 10:20:32 +00:00
|
|
|
The
|
2000-08-22 02:15:54 +00:00
|
|
|
.Fn crypt_set_format
|
2003-06-08 10:20:32 +00:00
|
|
|
function will return 1 if the supplied encoding format was valid.
|
2000-08-22 02:15:54 +00:00
|
|
|
Otherwise, a value of 0 is returned.
|
1999-09-20 12:45:49 +00:00
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr login 1 ,
|
|
|
|
.Xr passwd 1 ,
|
|
|
|
.Xr getpass 3 ,
|
2001-07-10 18:00:19 +00:00
|
|
|
.Xr passwd 5
|
1999-09-20 12:45:49 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
A rotor-based
|
|
|
|
.Fn crypt
|
|
|
|
function appeared in
|
|
|
|
.At v6 .
|
|
|
|
The current style
|
|
|
|
.Fn crypt
|
|
|
|
first appeared in
|
|
|
|
.At v7 .
|
|
|
|
.Pp
|
2000-04-22 15:56:59 +00:00
|
|
|
The
|
|
|
|
.Tn DES
|
|
|
|
section of the code (FreeSec 1.0) was developed outside the United
|
|
|
|
States of America as an unencumbered replacement for the U.S.-only
|
|
|
|
.Nx
|
1999-09-20 12:45:49 +00:00
|
|
|
libcrypt encryption library.
|
2016-08-10 15:16:28 +00:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Fn crypt_r
|
|
|
|
function was added in
|
|
|
|
.Fx 12.0 .
|
1999-09-20 12:45:49 +00:00
|
|
|
.Sh AUTHORS
|
2000-11-22 09:23:54 +00:00
|
|
|
.An -nosplit
|
2000-04-22 15:56:59 +00:00
|
|
|
Originally written by
|
2014-06-23 08:23:05 +00:00
|
|
|
.An David Burren Aq Mt davidb@werj.com.au ,
|
2000-04-22 15:56:59 +00:00
|
|
|
later additions and changes by
|
2000-11-22 09:23:54 +00:00
|
|
|
.An Poul-Henning Kamp ,
|
2000-08-22 02:15:54 +00:00
|
|
|
.An Mark R V Murray ,
|
2003-06-02 19:29:27 +00:00
|
|
|
.An Michael Bretterklieber ,
|
2001-03-11 16:05:43 +00:00
|
|
|
.An Kris Kennaway ,
|
|
|
|
.An Brian Feldman ,
|
|
|
|
.An Paul Herman
|
2000-08-22 02:15:54 +00:00
|
|
|
and
|
2001-03-11 16:05:43 +00:00
|
|
|
.An Niels Provos .
|
2005-01-20 09:17:07 +00:00
|
|
|
.Sh BUGS
|
|
|
|
The
|
|
|
|
.Fn crypt
|
|
|
|
function returns a pointer to static data, and subsequent calls to
|
|
|
|
.Fn crypt
|
|
|
|
will modify the same data.
|
|
|
|
Likewise,
|
|
|
|
.Fn crypt_set_format
|
|
|
|
modifies static data.
|
|
|
|
.Pp
|
|
|
|
The NT-hash scheme does not use a salt,
|
|
|
|
and is not hard
|
|
|
|
for a competent attacker
|
|
|
|
to break.
|
|
|
|
Its use is not recommended.
|