summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt/crypt.3
diff options
context:
space:
mode:
authorderaadt <>1995-12-16 12:55:31 +0000
committerderaadt <>1995-12-16 12:55:31 +0000
commit767a35a43c1498fbfe4461e5456c6cd41f08de26 (patch)
treee617d22b73a45255f89c8b85781415b11dd8406a /src/lib/libc/crypt/crypt.3
parent8be58a122b61ab24a5524e848814fe5dd314d243 (diff)
downloadopenbsd-767a35a43c1498fbfe4461e5456c6cd41f08de26.tar.gz
openbsd-767a35a43c1498fbfe4461e5456c6cd41f08de26.tar.bz2
openbsd-767a35a43c1498fbfe4461e5456c6cd41f08de26.zip
non-USA crypto code by davidb@werj.com.au. The source has been split
& copied into two pieces so that use of crypt() pulls in a crypt.o that contains only that one programmer interface -- this permits USA export of binaries that use crypt() for authentication purposes. morecrypt.c contains the other DES programmer interfaces commonly used.
Diffstat (limited to 'src/lib/libc/crypt/crypt.3')
-rw-r--r--src/lib/libc/crypt/crypt.3237
1 files changed, 237 insertions, 0 deletions
diff --git a/src/lib/libc/crypt/crypt.3 b/src/lib/libc/crypt/crypt.3
new file mode 100644
index 0000000000..78a54b18a2
--- /dev/null
+++ b/src/lib/libc/crypt/crypt.3
@@ -0,0 +1,237 @@
1.\" FreeSec: libcrypt
2.\"
3.\" Copyright (c) 1994 David Burren
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\" notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\" notice, this list of conditions and the following disclaimer in the
13.\" documentation and/or other materials provided with the distribution.
14.\" 4. Neither the name of the author nor the names of other contributors
15.\" may be used to endorse or promote products derived from this software
16.\" without specific prior written permission.
17.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28.\" SUCH DAMAGE.
29.\"
30.\" $Id: crypt.3,v 1.1 1995/12/16 12:55:29 deraadt Exp $
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.Ft char
46.Fn *crypt "const char *key" "const char *setting"
47.Ft int
48.Fn setkey "char *key"
49.Ft int
50.Fn encrypt "char *block" "int flag"
51.Ft int
52.Fn des_setkey "const char *key"
53.Ft int
54.Fn des_cipher "const char *in" "char *out" "long salt" "int count"
55.Sh DESCRIPTION
56The
57.Fn crypt
58function performs password encryption, based on the
59.Tn NBS
60Data Encryption Standard (DES).
61Additional code has been added to deter key search attempts.
62The first argument to
63.Nm crypt
64is a
65.Dv null Ns -terminated
66string, typically a user's typed password.
67The second is in one of two forms:
68if it begins with an underscore (``_'') then an extended format is used
69in interpreting both the the key and the setting, as outlined below.
70.Ss Extended crypt:
71.Pp
72The
73.Ar key
74is divided into groups of 8 characters (the last group is null-padded)
75and the low-order 7 bits of each each character (56 bits per group) are
76used to form the DES key as follows:
77the first group of 56 bits becomes the initial DES key.
78For each additional group, the XOR of the encryption of the current DES
79key with itself and the group bits becomes the next DES key.
80.Pp
81The setting is a 9-character array consisting of an underscore followed
82by 4 bytes of iteration count and 4 bytes of salt.
83These are encoded as printable characters, 6 bits per character,
84least significant character first.
85The values 0 to 63 are encoded as ``./0-9A-Za-z''.
86This allows 24 bits for both
87.Fa count
88and
89.Fa salt .
90.Ss "Traditional" crypt:
91.Pp
92The first 8 bytes of the key are null-padded, and the low-order 7 bits of
93each character is used to form the 56-bit
94.Tn DES
95key.
96.Pp
97The setting is a 2-character array of the ASCII-encoded salt.
98Thus only 12 bits of
99.Fa salt
100are used.
101.Fa count
102is set to 25.
103.Ss Algorithm:
104.Pp
105The
106.Fa salt
107introduces disorder in the
108.Tn DES
109algorithm in one of 16777216 or 4096 possible ways
110(ie. with 24 or 12 bits: if bit
111.Em i
112of the
113.Ar salt
114is set, then bits
115.Em i
116and
117.Em i+24
118are swapped in the
119.Tn DES
120E-box output).
121.Pp
122The DES key is used to encrypt a 64-bit constant using
123.Ar count
124iterations of
125.Tn DES .
126The value returned is a
127.Dv null Ns -terminated
128string, 20 or 13 bytes (plus null) in length, consisting of the
129.Ar setting
130followed by the encoded 64-bit encryption.
131.Pp
132The functions,
133.Fn encrypt ,
134.Fn setkey ,
135.Fn des_setkey
136and
137.Fn des_cipher
138provide access to the
139.Tn DES
140algorithm itself.
141.Fn setkey
142is passed a 64-byte array of binary values (numeric 0 or 1).
143A 56-bit key is extracted from this array by dividing the
144array into groups of 8, and ignoring the last bit in each group.
145That bit is reserved for a byte parity check by DES, but is ignored
146by these functions.
147.Pp
148The
149.Fa block
150argument to
151.Fn encrypt
152is also a 64-byte array of binary values.
153If the value of
154.Fa flag
155is 0,
156.Fa block
157is encrypted otherwise it is decrypted.
158The result is returned in the original array
159.Fa block
160after using the key specified by
161.Fn setkey
162to process it.
163.Pp
164The argument to
165.Fn des_setkey
166is a character array of length 8.
167The least significant bit (the parity bit) in each character is ignored,
168and the remaining bits are concatenated to form a 56-bit key.
169The function
170.Fn des_cipher
171encrypts (or decrypts if
172.Fa count
173is negative) the 64-bits stored in the 8 characters at
174.Fa in
175using
176.Xr abs 3
177of
178.Fa count
179iterations of
180.Tn DES
181and stores the 64-bit result in the 8 characters at
182.Fa out
183(which may be the same as
184.Fa in
185).
186The
187.Fa salt
188specifies perturbations to the
189.Tn DES
190E-box output as described above.
191.Pp
192The function
193.Fn crypt
194returns a pointer to the encrypted value on success, and NULL on failure.
195The functions
196.Fn setkey ,
197.Fn encrypt ,
198.Fn des_setkey ,
199and
200.Fn des_cipher
201return 0 on success and 1 on failure.
202.Pp
203The
204.Fn crypt ,
205.Fn setkey
206and
207.Fn des_setkey
208functions all manipulate the same key space.
209.Sh SEE ALSO
210.Xr login 1 ,
211.Xr passwd 1 ,
212.Xr getpass 3 ,
213.Xr passwd 5
214.Sh BUGS
215The
216.Fn crypt
217function returns a pointer to static data, and subsequent calls to
218.Fn crypt
219will modify the same object.
220.Sh HISTORY
221A rotor-based
222.Fn crypt
223function appeared in
224.At v6 .
225The current style
226.Fn crypt
227first appeared in
228.At v7 .
229.Pp
230This library (FreeSec 1.0) was developed outside the United States of America
231as an unencumbered replacement for the U.S.-only libcrypt encryption
232library.
233Programs linked against the crypt() interface may be exported from the U.S.A.
234only if they use crypt() solely for authentication purposes and avoid use of
235the other programmer interfaces listed above.
236.Sh AUTHOR
237David Burren <davidb@werj.com.au>