1 .\" $OpenBSD: crypt.3,v 1.5 1996/12/10 09:06:09 deraadt Exp $
5 .\" Copyright (c) 1994 David Burren
6 .\" All rights reserved.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
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.
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
32 .\" Manual page, using -mandoc macros
45 .Fd #include <unistd.h>
47 .Fn *crypt "const char *key" "const char *setting"
49 .Fn setkey "char *key"
51 .Fn encrypt "char *block" "int flag"
53 .Fn des_setkey "const char *key"
55 .Fn des_cipher "const char *in" "char *out" "long salt" "int count"
59 function performs password encryption, based on the
61 Data Encryption Standard (DES).
62 Additional code has been added to deter key search attempts.
66 .Dv null Ns -terminated
67 string, typically a user's typed password.
68 The second is in one of two forms:
69 if it begins with an underscore (``_'') then an extended format is used
70 in interpreting both the key and the setting, as outlined below.
75 is divided into groups of 8 characters (the last group is null-padded)
76 and the low-order 7 bits of each each character (56 bits per group) are
77 used to form the DES key as follows:
78 the first group of 56 bits becomes the initial DES key.
79 For each additional group, the XOR of the encryption of the current DES
80 key with itself and the group bits becomes the next DES key.
82 The setting is a 9-character array consisting of an underscore followed
83 by 4 bytes of iteration count and 4 bytes of salt.
84 These are encoded as printable characters, 6 bits per character,
85 least significant character first.
86 The values 0 to 63 are encoded as ``./0-9A-Za-z''.
87 This allows 24 bits for both
91 .Ss "Traditional" crypt:
93 The first 8 bytes of the key are null-padded, and the low-order 7 bits of
94 each character is used to form the 56-bit
98 The setting is a 2-character array of the ASCII-encoded salt.
108 introduces disorder in the
110 algorithm in one of 16777216 or 4096 possible ways
111 (ie. with 24 or 12 bits: if bit
123 The DES key is used to encrypt a 64-bit constant using
127 The value returned is a
128 .Dv null Ns -terminated
129 string, 20 or 13 bytes (plus null) in length, consisting of the
131 followed by the encoded 64-bit encryption.
139 provide access to the
143 is passed a 64-byte array of binary values (numeric 0 or 1).
144 A 56-bit key is extracted from this array by dividing the
145 array into groups of 8, and ignoring the last bit in each group.
146 That bit is reserved for a byte parity check by DES, but is ignored
153 is also a 64-byte array of binary values.
158 is encrypted otherwise it is decrypted.
159 The result is returned in the original array
161 after using the key specified by
167 is a character array of length 8.
168 The least significant bit (the parity bit) in each character is ignored,
169 and the remaining bits are concatenated to form a 56-bit key.
172 encrypts (or decrypts if
174 is negative) the 64-bits stored in the 8 characters at
182 and stores the 64-bit result in the 8 characters at
184 (which may be the same as
189 specifies perturbations to the
191 E-box output as described above.
195 returns a pointer to the encrypted value on success, and NULL on failure.
202 return 0 on success and 1 on failure.
209 functions all manipulate the same key space.
218 function returns a pointer to static data, and subsequent calls to
220 will modify the same object.
231 This library (FreeSec 1.0) was developed outside the United States of America
232 as an unencumbered replacement for the U.S.-only libcrypt encryption
234 Programs linked against the
236 interface may be exported from the U.S.A. only if they use
238 solely for authentication purposes and avoid use of
239 the other programmer interfaces listed above. Special care has been taken
240 in the library so that programs which only use the
242 interface do not pull in the other components.
244 David Burren <davidb@werj.com.au>