des.h revision 1.1 1 1.1 thorpej /* $NetBSD: des.h,v 1.1 2000/06/14 19:45:35 thorpej Exp $ */
2 1.1 thorpej /* $KAME: des.h,v 1.4 2000/06/14 10:41:17 itojun Exp $ */
3 1.1 thorpej
4 1.1 thorpej /* lib/des/des.h */
5 1.1 thorpej /* Copyright (C) 1995-1996 Eric Young (eay (at) mincom.oz.au)
6 1.1 thorpej * All rights reserved.
7 1.1 thorpej *
8 1.1 thorpej * This file is part of an SSL implementation written
9 1.1 thorpej * by Eric Young (eay (at) mincom.oz.au).
10 1.1 thorpej * The implementation was written so as to conform with Netscapes SSL
11 1.1 thorpej * specification. This library and applications are
12 1.1 thorpej * FREE FOR COMMERCIAL AND NON-COMMERCIAL USE
13 1.1 thorpej * as long as the following conditions are aheared to.
14 1.1 thorpej *
15 1.1 thorpej * Copyright remains Eric Young's, and as such any Copyright notices in
16 1.1 thorpej * the code are not to be removed. If this code is used in a product,
17 1.1 thorpej * Eric Young should be given attribution as the author of the parts used.
18 1.1 thorpej * This can be in the form of a textual message at program startup or
19 1.1 thorpej * in documentation (online or textual) provided with the package.
20 1.1 thorpej *
21 1.1 thorpej * Redistribution and use in source and binary forms, with or without
22 1.1 thorpej * modification, are permitted provided that the following conditions
23 1.1 thorpej * are met:
24 1.1 thorpej * 1. Redistributions of source code must retain the copyright
25 1.1 thorpej * notice, this list of conditions and the following disclaimer.
26 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
27 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
28 1.1 thorpej * documentation and/or other materials provided with the distribution.
29 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
30 1.1 thorpej * must display the following acknowledgement:
31 1.1 thorpej * This product includes software developed by Eric Young (eay (at) mincom.oz.au)
32 1.1 thorpej *
33 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
34 1.1 thorpej * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 1.1 thorpej * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 1.1 thorpej * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
37 1.1 thorpej * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 1.1 thorpej * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 1.1 thorpej * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 1.1 thorpej * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 1.1 thorpej * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 1.1 thorpej * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43 1.1 thorpej * SUCH DAMAGE.
44 1.1 thorpej *
45 1.1 thorpej * The licence and distribution terms for any publically available version or
46 1.1 thorpej * derivative of this code cannot be changed. i.e. this code cannot simply be
47 1.1 thorpej * copied and put under another distribution licence
48 1.1 thorpej * [including the GNU Public Licence.]
49 1.1 thorpej */
50 1.1 thorpej
51 1.1 thorpej #ifndef HEADER_DES_H
52 1.1 thorpej #define HEADER_DES_H
53 1.1 thorpej
54 1.1 thorpej #ifdef __cplusplus
55 1.1 thorpej extern "C" {
56 1.1 thorpej #endif
57 1.1 thorpej
58 1.1 thorpej /* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
59 1.1 thorpej * %20 speed up (longs are 8 bytes, int's are 4). */
60 1.1 thorpej #ifndef DES_LONG
61 1.1 thorpej #define DES_LONG unsigned long
62 1.1 thorpej #endif
63 1.1 thorpej
64 1.1 thorpej typedef unsigned char des_cblock[8];
65 1.1 thorpej typedef struct des_ks_struct
66 1.1 thorpej {
67 1.1 thorpej union {
68 1.1 thorpej des_cblock _;
69 1.1 thorpej /* make sure things are correct size on machines with
70 1.1 thorpej * 8 byte longs */
71 1.1 thorpej DES_LONG pad[2];
72 1.1 thorpej } ks;
73 1.1 thorpej #undef _
74 1.1 thorpej #define _ ks._
75 1.1 thorpej } des_key_schedule[16];
76 1.1 thorpej
77 1.1 thorpej #define DES_KEY_SZ (sizeof(des_cblock))
78 1.1 thorpej #define DES_SCHEDULE_SZ (sizeof(des_key_schedule))
79 1.1 thorpej
80 1.1 thorpej #define DES_ENCRYPT 1
81 1.1 thorpej #define DES_DECRYPT 0
82 1.1 thorpej
83 1.1 thorpej #define DES_CBC_MODE 0
84 1.1 thorpej #define DES_PCBC_MODE 1
85 1.1 thorpej
86 1.1 thorpej #define des_ecb2_encrypt(i,o,k1,k2,e) \
87 1.1 thorpej des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
88 1.1 thorpej
89 1.1 thorpej #define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
90 1.1 thorpej des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
91 1.1 thorpej
92 1.1 thorpej #define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
93 1.1 thorpej des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
94 1.1 thorpej
95 1.1 thorpej #define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
96 1.1 thorpej des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
97 1.1 thorpej
98 1.1 thorpej #define C_Block des_cblock
99 1.1 thorpej #define Key_schedule des_key_schedule
100 1.1 thorpej #ifdef KERBEROS
101 1.1 thorpej #define ENCRYPT DES_ENCRYPT
102 1.1 thorpej #define DECRYPT DES_DECRYPT
103 1.1 thorpej #endif
104 1.1 thorpej #define KEY_SZ DES_KEY_SZ
105 1.1 thorpej #define string_to_key des_string_to_key
106 1.1 thorpej #define read_pw_string des_read_pw_string
107 1.1 thorpej #define random_key des_random_key
108 1.1 thorpej #define pcbc_encrypt des_pcbc_encrypt
109 1.1 thorpej #define set_key des_set_key
110 1.1 thorpej #define key_sched des_key_sched
111 1.1 thorpej #define ecb_encrypt des_ecb_encrypt
112 1.1 thorpej #define cbc_encrypt des_cbc_encrypt
113 1.1 thorpej #define ncbc_encrypt des_ncbc_encrypt
114 1.1 thorpej #define xcbc_encrypt des_xcbc_encrypt
115 1.1 thorpej #define cbc_cksum des_cbc_cksum
116 1.1 thorpej #define quad_cksum des_quad_cksum
117 1.1 thorpej
118 1.1 thorpej /* For compatibility with the MIT lib - eay 20/05/92 */
119 1.1 thorpej typedef des_key_schedule bit_64;
120 1.1 thorpej #define des_fixup_key_parity des_set_odd_parity
121 1.1 thorpej #define des_check_key_parity check_parity
122 1.1 thorpej
123 1.1 thorpej extern int des_check_key; /* defaults to false */
124 1.1 thorpej extern int des_rw_mode; /* defaults to DES_PCBC_MODE */
125 1.1 thorpej
126 1.1 thorpej /* The next line is used to disable full ANSI prototypes, if your
127 1.1 thorpej * compiler has problems with the prototypes, make sure this line always
128 1.1 thorpej * evaluates to true :-) */
129 1.1 thorpej #if defined(MSDOS) || defined(__STDC__)
130 1.1 thorpej #undef NOPROTO
131 1.1 thorpej #endif
132 1.1 thorpej #ifndef NOPROTO
133 1.1 thorpej char *des_options(void);
134 1.1 thorpej void des_ecb3_encrypt(des_cblock *input,des_cblock *output,
135 1.1 thorpej des_key_schedule ks1,des_key_schedule ks2,
136 1.1 thorpej des_key_schedule ks3, int enc);
137 1.1 thorpej DES_LONG des_cbc_cksum(des_cblock *input,des_cblock *output,
138 1.1 thorpej long length,des_key_schedule schedule,des_cblock *ivec);
139 1.1 thorpej /*
140 1.1 thorpej void des_cbc_encrypt(des_cblock *input,des_cblock *output,long length,
141 1.1 thorpej des_key_schedule schedule,des_cblock *ivec,int enc);
142 1.1 thorpej */
143 1.1 thorpej int des_cbc_encrypt(struct mbuf *, size_t, size_t,
144 1.1 thorpej des_key_schedule schedule,des_cblock *ivec, int enc);
145 1.1 thorpej void des_ncbc_encrypt(des_cblock *input,des_cblock *output,long length,
146 1.1 thorpej des_key_schedule schedule,des_cblock *ivec,int enc);
147 1.1 thorpej void des_xcbc_encrypt(des_cblock *input,des_cblock *output,long length,
148 1.1 thorpej des_key_schedule schedule,des_cblock *ivec,
149 1.1 thorpej des_cblock *inw,des_cblock *outw,int enc);
150 1.1 thorpej void des_3cbc_encrypt(des_cblock *input,des_cblock *output,long length,
151 1.1 thorpej des_key_schedule sk1,des_key_schedule sk2,
152 1.1 thorpej des_cblock *ivec1,des_cblock *ivec2,int enc);
153 1.1 thorpej extern int des_3cbc_process(struct mbuf *, size_t, size_t,
154 1.1 thorpej des_key_schedule *schedule, des_cblock *ivec, int mode);
155 1.1 thorpej void des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
156 1.1 thorpej long length,des_key_schedule schedule,des_cblock *ivec,int enc);
157 1.1 thorpej void des_ecb_encrypt(des_cblock *input,des_cblock *output,
158 1.1 thorpej des_key_schedule ks,int enc);
159 1.1 thorpej void des_encrypt(DES_LONG *data,des_key_schedule ks, int enc);
160 1.1 thorpej void des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc);
161 1.1 thorpej void des_ede3_cbc_encrypt(des_cblock *input, des_cblock *output,
162 1.1 thorpej long length, des_key_schedule ks1, des_key_schedule ks2,
163 1.1 thorpej des_key_schedule ks3, des_cblock *ivec, int enc);
164 1.1 thorpej void des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
165 1.1 thorpej long length, des_key_schedule ks1, des_key_schedule ks2,
166 1.1 thorpej des_key_schedule ks3, des_cblock *ivec, int *num, int encrypt);
167 1.1 thorpej void des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
168 1.1 thorpej long length, des_key_schedule ks1, des_key_schedule ks2,
169 1.1 thorpej des_key_schedule ks3, des_cblock *ivec, int *num);
170 1.1 thorpej
171 1.1 thorpej int des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
172 1.1 thorpej des_cblock *iv);
173 1.1 thorpej int des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
174 1.1 thorpej des_cblock *iv);
175 1.1 thorpej #ifdef PERL5
176 1.1 thorpej char *des_crypt(const char *buf,const char *salt);
177 1.1 thorpej #else
178 1.1 thorpej /* some stupid compilers complain because I have declared char instead
179 1.1 thorpej * of const char */
180 1.1 thorpej #if 1
181 1.1 thorpej char *crypt(const char *buf,const char *salt);
182 1.1 thorpej #else
183 1.1 thorpej char *crypt();
184 1.1 thorpej #endif
185 1.1 thorpej #endif
186 1.1 thorpej void des_ofb_encrypt(unsigned char *in,unsigned char *out,
187 1.1 thorpej int numbits,long length,des_key_schedule schedule,des_cblock *ivec);
188 1.1 thorpej void des_pcbc_encrypt(des_cblock *input,des_cblock *output,long length,
189 1.1 thorpej des_key_schedule schedule,des_cblock *ivec,int enc);
190 1.1 thorpej DES_LONG des_quad_cksum(des_cblock *input,des_cblock *output,
191 1.1 thorpej long length,int out_count,des_cblock *seed);
192 1.1 thorpej void des_random_seed(des_cblock key);
193 1.1 thorpej void des_random_key(des_cblock ret);
194 1.1 thorpej int des_read_password(des_cblock *key,char *prompt,int verify);
195 1.1 thorpej int des_read_2passwords(des_cblock *key1,des_cblock *key2,
196 1.1 thorpej char *prompt,int verify);
197 1.1 thorpej int des_read_pw_string(char *buf,int length,char *prompt,int verify);
198 1.1 thorpej void des_set_odd_parity(des_cblock *key);
199 1.1 thorpej int des_is_weak_key(des_cblock *key);
200 1.1 thorpej int des_set_key(des_cblock *key,des_key_schedule schedule);
201 1.1 thorpej int des_key_sched(des_cblock *key,des_key_schedule schedule);
202 1.1 thorpej void des_string_to_key(char *str,des_cblock *key);
203 1.1 thorpej void des_string_to_2keys(char *str,des_cblock *key1,des_cblock *key2);
204 1.1 thorpej void des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
205 1.1 thorpej des_key_schedule schedule, des_cblock *ivec, int *num, int enc);
206 1.1 thorpej void des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
207 1.1 thorpej des_key_schedule schedule, des_cblock *ivec, int *num);
208 1.1 thorpej
209 1.1 thorpej /* Extra functions from Mark Murray <mark (at) grondar.za> */
210 1.1 thorpej /*
211 1.1 thorpej void des_cblock_print_file(des_cblock *cb, FILE *fp);
212 1.1 thorpej */
213 1.1 thorpej /* The following functions are not in the normal unix build or the
214 1.1 thorpej * SSLeay build. When using the SSLeay build, use RAND_seed()
215 1.1 thorpej * and RAND_bytes() instead. */
216 1.1 thorpej int des_new_random_key(des_cblock *key);
217 1.1 thorpej void des_init_random_number_generator(des_cblock *key);
218 1.1 thorpej void des_set_random_generator_seed(des_cblock *key);
219 1.1 thorpej void des_set_sequence_number(des_cblock new_sequence_number);
220 1.1 thorpej void des_generate_random_block(des_cblock *block);
221 1.1 thorpej
222 1.1 thorpej #else
223 1.1 thorpej
224 1.1 thorpej char *des_options();
225 1.1 thorpej void des_ecb3_encrypt();
226 1.1 thorpej DES_LONG des_cbc_cksum();
227 1.1 thorpej void des_cbc_encrypt();
228 1.1 thorpej void des_ncbc_encrypt();
229 1.1 thorpej void des_xcbc_encrypt();
230 1.1 thorpej void des_3cbc_encrypt();
231 1.1 thorpej void des_cfb_encrypt();
232 1.1 thorpej void des_ede3_cfb64_encrypt();
233 1.1 thorpej void des_ede3_ofb64_encrypt();
234 1.1 thorpej void des_ecb_encrypt();
235 1.1 thorpej void des_encrypt();
236 1.1 thorpej void des_encrypt2();
237 1.1 thorpej void des_ede3_cbc_encrypt();
238 1.1 thorpej int des_enc_read();
239 1.1 thorpej int des_enc_write();
240 1.1 thorpej #ifdef PERL5
241 1.1 thorpej char *des_crypt();
242 1.1 thorpej #else
243 1.1 thorpej char *crypt();
244 1.1 thorpej #endif
245 1.1 thorpej void des_ofb_encrypt();
246 1.1 thorpej void des_pcbc_encrypt();
247 1.1 thorpej DES_LONG des_quad_cksum();
248 1.1 thorpej void des_random_seed();
249 1.1 thorpej void des_random_key();
250 1.1 thorpej int des_read_password();
251 1.1 thorpej int des_read_2passwords();
252 1.1 thorpej int des_read_pw_string();
253 1.1 thorpej void des_set_odd_parity();
254 1.1 thorpej int des_is_weak_key();
255 1.1 thorpej int des_set_key();
256 1.1 thorpej int des_key_sched();
257 1.1 thorpej void des_string_to_key();
258 1.1 thorpej void des_string_to_2keys();
259 1.1 thorpej void des_cfb64_encrypt();
260 1.1 thorpej void des_ofb64_encrypt();
261 1.1 thorpej
262 1.1 thorpej /* Extra functions from Mark Murray <mark (at) grondar.za> */
263 1.1 thorpej void des_cblock_print_file();
264 1.1 thorpej /* The following functions are not in the normal unix build or the
265 1.1 thorpej * SSLeay build. When using the SSLeay build, use RAND_seed()
266 1.1 thorpej * and RAND_bytes() instead. */
267 1.1 thorpej #ifdef FreeBSD
268 1.1 thorpej int des_new_random_key();
269 1.1 thorpej void des_init_random_number_generator();
270 1.1 thorpej void des_set_random_generator_seed();
271 1.1 thorpej void des_set_sequence_number();
272 1.1 thorpej void des_generate_random_block();
273 1.1 thorpej #endif
274 1.1 thorpej
275 1.1 thorpej #endif
276 1.1 thorpej
277 1.1 thorpej #ifdef __cplusplus
278 1.1 thorpej }
279 1.1 thorpej #endif
280 1.1 thorpej
281 1.1 thorpej #endif
282