]> git.saurik.com Git - apple/libc.git/blame - gen/crypt.3
Libc-498.1.5.tar.gz
[apple/libc.git] / gen / crypt.3
CommitLineData
59e0d9fe
A
1.\" $OpenBSD: crypt.3,v 1.5 1996/12/10 09:06:09 deraadt 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 "FreeSec 1.0"
37.Sh NAME
38.Nm crypt ,
59e0d9fe 39.Nm encrypt ,
224c7076 40.Nm setkey
59e0d9fe
A
41.Nd DES encryption
42.Sh SYNOPSIS
43.Fd #include <unistd.h>
224c7076
A
44.Ft char *
45.Fo crypt
46.Fa "const char *key"
47.Fa "const char *salt"
48.Fc
59e0d9fe 49.Ft void
224c7076
A
50.Fo encrypt
51.Fa "char *block"
52.Fa "int edflag"
53.Fc
54.Fd #include <stdlib.h>
59e0d9fe 55.Ft void
224c7076
A
56.Fo setkey
57.Fa "const char *key"
58.Fc
59e0d9fe
A
59.Sh DESCRIPTION
60The
61.Fn crypt
62function performs password encryption, based on the
63.Tn NBS
64Data Encryption Standard (DES).
65Additional code has been added to deter key search attempts.
66The first argument to
67.Fn crypt
68is a
69.Dv null Ns -terminated
70string, typically a user's typed password.
71The second is in one of two forms:
224c7076
A
72if it begins with an underscore (``_''), an extended format is used
73in interpreting both the key and the salt value, as outlined below.
59e0d9fe
A
74.Ss Extended crypt:
75.Pp
76The
77.Ar key
78is divided into groups of 8 characters (the last group is null-padded)
79and the low-order 7 bits of each each character (56 bits per group) are
80used to form the DES key as follows:
81the first group of 56 bits becomes the initial DES key.
82For each additional group, the XOR of the encryption of the current DES
83key with itself and the group bits becomes the next DES key.
84.Pp
224c7076
A
85The
86.Ar salt
87is a 9-character array consisting of an underscore, followed
59e0d9fe
A
88by 4 bytes of iteration count and 4 bytes of salt.
89These are encoded as printable characters, 6 bits per character,
90least significant character first.
91The values 0 to 63 are encoded as ``./0-9A-Za-z''.
92This allows 24 bits for both
93.Fa count
94and
95.Fa salt .
96.Ss "Traditional" crypt:
97.Pp
98The first 8 bytes of the key are null-padded, and the low-order 7 bits of
99each character is used to form the 56-bit
100.Tn DES
101key.
102.Pp
224c7076 103The
59e0d9fe 104.Fa salt
224c7076
A
105is a 2-character array of the ASCII-encoded salt.
106Thus, only 12 bits of salt are used.
59e0d9fe
A
107.Fa count
108is set to 25.
109.Ss Algorithm:
110.Pp
111The
112.Fa salt
113introduces disorder in the
114.Tn DES
115algorithm in one of 16777216 or 4096 possible ways
116(ie. with 24 or 12 bits: if bit
117.Em i
118of the
119.Ar salt
120is set, then bits
121.Em i
122and
123.Em i+24
124are swapped in the
125.Tn DES
126E-box output).
127.Pp
224c7076 128The DES key is used to encrypt a 64-bit constant, using
59e0d9fe
A
129.Ar count
130iterations of
131.Tn DES .
132The value returned is a
133.Dv null Ns -terminated
134string, 20 or 13 bytes (plus null) in length, consisting of the
224c7076 135.Ar salt ,
59e0d9fe
A
136followed by the encoded 64-bit encryption.
137.Pp
138The functions,
224c7076 139.Fn encrypt
59e0d9fe 140and
224c7076 141.Fn setkey
59e0d9fe
A
142provide access to the
143.Tn DES
144algorithm itself.
145.Fn setkey
146is passed a 64-byte array of binary values (numeric 0 or 1).
147A 56-bit key is extracted from this array by dividing the
224c7076 148array into groups of 8 and ignoring the last bit in each group.
59e0d9fe
A
149That bit is reserved for a byte parity check by DES, but is ignored
150by these functions.
151.Pp
152The
153.Fa block
154argument to
155.Fn encrypt
156is also a 64-byte array of binary values.
157If the value of
224c7076 158.Fa edflag
59e0d9fe
A
159is 0,
160.Fa block
224c7076 161is encrypted; otherwise, it is decrypted.
59e0d9fe 162The result is returned in the original array
224c7076 163.Fa block ,
59e0d9fe
A
164after using the key specified by
165.Fn setkey
166to process it.
167.Pp
59e0d9fe
A
168The function
169.Fn crypt
170returns a pointer to the encrypted value on success, and NULL on failure.
59e0d9fe
A
171.Pp
172The
224c7076 173.Fn crypt
59e0d9fe 174and
224c7076 175.Fn setkey
59e0d9fe
A
176functions all manipulate the same key space.
177.Sh SEE ALSO
178.Xr login 1 ,
179.Xr passwd 1 ,
180.Xr getpass 3 ,
224c7076 181.Xr compat 5 ,
59e0d9fe 182.Xr passwd 5
224c7076
A
183.Sh LEGACY SYNOPSIS
184.Fd #include <unistd.h>
185.Pp
186.Ft int
187.br
188.Fo encrypt
189.Fa "char *block"
190.Fa "int edflag"
191.Fc ;
192.Pp
193The function
194.Fn encrypt
195returns 0 on success and 1 on failure.
196.Pp
197.Ft void
198.br
199.Fo setkey
200.Fa "const char *key"
201.Fc ;
202.Pp
203The include file
204.In unistd.h
205is necessary and sufficient for the
206.Fn setkey
207function.
59e0d9fe
A
208.Sh BUGS
209The
210.Fn crypt
211function returns a pointer to static data, and subsequent calls to
212.Fn crypt
213will modify the same object.
214.Sh HISTORY
215A rotor-based
216.Fn crypt
217function appeared in
218.At v6 .
219The current style
220.Fn crypt
221first appeared in
222.At v7 .
223.Pp
224This library (FreeSec 1.0) was developed outside the United States of America
225as an unencumbered replacement for the U.S.-only libcrypt encryption
226library.
227Programs linked against the
228.Fn crypt
229interface may be exported from the U.S.A. only if they use
230.Fn crypt
231solely for authentication purposes and avoid use of
232the other programmer interfaces listed above. Special care has been taken
233in the library so that programs which only use the
234.Fn crypt
235interface do not pull in the other components.
236.Sh AUTHOR
237David Burren <davidb@werj.com.au>