home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume29 / libdes / part01 / speed.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-04  |  2.0 KB  |  82 lines

  1. /* speed.c */
  2. /* Copyright (C) 1992 Eric Young - see COPYING for more details */
  3. #include <stdio.h>
  4. #include <signal.h>
  5. #include <sys/types.h>
  6. #include <sys/times.h>
  7. #include "des.h"
  8.  
  9. /* The following if from times(3) man page.  It may need to be changed */
  10. #define HZ    60.0
  11.  
  12. #define BUFSIZE    (1024*8)
  13.  
  14. long run=0;
  15. int sig_done() { run=0; }
  16.  
  17. main(argc,argv)
  18. int argc;
  19. char *argv[];
  20.     {
  21.     struct tms tstart,tend;
  22.     int count;
  23.     FILE *in,*out,*std;
  24.     static unsigned char buf[BUFSIZE];
  25.     static des_cblock key={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
  26.     des_key_schedule sch;
  27.     int i,j,k,enc,cat=0,catfd;
  28.     double d,a,b,c;
  29.  
  30.     signal(SIGALRM,sig_done);
  31.  
  32.     printf("Doing set_key for 60 seconds\n");
  33.     alarm(60);
  34.     times(&tstart);
  35.     for (count=0,run=1; run; count++)
  36.         des_set_key(key,sch);
  37.     times(&tend);
  38.     d=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
  39.     printf("%d set_key's in %.2f second\n",
  40.         count,d);
  41.     a=((double)count)/d;
  42.  
  43.     printf("Doing des_ecb_encrypt's for 60 seconds\n");
  44.     alarm(60);
  45.     times(&tstart);
  46.     for (count=0,run=1; run; count++)
  47.         des_ecb_encrypt(buf,buf,&(sch[0]),DES_ENCRYPT);
  48.     times(&tend);
  49.     d=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
  50.     printf("%d des_ecb_encrypt's in %.2f second\n",
  51.         count,d);
  52.     b=((double)count*8)/d;
  53.  
  54.     printf("Doing des_cbc_encrypt on %d byte blocks for 60 seconds\n",
  55.         BUFSIZE);
  56.     alarm(60);
  57.     times(&tstart);
  58.     for (count=0,run=1; run; count++)
  59.         des_cbc_encrypt(buf,buf,BUFSIZE,&(sch[0]),
  60.         &(key[0]),DES_ENCRYPT);
  61.     times(&tend);
  62.     d=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
  63.     printf("%d des_cbc_encrypt's of %d byte blocks in %.2f second\n",
  64.         count,BUFSIZE,d);
  65.     c=((double)count*BUFSIZE)/d;
  66.  
  67.     printf("Doing crypt for 60 seconds\n");
  68.     alarm(60);
  69.     times(&tstart);
  70.     for (count=0,run=1; run; count++)
  71.         crypt("testing1","ef");
  72.     times(&tend);
  73.     d=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
  74.     printf("%d crypts in %.2f second\n",count,d);
  75.     d=((double)count)/d;
  76.  
  77.     printf("set_key       per sec = %12.2f\n",a);
  78.     printf("DES ecb bytes per sec = %12.2f\n",b);
  79.     printf("DES cbc bytes per sec = %12.2f\n",c);
  80.     printf("crypt         per sec = %12.2f\n",d);
  81.     }
  82.