d40dcf6e37fa1fc5d92f2b6c21a601506f9ff94a
[openssl.git] / crypto / des / des_old.h
1 /* crypto/des/des_comp.h -*- mode:C; c-file-style: "eay" -*- */
2 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3  * project 2001.
4  */
5 /* ====================================================================
6  * Copyright (c) 1998-2001 The OpenSSL Project.  All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer. 
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in
17  *    the documentation and/or other materials provided with the
18  *    distribution.
19  *
20  * 3. All advertising materials mentioning features or use of this
21  *    software must display the following acknowledgment:
22  *    "This product includes software developed by the OpenSSL Project
23  *    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24  *
25  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26  *    endorse or promote products derived from this software without
27  *    prior written permission. For written permission, please contact
28  *    openssl-core@openssl.org.
29  *
30  * 5. Products derived from this software may not be called "OpenSSL"
31  *    nor may "OpenSSL" appear in their names without prior written
32  *    permission of the OpenSSL Project.
33  *
34  * 6. Redistributions of any form whatsoever must retain the following
35  *    acknowledgment:
36  *    "This product includes software developed by the OpenSSL Project
37  *    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
43  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50  * OF THE POSSIBILITY OF SUCH DAMAGE.
51  * ====================================================================
52  *
53  * This product includes cryptographic software written by Eric Young
54  * (eay@cryptsoft.com).  This product includes software written by Tim
55  * Hudson (tjh@cryptsoft.com).
56  *
57  */
58
59 /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
60  *
61  * The function names in here are deprecated and are only present to
62  * provide an interface compatible with libdes.  OpenSSL now provides
63  * functions where "des_" has been replaced with "DES_" in the names,
64  * to make it possible to make incompatible changes that are needed
65  * for C type security and other stuff.
66  *
67  * Please consider starting to use the DES_ functions rather than the
68  * des_ ones.  The des_ functions will dissapear completely before
69  * OpenSSL 1.0!
70  *
71  * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
72  */
73
74 #ifndef HEADER_DES_COMP_H
75 #define HEADER_DES_COMP_H
76
77 #ifdef OPENSSL_NO_DES
78 #error DES is disabled.
79 #endif
80
81 #ifdef _KERBEROS_DES_H
82 #error <openssl/des_compat.h> replaces <kerberos/des.h>.
83 #endif
84
85 #include <openssl/opensslconf.h> /* DES_LONG */
86 #include <openssl/e_os2.h>      /* OPENSSL_EXTERN */
87 #include <openssl/des.h>
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 #define DES_KEY_SZ      (sizeof(DES_cblock))
111 #define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
112
113 #define DES_ENCRYPT     1
114 #define DES_DECRYPT     0
115
116 #define DES_CBC_MODE    0
117 #define DES_PCBC_MODE   1
118
119 #define des_ecb2_encrypt(i,o,k1,k2,e) \
120         des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
121
122 #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
123         des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
124
125 #define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
126         des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
127
128 #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
129         des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
130
131 #define des_check_key DES_check_key
132 #define des_rw_mode DES_rw_mode
133
134 const char *des_options(void);
135 void des_ecb3_encrypt(des_cblock *input,des_cblock *output,
136         des_key_schedule ks1,des_key_schedule ks2,
137         des_key_schedule ks3, int enc);
138 DES_LONG des_cbc_cksum(des_cblock *input,des_cblock *output,
139         long length,des_key_schedule schedule,des_cblock *ivec);
140 void des_cbc_encrypt(des_cblock *input,des_cblock *output,long length,
141         des_key_schedule schedule,des_cblock *ivec,int enc);
142 void des_ncbc_encrypt(des_cblock *input,des_cblock *output,long length,
143         des_key_schedule schedule,des_cblock *ivec,int enc);
144 void des_xcbc_encrypt(des_cblock *input,des_cblock *output,long length,
145         des_key_schedule schedule,des_cblock *ivec,
146         des_cblock *inw,des_cblock *outw,int enc);
147 void des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
148         long length,des_key_schedule schedule,des_cblock *ivec,int enc);
149 void des_ecb_encrypt(des_cblock *input,des_cblock *output,
150         des_key_schedule ks,int enc);
151 void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
152 void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
153 void des_encrypt3(DES_LONG *data, des_key_schedule ks1,
154         des_key_schedule ks2, des_key_schedule ks3);
155 void des_decrypt3(DES_LONG *data, des_key_schedule ks1,
156         des_key_schedule ks2, des_key_schedule ks3);
157 void des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output, 
158         long length, des_key_schedule ks1, des_key_schedule ks2, 
159         des_key_schedule ks3, des_cblock *ivec, int enc);
160 void des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
161         long length, des_key_schedule ks1, des_key_schedule ks2,
162         des_key_schedule ks3, des_cblock *ivec, int *num, int enc);
163 void des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
164         long length, des_key_schedule ks1, des_key_schedule ks2,
165         des_key_schedule ks3, des_cblock *ivec, int *num);
166
167 void des_xwhite_in2out(des_cblock (*des_key), des_cblock (*in_white),
168         des_cblock (*out_white));
169
170 int des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
171         des_cblock *iv);
172 int des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
173         des_cblock *iv);
174 char *des_fcrypt(const char *buf,const char *salt, char *ret);
175 char *des_crypt(const char *buf,const char *salt);
176 #if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
177 char *crypt(const char *buf,const char *salt);
178 #endif
179 void des_ofb_encrypt(unsigned char *in,unsigned char *out,
180         int numbits,long length,des_key_schedule schedule,des_cblock *ivec);
181 void des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length,
182         des_key_schedule schedule,des_cblock *ivec,int enc);
183 DES_LONG des_quad_cksum(des_cblock *input,des_cblock *output,
184         long length,int out_count,des_cblock *seed);
185 void des_random_seed(des_cblock key);
186 void des_random_key(des_cblock ret);
187 void des_set_odd_parity(des_cblock *key);
188 int des_is_weak_key(des_cblock *key);
189 int des_set_key(des_cblock *key,des_key_schedule schedule);
190 int des_key_sched(des_cblock *key,des_key_schedule schedule);
191 void des_string_to_key(char *str,des_cblock *key);
192 void des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2);
193 void des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
194         des_key_schedule schedule, des_cblock *ivec, int *num, int enc);
195 void des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
196         des_key_schedule schedule, des_cblock *ivec, int *num);
197
198 /* The following definitions provide compatibility with the MIT Kerberos
199  * library. The des_key_schedule structure is not binary compatible. */
200
201 #define _KERBEROS_DES_H
202
203 #define KRBDES_ENCRYPT DES_ENCRYPT
204 #define KRBDES_DECRYPT DES_DECRYPT
205
206 #ifdef KERBEROS
207 #  define ENCRYPT DES_ENCRYPT
208 #  define DECRYPT DES_DECRYPT
209 #endif
210
211 #ifndef NCOMPAT
212 #  define C_Block des_cblock
213 #  define Key_schedule des_key_schedule
214 #  define KEY_SZ DES_KEY_SZ
215 #  define string_to_key des_string_to_key
216 #  define read_pw_string des_read_pw_string
217 #  define random_key des_random_key
218 #  define pcbc_encrypt des_pcbc_encrypt
219 #  define set_key des_set_key
220 #  define key_sched des_key_sched
221 #  define ecb_encrypt des_ecb_encrypt
222 #  define cbc_encrypt des_cbc_encrypt
223 #  define ncbc_encrypt des_ncbc_encrypt
224 #  define xcbc_encrypt des_xcbc_encrypt
225 #  define cbc_cksum des_cbc_cksum
226 #  define quad_cksum des_quad_cksum
227 #  define check_parity des_check_key_parity
228 #endif
229
230 #define des_fixup_key_parity DES_fixup_key_parity
231
232 #ifdef  __cplusplus
233 }
234 #endif
235
236 #endif