1 .\" Copyright 2000 Nicolás Lichtmaier <nick@debian.org>
2 .\" Created 2000-07-22 00:52-0300
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 .\" GNU General Public License for more details.
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
25 .\" Modified 2002-07-23 19:21:35 CEST 2002 Walter Harms
26 .\" <walter.harms@informatik.uni-oldenburg.de>
28 .\" Modified 2003-04-04, aeb
30 .TH ENCRYPT 3 2018-04-30 "" "Linux Programmer's Manual"
32 encrypt, setkey, encrypt_r, setkey_r \- encrypt 64-bit messages
35 .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
36 .B #include <unistd.h>
38 .BI "void encrypt(char " block "[64], int " edflag );
40 .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
41 .B #include <stdlib.h>
43 .BI "void setkey(const char *" key );
45 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
46 .B "#include <crypt.h>"
48 .BI "void setkey_r(const char *" key ", struct crypt_data *" data );
49 .BI "void encrypt_r(char *" block ", int " edflag \
50 ", struct crypt_data *" data );
53 Each of these requires linking with \fI\-lcrypt\fP.
55 These functions encrypt and decrypt 64-bit messages.
58 function sets the key used by
62 argument used here is an array of 64 bytes, each of which has
63 numerical value 1 or 0.
64 The bytes key[n] where n=8*i-1 are ignored,
65 so that the effective key length is 56 bits.
69 function modifies the passed buffer, encoding if
71 is 0, and decoding if 1 is being passed.
76 is a bit vector representation of the actual value that is encoded.
77 The result is returned in that same vector.
79 These two functions are not reentrant, that is, the key data is
80 kept in static storage.
85 are the reentrant versions.
86 They use the following
87 structure to hold the key data:
92 char keysched[16 * 8];
99 long int current_saltbits;
109 .I data\->initialized
112 These functions do not return any value.
116 to zero before calling the above functions.
117 On success, it is unchanged.
120 The function is not provided.
121 (For example because of former USA export restrictions.)
123 Because they employ the DES block cipher,
124 which is no longer considered secure,
130 were removed in glibc 2.28.
131 Applications should switch to a modern cryptography library, such as
134 For an explanation of the terms used in this section, see
140 Interface Attribute Value
144 T} Thread safety MT-Unsafe race:crypt
148 T} Thread safety MT-Safe
153 POSIX.1-2001, POSIX.1-2008, SUS, SVr4.
161 .SS Availability in glibc
164 .SS Features in glibc
165 In glibc 2.2, these functions use the DES algorithm.
168 #define _XOPEN_SOURCE
178 char orig[9] = "eggplant";
183 for (i = 0; i < 64; i++) {
187 for (i = 0; i < 8; i++) {
188 for (j = 0; j < 8; j++) {
189 buf[i * 8 + j] = orig[i] >> j & 1;
193 printf("Before encrypting: %s\en", orig);
196 for (i = 0; i < 8; i++) {
197 for (j = 0, txt[i] = \(aq\e0\(aq; j < 8; j++) {
198 txt[i] |= buf[i * 8 + j] << j;
200 txt[8] = \(aq\e0\(aq;
202 printf("After encrypting: %s\en", txt);
205 for (i = 0; i < 8; i++) {
206 for (j = 0, txt[i] = \(aq\e0\(aq; j < 8; j++) {
207 txt[i] |= buf[i * 8 + j] << j;
209 txt[8] = \(aq\e0\(aq;
211 printf("After decrypting: %s\en", txt);