sl@0
|
1 |
/* crypto/des/des_opts.c */
|
sl@0
|
2 |
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
*
|
sl@0
|
5 |
* This package is an SSL implementation written
|
sl@0
|
6 |
* by Eric Young (eay@cryptsoft.com).
|
sl@0
|
7 |
* The implementation was written so as to conform with Netscapes SSL.
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* This library is free for commercial and non-commercial use as long as
|
sl@0
|
10 |
* the following conditions are aheared to. The following conditions
|
sl@0
|
11 |
* apply to all code found in this distribution, be it the RC4, RSA,
|
sl@0
|
12 |
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
sl@0
|
13 |
* included with this distribution is covered by the same copyright terms
|
sl@0
|
14 |
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
sl@0
|
15 |
*
|
sl@0
|
16 |
* Copyright remains Eric Young's, and as such any Copyright notices in
|
sl@0
|
17 |
* the code are not to be removed.
|
sl@0
|
18 |
* If this package is used in a product, Eric Young should be given attribution
|
sl@0
|
19 |
* as the author of the parts of the library used.
|
sl@0
|
20 |
* This can be in the form of a textual message at program startup or
|
sl@0
|
21 |
* in documentation (online or textual) provided with the package.
|
sl@0
|
22 |
*
|
sl@0
|
23 |
* Redistribution and use in source and binary forms, with or without
|
sl@0
|
24 |
* modification, are permitted provided that the following conditions
|
sl@0
|
25 |
* are met:
|
sl@0
|
26 |
* 1. Redistributions of source code must retain the copyright
|
sl@0
|
27 |
* notice, this list of conditions and the following disclaimer.
|
sl@0
|
28 |
* 2. Redistributions in binary form must reproduce the above copyright
|
sl@0
|
29 |
* notice, this list of conditions and the following disclaimer in the
|
sl@0
|
30 |
* documentation and/or other materials provided with the distribution.
|
sl@0
|
31 |
* 3. All advertising materials mentioning features or use of this software
|
sl@0
|
32 |
* must display the following acknowledgement:
|
sl@0
|
33 |
* "This product includes cryptographic software written by
|
sl@0
|
34 |
* Eric Young (eay@cryptsoft.com)"
|
sl@0
|
35 |
* The word 'cryptographic' can be left out if the rouines from the library
|
sl@0
|
36 |
* being used are not cryptographic related :-).
|
sl@0
|
37 |
* 4. If you include any Windows specific code (or a derivative thereof) from
|
sl@0
|
38 |
* the apps directory (application code) you must include an acknowledgement:
|
sl@0
|
39 |
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
sl@0
|
40 |
*
|
sl@0
|
41 |
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
sl@0
|
42 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
sl@0
|
43 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
sl@0
|
44 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
sl@0
|
45 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
sl@0
|
46 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
sl@0
|
47 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
sl@0
|
48 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
sl@0
|
49 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
sl@0
|
50 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
sl@0
|
51 |
* SUCH DAMAGE.
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* The licence and distribution terms for any publically available version or
|
sl@0
|
54 |
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
sl@0
|
55 |
* copied and put under another distribution licence
|
sl@0
|
56 |
* [including the GNU Public Licence.]
|
sl@0
|
57 |
*/
|
sl@0
|
58 |
|
sl@0
|
59 |
/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
|
sl@0
|
60 |
* This is for machines with 64k code segment size restrictions. */
|
sl@0
|
61 |
|
sl@0
|
62 |
#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
|
sl@0
|
63 |
#define TIMES
|
sl@0
|
64 |
#endif
|
sl@0
|
65 |
|
sl@0
|
66 |
#include <stdio.h>
|
sl@0
|
67 |
#ifndef OPENSSL_SYS_MSDOS
|
sl@0
|
68 |
#include <openssl/e_os2.h>
|
sl@0
|
69 |
#include OPENSSL_UNISTD
|
sl@0
|
70 |
#else
|
sl@0
|
71 |
#include <io.h>
|
sl@0
|
72 |
extern void exit();
|
sl@0
|
73 |
#endif
|
sl@0
|
74 |
|
sl@0
|
75 |
#ifndef OPENSSL_SYS_NETWARE
|
sl@0
|
76 |
#include <signal.h>
|
sl@0
|
77 |
#endif
|
sl@0
|
78 |
|
sl@0
|
79 |
#ifndef _IRIX
|
sl@0
|
80 |
#include <time.h>
|
sl@0
|
81 |
#endif
|
sl@0
|
82 |
#ifdef TIMES
|
sl@0
|
83 |
#include <sys/types.h>
|
sl@0
|
84 |
#include <sys/times.h>
|
sl@0
|
85 |
#endif
|
sl@0
|
86 |
|
sl@0
|
87 |
/* Depending on the VMS version, the tms structure is perhaps defined.
|
sl@0
|
88 |
The __TMS macro will show if it was. If it wasn't defined, we should
|
sl@0
|
89 |
undefine TIMES, since that tells the rest of the program how things
|
sl@0
|
90 |
should be handled. -- Richard Levitte */
|
sl@0
|
91 |
#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
|
sl@0
|
92 |
#undef TIMES
|
sl@0
|
93 |
#endif
|
sl@0
|
94 |
|
sl@0
|
95 |
#ifndef TIMES
|
sl@0
|
96 |
#include <sys/timeb.h>
|
sl@0
|
97 |
#endif
|
sl@0
|
98 |
|
sl@0
|
99 |
|
sl@0
|
100 |
#if defined(sun) || defined(__ultrix)
|
sl@0
|
101 |
#define _POSIX_SOURCE
|
sl@0
|
102 |
#include <limits.h>
|
sl@0
|
103 |
#include <sys/param.h>
|
sl@0
|
104 |
#endif
|
sl@0
|
105 |
|
sl@0
|
106 |
#include <openssl/des.h>
|
sl@0
|
107 |
#include "spr.h"
|
sl@0
|
108 |
|
sl@0
|
109 |
#define DES_DEFAULT_OPTIONS
|
sl@0
|
110 |
|
sl@0
|
111 |
#if !defined(PART1) && !defined(PART2) && !defined(PART3) && !defined(PART4)
|
sl@0
|
112 |
#define PART1
|
sl@0
|
113 |
#define PART2
|
sl@0
|
114 |
#define PART3
|
sl@0
|
115 |
#define PART4
|
sl@0
|
116 |
#endif
|
sl@0
|
117 |
|
sl@0
|
118 |
#ifdef PART1
|
sl@0
|
119 |
|
sl@0
|
120 |
#undef DES_UNROLL
|
sl@0
|
121 |
#undef DES_RISC1
|
sl@0
|
122 |
#undef DES_RISC2
|
sl@0
|
123 |
#undef DES_PTR
|
sl@0
|
124 |
#undef D_ENCRYPT
|
sl@0
|
125 |
#define DES_encrypt1 des_encrypt_u4_cisc_idx
|
sl@0
|
126 |
#define DES_encrypt2 des_encrypt2_u4_cisc_idx
|
sl@0
|
127 |
#define DES_encrypt3 des_encrypt3_u4_cisc_idx
|
sl@0
|
128 |
#define DES_decrypt3 des_decrypt3_u4_cisc_idx
|
sl@0
|
129 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
130 |
#include "des_enc.c"
|
sl@0
|
131 |
|
sl@0
|
132 |
#define DES_UNROLL
|
sl@0
|
133 |
#undef DES_RISC1
|
sl@0
|
134 |
#undef DES_RISC2
|
sl@0
|
135 |
#undef DES_PTR
|
sl@0
|
136 |
#undef D_ENCRYPT
|
sl@0
|
137 |
#undef DES_encrypt1
|
sl@0
|
138 |
#undef DES_encrypt2
|
sl@0
|
139 |
#undef DES_encrypt3
|
sl@0
|
140 |
#undef DES_decrypt3
|
sl@0
|
141 |
#define DES_encrypt1 des_encrypt_u16_cisc_idx
|
sl@0
|
142 |
#define DES_encrypt2 des_encrypt2_u16_cisc_idx
|
sl@0
|
143 |
#define DES_encrypt3 des_encrypt3_u16_cisc_idx
|
sl@0
|
144 |
#define DES_decrypt3 des_decrypt3_u16_cisc_idx
|
sl@0
|
145 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
146 |
#include "des_enc.c"
|
sl@0
|
147 |
|
sl@0
|
148 |
#undef DES_UNROLL
|
sl@0
|
149 |
#define DES_RISC1
|
sl@0
|
150 |
#undef DES_RISC2
|
sl@0
|
151 |
#undef DES_PTR
|
sl@0
|
152 |
#undef D_ENCRYPT
|
sl@0
|
153 |
#undef DES_encrypt1
|
sl@0
|
154 |
#undef DES_encrypt2
|
sl@0
|
155 |
#undef DES_encrypt3
|
sl@0
|
156 |
#undef DES_decrypt3
|
sl@0
|
157 |
#define DES_encrypt1 des_encrypt_u4_risc1_idx
|
sl@0
|
158 |
#define DES_encrypt2 des_encrypt2_u4_risc1_idx
|
sl@0
|
159 |
#define DES_encrypt3 des_encrypt3_u4_risc1_idx
|
sl@0
|
160 |
#define DES_decrypt3 des_decrypt3_u4_risc1_idx
|
sl@0
|
161 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
162 |
#include "des_enc.c"
|
sl@0
|
163 |
|
sl@0
|
164 |
#endif
|
sl@0
|
165 |
|
sl@0
|
166 |
#ifdef PART2
|
sl@0
|
167 |
|
sl@0
|
168 |
#undef DES_UNROLL
|
sl@0
|
169 |
#undef DES_RISC1
|
sl@0
|
170 |
#define DES_RISC2
|
sl@0
|
171 |
#undef DES_PTR
|
sl@0
|
172 |
#undef D_ENCRYPT
|
sl@0
|
173 |
#undef DES_encrypt1
|
sl@0
|
174 |
#undef DES_encrypt2
|
sl@0
|
175 |
#undef DES_encrypt3
|
sl@0
|
176 |
#undef DES_decrypt3
|
sl@0
|
177 |
#define DES_encrypt1 des_encrypt_u4_risc2_idx
|
sl@0
|
178 |
#define DES_encrypt2 des_encrypt2_u4_risc2_idx
|
sl@0
|
179 |
#define DES_encrypt3 des_encrypt3_u4_risc2_idx
|
sl@0
|
180 |
#define DES_decrypt3 des_decrypt3_u4_risc2_idx
|
sl@0
|
181 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
182 |
#include "des_enc.c"
|
sl@0
|
183 |
|
sl@0
|
184 |
#define DES_UNROLL
|
sl@0
|
185 |
#define DES_RISC1
|
sl@0
|
186 |
#undef DES_RISC2
|
sl@0
|
187 |
#undef DES_PTR
|
sl@0
|
188 |
#undef D_ENCRYPT
|
sl@0
|
189 |
#undef DES_encrypt1
|
sl@0
|
190 |
#undef DES_encrypt2
|
sl@0
|
191 |
#undef DES_encrypt3
|
sl@0
|
192 |
#undef DES_decrypt3
|
sl@0
|
193 |
#define DES_encrypt1 des_encrypt_u16_risc1_idx
|
sl@0
|
194 |
#define DES_encrypt2 des_encrypt2_u16_risc1_idx
|
sl@0
|
195 |
#define DES_encrypt3 des_encrypt3_u16_risc1_idx
|
sl@0
|
196 |
#define DES_decrypt3 des_decrypt3_u16_risc1_idx
|
sl@0
|
197 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
198 |
#include "des_enc.c"
|
sl@0
|
199 |
|
sl@0
|
200 |
#define DES_UNROLL
|
sl@0
|
201 |
#undef DES_RISC1
|
sl@0
|
202 |
#define DES_RISC2
|
sl@0
|
203 |
#undef DES_PTR
|
sl@0
|
204 |
#undef D_ENCRYPT
|
sl@0
|
205 |
#undef DES_encrypt1
|
sl@0
|
206 |
#undef DES_encrypt2
|
sl@0
|
207 |
#undef DES_encrypt3
|
sl@0
|
208 |
#undef DES_decrypt3
|
sl@0
|
209 |
#define DES_encrypt1 des_encrypt_u16_risc2_idx
|
sl@0
|
210 |
#define DES_encrypt2 des_encrypt2_u16_risc2_idx
|
sl@0
|
211 |
#define DES_encrypt3 des_encrypt3_u16_risc2_idx
|
sl@0
|
212 |
#define DES_decrypt3 des_decrypt3_u16_risc2_idx
|
sl@0
|
213 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
214 |
#include "des_enc.c"
|
sl@0
|
215 |
|
sl@0
|
216 |
#endif
|
sl@0
|
217 |
|
sl@0
|
218 |
#ifdef PART3
|
sl@0
|
219 |
|
sl@0
|
220 |
#undef DES_UNROLL
|
sl@0
|
221 |
#undef DES_RISC1
|
sl@0
|
222 |
#undef DES_RISC2
|
sl@0
|
223 |
#define DES_PTR
|
sl@0
|
224 |
#undef D_ENCRYPT
|
sl@0
|
225 |
#undef DES_encrypt1
|
sl@0
|
226 |
#undef DES_encrypt2
|
sl@0
|
227 |
#undef DES_encrypt3
|
sl@0
|
228 |
#undef DES_decrypt3
|
sl@0
|
229 |
#define DES_encrypt1 des_encrypt_u4_cisc_ptr
|
sl@0
|
230 |
#define DES_encrypt2 des_encrypt2_u4_cisc_ptr
|
sl@0
|
231 |
#define DES_encrypt3 des_encrypt3_u4_cisc_ptr
|
sl@0
|
232 |
#define DES_decrypt3 des_decrypt3_u4_cisc_ptr
|
sl@0
|
233 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
234 |
#include "des_enc.c"
|
sl@0
|
235 |
|
sl@0
|
236 |
#define DES_UNROLL
|
sl@0
|
237 |
#undef DES_RISC1
|
sl@0
|
238 |
#undef DES_RISC2
|
sl@0
|
239 |
#define DES_PTR
|
sl@0
|
240 |
#undef D_ENCRYPT
|
sl@0
|
241 |
#undef DES_encrypt1
|
sl@0
|
242 |
#undef DES_encrypt2
|
sl@0
|
243 |
#undef DES_encrypt3
|
sl@0
|
244 |
#undef DES_decrypt3
|
sl@0
|
245 |
#define DES_encrypt1 des_encrypt_u16_cisc_ptr
|
sl@0
|
246 |
#define DES_encrypt2 des_encrypt2_u16_cisc_ptr
|
sl@0
|
247 |
#define DES_encrypt3 des_encrypt3_u16_cisc_ptr
|
sl@0
|
248 |
#define DES_decrypt3 des_decrypt3_u16_cisc_ptr
|
sl@0
|
249 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
250 |
#include "des_enc.c"
|
sl@0
|
251 |
|
sl@0
|
252 |
#undef DES_UNROLL
|
sl@0
|
253 |
#define DES_RISC1
|
sl@0
|
254 |
#undef DES_RISC2
|
sl@0
|
255 |
#define DES_PTR
|
sl@0
|
256 |
#undef D_ENCRYPT
|
sl@0
|
257 |
#undef DES_encrypt1
|
sl@0
|
258 |
#undef DES_encrypt2
|
sl@0
|
259 |
#undef DES_encrypt3
|
sl@0
|
260 |
#undef DES_decrypt3
|
sl@0
|
261 |
#define DES_encrypt1 des_encrypt_u4_risc1_ptr
|
sl@0
|
262 |
#define DES_encrypt2 des_encrypt2_u4_risc1_ptr
|
sl@0
|
263 |
#define DES_encrypt3 des_encrypt3_u4_risc1_ptr
|
sl@0
|
264 |
#define DES_decrypt3 des_decrypt3_u4_risc1_ptr
|
sl@0
|
265 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
266 |
#include "des_enc.c"
|
sl@0
|
267 |
|
sl@0
|
268 |
#endif
|
sl@0
|
269 |
|
sl@0
|
270 |
#ifdef PART4
|
sl@0
|
271 |
|
sl@0
|
272 |
#undef DES_UNROLL
|
sl@0
|
273 |
#undef DES_RISC1
|
sl@0
|
274 |
#define DES_RISC2
|
sl@0
|
275 |
#define DES_PTR
|
sl@0
|
276 |
#undef D_ENCRYPT
|
sl@0
|
277 |
#undef DES_encrypt1
|
sl@0
|
278 |
#undef DES_encrypt2
|
sl@0
|
279 |
#undef DES_encrypt3
|
sl@0
|
280 |
#undef DES_decrypt3
|
sl@0
|
281 |
#define DES_encrypt1 des_encrypt_u4_risc2_ptr
|
sl@0
|
282 |
#define DES_encrypt2 des_encrypt2_u4_risc2_ptr
|
sl@0
|
283 |
#define DES_encrypt3 des_encrypt3_u4_risc2_ptr
|
sl@0
|
284 |
#define DES_decrypt3 des_decrypt3_u4_risc2_ptr
|
sl@0
|
285 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
286 |
#include "des_enc.c"
|
sl@0
|
287 |
|
sl@0
|
288 |
#define DES_UNROLL
|
sl@0
|
289 |
#define DES_RISC1
|
sl@0
|
290 |
#undef DES_RISC2
|
sl@0
|
291 |
#define DES_PTR
|
sl@0
|
292 |
#undef D_ENCRYPT
|
sl@0
|
293 |
#undef DES_encrypt1
|
sl@0
|
294 |
#undef DES_encrypt2
|
sl@0
|
295 |
#undef DES_encrypt3
|
sl@0
|
296 |
#undef DES_decrypt3
|
sl@0
|
297 |
#define DES_encrypt1 des_encrypt_u16_risc1_ptr
|
sl@0
|
298 |
#define DES_encrypt2 des_encrypt2_u16_risc1_ptr
|
sl@0
|
299 |
#define DES_encrypt3 des_encrypt3_u16_risc1_ptr
|
sl@0
|
300 |
#define DES_decrypt3 des_decrypt3_u16_risc1_ptr
|
sl@0
|
301 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
302 |
#include "des_enc.c"
|
sl@0
|
303 |
|
sl@0
|
304 |
#define DES_UNROLL
|
sl@0
|
305 |
#undef DES_RISC1
|
sl@0
|
306 |
#define DES_RISC2
|
sl@0
|
307 |
#define DES_PTR
|
sl@0
|
308 |
#undef D_ENCRYPT
|
sl@0
|
309 |
#undef DES_encrypt1
|
sl@0
|
310 |
#undef DES_encrypt2
|
sl@0
|
311 |
#undef DES_encrypt3
|
sl@0
|
312 |
#undef DES_decrypt3
|
sl@0
|
313 |
#define DES_encrypt1 des_encrypt_u16_risc2_ptr
|
sl@0
|
314 |
#define DES_encrypt2 des_encrypt2_u16_risc2_ptr
|
sl@0
|
315 |
#define DES_encrypt3 des_encrypt3_u16_risc2_ptr
|
sl@0
|
316 |
#define DES_decrypt3 des_decrypt3_u16_risc2_ptr
|
sl@0
|
317 |
#undef HEADER_DES_LOCL_H
|
sl@0
|
318 |
#include "des_enc.c"
|
sl@0
|
319 |
|
sl@0
|
320 |
#endif
|
sl@0
|
321 |
|
sl@0
|
322 |
/* The following if from times(3) man page. It may need to be changed */
|
sl@0
|
323 |
#ifndef HZ
|
sl@0
|
324 |
# ifndef CLK_TCK
|
sl@0
|
325 |
# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
|
sl@0
|
326 |
# define HZ 100.0
|
sl@0
|
327 |
# else /* _BSD_CLK_TCK_ */
|
sl@0
|
328 |
# define HZ ((double)_BSD_CLK_TCK_)
|
sl@0
|
329 |
# endif
|
sl@0
|
330 |
# else /* CLK_TCK */
|
sl@0
|
331 |
# define HZ ((double)CLK_TCK)
|
sl@0
|
332 |
# endif
|
sl@0
|
333 |
#endif
|
sl@0
|
334 |
|
sl@0
|
335 |
#define BUFSIZE ((long)1024)
|
sl@0
|
336 |
long run=0;
|
sl@0
|
337 |
|
sl@0
|
338 |
double Time_F(int s);
|
sl@0
|
339 |
#ifdef SIGALRM
|
sl@0
|
340 |
#if defined(__STDC__) || defined(sgi)
|
sl@0
|
341 |
#define SIGRETTYPE void
|
sl@0
|
342 |
#else
|
sl@0
|
343 |
#define SIGRETTYPE int
|
sl@0
|
344 |
#endif
|
sl@0
|
345 |
|
sl@0
|
346 |
SIGRETTYPE sig_done(int sig);
|
sl@0
|
347 |
SIGRETTYPE sig_done(int sig)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
signal(SIGALRM,sig_done);
|
sl@0
|
350 |
run=0;
|
sl@0
|
351 |
#ifdef LINT
|
sl@0
|
352 |
sig=sig;
|
sl@0
|
353 |
#endif
|
sl@0
|
354 |
}
|
sl@0
|
355 |
#endif
|
sl@0
|
356 |
|
sl@0
|
357 |
#define START 0
|
sl@0
|
358 |
#define STOP 1
|
sl@0
|
359 |
|
sl@0
|
360 |
double Time_F(int s)
|
sl@0
|
361 |
{
|
sl@0
|
362 |
double ret;
|
sl@0
|
363 |
#ifdef TIMES
|
sl@0
|
364 |
static struct tms tstart,tend;
|
sl@0
|
365 |
|
sl@0
|
366 |
if (s == START)
|
sl@0
|
367 |
{
|
sl@0
|
368 |
times(&tstart);
|
sl@0
|
369 |
return(0);
|
sl@0
|
370 |
}
|
sl@0
|
371 |
else
|
sl@0
|
372 |
{
|
sl@0
|
373 |
times(&tend);
|
sl@0
|
374 |
ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
|
sl@0
|
375 |
return((ret == 0.0)?1e-6:ret);
|
sl@0
|
376 |
}
|
sl@0
|
377 |
#else /* !times() */
|
sl@0
|
378 |
static struct timeb tstart,tend;
|
sl@0
|
379 |
long i;
|
sl@0
|
380 |
|
sl@0
|
381 |
if (s == START)
|
sl@0
|
382 |
{
|
sl@0
|
383 |
ftime(&tstart);
|
sl@0
|
384 |
return(0);
|
sl@0
|
385 |
}
|
sl@0
|
386 |
else
|
sl@0
|
387 |
{
|
sl@0
|
388 |
ftime(&tend);
|
sl@0
|
389 |
i=(long)tend.millitm-(long)tstart.millitm;
|
sl@0
|
390 |
ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
|
sl@0
|
391 |
return((ret == 0.0)?1e-6:ret);
|
sl@0
|
392 |
}
|
sl@0
|
393 |
#endif
|
sl@0
|
394 |
}
|
sl@0
|
395 |
|
sl@0
|
396 |
#ifdef SIGALRM
|
sl@0
|
397 |
#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
|
sl@0
|
398 |
#else
|
sl@0
|
399 |
#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
|
sl@0
|
400 |
#endif
|
sl@0
|
401 |
|
sl@0
|
402 |
#define time_it(func,name,index) \
|
sl@0
|
403 |
print_name(name); \
|
sl@0
|
404 |
Time_F(START); \
|
sl@0
|
405 |
for (count=0,run=1; COND(cb); count++) \
|
sl@0
|
406 |
{ \
|
sl@0
|
407 |
unsigned long d[2]; \
|
sl@0
|
408 |
func(d,&sch,DES_ENCRYPT); \
|
sl@0
|
409 |
} \
|
sl@0
|
410 |
tm[index]=Time_F(STOP); \
|
sl@0
|
411 |
fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
|
sl@0
|
412 |
tm[index]=((double)COUNT(cb))/tm[index];
|
sl@0
|
413 |
|
sl@0
|
414 |
#define print_it(name,index) \
|
sl@0
|
415 |
fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
|
sl@0
|
416 |
tm[index]*8,1.0e6/tm[index]);
|
sl@0
|
417 |
|
sl@0
|
418 |
int main(int argc, char **argv)
|
sl@0
|
419 |
{
|
sl@0
|
420 |
long count;
|
sl@0
|
421 |
static unsigned char buf[BUFSIZE];
|
sl@0
|
422 |
static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
|
sl@0
|
423 |
static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
|
sl@0
|
424 |
static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
|
sl@0
|
425 |
DES_key_schedule sch,sch2,sch3;
|
sl@0
|
426 |
double d,tm[16],max=0;
|
sl@0
|
427 |
int rank[16];
|
sl@0
|
428 |
char *str[16];
|
sl@0
|
429 |
int max_idx=0,i,num=0,j;
|
sl@0
|
430 |
#ifndef SIGALARM
|
sl@0
|
431 |
long ca,cb,cc,cd,ce;
|
sl@0
|
432 |
#endif
|
sl@0
|
433 |
|
sl@0
|
434 |
for (i=0; i<12; i++)
|
sl@0
|
435 |
{
|
sl@0
|
436 |
tm[i]=0.0;
|
sl@0
|
437 |
rank[i]=0;
|
sl@0
|
438 |
}
|
sl@0
|
439 |
|
sl@0
|
440 |
#ifndef TIMES
|
sl@0
|
441 |
fprintf(stderr,"To get the most accurate results, try to run this\n");
|
sl@0
|
442 |
fprintf(stderr,"program when this computer is idle.\n");
|
sl@0
|
443 |
#endif
|
sl@0
|
444 |
|
sl@0
|
445 |
DES_set_key_unchecked(&key,&sch);
|
sl@0
|
446 |
DES_set_key_unchecked(&key2,&sch2);
|
sl@0
|
447 |
DES_set_key_unchecked(&key3,&sch3);
|
sl@0
|
448 |
|
sl@0
|
449 |
#ifndef SIGALRM
|
sl@0
|
450 |
fprintf(stderr,"First we calculate the approximate speed ...\n");
|
sl@0
|
451 |
DES_set_key_unchecked(&key,sch);
|
sl@0
|
452 |
count=10;
|
sl@0
|
453 |
do {
|
sl@0
|
454 |
long i;
|
sl@0
|
455 |
unsigned long data[2];
|
sl@0
|
456 |
|
sl@0
|
457 |
count*=2;
|
sl@0
|
458 |
Time_F(START);
|
sl@0
|
459 |
for (i=count; i; i--)
|
sl@0
|
460 |
DES_encrypt1(data,&(sch[0]),DES_ENCRYPT);
|
sl@0
|
461 |
d=Time_F(STOP);
|
sl@0
|
462 |
} while (d < 3.0);
|
sl@0
|
463 |
ca=count;
|
sl@0
|
464 |
cb=count*3;
|
sl@0
|
465 |
cc=count*3*8/BUFSIZE+1;
|
sl@0
|
466 |
cd=count*8/BUFSIZE+1;
|
sl@0
|
467 |
|
sl@0
|
468 |
ce=count/20+1;
|
sl@0
|
469 |
#define COND(d) (count != (d))
|
sl@0
|
470 |
#define COUNT(d) (d)
|
sl@0
|
471 |
#else
|
sl@0
|
472 |
#define COND(c) (run)
|
sl@0
|
473 |
#define COUNT(d) (count)
|
sl@0
|
474 |
signal(SIGALRM,sig_done);
|
sl@0
|
475 |
alarm(10);
|
sl@0
|
476 |
#endif
|
sl@0
|
477 |
|
sl@0
|
478 |
#ifdef PART1
|
sl@0
|
479 |
time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0);
|
sl@0
|
480 |
time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1);
|
sl@0
|
481 |
time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2);
|
sl@0
|
482 |
num+=3;
|
sl@0
|
483 |
#endif
|
sl@0
|
484 |
#ifdef PART2
|
sl@0
|
485 |
time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3);
|
sl@0
|
486 |
time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4);
|
sl@0
|
487 |
time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5);
|
sl@0
|
488 |
num+=3;
|
sl@0
|
489 |
#endif
|
sl@0
|
490 |
#ifdef PART3
|
sl@0
|
491 |
time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6);
|
sl@0
|
492 |
time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7);
|
sl@0
|
493 |
time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8);
|
sl@0
|
494 |
num+=3;
|
sl@0
|
495 |
#endif
|
sl@0
|
496 |
#ifdef PART4
|
sl@0
|
497 |
time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9);
|
sl@0
|
498 |
time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10);
|
sl@0
|
499 |
time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11);
|
sl@0
|
500 |
num+=3;
|
sl@0
|
501 |
#endif
|
sl@0
|
502 |
|
sl@0
|
503 |
#ifdef PART1
|
sl@0
|
504 |
str[0]=" 4 c i";
|
sl@0
|
505 |
print_it("des_encrypt_u4_cisc_idx ",0);
|
sl@0
|
506 |
max=tm[0];
|
sl@0
|
507 |
max_idx=0;
|
sl@0
|
508 |
str[1]="16 c i";
|
sl@0
|
509 |
print_it("des_encrypt_u16_cisc_idx ",1);
|
sl@0
|
510 |
if (max < tm[1]) { max=tm[1]; max_idx=1; }
|
sl@0
|
511 |
str[2]=" 4 r1 i";
|
sl@0
|
512 |
print_it("des_encrypt_u4_risc1_idx ",2);
|
sl@0
|
513 |
if (max < tm[2]) { max=tm[2]; max_idx=2; }
|
sl@0
|
514 |
#endif
|
sl@0
|
515 |
#ifdef PART2
|
sl@0
|
516 |
str[3]="16 r1 i";
|
sl@0
|
517 |
print_it("des_encrypt_u16_risc1_idx",3);
|
sl@0
|
518 |
if (max < tm[3]) { max=tm[3]; max_idx=3; }
|
sl@0
|
519 |
str[4]=" 4 r2 i";
|
sl@0
|
520 |
print_it("des_encrypt_u4_risc2_idx ",4);
|
sl@0
|
521 |
if (max < tm[4]) { max=tm[4]; max_idx=4; }
|
sl@0
|
522 |
str[5]="16 r2 i";
|
sl@0
|
523 |
print_it("des_encrypt_u16_risc2_idx",5);
|
sl@0
|
524 |
if (max < tm[5]) { max=tm[5]; max_idx=5; }
|
sl@0
|
525 |
#endif
|
sl@0
|
526 |
#ifdef PART3
|
sl@0
|
527 |
str[6]=" 4 c p";
|
sl@0
|
528 |
print_it("des_encrypt_u4_cisc_ptr ",6);
|
sl@0
|
529 |
if (max < tm[6]) { max=tm[6]; max_idx=6; }
|
sl@0
|
530 |
str[7]="16 c p";
|
sl@0
|
531 |
print_it("des_encrypt_u16_cisc_ptr ",7);
|
sl@0
|
532 |
if (max < tm[7]) { max=tm[7]; max_idx=7; }
|
sl@0
|
533 |
str[8]=" 4 r1 p";
|
sl@0
|
534 |
print_it("des_encrypt_u4_risc1_ptr ",8);
|
sl@0
|
535 |
if (max < tm[8]) { max=tm[8]; max_idx=8; }
|
sl@0
|
536 |
#endif
|
sl@0
|
537 |
#ifdef PART4
|
sl@0
|
538 |
str[9]="16 r1 p";
|
sl@0
|
539 |
print_it("des_encrypt_u16_risc1_ptr",9);
|
sl@0
|
540 |
if (max < tm[9]) { max=tm[9]; max_idx=9; }
|
sl@0
|
541 |
str[10]=" 4 r2 p";
|
sl@0
|
542 |
print_it("des_encrypt_u4_risc2_ptr ",10);
|
sl@0
|
543 |
if (max < tm[10]) { max=tm[10]; max_idx=10; }
|
sl@0
|
544 |
str[11]="16 r2 p";
|
sl@0
|
545 |
print_it("des_encrypt_u16_risc2_ptr",11);
|
sl@0
|
546 |
if (max < tm[11]) { max=tm[11]; max_idx=11; }
|
sl@0
|
547 |
#endif
|
sl@0
|
548 |
printf("options des ecb/s\n");
|
sl@0
|
549 |
printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
|
sl@0
|
550 |
d=tm[max_idx];
|
sl@0
|
551 |
tm[max_idx]= -2.0;
|
sl@0
|
552 |
max= -1.0;
|
sl@0
|
553 |
for (;;)
|
sl@0
|
554 |
{
|
sl@0
|
555 |
for (i=0; i<12; i++)
|
sl@0
|
556 |
{
|
sl@0
|
557 |
if (max < tm[i]) { max=tm[i]; j=i; }
|
sl@0
|
558 |
}
|
sl@0
|
559 |
if (max < 0.0) break;
|
sl@0
|
560 |
printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
|
sl@0
|
561 |
tm[j]= -2.0;
|
sl@0
|
562 |
max= -1.0;
|
sl@0
|
563 |
}
|
sl@0
|
564 |
|
sl@0
|
565 |
switch (max_idx)
|
sl@0
|
566 |
{
|
sl@0
|
567 |
case 0:
|
sl@0
|
568 |
printf("-DDES_DEFAULT_OPTIONS\n");
|
sl@0
|
569 |
break;
|
sl@0
|
570 |
case 1:
|
sl@0
|
571 |
printf("-DDES_UNROLL\n");
|
sl@0
|
572 |
break;
|
sl@0
|
573 |
case 2:
|
sl@0
|
574 |
printf("-DDES_RISC1\n");
|
sl@0
|
575 |
break;
|
sl@0
|
576 |
case 3:
|
sl@0
|
577 |
printf("-DDES_UNROLL -DDES_RISC1\n");
|
sl@0
|
578 |
break;
|
sl@0
|
579 |
case 4:
|
sl@0
|
580 |
printf("-DDES_RISC2\n");
|
sl@0
|
581 |
break;
|
sl@0
|
582 |
case 5:
|
sl@0
|
583 |
printf("-DDES_UNROLL -DDES_RISC2\n");
|
sl@0
|
584 |
break;
|
sl@0
|
585 |
case 6:
|
sl@0
|
586 |
printf("-DDES_PTR\n");
|
sl@0
|
587 |
break;
|
sl@0
|
588 |
case 7:
|
sl@0
|
589 |
printf("-DDES_UNROLL -DDES_PTR\n");
|
sl@0
|
590 |
break;
|
sl@0
|
591 |
case 8:
|
sl@0
|
592 |
printf("-DDES_RISC1 -DDES_PTR\n");
|
sl@0
|
593 |
break;
|
sl@0
|
594 |
case 9:
|
sl@0
|
595 |
printf("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n");
|
sl@0
|
596 |
break;
|
sl@0
|
597 |
case 10:
|
sl@0
|
598 |
printf("-DDES_RISC2 -DDES_PTR\n");
|
sl@0
|
599 |
break;
|
sl@0
|
600 |
case 11:
|
sl@0
|
601 |
printf("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n");
|
sl@0
|
602 |
break;
|
sl@0
|
603 |
}
|
sl@0
|
604 |
exit(0);
|
sl@0
|
605 |
#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
|
sl@0
|
606 |
return(0);
|
sl@0
|
607 |
#endif
|
sl@0
|
608 |
}
|