]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/crypt.3
membarrier.2: Remove redundant mention of return value of MEMBARRIER_CMD_SHARED
[thirdparty/man-pages.git] / man3 / crypt.3
CommitLineData
3d54a910
MK
1.\" Michael Haardt (michael@cantor.informatik.rwth.aachen.de)
2.\" Sat Sep 3 22:00:30 MET DST 1994
fea681da 3.\"
1dd72f9c 4.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
5.\" This is free documentation; you can redistribute it and/or
6.\" modify it under the terms of the GNU General Public License as
7.\" published by the Free Software Foundation; either version 2 of
8.\" the License, or (at your option) any later version.
9.\"
10.\" The GNU General Public License's references to "object code"
11.\" and "executables" are to be interpreted as the output of any
12.\" document formatting or typesetting system, including
13.\" intermediate and printed output.
14.\"
15.\" This manual is distributed in the hope that it will be useful,
16.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18.\" GNU General Public License for more details.
19.\"
20.\" You should have received a copy of the GNU General Public
c715f741
MK
21.\" License along with this manual; if not, see
22.\" <http://www.gnu.org/licenses/>.
6a8d8745 23.\" %%%LICENSE_END
fea681da
MK
24.\"
25.\" Sun Feb 19 21:32:25 1995, faith@cs.unc.edu edited details away
26.\"
c13182ef 27.\" TO DO: This manual page should go more into detail how DES is perturbed,
fea681da
MK
28.\" which string will be encrypted, and what determines the repetition factor.
29.\" Is a simple repetition using ECB used, or something more advanced? I hope
30.\" the presented explanations are at least better than nothing, but by no
31.\" means enough.
32.\"
33.\" added _XOPEN_SOURCE, aeb, 970705
34.\" added GNU MD5 stuff, aeb, 011223
35.\"
460495ca 36.TH CRYPT 3 2015-08-08 "" "Linux Programmer's Manual"
fea681da 37.SH NAME
4e602cb2 38crypt, crypt_r \- password and data encryption
fea681da 39.SH SYNOPSIS
4e602cb2 40.nf
b80f966b 41.BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
fea681da
MK
42.br
43.B #include <unistd.h>
44.sp
45.BI "char *crypt(const char *" key ", const char *" salt );
e9329f6d 46.sp
3c5faf11
MK
47.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
48.br
49.B #include <crypt.h>
50.sp
8fe60aef 51.BI "char *crypt_r(const char *" key ", const char *" salt ,
4e602cb2
MK
52.BI " struct crypt_data *" data );
53.fi
54.sp
e9329f6d 55Link with \fI\-lcrypt\fP.
fea681da 56.SH DESCRIPTION
e511ffb6 57.BR crypt ()
c13182ef
MK
58is the password encryption function.
59It is based on the Data Encryption
fea681da
MK
60Standard algorithm with variations intended (among other things) to
61discourage use of hardware implementations of a key search.
62.PP
63.I key
64is a user's typed password.
65.PP
66.I salt
67is a two-character string chosen from the set
3cc95d3f 68[\fBa\-zA\-Z0\-9./\fP].
c13182ef 69This string is used to
fea681da
MK
70perturb the algorithm in one of 4096 different ways.
71.PP
72By taking the lowest 7 bits of each of the first eight characters of the
73.IR key ,
c13182ef
MK
74a 56-bit key is obtained.
75This 56-bit key is used to encrypt repeatedly a
76constant string (usually a string consisting of all zeros).
77The returned
fea681da 78value points to the encrypted password, a series of 13 printable ASCII
c13182ef
MK
79characters (the first two characters represent the salt itself).
80The return value points to static data whose content is
81overwritten by each call.
fea681da
MK
82.PP
83Warning: The key space consists of
84.if t 2\s-2\u56\s0\d
85.if n 2**56
c13182ef
MK
86equal 7.2e16 possible values.
87Exhaustive searches of this key space are
88possible using massively parallel computers.
89Software, such as
fea681da
MK
90.BR crack (1),
91is available which will search the portion of this key space that is
c13182ef
MK
92generally used by humans for passwords.
93Hence, password selection should,
94at minimum, avoid common words and names.
95The use of a
fea681da
MK
96.BR passwd (1)
97program that checks for crackable passwords during the selection process is
98recommended.
99.PP
100The DES algorithm itself has a few quirks which make the use of the
2777b1ca 101.BR crypt ()
fea681da 102interface a very poor choice for anything other than password
c13182ef
MK
103authentication.
104If you are planning on using the
2777b1ca 105.BR crypt ()
fea681da
MK
106interface for a cryptography project, don't do it: get a good book on
107encryption and one of the widely available DES libraries.
4e602cb2
MK
108
109.BR crypt_r ()
110is a reentrant version of
111.BR crypt ().
112The structure pointed to by
113.I data
114is used to store result data and bookkeeping information.
115Other than allocating it,
116the only thing that the caller should do with this structure is to set
117.I data->initialized
118to zero before the first call to
119.BR crypt_r ().
47297adb 120.SH RETURN VALUE
4e602cb2 121On success, a pointer to the encrypted password is returned.
fea681da
MK
122On error, NULL is returned.
123.SH ERRORS
124.TP
17b028d6
MK
125.B EINVAL
126.I salt
127has the wrong format.
128.TP
129.B
130.TP
fea681da 131.B ENOSYS
c13182ef 132The
e511ffb6 133.BR crypt ()
fea681da
MK
134function was not implemented, probably because of U.S.A. export restrictions.
135.\" This level of detail is not necessary in this man page. . .
136.\" .PP
137.\" When encrypting a plain text P using DES with the key K results in the
138.\" encrypted text C, then the complementary plain text P' being encrypted
139.\" using the complementary key K' will result in the complementary encrypted
140.\" text C'.
141.\" .PP
142.\" Weak keys are keys which stay invariant under the DES key transformation.
143.\" The four known weak keys 0101010101010101, fefefefefefefefe,
144.\" 1f1f1f1f0e0e0e0e and e0e0e0e0f1f1f1f1 must be avoided.
145.\" .PP
146.\" There are six known half weak key pairs, which keys lead to the same
147.\" encrypted data. Keys which are part of such key clusters should be
148.\" avoided.
149.\" Sorry, I could not find out what they are.
150.\""
151.\" .PP
152.\" Heavily redundant data causes trouble with DES encryption, when used in the
153.\" .I codebook
154.\" mode that
2777b1ca 155.\" .BR crypt ()
fea681da 156.\" implements. The
2777b1ca 157.\" .BR crypt ()
fea681da
MK
158.\" interface should be used only for its intended purpose of password
159.\" verification, and should not be used as part of a data encryption tool.
160.\" .PP
161.\" The first and last three output bits of the fourth S-box can be
162.\" represented as function of their input bits. Empiric studies have
163.\" shown that S-boxes partially compute the same output for similar input.
164.\" It is suspected that this may contain a back door which could allow the
165.\" NSA to decrypt DES encrypted data.
166.\" .PP
b9560046 167.\" Making encrypted data computed using crypt() publicly available has
fea681da 168.\" to be considered insecure for the given reasons.
17b028d6
MK
169.TP
170.B EPERM
fa16a05d
SP
171.I /proc/sys/crypto/fips_enabled
172has a nonzero value,
17b028d6 173and an attempt was made to use a weak encryption type, such as DES.
dee90154 174.SH ATTRIBUTES
aca8edbf
MK
175For an explanation of the terms used in this section, see
176.BR attributes (7).
177.TS
178allbox;
179lb lb lb
180l l l.
181Interface Attribute Value
182T{
dee90154 183.BR crypt ()
11f85593 184T} Thread safety MT-Unsafe race:crypt
aca8edbf 185T{
dee90154 186.BR crypt_r ()
aca8edbf
MK
187T} Thread safety MT-Safe
188.TE
47297adb 189.SH CONFORMING TO
4e602cb2 190.BR crypt ():
da93f334 191POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.
4209865f
PB
192.BR crypt_r ()
193is a GNU extension.
d597239c 194.SH NOTES
c634028a 195.SS Glibc notes
cefb5a17
MK
196The glibc2 version of this function supports additional
197encryption algorithms.
198
fea681da
MK
199If
200.I salt
cefb5a17
MK
201is a character string starting with the characters "$\fIid\fP$"
202followed by a string terminated by "$":
4391d173 203.RS
cefb5a17
MK
204
205$\fIid\fP$\fIsalt\fP$\fIencrypted\fP
206
4391d173 207.RE
cefb5a17
MK
208then instead of using the DES machine,
209.I id
210identifies the encryption method used and this then determines how the rest
211of the password string is interpreted.
212The following values of
213.I id
214are supported:
bb3797a4 215.RS
cefb5a17
MK
216.TS
217l l.
218ID | Method
219_
2201 | MD5
caa21260
MK
2212a | Blowfish (not in mainline glibc; added in some
222 | Linux distributions)
bb3797a4
MK
223.\" openSUSE has Blowfish, but AFAICS, this option is not supported
224.\" natively by glibc -- mtk, Jul 08
225.\"
cefb5a17 226.\" md5 | Sun MD5
bb3797a4
MK
227.\" glibc doesn't appear to natively support Sun MD5; I don't know
228.\" if any distros add the support.
cefb5a17
MK
2295 | SHA-256 (since glibc 2.7)
2306 | SHA-512 (since glibc 2.7)
231.TE
bb3797a4 232.RE
cefb5a17
MK
233
234So $5$\fIsalt\fP$\fIencrypted\fP is an SHA-256 encoded
235password and $6$\fIsalt\fP$\fIencrypted\fP is an
236SHA-512 encoded one.
237
bb3797a4
MK
238"\fIsalt\fP" stands for the up to 16 characters
239following "$\fIid\fP$" in the salt.
cefb5a17
MK
240The encrypted part of the password string is the actual computed password.
241The size of this string is fixed:
242.TS
243l l.
244MD5 | 22 characters
245SHA-256 | 43 characters
246SHA-512 | 86 characters
247.TE
248
249The characters in "\fIsalt\fP" and "\fIencrypted\fP" are drawn from the set
43d19bc7 250[\fBa\-zA\-Z0\-9./\fP].
2419294d 251In the MD5 and SHA implementations the entire
c13182ef 252.I key
cefb5a17 253is significant (instead of only the first
2419294d 2548 bytes in DES).
47297adb 255.SH SEE ALSO
fea681da
MK
256.BR login (1),
257.BR passwd (1),
258.BR encrypt (3),
259.BR getpass (3),
0a4f8b7b 260.BR passwd (5)