10Sstevel@tonic-gate /* crypto/des/des_opts.c */
20Sstevel@tonic-gate /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
30Sstevel@tonic-gate * All rights reserved.
40Sstevel@tonic-gate *
50Sstevel@tonic-gate * This package is an SSL implementation written
60Sstevel@tonic-gate * by Eric Young (eay@cryptsoft.com).
70Sstevel@tonic-gate * The implementation was written so as to conform with Netscapes SSL.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * This library is free for commercial and non-commercial use as long as
100Sstevel@tonic-gate * the following conditions are aheared to. The following conditions
110Sstevel@tonic-gate * apply to all code found in this distribution, be it the RC4, RSA,
120Sstevel@tonic-gate * lhash, DES, etc., code; not just the SSL code. The SSL documentation
130Sstevel@tonic-gate * included with this distribution is covered by the same copyright terms
140Sstevel@tonic-gate * except that the holder is Tim Hudson (tjh@cryptsoft.com).
150Sstevel@tonic-gate *
160Sstevel@tonic-gate * Copyright remains Eric Young's, and as such any Copyright notices in
170Sstevel@tonic-gate * the code are not to be removed.
180Sstevel@tonic-gate * If this package is used in a product, Eric Young should be given attribution
190Sstevel@tonic-gate * as the author of the parts of the library used.
200Sstevel@tonic-gate * This can be in the form of a textual message at program startup or
210Sstevel@tonic-gate * in documentation (online or textual) provided with the package.
220Sstevel@tonic-gate *
230Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
240Sstevel@tonic-gate * modification, are permitted provided that the following conditions
250Sstevel@tonic-gate * are met:
260Sstevel@tonic-gate * 1. Redistributions of source code must retain the copyright
270Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
280Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
290Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the
300Sstevel@tonic-gate * documentation and/or other materials provided with the distribution.
310Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software
320Sstevel@tonic-gate * must display the following acknowledgement:
330Sstevel@tonic-gate * "This product includes cryptographic software written by
340Sstevel@tonic-gate * Eric Young (eay@cryptsoft.com)"
350Sstevel@tonic-gate * The word 'cryptographic' can be left out if the rouines from the library
360Sstevel@tonic-gate * being used are not cryptographic related :-).
370Sstevel@tonic-gate * 4. If you include any Windows specific code (or a derivative thereof) from
380Sstevel@tonic-gate * the apps directory (application code) you must include an acknowledgement:
390Sstevel@tonic-gate * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
400Sstevel@tonic-gate *
410Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
420Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
430Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
440Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
450Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
460Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
470Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
480Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
490Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
500Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
510Sstevel@tonic-gate * SUCH DAMAGE.
520Sstevel@tonic-gate *
530Sstevel@tonic-gate * The licence and distribution terms for any publically available version or
540Sstevel@tonic-gate * derivative of this code cannot be changed. i.e. this code cannot simply be
550Sstevel@tonic-gate * copied and put under another distribution licence
560Sstevel@tonic-gate * [including the GNU Public Licence.]
570Sstevel@tonic-gate */
580Sstevel@tonic-gate
590Sstevel@tonic-gate /* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
600Sstevel@tonic-gate * This is for machines with 64k code segment size restrictions. */
610Sstevel@tonic-gate
620Sstevel@tonic-gate #if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
630Sstevel@tonic-gate #define TIMES
640Sstevel@tonic-gate #endif
650Sstevel@tonic-gate
660Sstevel@tonic-gate #include <stdio.h>
670Sstevel@tonic-gate #ifndef OPENSSL_SYS_MSDOS
680Sstevel@tonic-gate #include <openssl/e_os2.h>
690Sstevel@tonic-gate #include OPENSSL_UNISTD
700Sstevel@tonic-gate #else
710Sstevel@tonic-gate #include <io.h>
720Sstevel@tonic-gate extern void exit();
730Sstevel@tonic-gate #endif
74*2139Sjp161948
75*2139Sjp161948 #ifndef OPENSSL_SYS_NETWARE
760Sstevel@tonic-gate #include <signal.h>
77*2139Sjp161948 #endif
78*2139Sjp161948
790Sstevel@tonic-gate #ifndef _IRIX
800Sstevel@tonic-gate #include <time.h>
810Sstevel@tonic-gate #endif
820Sstevel@tonic-gate #ifdef TIMES
830Sstevel@tonic-gate #include <sys/types.h>
840Sstevel@tonic-gate #include <sys/times.h>
850Sstevel@tonic-gate #endif
860Sstevel@tonic-gate
870Sstevel@tonic-gate /* Depending on the VMS version, the tms structure is perhaps defined.
880Sstevel@tonic-gate The __TMS macro will show if it was. If it wasn't defined, we should
890Sstevel@tonic-gate undefine TIMES, since that tells the rest of the program how things
900Sstevel@tonic-gate should be handled. -- Richard Levitte */
910Sstevel@tonic-gate #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
920Sstevel@tonic-gate #undef TIMES
930Sstevel@tonic-gate #endif
940Sstevel@tonic-gate
950Sstevel@tonic-gate #ifndef TIMES
960Sstevel@tonic-gate #include <sys/timeb.h>
970Sstevel@tonic-gate #endif
980Sstevel@tonic-gate
990Sstevel@tonic-gate
1000Sstevel@tonic-gate #if defined(sun) || defined(__ultrix)
1010Sstevel@tonic-gate #define _POSIX_SOURCE
1020Sstevel@tonic-gate #include <limits.h>
1030Sstevel@tonic-gate #include <sys/param.h>
1040Sstevel@tonic-gate #endif
1050Sstevel@tonic-gate
1060Sstevel@tonic-gate #include <openssl/des.h>
1070Sstevel@tonic-gate #include "spr.h"
1080Sstevel@tonic-gate
1090Sstevel@tonic-gate #define DES_DEFAULT_OPTIONS
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate #if !defined(PART1) && !defined(PART2) && !defined(PART3) && !defined(PART4)
1120Sstevel@tonic-gate #define PART1
1130Sstevel@tonic-gate #define PART2
1140Sstevel@tonic-gate #define PART3
1150Sstevel@tonic-gate #define PART4
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate #ifdef PART1
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate #undef DES_UNROLL
1210Sstevel@tonic-gate #undef DES_RISC1
1220Sstevel@tonic-gate #undef DES_RISC2
1230Sstevel@tonic-gate #undef DES_PTR
1240Sstevel@tonic-gate #undef D_ENCRYPT
1250Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u4_cisc_idx
1260Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u4_cisc_idx
1270Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u4_cisc_idx
1280Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u4_cisc_idx
1290Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
1300Sstevel@tonic-gate #include "des_enc.c"
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate #define DES_UNROLL
1330Sstevel@tonic-gate #undef DES_RISC1
1340Sstevel@tonic-gate #undef DES_RISC2
1350Sstevel@tonic-gate #undef DES_PTR
1360Sstevel@tonic-gate #undef D_ENCRYPT
1370Sstevel@tonic-gate #undef DES_encrypt1
1380Sstevel@tonic-gate #undef DES_encrypt2
1390Sstevel@tonic-gate #undef DES_encrypt3
1400Sstevel@tonic-gate #undef DES_decrypt3
1410Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u16_cisc_idx
1420Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u16_cisc_idx
1430Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u16_cisc_idx
1440Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u16_cisc_idx
1450Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
1460Sstevel@tonic-gate #include "des_enc.c"
1470Sstevel@tonic-gate
1480Sstevel@tonic-gate #undef DES_UNROLL
1490Sstevel@tonic-gate #define DES_RISC1
1500Sstevel@tonic-gate #undef DES_RISC2
1510Sstevel@tonic-gate #undef DES_PTR
1520Sstevel@tonic-gate #undef D_ENCRYPT
1530Sstevel@tonic-gate #undef DES_encrypt1
1540Sstevel@tonic-gate #undef DES_encrypt2
1550Sstevel@tonic-gate #undef DES_encrypt3
1560Sstevel@tonic-gate #undef DES_decrypt3
1570Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u4_risc1_idx
1580Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u4_risc1_idx
1590Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u4_risc1_idx
1600Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u4_risc1_idx
1610Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
1620Sstevel@tonic-gate #include "des_enc.c"
1630Sstevel@tonic-gate
1640Sstevel@tonic-gate #endif
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate #ifdef PART2
1670Sstevel@tonic-gate
1680Sstevel@tonic-gate #undef DES_UNROLL
1690Sstevel@tonic-gate #undef DES_RISC1
1700Sstevel@tonic-gate #define DES_RISC2
1710Sstevel@tonic-gate #undef DES_PTR
1720Sstevel@tonic-gate #undef D_ENCRYPT
1730Sstevel@tonic-gate #undef DES_encrypt1
1740Sstevel@tonic-gate #undef DES_encrypt2
1750Sstevel@tonic-gate #undef DES_encrypt3
1760Sstevel@tonic-gate #undef DES_decrypt3
1770Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u4_risc2_idx
1780Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u4_risc2_idx
1790Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u4_risc2_idx
1800Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u4_risc2_idx
1810Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
1820Sstevel@tonic-gate #include "des_enc.c"
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate #define DES_UNROLL
1850Sstevel@tonic-gate #define DES_RISC1
1860Sstevel@tonic-gate #undef DES_RISC2
1870Sstevel@tonic-gate #undef DES_PTR
1880Sstevel@tonic-gate #undef D_ENCRYPT
1890Sstevel@tonic-gate #undef DES_encrypt1
1900Sstevel@tonic-gate #undef DES_encrypt2
1910Sstevel@tonic-gate #undef DES_encrypt3
1920Sstevel@tonic-gate #undef DES_decrypt3
1930Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u16_risc1_idx
1940Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u16_risc1_idx
1950Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u16_risc1_idx
1960Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u16_risc1_idx
1970Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
1980Sstevel@tonic-gate #include "des_enc.c"
1990Sstevel@tonic-gate
2000Sstevel@tonic-gate #define DES_UNROLL
2010Sstevel@tonic-gate #undef DES_RISC1
2020Sstevel@tonic-gate #define DES_RISC2
2030Sstevel@tonic-gate #undef DES_PTR
2040Sstevel@tonic-gate #undef D_ENCRYPT
2050Sstevel@tonic-gate #undef DES_encrypt1
2060Sstevel@tonic-gate #undef DES_encrypt2
2070Sstevel@tonic-gate #undef DES_encrypt3
2080Sstevel@tonic-gate #undef DES_decrypt3
2090Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u16_risc2_idx
2100Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u16_risc2_idx
2110Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u16_risc2_idx
2120Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u16_risc2_idx
2130Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
2140Sstevel@tonic-gate #include "des_enc.c"
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate #endif
2170Sstevel@tonic-gate
2180Sstevel@tonic-gate #ifdef PART3
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate #undef DES_UNROLL
2210Sstevel@tonic-gate #undef DES_RISC1
2220Sstevel@tonic-gate #undef DES_RISC2
2230Sstevel@tonic-gate #define DES_PTR
2240Sstevel@tonic-gate #undef D_ENCRYPT
2250Sstevel@tonic-gate #undef DES_encrypt1
2260Sstevel@tonic-gate #undef DES_encrypt2
2270Sstevel@tonic-gate #undef DES_encrypt3
2280Sstevel@tonic-gate #undef DES_decrypt3
2290Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u4_cisc_ptr
2300Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u4_cisc_ptr
2310Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u4_cisc_ptr
2320Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u4_cisc_ptr
2330Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
2340Sstevel@tonic-gate #include "des_enc.c"
2350Sstevel@tonic-gate
2360Sstevel@tonic-gate #define DES_UNROLL
2370Sstevel@tonic-gate #undef DES_RISC1
2380Sstevel@tonic-gate #undef DES_RISC2
2390Sstevel@tonic-gate #define DES_PTR
2400Sstevel@tonic-gate #undef D_ENCRYPT
2410Sstevel@tonic-gate #undef DES_encrypt1
2420Sstevel@tonic-gate #undef DES_encrypt2
2430Sstevel@tonic-gate #undef DES_encrypt3
2440Sstevel@tonic-gate #undef DES_decrypt3
2450Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u16_cisc_ptr
2460Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u16_cisc_ptr
2470Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u16_cisc_ptr
2480Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u16_cisc_ptr
2490Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
2500Sstevel@tonic-gate #include "des_enc.c"
2510Sstevel@tonic-gate
2520Sstevel@tonic-gate #undef DES_UNROLL
2530Sstevel@tonic-gate #define DES_RISC1
2540Sstevel@tonic-gate #undef DES_RISC2
2550Sstevel@tonic-gate #define DES_PTR
2560Sstevel@tonic-gate #undef D_ENCRYPT
2570Sstevel@tonic-gate #undef DES_encrypt1
2580Sstevel@tonic-gate #undef DES_encrypt2
2590Sstevel@tonic-gate #undef DES_encrypt3
2600Sstevel@tonic-gate #undef DES_decrypt3
2610Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u4_risc1_ptr
2620Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u4_risc1_ptr
2630Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u4_risc1_ptr
2640Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u4_risc1_ptr
2650Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
2660Sstevel@tonic-gate #include "des_enc.c"
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate #endif
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate #ifdef PART4
2710Sstevel@tonic-gate
2720Sstevel@tonic-gate #undef DES_UNROLL
2730Sstevel@tonic-gate #undef DES_RISC1
2740Sstevel@tonic-gate #define DES_RISC2
2750Sstevel@tonic-gate #define DES_PTR
2760Sstevel@tonic-gate #undef D_ENCRYPT
2770Sstevel@tonic-gate #undef DES_encrypt1
2780Sstevel@tonic-gate #undef DES_encrypt2
2790Sstevel@tonic-gate #undef DES_encrypt3
2800Sstevel@tonic-gate #undef DES_decrypt3
2810Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u4_risc2_ptr
2820Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u4_risc2_ptr
2830Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u4_risc2_ptr
2840Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u4_risc2_ptr
2850Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
2860Sstevel@tonic-gate #include "des_enc.c"
2870Sstevel@tonic-gate
2880Sstevel@tonic-gate #define DES_UNROLL
2890Sstevel@tonic-gate #define DES_RISC1
2900Sstevel@tonic-gate #undef DES_RISC2
2910Sstevel@tonic-gate #define DES_PTR
2920Sstevel@tonic-gate #undef D_ENCRYPT
2930Sstevel@tonic-gate #undef DES_encrypt1
2940Sstevel@tonic-gate #undef DES_encrypt2
2950Sstevel@tonic-gate #undef DES_encrypt3
2960Sstevel@tonic-gate #undef DES_decrypt3
2970Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u16_risc1_ptr
2980Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u16_risc1_ptr
2990Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u16_risc1_ptr
3000Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u16_risc1_ptr
3010Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
3020Sstevel@tonic-gate #include "des_enc.c"
3030Sstevel@tonic-gate
3040Sstevel@tonic-gate #define DES_UNROLL
3050Sstevel@tonic-gate #undef DES_RISC1
3060Sstevel@tonic-gate #define DES_RISC2
3070Sstevel@tonic-gate #define DES_PTR
3080Sstevel@tonic-gate #undef D_ENCRYPT
3090Sstevel@tonic-gate #undef DES_encrypt1
3100Sstevel@tonic-gate #undef DES_encrypt2
3110Sstevel@tonic-gate #undef DES_encrypt3
3120Sstevel@tonic-gate #undef DES_decrypt3
3130Sstevel@tonic-gate #define DES_encrypt1 des_encrypt_u16_risc2_ptr
3140Sstevel@tonic-gate #define DES_encrypt2 des_encrypt2_u16_risc2_ptr
3150Sstevel@tonic-gate #define DES_encrypt3 des_encrypt3_u16_risc2_ptr
3160Sstevel@tonic-gate #define DES_decrypt3 des_decrypt3_u16_risc2_ptr
3170Sstevel@tonic-gate #undef HEADER_DES_LOCL_H
3180Sstevel@tonic-gate #include "des_enc.c"
3190Sstevel@tonic-gate
3200Sstevel@tonic-gate #endif
3210Sstevel@tonic-gate
3220Sstevel@tonic-gate /* The following if from times(3) man page. It may need to be changed */
3230Sstevel@tonic-gate #ifndef HZ
3240Sstevel@tonic-gate # ifndef CLK_TCK
3250Sstevel@tonic-gate # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
3260Sstevel@tonic-gate # define HZ 100.0
3270Sstevel@tonic-gate # else /* _BSD_CLK_TCK_ */
3280Sstevel@tonic-gate # define HZ ((double)_BSD_CLK_TCK_)
3290Sstevel@tonic-gate # endif
3300Sstevel@tonic-gate # else /* CLK_TCK */
3310Sstevel@tonic-gate # define HZ ((double)CLK_TCK)
3320Sstevel@tonic-gate # endif
3330Sstevel@tonic-gate #endif
3340Sstevel@tonic-gate
3350Sstevel@tonic-gate #define BUFSIZE ((long)1024)
3360Sstevel@tonic-gate long run=0;
3370Sstevel@tonic-gate
3380Sstevel@tonic-gate double Time_F(int s);
3390Sstevel@tonic-gate #ifdef SIGALRM
3400Sstevel@tonic-gate #if defined(__STDC__) || defined(sgi)
3410Sstevel@tonic-gate #define SIGRETTYPE void
3420Sstevel@tonic-gate #else
3430Sstevel@tonic-gate #define SIGRETTYPE int
3440Sstevel@tonic-gate #endif
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate SIGRETTYPE sig_done(int sig);
sig_done(int sig)3470Sstevel@tonic-gate SIGRETTYPE sig_done(int sig)
3480Sstevel@tonic-gate {
3490Sstevel@tonic-gate signal(SIGALRM,sig_done);
3500Sstevel@tonic-gate run=0;
3510Sstevel@tonic-gate #ifdef LINT
3520Sstevel@tonic-gate sig=sig;
3530Sstevel@tonic-gate #endif
3540Sstevel@tonic-gate }
3550Sstevel@tonic-gate #endif
3560Sstevel@tonic-gate
3570Sstevel@tonic-gate #define START 0
3580Sstevel@tonic-gate #define STOP 1
3590Sstevel@tonic-gate
Time_F(int s)3600Sstevel@tonic-gate double Time_F(int s)
3610Sstevel@tonic-gate {
3620Sstevel@tonic-gate double ret;
3630Sstevel@tonic-gate #ifdef TIMES
3640Sstevel@tonic-gate static struct tms tstart,tend;
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate if (s == START)
3670Sstevel@tonic-gate {
3680Sstevel@tonic-gate times(&tstart);
3690Sstevel@tonic-gate return(0);
3700Sstevel@tonic-gate }
3710Sstevel@tonic-gate else
3720Sstevel@tonic-gate {
3730Sstevel@tonic-gate times(&tend);
3740Sstevel@tonic-gate ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
3750Sstevel@tonic-gate return((ret == 0.0)?1e-6:ret);
3760Sstevel@tonic-gate }
3770Sstevel@tonic-gate #else /* !times() */
3780Sstevel@tonic-gate static struct timeb tstart,tend;
3790Sstevel@tonic-gate long i;
3800Sstevel@tonic-gate
3810Sstevel@tonic-gate if (s == START)
3820Sstevel@tonic-gate {
3830Sstevel@tonic-gate ftime(&tstart);
3840Sstevel@tonic-gate return(0);
3850Sstevel@tonic-gate }
3860Sstevel@tonic-gate else
3870Sstevel@tonic-gate {
3880Sstevel@tonic-gate ftime(&tend);
3890Sstevel@tonic-gate i=(long)tend.millitm-(long)tstart.millitm;
3900Sstevel@tonic-gate ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
3910Sstevel@tonic-gate return((ret == 0.0)?1e-6:ret);
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate #endif
3940Sstevel@tonic-gate }
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate #ifdef SIGALRM
3970Sstevel@tonic-gate #define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
3980Sstevel@tonic-gate #else
3990Sstevel@tonic-gate #define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
4000Sstevel@tonic-gate #endif
4010Sstevel@tonic-gate
4020Sstevel@tonic-gate #define time_it(func,name,index) \
4030Sstevel@tonic-gate print_name(name); \
4040Sstevel@tonic-gate Time_F(START); \
4050Sstevel@tonic-gate for (count=0,run=1; COND(cb); count++) \
4060Sstevel@tonic-gate { \
4070Sstevel@tonic-gate unsigned long d[2]; \
4080Sstevel@tonic-gate func(d,&sch,DES_ENCRYPT); \
4090Sstevel@tonic-gate } \
4100Sstevel@tonic-gate tm[index]=Time_F(STOP); \
4110Sstevel@tonic-gate fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
4120Sstevel@tonic-gate tm[index]=((double)COUNT(cb))/tm[index];
4130Sstevel@tonic-gate
4140Sstevel@tonic-gate #define print_it(name,index) \
4150Sstevel@tonic-gate fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
4160Sstevel@tonic-gate tm[index]*8,1.0e6/tm[index]);
4170Sstevel@tonic-gate
main(int argc,char ** argv)4180Sstevel@tonic-gate int main(int argc, char **argv)
4190Sstevel@tonic-gate {
4200Sstevel@tonic-gate long count;
4210Sstevel@tonic-gate static unsigned char buf[BUFSIZE];
4220Sstevel@tonic-gate static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
4230Sstevel@tonic-gate static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
4240Sstevel@tonic-gate static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
4250Sstevel@tonic-gate DES_key_schedule sch,sch2,sch3;
4260Sstevel@tonic-gate double d,tm[16],max=0;
4270Sstevel@tonic-gate int rank[16];
4280Sstevel@tonic-gate char *str[16];
4290Sstevel@tonic-gate int max_idx=0,i,num=0,j;
4300Sstevel@tonic-gate #ifndef SIGALARM
4310Sstevel@tonic-gate long ca,cb,cc,cd,ce;
4320Sstevel@tonic-gate #endif
4330Sstevel@tonic-gate
4340Sstevel@tonic-gate for (i=0; i<12; i++)
4350Sstevel@tonic-gate {
4360Sstevel@tonic-gate tm[i]=0.0;
4370Sstevel@tonic-gate rank[i]=0;
4380Sstevel@tonic-gate }
4390Sstevel@tonic-gate
4400Sstevel@tonic-gate #ifndef TIMES
4410Sstevel@tonic-gate fprintf(stderr,"To get the most accurate results, try to run this\n");
4420Sstevel@tonic-gate fprintf(stderr,"program when this computer is idle.\n");
4430Sstevel@tonic-gate #endif
4440Sstevel@tonic-gate
4450Sstevel@tonic-gate DES_set_key_unchecked(&key,&sch);
4460Sstevel@tonic-gate DES_set_key_unchecked(&key2,&sch2);
4470Sstevel@tonic-gate DES_set_key_unchecked(&key3,&sch3);
4480Sstevel@tonic-gate
4490Sstevel@tonic-gate #ifndef SIGALRM
4500Sstevel@tonic-gate fprintf(stderr,"First we calculate the approximate speed ...\n");
4510Sstevel@tonic-gate DES_set_key_unchecked(&key,sch);
4520Sstevel@tonic-gate count=10;
4530Sstevel@tonic-gate do {
4540Sstevel@tonic-gate long i;
4550Sstevel@tonic-gate unsigned long data[2];
4560Sstevel@tonic-gate
4570Sstevel@tonic-gate count*=2;
4580Sstevel@tonic-gate Time_F(START);
4590Sstevel@tonic-gate for (i=count; i; i--)
4600Sstevel@tonic-gate DES_encrypt1(data,&(sch[0]),DES_ENCRYPT);
4610Sstevel@tonic-gate d=Time_F(STOP);
4620Sstevel@tonic-gate } while (d < 3.0);
4630Sstevel@tonic-gate ca=count;
4640Sstevel@tonic-gate cb=count*3;
4650Sstevel@tonic-gate cc=count*3*8/BUFSIZE+1;
4660Sstevel@tonic-gate cd=count*8/BUFSIZE+1;
4670Sstevel@tonic-gate
4680Sstevel@tonic-gate ce=count/20+1;
4690Sstevel@tonic-gate #define COND(d) (count != (d))
4700Sstevel@tonic-gate #define COUNT(d) (d)
4710Sstevel@tonic-gate #else
4720Sstevel@tonic-gate #define COND(c) (run)
4730Sstevel@tonic-gate #define COUNT(d) (count)
4740Sstevel@tonic-gate signal(SIGALRM,sig_done);
4750Sstevel@tonic-gate alarm(10);
4760Sstevel@tonic-gate #endif
4770Sstevel@tonic-gate
4780Sstevel@tonic-gate #ifdef PART1
4790Sstevel@tonic-gate time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0);
4800Sstevel@tonic-gate time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1);
4810Sstevel@tonic-gate time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2);
4820Sstevel@tonic-gate num+=3;
4830Sstevel@tonic-gate #endif
4840Sstevel@tonic-gate #ifdef PART2
4850Sstevel@tonic-gate time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3);
4860Sstevel@tonic-gate time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4);
4870Sstevel@tonic-gate time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5);
4880Sstevel@tonic-gate num+=3;
4890Sstevel@tonic-gate #endif
4900Sstevel@tonic-gate #ifdef PART3
4910Sstevel@tonic-gate time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6);
4920Sstevel@tonic-gate time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7);
4930Sstevel@tonic-gate time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8);
4940Sstevel@tonic-gate num+=3;
4950Sstevel@tonic-gate #endif
4960Sstevel@tonic-gate #ifdef PART4
4970Sstevel@tonic-gate time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9);
4980Sstevel@tonic-gate time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10);
4990Sstevel@tonic-gate time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11);
5000Sstevel@tonic-gate num+=3;
5010Sstevel@tonic-gate #endif
5020Sstevel@tonic-gate
5030Sstevel@tonic-gate #ifdef PART1
5040Sstevel@tonic-gate str[0]=" 4 c i";
5050Sstevel@tonic-gate print_it("des_encrypt_u4_cisc_idx ",0);
5060Sstevel@tonic-gate max=tm[0];
5070Sstevel@tonic-gate max_idx=0;
5080Sstevel@tonic-gate str[1]="16 c i";
5090Sstevel@tonic-gate print_it("des_encrypt_u16_cisc_idx ",1);
5100Sstevel@tonic-gate if (max < tm[1]) { max=tm[1]; max_idx=1; }
5110Sstevel@tonic-gate str[2]=" 4 r1 i";
5120Sstevel@tonic-gate print_it("des_encrypt_u4_risc1_idx ",2);
5130Sstevel@tonic-gate if (max < tm[2]) { max=tm[2]; max_idx=2; }
5140Sstevel@tonic-gate #endif
5150Sstevel@tonic-gate #ifdef PART2
5160Sstevel@tonic-gate str[3]="16 r1 i";
5170Sstevel@tonic-gate print_it("des_encrypt_u16_risc1_idx",3);
5180Sstevel@tonic-gate if (max < tm[3]) { max=tm[3]; max_idx=3; }
5190Sstevel@tonic-gate str[4]=" 4 r2 i";
5200Sstevel@tonic-gate print_it("des_encrypt_u4_risc2_idx ",4);
5210Sstevel@tonic-gate if (max < tm[4]) { max=tm[4]; max_idx=4; }
5220Sstevel@tonic-gate str[5]="16 r2 i";
5230Sstevel@tonic-gate print_it("des_encrypt_u16_risc2_idx",5);
5240Sstevel@tonic-gate if (max < tm[5]) { max=tm[5]; max_idx=5; }
5250Sstevel@tonic-gate #endif
5260Sstevel@tonic-gate #ifdef PART3
5270Sstevel@tonic-gate str[6]=" 4 c p";
5280Sstevel@tonic-gate print_it("des_encrypt_u4_cisc_ptr ",6);
5290Sstevel@tonic-gate if (max < tm[6]) { max=tm[6]; max_idx=6; }
5300Sstevel@tonic-gate str[7]="16 c p";
5310Sstevel@tonic-gate print_it("des_encrypt_u16_cisc_ptr ",7);
5320Sstevel@tonic-gate if (max < tm[7]) { max=tm[7]; max_idx=7; }
5330Sstevel@tonic-gate str[8]=" 4 r1 p";
5340Sstevel@tonic-gate print_it("des_encrypt_u4_risc1_ptr ",8);
5350Sstevel@tonic-gate if (max < tm[8]) { max=tm[8]; max_idx=8; }
5360Sstevel@tonic-gate #endif
5370Sstevel@tonic-gate #ifdef PART4
5380Sstevel@tonic-gate str[9]="16 r1 p";
5390Sstevel@tonic-gate print_it("des_encrypt_u16_risc1_ptr",9);
5400Sstevel@tonic-gate if (max < tm[9]) { max=tm[9]; max_idx=9; }
5410Sstevel@tonic-gate str[10]=" 4 r2 p";
5420Sstevel@tonic-gate print_it("des_encrypt_u4_risc2_ptr ",10);
5430Sstevel@tonic-gate if (max < tm[10]) { max=tm[10]; max_idx=10; }
5440Sstevel@tonic-gate str[11]="16 r2 p";
5450Sstevel@tonic-gate print_it("des_encrypt_u16_risc2_ptr",11);
5460Sstevel@tonic-gate if (max < tm[11]) { max=tm[11]; max_idx=11; }
5470Sstevel@tonic-gate #endif
5480Sstevel@tonic-gate printf("options des ecb/s\n");
5490Sstevel@tonic-gate printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
5500Sstevel@tonic-gate d=tm[max_idx];
5510Sstevel@tonic-gate tm[max_idx]= -2.0;
5520Sstevel@tonic-gate max= -1.0;
5530Sstevel@tonic-gate for (;;)
5540Sstevel@tonic-gate {
5550Sstevel@tonic-gate for (i=0; i<12; i++)
5560Sstevel@tonic-gate {
5570Sstevel@tonic-gate if (max < tm[i]) { max=tm[i]; j=i; }
5580Sstevel@tonic-gate }
5590Sstevel@tonic-gate if (max < 0.0) break;
5600Sstevel@tonic-gate printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
5610Sstevel@tonic-gate tm[j]= -2.0;
5620Sstevel@tonic-gate max= -1.0;
5630Sstevel@tonic-gate }
5640Sstevel@tonic-gate
5650Sstevel@tonic-gate switch (max_idx)
5660Sstevel@tonic-gate {
5670Sstevel@tonic-gate case 0:
5680Sstevel@tonic-gate printf("-DDES_DEFAULT_OPTIONS\n");
5690Sstevel@tonic-gate break;
5700Sstevel@tonic-gate case 1:
5710Sstevel@tonic-gate printf("-DDES_UNROLL\n");
5720Sstevel@tonic-gate break;
5730Sstevel@tonic-gate case 2:
5740Sstevel@tonic-gate printf("-DDES_RISC1\n");
5750Sstevel@tonic-gate break;
5760Sstevel@tonic-gate case 3:
5770Sstevel@tonic-gate printf("-DDES_UNROLL -DDES_RISC1\n");
5780Sstevel@tonic-gate break;
5790Sstevel@tonic-gate case 4:
5800Sstevel@tonic-gate printf("-DDES_RISC2\n");
5810Sstevel@tonic-gate break;
5820Sstevel@tonic-gate case 5:
5830Sstevel@tonic-gate printf("-DDES_UNROLL -DDES_RISC2\n");
5840Sstevel@tonic-gate break;
5850Sstevel@tonic-gate case 6:
5860Sstevel@tonic-gate printf("-DDES_PTR\n");
5870Sstevel@tonic-gate break;
5880Sstevel@tonic-gate case 7:
5890Sstevel@tonic-gate printf("-DDES_UNROLL -DDES_PTR\n");
5900Sstevel@tonic-gate break;
5910Sstevel@tonic-gate case 8:
5920Sstevel@tonic-gate printf("-DDES_RISC1 -DDES_PTR\n");
5930Sstevel@tonic-gate break;
5940Sstevel@tonic-gate case 9:
5950Sstevel@tonic-gate printf("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n");
5960Sstevel@tonic-gate break;
5970Sstevel@tonic-gate case 10:
5980Sstevel@tonic-gate printf("-DDES_RISC2 -DDES_PTR\n");
5990Sstevel@tonic-gate break;
6000Sstevel@tonic-gate case 11:
6010Sstevel@tonic-gate printf("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n");
6020Sstevel@tonic-gate break;
6030Sstevel@tonic-gate }
6040Sstevel@tonic-gate exit(0);
6050Sstevel@tonic-gate #if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
6060Sstevel@tonic-gate return(0);
6070Sstevel@tonic-gate #endif
6080Sstevel@tonic-gate }
609