1 /* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */
3 /* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
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.
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
18 /* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
21 /* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
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
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/)"
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.
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.
50 * 6. Redistributions of any form whatsoever must retain the following
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
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 * ====================================================================
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).
75 #ifndef HEADER_DES_COMP_H
76 #define HEADER_DES_COMP_H
79 #error DES is disabled.
82 #ifdef _KERBEROS_DES_H
83 #error <openssl/des_old.h> replaces <kerberos/des.h>.
86 #include <openssl/opensslconf.h> /* DES_LONG */
87 #include <openssl/e_os2.h> /* OPENSSL_EXTERN */
88 #include <openssl/des.h>
89 #include <openssl/symhacks.h>
91 #ifdef OPENSSL_BUILD_SHLIBCRYPTO
92 # undef OPENSSL_EXTERN
93 # define OPENSSL_EXTERN OPENSSL_EXPORT
100 typedef unsigned char des_cblock[8];
101 typedef struct des_ks_struct
105 /* make sure things are correct size on machines with
109 } des_key_schedule[16];
111 #define DES_KEY_SZ (sizeof(DES_cblock))
112 #define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
114 #define DES_ENCRYPT 1
115 #define DES_DECRYPT 0
117 #define DES_CBC_MODE 0
118 #define DES_PCBC_MODE 1
120 #define des_ecb2_encrypt(i,o,k1,k2,e) \
121 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
123 #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
124 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
126 #define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
127 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
129 #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
130 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
132 #define des_check_key DES_check_key
133 #define des_rw_mode DES_rw_mode
135 const char *des_options(void);
136 void des_ecb3_encrypt(des_cblock *input,des_cblock *output,
137 des_key_schedule ks1,des_key_schedule ks2,
138 des_key_schedule ks3, int enc);
139 DES_LONG des_cbc_cksum(des_cblock *input,des_cblock *output,
140 long length,des_key_schedule schedule,des_cblock *ivec);
141 void des_cbc_encrypt(des_cblock *input,des_cblock *output,long length,
142 des_key_schedule schedule,des_cblock *ivec,int enc);
143 void des_ncbc_encrypt(des_cblock *input,des_cblock *output,long length,
144 des_key_schedule schedule,des_cblock *ivec,int enc);
145 void des_xcbc_encrypt(des_cblock *input,des_cblock *output,long length,
146 des_key_schedule schedule,des_cblock *ivec,
147 des_cblock *inw,des_cblock *outw,int enc);
148 void des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
149 long length,des_key_schedule schedule,des_cblock *ivec,int enc);
150 void des_ecb_encrypt(des_cblock *input,des_cblock *output,
151 des_key_schedule ks,int enc);
152 void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
153 void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
154 void des_encrypt3(DES_LONG *data, des_key_schedule ks1,
155 des_key_schedule ks2, des_key_schedule ks3);
156 void des_decrypt3(DES_LONG *data, des_key_schedule ks1,
157 des_key_schedule ks2, des_key_schedule ks3);
158 void des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output,
159 long length, des_key_schedule ks1, des_key_schedule ks2,
160 des_key_schedule ks3, des_cblock *ivec, int enc);
161 void des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
162 long length, des_key_schedule ks1, des_key_schedule ks2,
163 des_key_schedule ks3, des_cblock *ivec, int *num, int enc);
164 void des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
165 long length, des_key_schedule ks1, des_key_schedule ks2,
166 des_key_schedule ks3, des_cblock *ivec, int *num);
168 void des_xwhite_in2out(des_cblock (*des_key), des_cblock (*in_white),
169 des_cblock (*out_white));
171 int des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
173 int des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
175 char *des_fcrypt(const char *buf,const char *salt, char *ret);
176 char *des_crypt(const char *buf,const char *salt);
177 #if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT)
178 char *crypt(const char *buf,const char *salt);
180 void des_ofb_encrypt(unsigned char *in,unsigned char *out,
181 int numbits,long length,des_key_schedule schedule,des_cblock *ivec);
182 void des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length,
183 des_key_schedule schedule,des_cblock *ivec,int enc);
184 DES_LONG des_quad_cksum(des_cblock *input,des_cblock *output,
185 long length,int out_count,des_cblock *seed);
186 void des_random_seed(des_cblock key);
187 void des_random_key(des_cblock ret);
188 void des_set_odd_parity(des_cblock *key);
189 int des_is_weak_key(des_cblock *key);
190 int des_set_key(des_cblock *key,des_key_schedule schedule);
191 int des_key_sched(des_cblock *key,des_key_schedule schedule);
192 void des_string_to_key(char *str,des_cblock *key);
193 void des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2);
194 void des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
195 des_key_schedule schedule, des_cblock *ivec, int *num, int enc);
196 void des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
197 des_key_schedule schedule, des_cblock *ivec, int *num);
199 /* The following definitions provide compatibility with the MIT Kerberos
200 * library. The des_key_schedule structure is not binary compatible. */
202 #define _KERBEROS_DES_H
204 #define KRBDES_ENCRYPT DES_ENCRYPT
205 #define KRBDES_DECRYPT DES_DECRYPT
208 # define ENCRYPT DES_ENCRYPT
209 # define DECRYPT DES_DECRYPT
213 # define C_Block des_cblock
214 # define Key_schedule des_key_schedule
215 # define KEY_SZ DES_KEY_SZ
216 # define string_to_key des_string_to_key
217 # define read_pw_string des_read_pw_string
218 # define random_key des_random_key
219 # define pcbc_encrypt des_pcbc_encrypt
220 # define set_key des_set_key
221 # define key_sched des_key_sched
222 # define ecb_encrypt des_ecb_encrypt
223 # define cbc_encrypt des_cbc_encrypt
224 # define ncbc_encrypt des_ncbc_encrypt
225 # define xcbc_encrypt des_xcbc_encrypt
226 # define cbc_cksum des_cbc_cksum
227 # define quad_cksum des_quad_cksum
228 # define check_parity des_check_key_parity
231 #define des_fixup_key_parity DES_fixup_key_parity