home *** CD-ROM | disk | FTP | other *** search
- /* speed.c */
- /* Copyright (C) 1992 Eric Young - see COPYING for more details */
- #include <stdio.h>
- #include <signal.h>
- #include <sys/types.h>
- #include <sys/times.h>
- #include "des.h"
-
- /* The following if from times(3) man page. It may need to be changed */
- #define HZ 60.0
-
- #define BUFSIZE (1024*8)
-
- long run=0;
- int sig_done() { run=0; }
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- struct tms tstart,tend;
- int count;
- FILE *in,*out,*std;
- static unsigned char buf[BUFSIZE];
- static des_cblock key={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
- des_key_schedule sch;
- int i,j,k,enc,cat=0,catfd;
- double d,a,b,c;
-
- signal(SIGALRM,sig_done);
-
- printf("Doing set_key for 60 seconds\n");
- alarm(60);
- times(&tstart);
- for (count=0,run=1; run; count++)
- des_set_key(key,sch);
- times(&tend);
- d=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
- printf("%d set_key's in %.2f second\n",
- count,d);
- a=((double)count)/d;
-
- printf("Doing des_ecb_encrypt's for 60 seconds\n");
- alarm(60);
- times(&tstart);
- for (count=0,run=1; run; count++)
- des_ecb_encrypt(buf,buf,&(sch[0]),DES_ENCRYPT);
- times(&tend);
- d=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
- printf("%d des_ecb_encrypt's in %.2f second\n",
- count,d);
- b=((double)count*8)/d;
-
- printf("Doing des_cbc_encrypt on %d byte blocks for 60 seconds\n",
- BUFSIZE);
- alarm(60);
- times(&tstart);
- for (count=0,run=1; run; count++)
- des_cbc_encrypt(buf,buf,BUFSIZE,&(sch[0]),
- &(key[0]),DES_ENCRYPT);
- times(&tend);
- d=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
- printf("%d des_cbc_encrypt's of %d byte blocks in %.2f second\n",
- count,BUFSIZE,d);
- c=((double)count*BUFSIZE)/d;
-
- printf("Doing crypt for 60 seconds\n");
- alarm(60);
- times(&tstart);
- for (count=0,run=1; run; count++)
- crypt("testing1","ef");
- times(&tend);
- d=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
- printf("%d crypts in %.2f second\n",count,d);
- d=((double)count)/d;
-
- printf("set_key per sec = %12.2f\n",a);
- printf("DES ecb bytes per sec = %12.2f\n",b);
- printf("DES cbc bytes per sec = %12.2f\n",c);
- printf("crypt per sec = %12.2f\n",d);
- }
-