00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <signal.h>
00012 #include <stdio.h>
00013
00014 #ifndef SIGVTALRM
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #define NO_ITIMER
00026 #endif
00027
00028 #ifdef NO_ITIMER
00029 #include <sys/types.h>
00030 #include <sys/times.h>
00031 #else
00032 #include <sys/time.h>
00033 #endif
00034
00035 static int cnt;
00036 #ifdef NO_ITIMER
00037 char *hz;
00038 struct tms tstart, tfinish;
00039 #endif
00040 #define ITIME 10
00041
00042 char *crypt(), *fcrypt();
00043
00044 void
00045 Stop ()
00046 {
00047 double elapsed;
00048 #ifdef NO_ITIMER
00049 (void) times(&tfinish);
00050 elapsed = ((tfinish.tms_utime + tfinish.tms_stime) -
00051 (tstart.tms_utime + tstart.tms_stime)) / atoi(hz);
00052 printf("elapsed time = %d sec, CPU time = %f sec\n", ITIME, elapsed);
00053 #else
00054 elapsed = ITIME;
00055 #endif
00056 printf ("Did %f %s()s per second.\n", ((float) cnt) / elapsed,
00057 #if defined(FCRYPT)
00058 "fcrypt"
00059 #else
00060 "crypt"
00061 #endif
00062 );
00063 exit (0);
00064 }
00065
00066
00067
00068
00069
00070
00071
00072 static void clearmem(start, cnt)
00073 char *start;
00074 int cnt;
00075 { while(cnt--)
00076 *start++ = '\0';
00077 }
00078
00079 main ()
00080 {
00081 char *s;
00082 #ifdef NO_ITIMER
00083 extern char *getenv();
00084 #else
00085 struct itimerval itv;
00086 #endif
00087
00088 #ifdef NO_ITIMER
00089 if ((hz = getenv("HZ")) == NULL) {
00090 fprintf(stderr, "HZ environment parameter undefined\n");
00091 exit(1);
00092 }
00093 #endif
00094
00095 #ifdef FCRYPT
00096 printf("\n");
00097 printf("Warning: this version of the speed program may run slower when\n");
00098 printf("benchmarking UFC-crypt than previous versions. This is because it\n");
00099 printf("stresses the CPU hardware cache in order to get benchmark figures\n");
00100 printf("that corresponds closer to the performance that can be expected in\n");
00101 printf("a password cracker.\n\n");
00102 #endif
00103
00104 printf ("Running %s for %d seconds of virtual time ...\n",
00105 #ifdef FCRYPT
00106 "UFC-crypt",
00107 #else
00108 "crypt(libc)",
00109 #endif
00110 ITIME);
00111
00112 #ifdef FCRYPT
00113 init_des ();
00114 #endif
00115
00116 #ifdef NO_ITIMER
00117 signal(SIGALRM, Stop);
00118 switch (fork()) {
00119 case -1:
00120 perror("fork failed");
00121 exit(1);
00122 case 0:
00123 sleep(10);
00124 kill(getppid(), SIGALRM);
00125 exit(0);
00126 default:
00127 (void) times(&tstart);
00128 }
00129 #else
00130 memset(&itv, 0, sizeof(itv));
00131 signal (SIGVTALRM, Stop);
00132 itv.it_value.tv_sec = ITIME;
00133 itv.it_value.tv_usec = 0;
00134 setitimer (ITIMER_VIRTUAL, &itv, NULL);
00135 #endif
00136
00137
00138 s = "fredred";
00139 for (cnt = 0;; cnt++)
00140 {
00141 #ifdef FCRYPT
00142 s = fcrypt (s, "eek");
00143 #else
00144 s = crypt (s, "eek");
00145 #endif
00146 }
00147 }
00148
00149
00150
00151
00152
00153