1 /* crypto/des/des.h */
\r
2 /* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
\r
3 * All rights reserved.
\r
5 * This package is an SSL implementation written
\r
6 * by Eric Young (eay@cryptsoft.com).
\r
7 * The implementation was written so as to conform with Netscapes SSL.
\r
9 * This library is free for commercial and non-commercial use as long as
\r
10 * the following conditions are aheared to. The following conditions
\r
11 * apply to all code found in this distribution, be it the RC4, RSA,
\r
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
\r
13 * included with this distribution is covered by the same copyright terms
\r
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
\r
16 * Copyright remains Eric Young's, and as such any Copyright notices in
\r
17 * the code are not to be removed.
\r
18 * If this package is used in a product, Eric Young should be given attribution
\r
19 * as the author of the parts of the library used.
\r
20 * This can be in the form of a textual message at program startup or
\r
21 * in documentation (online or textual) provided with the package.
\r
23 * Redistribution and use in source and binary forms, with or without
\r
24 * modification, are permitted provided that the following conditions
\r
26 * 1. Redistributions of source code must retain the copyright
\r
27 * notice, this list of conditions and the following disclaimer.
\r
28 * 2. Redistributions in binary form must reproduce the above copyright
\r
29 * notice, this list of conditions and the following disclaimer in the
\r
30 * documentation and/or other materials provided with the distribution.
\r
31 * 3. All advertising materials mentioning features or use of this software
\r
32 * must display the following acknowledgement:
\r
33 * "This product includes cryptographic software written by
\r
34 * Eric Young (eay@cryptsoft.com)"
\r
35 * The word 'cryptographic' can be left out if the rouines from the library
\r
36 * being used are not cryptographic related :-).
\r
37 * 4. If you include any Windows specific code (or a derivative thereof) from
\r
38 * the apps directory (application code) you must include an acknowledgement:
\r
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
\r
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
\r
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
\r
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
\r
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
\r
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
\r
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
\r
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
\r
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
\r
53 * The licence and distribution terms for any publically available version or
\r
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
\r
55 * copied and put under another distribution licence
\r
56 * [including the GNU Public Licence.]
\r
59 #ifndef HEADER_NEW_DES_H
\r
60 #define HEADER_NEW_DES_H
\r
62 #include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES,
\r
63 DES_LONG (via openssl/opensslconf.h */
\r
65 #ifdef OPENSSL_NO_DES
\r
66 #error DES is disabled.
\r
69 #ifdef OPENSSL_BUILD_SHLIBCRYPTO
\r
70 # undef OPENSSL_EXTERN
\r
71 # define OPENSSL_EXTERN OPENSSL_EXPORT
\r
78 typedef unsigned char DES_cblock[8];
\r
79 typedef /* const */ unsigned char const_DES_cblock[8];
\r
80 /* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock *
\r
81 * and const_DES_cblock * are incompatible pointer types. */
\r
83 typedef struct DES_ks
\r
88 /* make sure things are correct size on machines with
\r
90 DES_LONG deslong[2];
\r
94 #ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT
\r
95 # ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT
\r
96 # define OPENSSL_ENABLE_OLD_DES_SUPPORT
\r
100 #ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT
\r
101 # include <openssl/des_old.h>
\r
104 #define DES_KEY_SZ (sizeof(DES_cblock))
\r
105 #define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
\r
107 #define DES_ENCRYPT 1
\r
108 #define DES_DECRYPT 0
\r
110 #define DES_CBC_MODE 0
\r
111 #define DES_PCBC_MODE 1
\r
113 #define DES_ecb2_encrypt(i,o,k1,k2,e) \
\r
114 DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
\r
116 #define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
\r
117 DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
\r
119 #define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
\r
120 DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
\r
122 #define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
\r
123 DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
\r
125 OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */
\r
126 #define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
\r
127 OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */
\r
128 #define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode)
\r
130 const char *DES_options(void);
\r
131 void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
\r
132 DES_key_schedule *ks1,DES_key_schedule *ks2,
\r
133 DES_key_schedule *ks3, int enc);
\r
134 DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,
\r
135 long length,DES_key_schedule *schedule,
\r
136 const_DES_cblock *ivec);
\r
137 /* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
\r
138 void DES_cbc_encrypt(const unsigned char *input,unsigned char *output,
\r
139 long length,DES_key_schedule *schedule,DES_cblock *ivec,
\r
141 void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output,
\r
142 long length,DES_key_schedule *schedule,DES_cblock *ivec,
\r
144 void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output,
\r
145 long length,DES_key_schedule *schedule,DES_cblock *ivec,
\r
146 const_DES_cblock *inw,const_DES_cblock *outw,int enc);
\r
147 void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
\r
148 long length,DES_key_schedule *schedule,DES_cblock *ivec,
\r
150 void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output,
\r
151 DES_key_schedule *ks,int enc);
\r
153 /* This is the DES encryption function that gets called by just about
\r
154 every other DES routine in the library. You should not use this
\r
155 function except to implement 'modes' of DES. I say this because the
\r
156 functions that call this routine do the conversion from 'char *' to
\r
157 long, and this needs to be done to make sure 'non-aligned' memory
\r
158 access do not occur. The characters are loaded 'little endian'.
\r
159 Data is a pointer to 2 unsigned long's and ks is the
\r
160 DES_key_schedule to use. enc, is non zero specifies encryption,
\r
161 zero if decryption. */
\r
162 void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc);
\r
164 /* This functions is the same as DES_encrypt1() except that the DES
\r
165 initial permutation (IP) and final permutation (FP) have been left
\r
166 out. As for DES_encrypt1(), you should not use this function.
\r
167 It is used by the routines in the library that implement triple DES.
\r
168 IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same
\r
169 as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */
\r
170 void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc);
\r
172 void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
\r
173 DES_key_schedule *ks2, DES_key_schedule *ks3);
\r
174 void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
\r
175 DES_key_schedule *ks2, DES_key_schedule *ks3);
\r
176 void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output,
\r
178 DES_key_schedule *ks1,DES_key_schedule *ks2,
\r
179 DES_key_schedule *ks3,DES_cblock *ivec,int enc);
\r
180 void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out,
\r
182 DES_key_schedule *ks1,DES_key_schedule *ks2,
\r
183 DES_key_schedule *ks3,
\r
184 DES_cblock *ivec1,DES_cblock *ivec2,
\r
186 void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out,
\r
187 long length,DES_key_schedule *ks1,
\r
188 DES_key_schedule *ks2,DES_key_schedule *ks3,
\r
189 DES_cblock *ivec,int *num,int enc);
\r
190 void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
\r
191 int numbits,long length,DES_key_schedule *ks1,
\r
192 DES_key_schedule *ks2,DES_key_schedule *ks3,
\r
193 DES_cblock *ivec,int enc);
\r
194 void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
\r
195 long length,DES_key_schedule *ks1,
\r
196 DES_key_schedule *ks2,DES_key_schedule *ks3,
\r
197 DES_cblock *ivec,int *num);
\r
199 void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,
\r
200 DES_cblock *out_white);
\r
202 int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
\r
204 int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched,
\r
206 char *DES_fcrypt(const char *buf,const char *salt, char *ret);
\r
207 char *DES_crypt(const char *buf,const char *salt);
\r
208 void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits,
\r
209 long length,DES_key_schedule *schedule,DES_cblock *ivec);
\r
210 void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output,
\r
211 long length,DES_key_schedule *schedule,DES_cblock *ivec,
\r
213 DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[],
\r
214 long length,int out_count,DES_cblock *seed);
\r
215 int DES_random_key(DES_cblock *ret);
\r
216 void DES_set_odd_parity(DES_cblock *key);
\r
217 int DES_check_key_parity(const_DES_cblock *key);
\r
218 int DES_is_weak_key(const_DES_cblock *key);
\r
219 /* DES_set_key (= set_key = DES_key_sched = key_sched) calls
\r
220 * DES_set_key_checked if global variable DES_check_key is set,
\r
221 * DES_set_key_unchecked otherwise. */
\r
222 int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule);
\r
223 int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule);
\r
224 int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule);
\r
225 void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule);
\r
226 void DES_string_to_key(const char *str,DES_cblock *key);
\r
227 void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2);
\r
228 void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length,
\r
229 DES_key_schedule *schedule,DES_cblock *ivec,int *num,
\r
231 void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length,
\r
232 DES_key_schedule *schedule,DES_cblock *ivec,int *num);
\r
234 int DES_read_password(DES_cblock *key, const char *prompt, int verify);
\r
235 int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
\r
238 #define DES_fixup_key_parity DES_set_odd_parity
\r