734bfff5cc89f51763c64307acb26425c12ddeea
[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 des_cblock[8];
100 typedef struct des_ks_struct
101         {
102         union   {
103                 des_cblock _;
104                 /* make sure things are correct size on machines with
105                  * 8 byte longs */
106                 DES_LONG pad[2];
107                 } ks;
108         } des_key_schedule[16];
109
110 /* Map all function names to _ossl_old_des_* form, so we avoid all
111    clashes with libdes */
112 #define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
113         _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e))
114 #define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
115         _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
116 #define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
117         _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
118 #define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
119         _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n))
120 #define des_options()\
121         _ossl_old_des_options()
122 #define des_cbc_cksum(i,o,l,k,iv)\
123         _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv))
124 #define des_cbc_encrypt(i,o,l,k,iv,e)\
125         _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e))
126 #define des_ncbc_encrypt(i,o,l,k,iv,e)\
127         _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e))
128 #define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
129         _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e))
130 #define des_cfb_encrypt(i,o,l,k,iv,e)\
131         _ossl_old_des_cfb_encrypt((i),(o),(l),(k),(iv),(e))
132 #define des_ecb_encrypt(i,o,k,e)\
133         _ossl_old_des_ecb_encrypt((i),(o),(k),(e))
134 #define des_encrypt(d,k,e)\
135         _ossl_old_des_encrypt((d),(k),(e))
136 #define des_encrypt2(d,k,e)\
137         _ossl_old_des_encrypt2((d),(k),(e))
138 #define des_encrypt3(d,k1,k2,k3)\
139         _ossl_old_des_encrypt3((d),(k1),(k2),(k3))
140 #define des_decrypt3(d,k1,k2,k3)\
141         _ossl_old_des_decrypt3((d),(k1),(k2),(k3))
142 #define des_xwhite_in2out(k,i,o)\
143         _ossl_old_des_xwhite_in2out((k),(i),(o))
144 #define des_enc_read(f,b,l,k,iv)\
145         _ossl_old_des_enc_read((f),(b),(l),(k),(iv))
146 #define des_enc_write(f,b,l,k,iv)\
147         _ossl_old_des_enc_write((f),(b),(l),(k),(iv))
148 #define des_fcrypt(b,s,r)\
149         _ossl_old_des_fcrypt((b),(s),(r))
150 #define des_crypt(b,s)\
151         _ossl_old_des_crypt((b),(s))
152 #define crypt(b,s)\
153         _ossl_old_crypt((b),(s))
154 #define des_ofb_encrypt(i,o,n,l,k,iv)\
155         _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv))
156 #define des_pcbc_encrypt(i,o,l,k,iv,e)\
157         _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e))
158 #define des_quad_cksum(i,o,l,c,s)\
159         _ossl_old_des_quad_cksum((i),(o),(l),(c),(s))
160 #define des_random_seed(k)\
161         _ossl_old_des_random_seed((k))
162 #define des_random_key(r)\
163         _ossl_old_des_random_key((r))
164 #define des_set_odd_parity(k)\
165         _ossl_old_des_set_odd_parity((k))
166 #define des_is_weak_key(k)\
167         _ossl_old_des_is_weak_key((k))
168 #define des_set_key(k,ks)\
169         _ossl_old_des_set_key((k),(ks))
170 #define des_key_sched(k,ks)\
171         _ossl_old_des_key_sched((k),(ks))
172 #define des_string_to_key(s,k)\
173         _ossl_old_des_string_to_key((s),(k))
174 #define des_string_to_2keys(s,k1,k2)\
175         _ossl_old_des_string_to_2keys((s),(k1),(k2))
176 #define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
177         _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e))
178 #define des_ofb64_encrypt(i,o,l,ks,iv,n)\
179         _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n))
180                 
181
182 #define des_ecb2_encrypt(i,o,k1,k2,e) \
183         des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
184
185 #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
186         des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
187
188 #define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
189         des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
190
191 #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
192         des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
193
194 #define des_check_key DES_check_key
195 #define des_rw_mode DES_rw_mode
196
197 const char *_ossl_old_des_options(void);
198 void _ossl_old_des_ecb3_encrypt(des_cblock *input,des_cblock *output,
199         des_key_schedule ks1,des_key_schedule ks2,
200         des_key_schedule ks3, int enc);
201 DES_LONG _ossl_old_des_cbc_cksum(des_cblock *input,des_cblock *output,
202         long length,des_key_schedule schedule,des_cblock *ivec);
203 void _ossl_old_des_cbc_encrypt(des_cblock *input,des_cblock *output,long length,
204         des_key_schedule schedule,des_cblock *ivec,int enc);
205 void _ossl_old_des_ncbc_encrypt(des_cblock *input,des_cblock *output,long length,
206         des_key_schedule schedule,des_cblock *ivec,int enc);
207 void _ossl_old_des_xcbc_encrypt(des_cblock *input,des_cblock *output,long length,
208         des_key_schedule schedule,des_cblock *ivec,
209         des_cblock *inw,des_cblock *outw,int enc);
210 void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
211         long length,des_key_schedule schedule,des_cblock *ivec,int enc);
212 void _ossl_old_des_ecb_encrypt(des_cblock *input,des_cblock *output,
213         des_key_schedule ks,int enc);
214 void _ossl_old_des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
215 void _ossl_old_des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
216 void _ossl_old_des_encrypt3(DES_LONG *data, des_key_schedule ks1,
217         des_key_schedule ks2, des_key_schedule ks3);
218 void _ossl_old_des_decrypt3(DES_LONG *data, des_key_schedule ks1,
219         des_key_schedule ks2, des_key_schedule ks3);
220 void _ossl_old_des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output, 
221         long length, des_key_schedule ks1, des_key_schedule ks2, 
222         des_key_schedule ks3, des_cblock *ivec, int enc);
223 void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
224         long length, des_key_schedule ks1, des_key_schedule ks2,
225         des_key_schedule ks3, des_cblock *ivec, int *num, int enc);
226 void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
227         long length, des_key_schedule ks1, des_key_schedule ks2,
228         des_key_schedule ks3, des_cblock *ivec, int *num);
229
230 void _ossl_old_des_xwhite_in2out(des_cblock (*des_key), des_cblock (*in_white),
231         des_cblock (*out_white));
232
233 int _ossl_old_des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
234         des_cblock *iv);
235 int _ossl_old_des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
236         des_cblock *iv);
237 char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret);
238 char *_ossl_old_des_crypt(const char *buf,const char *salt);
239 #if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
240 char *_ossl_old_crypt(const char *buf,const char *salt);
241 #endif
242 void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
243         int numbits,long length,des_key_schedule schedule,des_cblock *ivec);
244 void _ossl_old_des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length,
245         des_key_schedule schedule,des_cblock *ivec,int enc);
246 DES_LONG _ossl_old_des_quad_cksum(des_cblock *input,des_cblock *output,
247         long length,int out_count,des_cblock *seed);
248 void _ossl_old_des_random_seed(des_cblock key);
249 void _ossl_old_des_random_key(des_cblock ret);
250 void _ossl_old_des_set_odd_parity(des_cblock *key);
251 int _ossl_old_des_is_weak_key(des_cblock *key);
252 int _ossl_old_des_set_key(des_cblock *key,des_key_schedule schedule);
253 int _ossl_old_des_key_sched(des_cblock *key,des_key_schedule schedule);
254 void _ossl_old_des_string_to_key(char *str,des_cblock *key);
255 void _ossl_old_des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2);
256 void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
257         des_key_schedule schedule, des_cblock *ivec, int *num, int enc);
258 void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
259         des_key_schedule schedule, des_cblock *ivec, int *num);
260
261 /* The following definitions provide compatibility with the MIT Kerberos
262  * library. The des_key_schedule structure is not binary compatible. */
263
264 #define _KERBEROS_DES_H
265
266 #define KRBDES_ENCRYPT DES_ENCRYPT
267 #define KRBDES_DECRYPT DES_DECRYPT
268
269 #ifdef KERBEROS
270 #  define ENCRYPT DES_ENCRYPT
271 #  define DECRYPT DES_DECRYPT
272 #endif
273
274 #ifndef NCOMPAT
275 #  define C_Block des_cblock
276 #  define Key_schedule des_key_schedule
277 #  define KEY_SZ DES_KEY_SZ
278 #  define string_to_key des_string_to_key
279 #  define read_pw_string des_read_pw_string
280 #  define random_key des_random_key
281 #  define pcbc_encrypt des_pcbc_encrypt
282 #  define set_key des_set_key
283 #  define key_sched des_key_sched
284 #  define ecb_encrypt des_ecb_encrypt
285 #  define cbc_encrypt des_cbc_encrypt
286 #  define ncbc_encrypt des_ncbc_encrypt
287 #  define xcbc_encrypt des_xcbc_encrypt
288 #  define cbc_cksum des_cbc_cksum
289 #  define quad_cksum des_quad_cksum
290 #  define check_parity des_check_key_parity
291 #endif
292
293 #define des_fixup_key_parity DES_fixup_key_parity
294
295 #ifdef  __cplusplus
296 }
297 #endif
298
299 #endif