1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11: #include <signal.h>
12: #include <stdio.h>
13:
14: #ifndef SIGVTALRM
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25: #define NO_ITIMER
26: #endif
27:
28: #ifdef NO_ITIMER
29: #include <sys/types.h>
30: #include <sys/times.h>
31: #else
32: #include <sys/time.h>
33: #endif
34:
35: static int cnt;
36: #ifdef NO_ITIMER
37: char *hz;
38: struct tms tstart, tfinish;
39: #endif
40: #define ITIME 10
41:
42: char *crypt(), *fcrypt();
43:
44: void
45: Stop ()
46: {
47: double elapsed;
48: #ifdef NO_ITIMER
49: (void) times(&tfinish);
50: elapsed = ((tfinish.tms_utime + tfinish.tms_stime) -
51: (tstart.tms_utime + tstart.tms_stime)) / atoi(hz);
52: printf("elapsed time = %d sec, CPU time = %f sec\n", ITIME, elapsed);
53: #else
54: elapsed = ITIME;
55: #endif
56: printf ("Did %f %s()s per second.\n", ((float) cnt) / elapsed,
57: #if defined(FCRYPT)
58: "fcrypt"
59: #else
60: "crypt"
61: #endif
62: );
63: exit (0);
64: }
65:
66:
67:
68:
69:
70:
71:
72: static void clearmem(start, cnt)
73: char *start;
74: int cnt;
75: { while(cnt--)
76: *start++ = '\0';
77: }
78:
79: main ()
80: {
81: char *s;
82: #ifdef NO_ITIMER
83: extern char *getenv();
84: #else
85: struct itimerval itv;
86: #endif
87:
88: #ifdef NO_ITIMER
89: if ((hz = getenv("HZ")) == NULL) {
90: fprintf(stderr, "HZ environment parameter undefined\n");
91: exit(1);
92: }
93: #endif
94:
95: #ifdef FCRYPT
96: printf("\n");
97: printf("Warning: this version of the speed program may run slower when\n");
98: printf("benchmarking UFC-crypt than previous versions. This is because it\n");
99: printf("stresses the CPU hardware cache in order to get benchmark figures\n");
100: printf("that corresponds closer to the performance that can be expected in\n");
101: printf("a password cracker.\n\n");
102: #endif
103:
104: printf ("Running %s for %d seconds of virtual time ...\n",
105: #ifdef FCRYPT
106: "UFC-crypt",
107: #else
108: "crypt(libc)",
109: #endif
110: ITIME);
111:
112: #ifdef FCRYPT
113: init_des ();
114: #endif
115:
116: #ifdef NO_ITIMER
117: signal(SIGALRM, Stop);
118: switch (fork()) {
119: case -1:
120: perror("fork failed");
121: exit(1);
122: case 0:
123: sleep(10);
124: kill(getppid(), SIGALRM);
125: exit(0);
126: default:
127: (void) times(&tstart);
128: }
129: #else
130: clearmem ((char*)&itv, (int)sizeof (itv));
131: signal (SIGVTALRM, Stop);
132: itv.it_value.tv_sec = ITIME;
133: itv.it_value.tv_usec = 0;
134: setitimer (ITIMER_VIRTUAL, &itv, NULL);
135: #endif
136:
137:
138: s = "fredred";
139: for (cnt = 0;; cnt++)
140: {
141: #ifdef FCRYPT
142: s = fcrypt (s, "eek");
143: #else
144: s = crypt (s, "eek");
145: #endif
146: }
147: }
148:
149:
150:
151:
152:
153: