]>
Commit | Line | Data |
---|---|---|
e00c3a07 | 1 | .\" Copyright 2000 Nicolás Lichtmaier <nick@debian.org> |
fea681da MK |
2 | .\" Created 2000-07-22 00:52-0300 |
3 | .\" | |
1dd72f9c | 4 | .\" %%%LICENSE_START(GPLv2+_DOC_FULL) |
fea681da MK |
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. | |
9 | .\" | |
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. | |
14 | .\" | |
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. | |
19 | .\" | |
faede11f MK |
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/>. | |
6a8d8745 | 23 | .\" %%%LICENSE_END |
faede11f | 24 | .\" |
fea681da MK |
25 | .\" Modified 2002-07-23 19:21:35 CEST 2002 Walter Harms |
26 | .\" <walter.harms@informatik.uni-oldenburg.de> | |
27 | .\" | |
28 | .\" Modified 2003-04-04, aeb | |
29 | .\" | |
09b8afdc | 30 | .TH ENCRYPT 3 2018-04-30 "" "Linux Programmer's Manual" |
fea681da MK |
31 | .SH NAME |
32 | encrypt, setkey, encrypt_r, setkey_r \- encrypt 64-bit messages | |
33 | .SH SYNOPSIS | |
3f89e93d | 34 | .nf |
b80f966b | 35 | .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */" |
fea681da | 36 | .B #include <unistd.h> |
68e4db0a | 37 | .PP |
fea681da | 38 | .BI "void encrypt(char " block "[64], int " edflag ); |
f90f031e | 39 | |
b80f966b | 40 | .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */" |
fea681da | 41 | .B #include <stdlib.h> |
68e4db0a | 42 | .PP |
fea681da | 43 | .BI "void setkey(const char *" key ); |
f90f031e | 44 | |
b80f966b | 45 | .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
0daa9e92 | 46 | .B "#include <crypt.h>" |
68e4db0a | 47 | .PP |
b9f02710 | 48 | .BI "void setkey_r(const char *" key ", struct crypt_data *" data ); |
b9f02710 MK |
49 | .BI "void encrypt_r(char *" block ", int " edflag \ |
50 | ", struct crypt_data *" data ); | |
3f89e93d | 51 | .fi |
68e4db0a | 52 | .PP |
e9329f6d | 53 | Each of these requires linking with \fI\-lcrypt\fP. |
fea681da | 54 | .SH DESCRIPTION |
c13182ef MK |
55 | These functions encrypt and decrypt 64-bit messages. |
56 | The | |
63aa9df0 | 57 | .BR setkey () |
fea681da | 58 | function sets the key used by |
63aa9df0 | 59 | .BR encrypt (). |
fea681da MK |
60 | The |
61 | .I key | |
c4bb193f | 62 | argument used here is an array of 64 bytes, each of which has |
c13182ef MK |
63 | numerical value 1 or 0. |
64 | The bytes key[n] where n=8*i-1 are ignored, | |
fea681da MK |
65 | so that the effective key length is 56 bits. |
66 | .PP | |
c13182ef MK |
67 | The |
68 | .BR encrypt () | |
b5cc2ffb | 69 | function modifies the passed buffer, encoding if |
fea681da | 70 | .I edflag |
c13182ef | 71 | is 0, and decoding if 1 is being passed. |
c4bb193f MK |
72 | Like the |
73 | .I key | |
74 | argument, also | |
fea681da MK |
75 | .I block |
76 | is a bit vector representation of the actual value that is encoded. | |
77 | The result is returned in that same vector. | |
78 | .PP | |
79 | These two functions are not reentrant, that is, the key data is | |
c13182ef MK |
80 | kept in static storage. |
81 | The functions | |
63aa9df0 | 82 | .BR setkey_r () |
fea681da | 83 | and |
63aa9df0 | 84 | .BR encrypt_r () |
c13182ef MK |
85 | are the reentrant versions. |
86 | They use the following | |
fea681da | 87 | structure to hold the key data: |
e646a1ba | 88 | .PP |
bd191423 | 89 | .in +4n |
e646a1ba | 90 | .EX |
fea681da | 91 | struct crypt_data { |
42ca79eb MK |
92 | char keysched[16 * 8]; |
93 | char sb0[32768]; | |
94 | char sb1[32768]; | |
95 | char sb2[32768]; | |
96 | char sb3[32768]; | |
97 | char crypt_3_buf[14]; | |
98 | char current_salt[2]; | |
99 | long int current_saltbits; | |
100 | int direction; | |
101 | int initialized; | |
fea681da | 102 | }; |
b8302363 | 103 | .EE |
bd191423 | 104 | .in |
e5056894 | 105 | .PP |
fea681da | 106 | Before calling |
63aa9df0 | 107 | .BR setkey_r () |
fea681da | 108 | set |
94e9d9fe | 109 | .I data\->initialized |
fea681da | 110 | to zero. |
47297adb | 111 | .SH RETURN VALUE |
fea681da MK |
112 | These functions do not return any value. |
113 | .SH ERRORS | |
114 | Set | |
115 | .I errno | |
116 | to zero before calling the above functions. | |
117 | On success, it is unchanged. | |
118 | .TP | |
0daa9e92 | 119 | .B ENOSYS |
fea681da MK |
120 | The function is not provided. |
121 | (For example because of former USA export restrictions.) | |
4cdc879a MK |
122 | .SH VERSIONS |
123 | Because they employ the DES block cipher, | |
124 | which is no longer considered secure, | |
125 | .BR crypt (), | |
126 | .BR crypt_r (), | |
127 | .BR setkey (), | |
128 | and | |
129 | .BR setkey_r () | |
130 | were removed in glibc 2.28. | |
131 | Applications should switch to a modern cryptography library, such as | |
132 | .BR libgcrypt . | |
4fc2f647 | 133 | .SH ATTRIBUTES |
38688339 MK |
134 | For an explanation of the terms used in this section, see |
135 | .BR attributes (7). | |
136 | .TS | |
137 | allbox; | |
138 | lbw23 lb lb | |
139 | l l l. | |
140 | Interface Attribute Value | |
141 | T{ | |
142 | .BR encrypt (), | |
4fc2f647 | 143 | .BR setkey () |
89456d09 | 144 | T} Thread safety MT-Unsafe race:crypt |
38688339 MK |
145 | T{ |
146 | .BR encrypt_r (), | |
4fc2f647 | 147 | .BR setkey_r () |
38688339 MK |
148 | T} Thread safety MT-Safe |
149 | .TE | |
47297adb | 150 | .SH CONFORMING TO |
d0aab8a9 MK |
151 | .BR encrypt (), |
152 | .BR setkey (): | |
153 | POSIX.1-2001, POSIX.1-2008, SUS, SVr4. | |
847e0d88 | 154 | .PP |
2b2581ee MK |
155 | The functions |
156 | .BR encrypt_r () | |
157 | and | |
158 | .BR setkey_r () | |
159 | are GNU extensions. | |
160 | .SH NOTES | |
629a86ec | 161 | .SS Availability in glibc |
924f7667 MK |
162 | See |
163 | .BR crypt (3). | |
629a86ec | 164 | .SS Features in glibc |
a53a30b7 | 165 | In glibc 2.2, these functions use the DES algorithm. |
fea681da | 166 | .SH EXAMPLE |
207050fa | 167 | .EX |
5aa145bd | 168 | #define _XOPEN_SOURCE |
ec5308ca | 169 | #include <stdio.h> |
5aa145bd | 170 | #include <stdlib.h> |
ec5308ca RS |
171 | #include <unistd.h> |
172 | #include <crypt.h> | |
fea681da | 173 | |
cf0a9ace | 174 | int |
c13182ef | 175 | main(void) |
cf0a9ace | 176 | { |
ec5308ca RS |
177 | char key[64]; |
178 | char orig[9] = "eggplant"; | |
179 | char buf[64]; | |
180 | char txt[9]; | |
181 | int i, j; | |
182 | ||
183 | for (i = 0; i < 64; i++) { | |
184 | key[i] = rand() & 1; | |
185 | } | |
186 | ||
187 | for (i = 0; i < 8; i++) { | |
188 | for (j = 0; j < 8; j++) { | |
189 | buf[i * 8 + j] = orig[i] >> j & 1; | |
190 | } | |
191 | setkey(key); | |
192 | } | |
d1a71985 | 193 | printf("Before encrypting: %s\en", orig); |
ec5308ca RS |
194 | |
195 | encrypt(buf, 0); | |
196 | for (i = 0; i < 8; i++) { | |
d1a71985 | 197 | for (j = 0, txt[i] = \(aq\e0\(aq; j < 8; j++) { |
ec5308ca RS |
198 | txt[i] |= buf[i * 8 + j] << j; |
199 | } | |
d1a71985 | 200 | txt[8] = \(aq\e0\(aq; |
ec5308ca | 201 | } |
d1a71985 | 202 | printf("After encrypting: %s\en", txt); |
cf0a9ace | 203 | |
ec5308ca RS |
204 | encrypt(buf, 1); |
205 | for (i = 0; i < 8; i++) { | |
d1a71985 | 206 | for (j = 0, txt[i] = \(aq\e0\(aq; j < 8; j++) { |
ec5308ca RS |
207 | txt[i] |= buf[i * 8 + j] << j; |
208 | } | |
d1a71985 | 209 | txt[8] = \(aq\e0\(aq; |
ec5308ca | 210 | } |
d1a71985 | 211 | printf("After decrypting: %s\en", txt); |
ec5308ca | 212 | exit(EXIT_SUCCESS); |
fea681da | 213 | } |
207050fa | 214 | .EE |
47297adb | 215 | .SH SEE ALSO |
fea681da MK |
216 | .BR cbc_crypt (3), |
217 | .BR crypt (3), | |
218 | .BR ecb_crypt (3), | |
0a4f8b7b | 219 | .\" .BR fcrypt (3) |