]>
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 | .\" | |
460495ca | 30 | .TH ENCRYPT 3 2015-08-08 "" "Linux Programmer's Manual" |
fea681da MK |
31 | .SH NAME |
32 | encrypt, setkey, encrypt_r, setkey_r \- encrypt 64-bit messages | |
33 | .SH SYNOPSIS | |
b80f966b | 34 | .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */" |
fea681da MK |
35 | .br |
36 | .B #include <unistd.h> | |
37 | .sp | |
38 | .BI "void encrypt(char " block "[64], int " edflag ); | |
39 | .sp | |
b80f966b | 40 | .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */" |
fea681da MK |
41 | .br |
42 | .B #include <stdlib.h> | |
43 | .sp | |
44 | .BI "void setkey(const char *" key ); | |
45 | .sp | |
b80f966b | 46 | .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
fea681da | 47 | .br |
0daa9e92 | 48 | .B "#include <crypt.h>" |
fea681da | 49 | .sp |
b9f02710 | 50 | .BI "void setkey_r(const char *" key ", struct crypt_data *" data ); |
fea681da | 51 | .br |
b9f02710 MK |
52 | .BI "void encrypt_r(char *" block ", int " edflag \ |
53 | ", struct crypt_data *" data ); | |
fea681da | 54 | .sp |
e9329f6d | 55 | Each of these requires linking with \fI\-lcrypt\fP. |
fea681da | 56 | .SH DESCRIPTION |
c13182ef MK |
57 | These functions encrypt and decrypt 64-bit messages. |
58 | The | |
63aa9df0 | 59 | .BR setkey () |
fea681da | 60 | function sets the key used by |
63aa9df0 | 61 | .BR encrypt (). |
fea681da MK |
62 | The |
63 | .I key | |
c4bb193f | 64 | argument used here is an array of 64 bytes, each of which has |
c13182ef MK |
65 | numerical value 1 or 0. |
66 | The bytes key[n] where n=8*i-1 are ignored, | |
fea681da MK |
67 | so that the effective key length is 56 bits. |
68 | .PP | |
c13182ef MK |
69 | The |
70 | .BR encrypt () | |
b5cc2ffb | 71 | function modifies the passed buffer, encoding if |
fea681da | 72 | .I edflag |
c13182ef | 73 | is 0, and decoding if 1 is being passed. |
c4bb193f MK |
74 | Like the |
75 | .I key | |
76 | argument, also | |
fea681da MK |
77 | .I block |
78 | is a bit vector representation of the actual value that is encoded. | |
79 | The result is returned in that same vector. | |
80 | .PP | |
81 | These two functions are not reentrant, that is, the key data is | |
c13182ef MK |
82 | kept in static storage. |
83 | The functions | |
63aa9df0 | 84 | .BR setkey_r () |
fea681da | 85 | and |
63aa9df0 | 86 | .BR encrypt_r () |
c13182ef MK |
87 | are the reentrant versions. |
88 | They use the following | |
fea681da | 89 | structure to hold the key data: |
bd191423 | 90 | .in +4n |
fea681da | 91 | .nf |
e5056894 | 92 | |
fea681da | 93 | struct crypt_data { |
42ca79eb MK |
94 | char keysched[16 * 8]; |
95 | char sb0[32768]; | |
96 | char sb1[32768]; | |
97 | char sb2[32768]; | |
98 | char sb3[32768]; | |
99 | char crypt_3_buf[14]; | |
100 | char current_salt[2]; | |
101 | long int current_saltbits; | |
102 | int direction; | |
103 | int initialized; | |
fea681da MK |
104 | }; |
105 | .fi | |
bd191423 | 106 | .in |
e5056894 | 107 | .PP |
fea681da | 108 | Before calling |
63aa9df0 | 109 | .BR setkey_r () |
fea681da | 110 | set |
94e9d9fe | 111 | .I data\->initialized |
fea681da | 112 | to zero. |
47297adb | 113 | .SH RETURN VALUE |
fea681da MK |
114 | These functions do not return any value. |
115 | .SH ERRORS | |
116 | Set | |
117 | .I errno | |
118 | to zero before calling the above functions. | |
119 | On success, it is unchanged. | |
120 | .TP | |
0daa9e92 | 121 | .B ENOSYS |
fea681da MK |
122 | The function is not provided. |
123 | (For example because of former USA export restrictions.) | |
4fc2f647 | 124 | .SH ATTRIBUTES |
38688339 MK |
125 | For an explanation of the terms used in this section, see |
126 | .BR attributes (7). | |
127 | .TS | |
128 | allbox; | |
129 | lbw23 lb lb | |
130 | l l l. | |
131 | Interface Attribute Value | |
132 | T{ | |
133 | .BR encrypt (), | |
4fc2f647 | 134 | .BR setkey () |
89456d09 | 135 | T} Thread safety MT-Unsafe race:crypt |
38688339 MK |
136 | T{ |
137 | .BR encrypt_r (), | |
4fc2f647 | 138 | .BR setkey_r () |
38688339 MK |
139 | T} Thread safety MT-Safe |
140 | .TE | |
47297adb | 141 | .SH CONFORMING TO |
d0aab8a9 MK |
142 | .BR encrypt (), |
143 | .BR setkey (): | |
144 | POSIX.1-2001, POSIX.1-2008, SUS, SVr4. | |
145 | ||
2b2581ee MK |
146 | The functions |
147 | .BR encrypt_r () | |
148 | and | |
149 | .BR setkey_r () | |
150 | are GNU extensions. | |
151 | .SH NOTES | |
a53a30b7 | 152 | In glibc 2.2, these functions use the DES algorithm. |
fea681da | 153 | .SH EXAMPLE |
fea681da | 154 | .nf |
5aa145bd | 155 | #define _XOPEN_SOURCE |
ec5308ca | 156 | #include <stdio.h> |
5aa145bd | 157 | #include <stdlib.h> |
ec5308ca RS |
158 | #include <unistd.h> |
159 | #include <crypt.h> | |
fea681da | 160 | |
cf0a9ace | 161 | int |
c13182ef | 162 | main(void) |
cf0a9ace | 163 | { |
ec5308ca RS |
164 | char key[64]; |
165 | char orig[9] = "eggplant"; | |
166 | char buf[64]; | |
167 | char txt[9]; | |
168 | int i, j; | |
169 | ||
170 | for (i = 0; i < 64; i++) { | |
171 | key[i] = rand() & 1; | |
172 | } | |
173 | ||
174 | for (i = 0; i < 8; i++) { | |
175 | for (j = 0; j < 8; j++) { | |
176 | buf[i * 8 + j] = orig[i] >> j & 1; | |
177 | } | |
178 | setkey(key); | |
179 | } | |
180 | printf("Before encrypting: %s\\n", orig); | |
181 | ||
182 | encrypt(buf, 0); | |
183 | for (i = 0; i < 8; i++) { | |
184 | for (j = 0, txt[i] = \(aq\\0\(aq; j < 8; j++) { | |
185 | txt[i] |= buf[i * 8 + j] << j; | |
186 | } | |
187 | txt[8] = \(aq\\0\(aq; | |
188 | } | |
189 | printf("After encrypting: %s\\n", txt); | |
cf0a9ace | 190 | |
ec5308ca RS |
191 | encrypt(buf, 1); |
192 | for (i = 0; i < 8; i++) { | |
193 | for (j = 0, txt[i] = \(aq\\0\(aq; j < 8; j++) { | |
194 | txt[i] |= buf[i * 8 + j] << j; | |
195 | } | |
196 | txt[8] = \(aq\\0\(aq; | |
197 | } | |
198 | printf("After decrypting: %s\\n", txt); | |
199 | exit(EXIT_SUCCESS); | |
fea681da MK |
200 | } |
201 | .fi | |
47297adb | 202 | .SH SEE ALSO |
fea681da MK |
203 | .BR cbc_crypt (3), |
204 | .BR crypt (3), | |
205 | .BR ecb_crypt (3), | |
0a4f8b7b | 206 | .\" .BR fcrypt (3) |