6bd88dbbe44c02da130b7b1d984d7eb891b6f1ed
[openssl.git] / crypto / des / des_old.c
1 /* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3 /*-
4  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
5  *
6  * The function names in here are deprecated and are only present to
7  * provide an interface compatible with libdes.  OpenSSL now provides
8  * functions where "des_" has been replaced with "DES_" in the names,
9  * to make it possible to make incompatible changes that are needed
10  * for C type security and other stuff.
11  *
12  * Please consider starting to use the DES_ functions rather than the
13  * des_ ones.  The des_ functions will dissapear completely before
14  * OpenSSL 1.0!
15  *
16  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
17  */
18
19 /*
20  * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project
21  * 2001.
22  */
23 /* ====================================================================
24  * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
25  *
26  * Redistribution and use in source and binary forms, with or without
27  * modification, are permitted provided that the following conditions
28  * are met:
29  *
30  * 1. Redistributions of source code must retain the above copyright
31  *    notice, this list of conditions and the following disclaimer.
32  *
33  * 2. Redistributions in binary form must reproduce the above copyright
34  *    notice, this list of conditions and the following disclaimer in
35  *    the documentation and/or other materials provided with the
36  *    distribution.
37  *
38  * 3. All advertising materials mentioning features or use of this
39  *    software must display the following acknowledgment:
40  *    "This product includes software developed by the OpenSSL Project
41  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
42  *
43  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
44  *    endorse or promote products derived from this software without
45  *    prior written permission. For written permission, please contact
46  *    openssl-core@openssl.org.
47  *
48  * 5. Products derived from this software may not be called "OpenSSL"
49  *    nor may "OpenSSL" appear in their names without prior written
50  *    permission of the OpenSSL Project.
51  *
52  * 6. Redistributions of any form whatsoever must retain the following
53  *    acknowledgment:
54  *    "This product includes software developed by the OpenSSL Project
55  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
56  *
57  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
58  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
60  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
61  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
62  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
63  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
64  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
66  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
67  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
68  * OF THE POSSIBILITY OF SUCH DAMAGE.
69  * ====================================================================
70  *
71  * This product includes cryptographic software written by Eric Young
72  * (eay@cryptsoft.com).  This product includes software written by Tim
73  * Hudson (tjh@cryptsoft.com).
74  *
75  */
76
77 #define OPENSSL_DES_LIBDES_COMPATIBILITY
78 #include <openssl/des.h>
79 #include <openssl/rand.h>
80
81 const char *_ossl_old_des_options(void)
82 {
83     return DES_options();
84 }
85
86 void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,
87                                 _ossl_old_des_cblock *output,
88                                 des_key_schedule ks1, des_key_schedule ks2,
89                                 des_key_schedule ks3, int enc)
90 {
91     DES_ecb3_encrypt((const_DES_cblock *)input, output,
92                      (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
93                      (DES_key_schedule *)ks3, enc);
94 }
95
96 DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,
97                                  _ossl_old_des_cblock *output, long length,
98                                  des_key_schedule schedule,
99                                  _ossl_old_des_cblock *ivec)
100 {
101     return DES_cbc_cksum((unsigned char *)input, output, length,
102                          (DES_key_schedule *)schedule, ivec);
103 }
104
105 void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,
106                                _ossl_old_des_cblock *output, long length,
107                                des_key_schedule schedule,
108                                _ossl_old_des_cblock *ivec, int enc)
109 {
110     DES_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
111                     length, (DES_key_schedule *)schedule, ivec, enc);
112 }
113
114 void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,
115                                 _ossl_old_des_cblock *output, long length,
116                                 des_key_schedule schedule,
117                                 _ossl_old_des_cblock *ivec, int enc)
118 {
119     DES_ncbc_encrypt((unsigned char *)input, (unsigned char *)output,
120                      length, (DES_key_schedule *)schedule, ivec, enc);
121 }
122
123 void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,
124                                 _ossl_old_des_cblock *output, long length,
125                                 des_key_schedule schedule,
126                                 _ossl_old_des_cblock *ivec,
127                                 _ossl_old_des_cblock *inw,
128                                 _ossl_old_des_cblock *outw, int enc)
129 {
130     DES_xcbc_encrypt((unsigned char *)input, (unsigned char *)output,
131                      length, (DES_key_schedule *)schedule, ivec, inw, outw,
132                      enc);
133 }
134
135 void _ossl_old_des_cfb_encrypt(unsigned char *in, unsigned char *out,
136                                int numbits, long length,
137                                des_key_schedule schedule,
138                                _ossl_old_des_cblock *ivec, int enc)
139 {
140     DES_cfb_encrypt(in, out, numbits, length,
141                     (DES_key_schedule *)schedule, ivec, enc);
142 }
143
144 void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,
145                                _ossl_old_des_cblock *output,
146                                des_key_schedule ks, int enc)
147 {
148     DES_ecb_encrypt(input, output, (DES_key_schedule *)ks, enc);
149 }
150
151 void _ossl_old_des_encrypt(DES_LONG *data, des_key_schedule ks, int enc)
152 {
153     DES_encrypt1(data, (DES_key_schedule *)ks, enc);
154 }
155
156 void _ossl_old_des_encrypt2(DES_LONG *data, des_key_schedule ks, int enc)
157 {
158     DES_encrypt2(data, (DES_key_schedule *)ks, enc);
159 }
160
161 void _ossl_old_des_encrypt3(DES_LONG *data, des_key_schedule ks1,
162                             des_key_schedule ks2, des_key_schedule ks3)
163 {
164     DES_encrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
165                  (DES_key_schedule *)ks3);
166 }
167
168 void _ossl_old_des_decrypt3(DES_LONG *data, des_key_schedule ks1,
169                             des_key_schedule ks2, des_key_schedule ks3)
170 {
171     DES_decrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
172                  (DES_key_schedule *)ks3);
173 }
174
175 void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input,
176                                     _ossl_old_des_cblock *output, long length,
177                                     des_key_schedule ks1,
178                                     des_key_schedule ks2,
179                                     des_key_schedule ks3,
180                                     _ossl_old_des_cblock *ivec, int enc)
181 {
182     DES_ede3_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
183                          length, (DES_key_schedule *)ks1,
184                          (DES_key_schedule *)ks2, (DES_key_schedule *)ks3,
185                          ivec, enc);
186 }
187
188 void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
189                                       long length, des_key_schedule ks1,
190                                       des_key_schedule ks2,
191                                       des_key_schedule ks3,
192                                       _ossl_old_des_cblock *ivec, int *num,
193                                       int enc)
194 {
195     DES_ede3_cfb64_encrypt(in, out, length,
196                            (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
197                            (DES_key_schedule *)ks3, ivec, num, enc);
198 }
199
200 void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
201                                       long length, des_key_schedule ks1,
202                                       des_key_schedule ks2,
203                                       des_key_schedule ks3,
204                                       _ossl_old_des_cblock *ivec, int *num)
205 {
206     DES_ede3_ofb64_encrypt(in, out, length,
207                            (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
208                            (DES_key_schedule *)ks3, ivec, num);
209 }
210
211 int _ossl_old_des_enc_read(int fd, char *buf, int len, des_key_schedule sched,
212                            _ossl_old_des_cblock *iv)
213 {
214     return DES_enc_read(fd, buf, len, (DES_key_schedule *)sched, iv);
215 }
216
217 int _ossl_old_des_enc_write(int fd, char *buf, int len,
218                             des_key_schedule sched, _ossl_old_des_cblock *iv)
219 {
220     return DES_enc_write(fd, buf, len, (DES_key_schedule *)sched, iv);
221 }
222
223 char *_ossl_old_des_fcrypt(const char *buf, const char *salt, char *ret)
224 {
225     return DES_fcrypt(buf, salt, ret);
226 }
227
228 char *_ossl_old_des_crypt(const char *buf, const char *salt)
229 {
230     return DES_crypt(buf, salt);
231 }
232
233 char *_ossl_old_crypt(const char *buf, const char *salt)
234 {
235     return DES_crypt(buf, salt);
236 }
237
238 void _ossl_old_des_ofb_encrypt(unsigned char *in, unsigned char *out,
239                                int numbits, long length,
240                                des_key_schedule schedule,
241                                _ossl_old_des_cblock *ivec)
242 {
243     DES_ofb_encrypt(in, out, numbits, length, (DES_key_schedule *)schedule,
244                     ivec);
245 }
246
247 void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,
248                                 _ossl_old_des_cblock *output, long length,
249                                 des_key_schedule schedule,
250                                 _ossl_old_des_cblock *ivec, int enc)
251 {
252     DES_pcbc_encrypt((unsigned char *)input, (unsigned char *)output,
253                      length, (DES_key_schedule *)schedule, ivec, enc);
254 }
255
256 DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,
257                                   _ossl_old_des_cblock *output, long length,
258                                   int out_count, _ossl_old_des_cblock *seed)
259 {
260     return DES_quad_cksum((unsigned char *)input, output, length,
261                           out_count, seed);
262 }
263
264 void _ossl_old_des_random_seed(_ossl_old_des_cblock key)
265 {
266     RAND_seed(key, sizeof(_ossl_old_des_cblock));
267 }
268
269 void _ossl_old_des_random_key(_ossl_old_des_cblock ret)
270 {
271     DES_random_key((DES_cblock *)ret);
272 }
273
274 int _ossl_old_des_read_password(_ossl_old_des_cblock *key, const char *prompt,
275                                 int verify)
276 {
277     return DES_read_password(key, prompt, verify);
278 }
279
280 int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,
281                                   _ossl_old_des_cblock *key2,
282                                   const char *prompt, int verify)
283 {
284     return DES_read_2passwords(key1, key2, prompt, verify);
285 }
286
287 void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key)
288 {
289     DES_set_odd_parity(key);
290 }
291
292 int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key)
293 {
294     return DES_is_weak_key(key);
295 }
296
297 int _ossl_old_des_set_key(_ossl_old_des_cblock *key,
298                           des_key_schedule schedule)
299 {
300     return DES_set_key(key, (DES_key_schedule *)schedule);
301 }
302
303 int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,
304                             des_key_schedule schedule)
305 {
306     return DES_key_sched(key, (DES_key_schedule *)schedule);
307 }
308
309 void _ossl_old_des_string_to_key(char *str, _ossl_old_des_cblock *key)
310 {
311     DES_string_to_key(str, key);
312 }
313
314 void _ossl_old_des_string_to_2keys(char *str, _ossl_old_des_cblock *key1,
315                                    _ossl_old_des_cblock *key2)
316 {
317     DES_string_to_2keys(str, key1, key2);
318 }
319
320 void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out,
321                                  long length, des_key_schedule schedule,
322                                  _ossl_old_des_cblock *ivec, int *num,
323                                  int enc)
324 {
325     DES_cfb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
326                       ivec, num, enc);
327 }
328
329 void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out,
330                                  long length, des_key_schedule schedule,
331                                  _ossl_old_des_cblock *ivec, int *num)
332 {
333     DES_ofb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
334                       ivec, num);
335 }