2 .\" Copyright 2000 Nicolás Lichtmaier <nick@debian.org>
3 .\" Created 2000-07-22 00:52-0300
5 .\" SPDX-License-Identifier: GPL-2.0-or-later
7 .\" Modified 2002-07-23 19:21:35 CEST 2002 Walter Harms
8 .\" <walter.harms@informatik.uni-oldenburg.de>
10 .\" Modified 2003-04-04, aeb
12 .TH encrypt 3 (date) "Linux man-pages (unreleased)"
14 encrypt, setkey, encrypt_r, setkey_r \- encrypt 64-bit messages
16 Encryption and decryption library
17 .RI ( libcrypto ", " \-lcrypto )
20 .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
21 .B #include <unistd.h>
23 .BI "[[deprecated]] void encrypt(char " block "[64], int " edflag );
25 .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
26 .B #include <stdlib.h>
28 .BI "[[deprecated]] void setkey(const char *" key );
30 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
33 .BI "[[deprecated]] void setkey_r(const char *" key ", struct crypt_data *" data );
34 .BI "[[deprecated]] void encrypt_r(char *" block ", int " edflag ,
35 .BI " struct crypt_data *" data );
38 These functions encrypt and decrypt 64-bit messages.
41 function sets the key used by
45 argument used here is an array of 64 bytes, each of which has
46 numerical value 1 or 0.
47 The bytes key[n] where n=8*i-1 are ignored,
48 so that the effective key length is 56 bits.
52 function modifies the passed buffer, encoding if
54 is 0, and decoding if 1 is being passed.
59 is a bit vector representation of the actual value that is encoded.
60 The result is returned in that same vector.
62 These two functions are not reentrant, that is, the key data is
63 kept in static storage.
68 are the reentrant versions.
69 They use the following
70 structure to hold the key data:
75 char keysched[16 * 8];
82 long current_saltbits;
95 These functions do not return any value.
99 to zero before calling the above functions.
105 The function is not provided.
106 (For example because of former USA export restrictions.)
108 Because they employ the DES block cipher,
109 which is no longer considered secure,
115 were removed in glibc 2.28.
116 Applications should switch to a modern cryptography library, such as
119 For an explanation of the terms used in this section, see
127 Interface Attribute Value
131 T} Thread safety MT-Unsafe race:crypt
135 T} Thread safety MT-Safe
143 POSIX.1-2001, POSIX.1-2008, SUS, SVr4.
151 .SS Availability in glibc
154 .SS Features in glibc
155 In glibc 2.2, these functions use the DES algorithm.
157 .\" [[deprecated]] SRC BEGIN (encrypt.c)
159 #define _XOPEN_SOURCE
169 char orig[9] = "eggplant";
173 for (size_t i = 0; i < 64; i++) {
177 for (size_t i = 0; i < 8; i++) {
178 for (size_t j = 0; j < 8; j++) {
179 buf[i * 8 + j] = orig[i] >> j & 1;
183 printf("Before encrypting: %s\en", orig);
186 for (size_t i = 0; i < 8; i++) {
187 for (size_t j = 0, txt[i] = \[aq]\e0\[aq]; j < 8; j++) {
188 txt[i] |= buf[i * 8 + j] << j;
190 txt[8] = \[aq]\e0\[aq];
192 printf("After encrypting: %s\en", txt);
195 for (size_t i = 0; i < 8; i++) {
196 for (size_t j = 0, txt[i] = \[aq]\e0\[aq]; j < 8; j++) {
197 txt[i] |= buf[i * 8 + j] << j;
199 txt[8] = \[aq]\e0\[aq];
201 printf("After decrypting: %s\en", txt);