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