typo
[openssl.git] / crypto / des / des_old.h
1 /* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */
2
3 /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4  *
5  * The function names in here are deprecated and are only present to
6  * provide an interface compatible with libdes.  OpenSSL now provides
7  * functions where "des_" has been replaced with "DES_" in the names,
8  * to make it possible to make incompatible changes that are needed
9  * for C type security and other stuff.
10  *
11  * Please consider starting to use the DES_ functions rather than the
12  * des_ ones.  The des_ functions will dissapear completely before
13  * OpenSSL 1.0!
14  *
15  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16  */
17
18 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19  * project 2001.
20  */
21 /* ====================================================================
22  * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
23  *
24  * Redistribution and use in source and binary forms, with or without
25  * modification, are permitted provided that the following conditions
26  * are met:
27  *
28  * 1. Redistributions of source code must retain the above copyright
29  *    notice, this list of conditions and the following disclaimer. 
30  *
31  * 2. Redistributions in binary form must reproduce the above copyright
32  *    notice, this list of conditions and the following disclaimer in
33  *    the documentation and/or other materials provided with the
34  *    distribution.
35  *
36  * 3. All advertising materials mentioning features or use of this
37  *    software must display the following acknowledgment:
38  *    "This product includes software developed by the OpenSSL Project
39  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40  *
41  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42  *    endorse or promote products derived from this software without
43  *    prior written permission. For written permission, please contact
44  *    openssl-core@openssl.org.
45  *
46  * 5. Products derived from this software may not be called "OpenSSL"
47  *    nor may "OpenSSL" appear in their names without prior written
48  *    permission of the OpenSSL Project.
49  *
50  * 6. Redistributions of any form whatsoever must retain the following
51  *    acknowledgment:
52  *    "This product includes software developed by the OpenSSL Project
53  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54  *
55  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
59  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66  * OF THE POSSIBILITY OF SUCH DAMAGE.
67  * ====================================================================
68  *
69  * This product includes cryptographic software written by Eric Young
70  * (eay@cryptsoft.com).  This product includes software written by Tim
71  * Hudson (tjh@cryptsoft.com).
72  *
73  */
74
75 #ifndef HEADER_DES_OLD_H
76 #define HEADER_DES_OLD_H
77
78 #ifdef OPENSSL_NO_DES
79 #error DES is disabled.
80 #endif
81
82 #ifdef _KERBEROS_DES_H
83 #error <openssl/des_old.h> replaces <kerberos/des.h>.
84 #endif
85
86 #include <openssl/opensslconf.h> /* DES_LONG */
87 #include <openssl/e_os2.h>      /* OPENSSL_EXTERN */
88 #include <openssl/symhacks.h>
89
90 #ifdef OPENSSL_BUILD_SHLIBCRYPTO
91 # undef OPENSSL_EXTERN
92 # define OPENSSL_EXTERN OPENSSL_EXPORT
93 #endif
94
95 #ifdef  __cplusplus
96 extern "C" {
97 #endif
98
99 typedef unsigned char _ossl_old_des_cblock[8];
100 typedef struct _ossl_old_des_ks_struct
101         {
102         union   {
103                 _ossl_old_des_cblock _;
104                 /* make sure things are correct size on machines with
105                  * 8 byte longs */
106                 DES_LONG pad[2];
107                 } ks;
108         } _ossl_old_des_key_schedule[16];
109
110 #ifdef OPENSSL_DES_PRE_0_9_7_COMPATIBILITY
111 #define des_cblock DES_cblock
112 #define des_key_schedule DES_key_schedule
113 #define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
114         DES_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e))
115 #define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
116         DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
117 #define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
118         DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
119 #define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
120         DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n))
121 #define des_options()\
122         DES_options()
123 #define des_cbc_cksum(i,o,l,k,iv)\
124         DES_cbc_cksum((i),(o),(l),(k),(iv))
125 #define des_cbc_encrypt(i,o,l,k,iv,e)\
126         DES_cbc_encrypt((i),(o),(l),(k),(iv),(e))
127 #define des_ncbc_encrypt(i,o,l,k,iv,e)\
128         DES_ncbc_encrypt((i),(o),(l),(k),(iv),(e))
129 #define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
130         DES_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e))
131 #define des_cfb_encrypt(i,o,l,k,iv,e)\
132         DES_cfb_encrypt((i),(o),(l),(k),(iv),(e))
133 #define des_ecb_encrypt(i,o,k,e)\
134         DES_ecb_encrypt((i),(o),(k),(e))
135 #define des_encrypt(d,k,e)\
136         DES_encrypt((d),(k),(e))
137 #define des_encrypt2(d,k,e)\
138         DES_encrypt2((d),(k),(e))
139 #define des_encrypt3(d,k1,k2,k3)\
140         DES_encrypt3((d),(k1),(k2),(k3))
141 #define des_decrypt3(d,k1,k2,k3)\
142         DES_decrypt3((d),(k1),(k2),(k3))
143 #define des_xwhite_in2out(k,i,o)\
144         DES_xwhite_in2out((k),(i),(o))
145 #define des_enc_read(f,b,l,k,iv)\
146         DES_enc_read((f),(b),(l),(k),(iv))
147 #define des_enc_write(f,b,l,k,iv)\
148         DES_enc_write((f),(b),(l),(k),(iv))
149 #define des_fcrypt(b,s,r)\
150         DES_fcrypt((b),(s),(r))
151 #define des_crypt(b,s)\
152         DES_crypt((b),(s))
153 #define des_ofb_encrypt(i,o,n,l,k,iv)\
154         DES_ofb_encrypt((i),(o),(n),(l),(k),(iv))
155 #define des_pcbc_encrypt(i,o,l,k,iv,e)\
156         DES_pcbc_encrypt((i),(o),(l),(k),(iv),(e))
157 #define des_quad_cksum(i,o,l,c,s)\
158         DES_quad_cksum((i),(o),(l),(c),(s))
159 #define des_random_seed(k)\
160         DES_random_seed((k))
161 #define des_random_key(r)\
162         DES_random_key((r))
163 #define des_read_password(k,p,v) \
164         DES_read_password((k),(p),(v))
165 #define des_read_2passwords(k1,k2,p,v) \
166         DES_read_2passwords((k1),(k2),(p),(v))
167 #define des_set_odd_parity(k)\
168         DES_set_odd_parity((k))
169 #define des_is_weak_key(k)\
170         DES_is_weak_key((k))
171 #define des_set_key(k,ks)\
172         DES_set_key((k),(ks))
173 #define des_key_sched(k,ks)\
174         DES_key_sched((k),(ks))
175 #define des_string_to_key(s,k)\
176         DES_string_to_key((s),(k))
177 #define des_string_to_2keys(s,k1,k2)\
178         DES_string_to_2keys((s),(k1),(k2))
179 #define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
180         DES_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e))
181 #define des_ofb64_encrypt(i,o,l,ks,iv,n)\
182         DES_ofb64_encrypt((i),(o),(l),(ks),(iv),(n))
183                 
184
185 #define des_ecb2_encrypt(i,o,k1,k2,e) \
186         des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
187
188 #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
189         des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
190
191 #define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
192         des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
193
194 #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
195         des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
196
197 #define des_check_key DES_check_key
198 #define des_rw_mode DES_rw_mode
199 #else /* libdes compatibility */
200 /* Map all symbol names to _ossl_old_des_* form, so we avoid all
201    clashes with libdes */
202 #define des_cblock _ossl_old_des_cblock
203 #define des_key_schedule _ossl_old_des_key_schedule
204 #define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
205         _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e))
206 #define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
207         _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
208 #define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
209         _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
210 #define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
211         _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n))
212 #define des_options()\
213         _ossl_old_des_options()
214 #define des_cbc_cksum(i,o,l,k,iv)\
215         _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv))
216 #define des_cbc_encrypt(i,o,l,k,iv,e)\
217         _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e))
218 #define des_ncbc_encrypt(i,o,l,k,iv,e)\
219         _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e))
220 #define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
221         _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e))
222 #define des_cfb_encrypt(i,o,l,k,iv,e)\
223         _ossl_old_des_cfb_encrypt((i),(o),(l),(k),(iv),(e))
224 #define des_ecb_encrypt(i,o,k,e)\
225         _ossl_old_des_ecb_encrypt((i),(o),(k),(e))
226 #define des_encrypt(d,k,e)\
227         _ossl_old_des_encrypt((d),(k),(e))
228 #define des_encrypt2(d,k,e)\
229         _ossl_old_des_encrypt2((d),(k),(e))
230 #define des_encrypt3(d,k1,k2,k3)\
231         _ossl_old_des_encrypt3((d),(k1),(k2),(k3))
232 #define des_decrypt3(d,k1,k2,k3)\
233         _ossl_old_des_decrypt3((d),(k1),(k2),(k3))
234 #define des_xwhite_in2out(k,i,o)\
235         _ossl_old_des_xwhite_in2out((k),(i),(o))
236 #define des_enc_read(f,b,l,k,iv)\
237         _ossl_old_des_enc_read((f),(b),(l),(k),(iv))
238 #define des_enc_write(f,b,l,k,iv)\
239         _ossl_old_des_enc_write((f),(b),(l),(k),(iv))
240 #define des_fcrypt(b,s,r)\
241         _ossl_old_des_fcrypt((b),(s),(r))
242 #define des_crypt(b,s)\
243         _ossl_old_des_crypt((b),(s))
244 #define crypt(b,s)\
245         _ossl_old_crypt((b),(s))
246 #define des_ofb_encrypt(i,o,n,l,k,iv)\
247         _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv))
248 #define des_pcbc_encrypt(i,o,l,k,iv,e)\
249         _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e))
250 #define des_quad_cksum(i,o,l,c,s)\
251         _ossl_old_des_quad_cksum((i),(o),(l),(c),(s))
252 #define des_random_seed(k)\
253         _ossl_old_des_random_seed((k))
254 #define des_random_key(r)\
255         _ossl_old_des_random_key((r))
256 #define des_read_password(k,p,v) \
257         _ossl_old_des_read_password((k),(p),(v))
258 #define des_read_2passwords(k1,k2,p,v) \
259         _ossl_old_des_read_2passwords((k1),(k2),(p),(v))
260 #define des_set_odd_parity(k)\
261         _ossl_old_des_set_odd_parity((k))
262 #define des_is_weak_key(k)\
263         _ossl_old_des_is_weak_key((k))
264 #define des_set_key(k,ks)\
265         _ossl_old_des_set_key((k),(ks))
266 #define des_key_sched(k,ks)\
267         _ossl_old_des_key_sched((k),(ks))
268 #define des_string_to_key(s,k)\
269         _ossl_old_des_string_to_key((s),(k))
270 #define des_string_to_2keys(s,k1,k2)\
271         _ossl_old_des_string_to_2keys((s),(k1),(k2))
272 #define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
273         _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e))
274 #define des_ofb64_encrypt(i,o,l,ks,iv,n)\
275         _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n))
276                 
277
278 #define des_ecb2_encrypt(i,o,k1,k2,e) \
279         des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
280
281 #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
282         des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
283
284 #define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
285         des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
286
287 #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
288         des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
289
290 #define des_check_key DES_check_key
291 #define des_rw_mode DES_rw_mode
292 #endif
293
294 const char *_ossl_old_des_options(void);
295 void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
296         _ossl_old_des_key_schedule ks1,_ossl_old_des_key_schedule ks2,
297         _ossl_old_des_key_schedule ks3, int enc);
298 DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
299         long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
300 void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
301         _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
302 void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
303         _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
304 void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
305         _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,
306         _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc);
307 void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
308         long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
309 void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
310         _ossl_old_des_key_schedule ks,int enc);
311 void _ossl_old_des_encrypt(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
312 void _ossl_old_des_encrypt2(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
313 void _ossl_old_des_encrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
314         _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
315 void _ossl_old_des_decrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
316         _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
317 void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output, 
318         long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2, 
319         _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc);
320 void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
321         long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
322         _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc);
323 void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
324         long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
325         _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num);
326
327 void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
328         _ossl_old_des_cblock (*out_white));
329
330 int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
331         _ossl_old_des_cblock *iv);
332 int _ossl_old_des_enc_write(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
333         _ossl_old_des_cblock *iv);
334 char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret);
335 char *_ossl_old_des_crypt(const char *buf,const char *salt);
336 #if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
337 char *_ossl_old_crypt(const char *buf,const char *salt);
338 #endif
339 void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
340         int numbits,long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
341 void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
342         _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
343 DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
344         long length,int out_count,_ossl_old_des_cblock *seed);
345 void _ossl_old_des_random_seed(_ossl_old_des_cblock key);
346 void _ossl_old_des_random_key(_ossl_old_des_cblock ret);
347 int _ossl_old_des_read_password(_ossl_old_des_cblock *key,const char *prompt,int verify);
348 int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2,
349         const char *prompt,int verify);
350 void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key);
351 int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key);
352 int _ossl_old_des_set_key(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
353 int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
354 void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key);
355 void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2);
356 void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
357         _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc);
358 void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
359         _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num);
360
361 /* The following definitions provide compatibility with the MIT Kerberos
362  * library. The _ossl_old_des_key_schedule structure is not binary compatible. */
363
364 #define _KERBEROS_DES_H
365
366 #define KRBDES_ENCRYPT DES_ENCRYPT
367 #define KRBDES_DECRYPT DES_DECRYPT
368
369 #ifdef KERBEROS
370 #  define ENCRYPT DES_ENCRYPT
371 #  define DECRYPT DES_DECRYPT
372 #endif
373
374 #ifndef NCOMPAT
375 #  define C_Block des_cblock
376 #  define Key_schedule des_key_schedule
377 #  define KEY_SZ DES_KEY_SZ
378 #  define string_to_key des_string_to_key
379 #  define read_pw_string des_read_pw_string
380 #  define random_key des_random_key
381 #  define pcbc_encrypt des_pcbc_encrypt
382 #  define set_key des_set_key
383 #  define key_sched des_key_sched
384 #  define ecb_encrypt des_ecb_encrypt
385 #  define cbc_encrypt des_cbc_encrypt
386 #  define ncbc_encrypt des_ncbc_encrypt
387 #  define xcbc_encrypt des_xcbc_encrypt
388 #  define cbc_cksum des_cbc_cksum
389 #  define quad_cksum des_quad_cksum
390 #  define check_parity des_check_key_parity
391 #endif
392
393 #define des_fixup_key_parity DES_fixup_key_parity
394
395 #ifdef  __cplusplus
396 }
397 #endif
398
399 /* for DES_read_pw_string et al */
400 #include <openssl/ui_compat.h>
401
402 #endif