summaryrefslogtreecommitdiff
path: root/src/lib/libc/crypt/crypt.3
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>1999-03-26 18:24:03 +0000
committercvs2svn <admin@example.com>1999-03-26 18:24:03 +0000
commit3fc228fb4c1a39aceaee3d7013365042a6077bd0 (patch)
treeaf769f6648929b3b2c1f9e053a3754fa989ce302 /src/lib/libc/crypt/crypt.3
parent536c76cbb863bab152f19842ab88772c01e922c7 (diff)
downloadopenbsd-OPENBSD_2_5.tar.gz
openbsd-OPENBSD_2_5.tar.bz2
openbsd-OPENBSD_2_5.zip
This commit was manufactured by cvs2git to create branch 'OPENBSD_2_5'.OPENBSD_2_5
Diffstat (limited to 'src/lib/libc/crypt/crypt.3')
-rw-r--r--src/lib/libc/crypt/crypt.3298
1 files changed, 298 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..239c9b3089
--- /dev/null
+++ b/src/lib/libc/crypt/crypt.3
@@ -0,0 +1,298 @@
1.\" $OpenBSD: crypt.3,v 1.12 1999/03/18 11:08:33 aaron 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
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 int
49.Fn setkey "char *key"
50.Ft int
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" "int32_t 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 and to use
63stronger hashing algorithms.
64The first argument to
65.Fn crypt
66is a
67.Dv null Ns -terminated
68string, typically a user's typed password.
69The second is in one of three forms:
70if it begins with an underscore (``_'') then an extended format is used
71in interpreting both the key and the setting, as outlined below. If it begins
72with an string character (``$'') and a number then a different algorithm
73is used depending on the number. At the moment a ``$1'' chooses MD5 hashing
74and a ``$2'' chooses Blowfish hashing, see below for more information.
75.Ss Extended crypt:
76.Pp
77The
78.Ar key
79is divided into groups of 8 characters (the last group is null-padded)
80and the low-order 7 bits of each character (56 bits per group) are
81used to form the DES key as follows:
82the first group of 56 bits becomes the initial DES key.
83For each additional group, the XOR of the encryption of the current DES
84key with itself and the group bits becomes the next DES key.
85.Pp
86The setting is a 9-character array consisting of an underscore followed
87by 4 bytes of iteration count and 4 bytes of salt.
88These are encoded as printable characters, 6 bits per character,
89least significant character first.
90The values 0 to 63 are encoded as ``./0-9A-Za-z''.
91This allows 24 bits for both
92.Fa count
93and
94.Fa salt .
95.Ss "MD5" crypt:
96.Pp
97For
98.Tn MD5
99crypt the version number,
100.Fa salt
101and the hashed password are separated
102by the ``$'' character. The maximum length of a password is limited by
103the length counter of the MD5 context, which is about
1042**64. A valid MD5 password entry looks like this:
105.Pp
106``$1$caeiHQwX$hsKqOjrFRRN6K32OWkCBf1''.
107.Pp
108The whole MD5 password string is passed as
109.Fa setting
110for interpretation.
111.Ss "Blowfish" crypt:
112.Pp
113The
114.Tn Blowfish
115version of crypt has 128 bits of
116.Fa salt
117in order to make building
118dictionaries of common passwords space consuming. The initial state
119of the
120.Tn Blowfish
121cipher is expanded using the
122.Fa salt
123and the
124.Fa password
125repeating the process a variable number of rounds, which is encoded in
126the password string. The maximum password length is 72. The final Blowfish
127password entry is created by encrypting
128the string ``OrpheanBeholderScryDoubt'' with the
129.Tn Blowfish
130state 64 times.
131.Pp
132The version number, the logarithm of the number of rounds and
133the concatenation of salt and
134hashed password are separated by the ``$'' character. An encoded ``8''
135would specify 256 rounds.
136A valid Blowfish password looks like this:
137.Pp
138``$2a$12$eIAq8PR8sIUnJ1HaohxX2O9x9Qlm2vK97LJ5dsXdmB.eXF42qjchC''.
139.Pp
140The whole Blowfish password string is passed as
141.Fa setting
142for interpretation.
143.Ss "Traditional" crypt:
144.Pp
145The first 8 bytes of the key are null-padded, and the low-order 7 bits of
146each character is used to form the 56-bit
147.Tn DES
148key.
149.Pp
150The setting is a 2-character array of the ASCII-encoded salt.
151Thus only 12 bits of
152.Fa salt
153are used.
154.Fa count
155is set to 25.
156.Ss DES Algorithm:
157.Pp
158The
159.Fa salt
160introduces disorder in the
161.Tn DES
162algorithm in one of 16777216 or 4096 possible ways
163(ie. with 24 or 12 bits: if bit
164.Em i
165of the
166.Ar salt
167is set, then bits
168.Em i
169and
170.Em i+24
171are swapped in the
172.Tn DES
173E-box output).
174.Pp
175The DES key is used to encrypt a 64-bit constant using
176.Ar count
177iterations of
178.Tn DES .
179The value returned is a
180.Dv null Ns -terminated
181string, 20 or 13 bytes (plus null) in length, consisting of the
182.Ar setting
183followed by the encoded 64-bit encryption.
184.Pp
185The functions,
186.Fn encrypt ,
187.Fn setkey ,
188.Fn des_setkey
189and
190.Fn des_cipher
191provide access to the
192.Tn DES
193algorithm itself.
194.Fn setkey
195is passed a 64-byte array of binary values (numeric 0 or 1).
196A 56-bit key is extracted from this array by dividing the
197array into groups of 8, and ignoring the last bit in each group.
198That bit is reserved for a byte parity check by DES, but is ignored
199by these functions.
200.Pp
201The
202.Fa block
203argument to
204.Fn encrypt
205is also a 64-byte array of binary values.
206If the value of
207.Fa flag
208is 0,
209.Fa block
210is encrypted otherwise it is decrypted.
211The result is returned in the original array
212.Fa block
213after using the key specified by
214.Fn setkey
215to process it.
216.Pp
217The argument to
218.Fn des_setkey
219is a character array of length 8.
220The least significant bit (the parity bit) in each character is ignored,
221and the remaining bits are concatenated to form a 56-bit key.
222The function
223.Fn des_cipher
224encrypts (or decrypts if
225.Fa count
226is negative) the 64-bits stored in the 8 characters at
227.Fa in
228using
229.Xr abs 3
230of
231.Fa count
232iterations of
233.Tn DES
234and stores the 64-bit result in the 8 characters at
235.Fa out
236(which may be the same as
237.Fa in
238).
239The
240.Fa salt
241specifies perturbations to the
242.Tn DES
243E-box output as described above.
244.Pp
245The function
246.Fn crypt
247returns a pointer to the encrypted value on success, and NULL on failure.
248The functions
249.Fn setkey ,
250.Fn encrypt ,
251.Fn des_setkey ,
252and
253.Fn des_cipher
254return 0 on success and 1 on failure.
255.Pp
256The
257.Fn crypt ,
258.Fn setkey
259and
260.Fn des_setkey
261functions all manipulate the same key space.
262.Sh SEE ALSO
263.Xr login 1 ,
264.Xr passwd 1 ,
265.Xr blowfish 3 ,
266.Xr getpass 3 ,
267.Xr md5 3 ,
268.Xr passwd 5
269.Sh BUGS
270The
271.Fn crypt
272function returns a pointer to static data, and subsequent calls to
273.Fn crypt
274will modify the same object.
275.Sh HISTORY
276A rotor-based
277.Fn crypt
278function appeared in
279.At v6 .
280The current style
281.Fn crypt
282first appeared in
283.At v7 .
284.Pp
285This library (FreeSec 1.0) was developed outside the United States of America
286as an unencumbered replacement for the U.S.-only libcrypt encryption
287library.
288Programs linked against the
289.Fn crypt
290interface may be exported from the U.S.A. only if they use
291.Fn crypt
292solely for authentication purposes and avoid use of
293the other programmer interfaces listed above. Special care has been taken
294in the library so that programs which only use the
295.Fn crypt
296interface do not pull in the other components.
297.Sh AUTHOR
298David Burren <davidb@werj.com.au>