1 /* apps/speed.c -*- mode:C; c-file-style: "eay" -*- */
2 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
59 /* most of this code has been pilfered from my libdes speed.c program */
63 #define RSA_SECONDS 10
64 #define DSA_SECONDS 10
66 /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */
67 /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */
70 #define PROG speed_main
78 #ifdef OPENSSL_NO_STDIO
81 #include <openssl/crypto.h>
82 #include <openssl/rand.h>
83 #include <openssl/err.h>
84 #include <openssl/evp.h>
85 #include <openssl/objects.h>
86 #if !defined(OPENSSL_SYS_MSDOS)
87 #include OPENSSL_UNISTD
90 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(OPENSSL_SYS_MACOSX)
92 #elif !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
95 #if !defined(_UNICOS) && !defined(__OpenBSD__) && !defined(sgi) && !defined(__FreeBSD__) && !(defined(__bsdi) || defined(__bsdi__)) && !defined(_AIX) && !defined(OPENSSL_SYS_MPE) && !defined(__NetBSD__) /* FIXME */
103 # include <sys/types.h>
104 # include <sys/times.h>
107 # include <sys/time.h>
108 # include <sys/resource.h>
111 /* Depending on the VMS version, the tms structure is perhaps defined.
112 The __TMS macro will show if it was. If it wasn't defined, we should
113 undefine TIMES, since that tells the rest of the program how things
114 should be handled. -- Richard Levitte */
115 #if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
120 #include <sys/timeb.h>
123 #if !defined(TIMES) && !defined(TIMEB) && !defined(USE_TOD)
124 #error "It seems neither struct tms nor struct timeb is supported in this platform!"
127 #if defined(sun) || defined(__ultrix)
128 #define _POSIX_SOURCE
130 #include <sys/param.h>
133 #ifndef OPENSSL_NO_DES
134 #include <openssl/des_old.h>
136 #ifndef OPENSSL_NO_MD2
137 #include <openssl/md2.h>
139 #ifndef OPENSSL_NO_MDC2
140 #include <openssl/mdc2.h>
142 #ifndef OPENSSL_NO_MD4
143 #include <openssl/md4.h>
145 #ifndef OPENSSL_NO_MD5
146 #include <openssl/md5.h>
148 #ifndef OPENSSL_NO_HMAC
149 #include <openssl/hmac.h>
151 #include <openssl/evp.h>
152 #ifndef OPENSSL_NO_SHA
153 #include <openssl/sha.h>
155 #ifndef OPENSSL_NO_RIPEMD
156 #include <openssl/ripemd.h>
158 #ifndef OPENSSL_NO_RC4
159 #include <openssl/rc4.h>
161 #ifndef OPENSSL_NO_RC5
162 #include <openssl/rc5.h>
164 #ifndef OPENSSL_NO_RC2
165 #include <openssl/rc2.h>
167 #ifndef OPENSSL_NO_IDEA
168 #include <openssl/idea.h>
170 #ifndef OPENSSL_NO_BF
171 #include <openssl/blowfish.h>
173 #ifndef OPENSSL_NO_CAST
174 #include <openssl/cast.h>
176 #ifndef OPENSSL_NO_RSA
177 #include <openssl/rsa.h>
178 #include "./testrsa.h"
180 #include <openssl/x509.h>
181 #ifndef OPENSSL_NO_DSA
182 #include "./testdsa.h"
185 /* The following if from times(3) man page. It may need to be changed */
188 # define HZ ((double)sysconf(_SC_CLK_TCK))
191 # ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
193 # else /* _BSD_CLK_TCK_ */
194 # define HZ ((double)_BSD_CLK_TCK_)
197 # define HZ ((double)CLK_TCK)
202 #if !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WINDOWS) && !defined(OPENSSL_SYS_MACINTOSH_CLASSIC) && !defined(OPENSSL_SYS_OS2)
207 #define BUFSIZE ((long)1024*8+1)
210 static char ftime_used = 0, times_used = 0, gettimeofday_used = 0, getrusage_used = 0;
212 static int usertime=1;
214 static double Time_F(int s);
215 static void print_message(const char *s,long num,int length);
216 static void pkey_print_message(char *str,char *str2,long num,int bits,int sec);
217 static void print_result(int alg,int run_no,int count,double time_used);
219 static int do_multi(int multi);
226 static const char *names[ALGOR_NUM]={
227 "md2","mdc2","md4","md5","hmac(md5)","sha1","rmd160","rc4",
228 "des cbc","des ede3","idea cbc",
229 "rc2 cbc","rc5-32/12 cbc","blowfish cbc","cast cbc"};
230 static double results[ALGOR_NUM][SIZE_NUM];
231 static int lengths[SIZE_NUM]={8,64,256,1024,8*1024};
232 static double rsa_results[RSA_NUM][2];
233 static double dsa_results[DSA_NUM][2];
236 #if defined(__STDC__) || defined(sgi) || defined(_AIX)
237 #define SIGRETTYPE void
239 #define SIGRETTYPE int
242 static SIGRETTYPE sig_done(int sig);
243 static SIGRETTYPE sig_done(int sig)
245 signal(SIGALRM,sig_done);
256 static double Time_F(int s)
263 static struct rusage tstart,tend;
268 getrusage(RUSAGE_SELF,&tstart);
275 getrusage(RUSAGE_SELF,&tend);
276 i=(long)tend.ru_utime.tv_usec-(long)tstart.ru_utime.tv_usec;
277 ret=((double)(tend.ru_utime.tv_sec-tstart.ru_utime.tv_sec))
278 +((double)i)/1000000.0;
279 return((ret < 0.001)?0.001:ret);
284 static struct timeval tstart,tend;
287 gettimeofday_used = 1;
290 gettimeofday(&tstart,NULL);
295 gettimeofday(&tend,NULL);
296 i=(long)tend.tv_usec-(long)tstart.tv_usec;
297 ret=((double)(tend.tv_sec-tstart.tv_sec))+((double)i)/1000000.0;
298 return((ret < 0.001)?0.001:ret);
301 #else /* ndef USE_TOD */
306 static struct tms tstart,tend;
317 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
318 return((ret < 1e-3)?1e-3:ret);
321 # endif /* times() */
322 # if defined(TIMES) && defined(TIMEB)
327 static struct timeb tstart,tend;
339 i=(long)tend.millitm-(long)tstart.millitm;
340 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
341 return((ret < 0.001)?0.001:ret);
348 int MAIN(int, char **);
350 int MAIN(int argc, char **argv)
353 unsigned char *buf=NULL,*buf2=NULL;
355 long count,rsa_count,save_count=0;
357 #ifndef OPENSSL_NO_RSA
360 unsigned char md[EVP_MAX_MD_SIZE];
361 #ifndef OPENSSL_NO_MD2
362 unsigned char md2[MD2_DIGEST_LENGTH];
364 #ifndef OPENSSL_NO_MDC2
365 unsigned char mdc2[MDC2_DIGEST_LENGTH];
367 #ifndef OPENSSL_NO_MD4
368 unsigned char md4[MD4_DIGEST_LENGTH];
370 #ifndef OPENSSL_NO_MD5
371 unsigned char md5[MD5_DIGEST_LENGTH];
372 unsigned char hmac[MD5_DIGEST_LENGTH];
374 #ifndef OPENSSL_NO_SHA
375 unsigned char sha[SHA_DIGEST_LENGTH];
377 #ifndef OPENSSL_NO_RIPEMD
378 unsigned char rmd160[RIPEMD160_DIGEST_LENGTH];
380 #ifndef OPENSSL_NO_RC4
383 #ifndef OPENSSL_NO_RC5
386 #ifndef OPENSSL_NO_RC2
389 #ifndef OPENSSL_NO_IDEA
390 IDEA_KEY_SCHEDULE idea_ks;
392 #ifndef OPENSSL_NO_BF
395 #ifndef OPENSSL_NO_CAST
398 static unsigned char key16[16]=
399 {0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
400 0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
402 #ifndef OPENSSL_NO_DES
403 DES_cblock *buf_as_des_cblock = NULL;
404 static des_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
405 static des_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
406 static des_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
407 DES_key_schedule sch;
408 DES_key_schedule sch2;
409 DES_key_schedule sch3;
421 #define D_CBC_IDEA 10
425 #define D_CBC_CAST 14
428 long c[ALGOR_NUM][SIZE_NUM];
436 #ifndef OPENSSL_NO_RSA
437 RSA *rsa_key[RSA_NUM];
438 long rsa_c[RSA_NUM][2];
439 static unsigned int rsa_bits[RSA_NUM]={512,1024,2048,4096};
440 static unsigned char *rsa_data[RSA_NUM]=
441 {test512,test1024,test2048,test4096};
442 static int rsa_data_length[RSA_NUM]={
443 sizeof(test512),sizeof(test1024),
444 sizeof(test2048),sizeof(test4096)};
446 #ifndef OPENSSL_NO_DSA
447 DSA *dsa_key[DSA_NUM];
448 long dsa_c[DSA_NUM][2];
449 static unsigned int dsa_bits[DSA_NUM]={512,1024,2048};
451 int rsa_doit[RSA_NUM];
452 int dsa_doit[DSA_NUM];
455 const EVP_CIPHER *evp_cipher=NULL;
456 const EVP_MD *evp_md=NULL;
467 memset(results, 0, sizeof(results));
468 #ifndef OPENSSL_NO_DSA
469 memset(dsa_key,0,sizeof(dsa_key));
473 if ((bio_err=BIO_new(BIO_s_file())) != NULL)
474 BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT);
476 #ifndef OPENSSL_NO_RSA
477 memset(rsa_key,0,sizeof(rsa_key));
478 for (i=0; i<RSA_NUM; i++)
482 if ((buf=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
484 BIO_printf(bio_err,"out of memory\n");
487 #ifndef OPENSSL_NO_DES
488 buf_as_des_cblock = (des_cblock *)buf;
490 if ((buf2=(unsigned char *)OPENSSL_malloc((int)BUFSIZE)) == NULL)
492 BIO_printf(bio_err,"out of memory\n");
496 memset(c,0,sizeof(c));
497 memset(iv,0,sizeof(iv));
499 for (i=0; i<ALGOR_NUM; i++)
501 for (i=0; i<RSA_NUM; i++)
503 for (i=0; i<DSA_NUM; i++)
511 if ((argc > 0) && (strcmp(*argv,"-elapsed") == 0))
514 j--; /* Otherwise, -elapsed gets confused with
517 else if ((argc > 0) && (strcmp(*argv,"-evp") == 0))
523 BIO_printf(bio_err,"no EVP given\n");
526 evp_cipher=EVP_get_cipherbyname(*argv);
529 evp_md=EVP_get_digestbyname(*argv);
531 if(!evp_cipher && !evp_md)
533 BIO_printf(bio_err,"%s is an unknown cipher or digest\n",*argv);
538 else if (argc > 0 && !strcmp(*argv,"-decrypt"))
541 j--; /* Otherwise, -elapsed gets confused with
544 else if ((argc > 0) && (strcmp(*argv,"-engine") == 0))
550 BIO_printf(bio_err,"no engine given\n");
553 e = setup_engine(bio_err, *argv, 0);
554 /* j will be increased again further down. We just
555 don't want speed to confuse an engine with an
556 algorithm, especially when none is given (which
557 means all of them should be run) */
561 else if ((argc > 0) && (strcmp(*argv,"-multi") == 0))
567 BIO_printf(bio_err,"no multi count given\n");
573 BIO_printf(bio_err,"bad multi count\n");
576 j--; /* Otherwise, -mr gets confused with
580 else if (argc > 0 && !strcmp(*argv,"-mr"))
583 j--; /* Otherwise, -mr gets confused with
587 #ifndef OPENSSL_NO_MD2
588 if (strcmp(*argv,"md2") == 0) doit[D_MD2]=1;
591 #ifndef OPENSSL_NO_MDC2
592 if (strcmp(*argv,"mdc2") == 0) doit[D_MDC2]=1;
595 #ifndef OPENSSL_NO_MD4
596 if (strcmp(*argv,"md4") == 0) doit[D_MD4]=1;
599 #ifndef OPENSSL_NO_MD5
600 if (strcmp(*argv,"md5") == 0) doit[D_MD5]=1;
603 #ifndef OPENSSL_NO_MD5
604 if (strcmp(*argv,"hmac") == 0) doit[D_HMAC]=1;
607 #ifndef OPENSSL_NO_SHA
608 if (strcmp(*argv,"sha1") == 0) doit[D_SHA1]=1;
610 if (strcmp(*argv,"sha") == 0) doit[D_SHA1]=1;
613 #ifndef OPENSSL_NO_RIPEMD
614 if (strcmp(*argv,"ripemd") == 0) doit[D_RMD160]=1;
616 if (strcmp(*argv,"rmd160") == 0) doit[D_RMD160]=1;
618 if (strcmp(*argv,"ripemd160") == 0) doit[D_RMD160]=1;
621 #ifndef OPENSSL_NO_RC4
622 if (strcmp(*argv,"rc4") == 0) doit[D_RC4]=1;
625 #ifndef OPENSSL_NO_DES
626 if (strcmp(*argv,"des-cbc") == 0) doit[D_CBC_DES]=1;
627 else if (strcmp(*argv,"des-ede3") == 0) doit[D_EDE3_DES]=1;
630 #ifndef OPENSSL_NO_RSA
631 #if 0 /* was: #ifdef RSAref */
632 if (strcmp(*argv,"rsaref") == 0)
634 RSA_set_default_openssl_method(RSA_PKCS1_RSAref());
640 if (strcmp(*argv,"openssl") == 0)
642 RSA_set_default_method(RSA_PKCS1_SSLeay());
647 #endif /* !OPENSSL_NO_RSA */
648 if (strcmp(*argv,"dsa512") == 0) dsa_doit[R_DSA_512]=2;
649 else if (strcmp(*argv,"dsa1024") == 0) dsa_doit[R_DSA_1024]=2;
650 else if (strcmp(*argv,"dsa2048") == 0) dsa_doit[R_DSA_2048]=2;
651 else if (strcmp(*argv,"rsa512") == 0) rsa_doit[R_RSA_512]=2;
652 else if (strcmp(*argv,"rsa1024") == 0) rsa_doit[R_RSA_1024]=2;
653 else if (strcmp(*argv,"rsa2048") == 0) rsa_doit[R_RSA_2048]=2;
654 else if (strcmp(*argv,"rsa4096") == 0) rsa_doit[R_RSA_4096]=2;
656 #ifndef OPENSSL_NO_RC2
657 if (strcmp(*argv,"rc2-cbc") == 0) doit[D_CBC_RC2]=1;
658 else if (strcmp(*argv,"rc2") == 0) doit[D_CBC_RC2]=1;
661 #ifndef OPENSSL_NO_RC5
662 if (strcmp(*argv,"rc5-cbc") == 0) doit[D_CBC_RC5]=1;
663 else if (strcmp(*argv,"rc5") == 0) doit[D_CBC_RC5]=1;
666 #ifndef OPENSSL_NO_IDEA
667 if (strcmp(*argv,"idea-cbc") == 0) doit[D_CBC_IDEA]=1;
668 else if (strcmp(*argv,"idea") == 0) doit[D_CBC_IDEA]=1;
671 #ifndef OPENSSL_NO_BF
672 if (strcmp(*argv,"bf-cbc") == 0) doit[D_CBC_BF]=1;
673 else if (strcmp(*argv,"blowfish") == 0) doit[D_CBC_BF]=1;
674 else if (strcmp(*argv,"bf") == 0) doit[D_CBC_BF]=1;
677 #ifndef OPENSSL_NO_CAST
678 if (strcmp(*argv,"cast-cbc") == 0) doit[D_CBC_CAST]=1;
679 else if (strcmp(*argv,"cast") == 0) doit[D_CBC_CAST]=1;
680 else if (strcmp(*argv,"cast5") == 0) doit[D_CBC_CAST]=1;
683 #ifndef OPENSSL_NO_DES
684 if (strcmp(*argv,"des") == 0)
691 #ifndef OPENSSL_NO_RSA
692 if (strcmp(*argv,"rsa") == 0)
694 rsa_doit[R_RSA_512]=1;
695 rsa_doit[R_RSA_1024]=1;
696 rsa_doit[R_RSA_2048]=1;
697 rsa_doit[R_RSA_4096]=1;
701 #ifndef OPENSSL_NO_DSA
702 if (strcmp(*argv,"dsa") == 0)
704 dsa_doit[R_DSA_512]=1;
705 dsa_doit[R_DSA_1024]=1;
710 BIO_printf(bio_err,"Error: bad option or value\n");
711 BIO_printf(bio_err,"\n");
712 BIO_printf(bio_err,"Available values:\n");
713 #ifndef OPENSSL_NO_MD2
714 BIO_printf(bio_err,"md2 ");
716 #ifndef OPENSSL_NO_MDC2
717 BIO_printf(bio_err,"mdc2 ");
719 #ifndef OPENSSL_NO_MD4
720 BIO_printf(bio_err,"md4 ");
722 #ifndef OPENSSL_NO_MD5
723 BIO_printf(bio_err,"md5 ");
724 #ifndef OPENSSL_NO_HMAC
725 BIO_printf(bio_err,"hmac ");
728 #ifndef OPENSSL_NO_SHA1
729 BIO_printf(bio_err,"sha1 ");
731 #ifndef OPENSSL_NO_RIPEMD160
732 BIO_printf(bio_err,"rmd160");
734 #if !defined(OPENSSL_NO_MD2) || !defined(OPENSSL_NO_MDC2) || \
735 !defined(OPENSSL_NO_MD4) || !defined(OPENSSL_NO_MD5) || \
736 !defined(OPENSSL_NO_SHA1) || !defined(OPENSSL_NO_RIPEMD160)
737 BIO_printf(bio_err,"\n");
740 #ifndef OPENSSL_NO_IDEA
741 BIO_printf(bio_err,"idea-cbc ");
743 #ifndef OPENSSL_NO_RC2
744 BIO_printf(bio_err,"rc2-cbc ");
746 #ifndef OPENSSL_NO_RC5
747 BIO_printf(bio_err,"rc5-cbc ");
749 #ifndef OPENSSL_NO_BF
750 BIO_printf(bio_err,"bf-cbc");
752 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
753 !defined(OPENSSL_NO_BF) || !defined(OPENSSL_NO_RC5)
754 BIO_printf(bio_err,"\n");
757 BIO_printf(bio_err,"des-cbc des-ede3 ");
758 #ifndef OPENSSL_NO_RC4
759 BIO_printf(bio_err,"rc4");
761 BIO_printf(bio_err,"\n");
763 #ifndef OPENSSL_NO_RSA
764 BIO_printf(bio_err,"rsa512 rsa1024 rsa2048 rsa4096\n");
767 #ifndef OPENSSL_NO_DSA
768 BIO_printf(bio_err,"dsa512 dsa1024 dsa2048\n");
771 #ifndef OPENSSL_NO_IDEA
772 BIO_printf(bio_err,"idea ");
774 #ifndef OPENSSL_NO_RC2
775 BIO_printf(bio_err,"rc2 ");
777 #ifndef OPENSSL_NO_DES
778 BIO_printf(bio_err,"des ");
780 #ifndef OPENSSL_NO_RSA
781 BIO_printf(bio_err,"rsa ");
783 #ifndef OPENSSL_NO_BF
784 BIO_printf(bio_err,"blowfish");
786 #if !defined(OPENSSL_NO_IDEA) || !defined(OPENSSL_NO_RC2) || \
787 !defined(OPENSSL_NO_DES) || !defined(OPENSSL_NO_RSA) || \
788 !defined(OPENSSL_NO_BF)
789 BIO_printf(bio_err,"\n");
792 BIO_printf(bio_err,"\n");
793 BIO_printf(bio_err,"Available options:\n");
795 BIO_printf(bio_err,"-elapsed measure time in real time instead of CPU user time.\n");
797 BIO_printf(bio_err,"-engine e use engine e, possibly a hardware device.\n");
798 BIO_printf(bio_err,"-evp e use EVP e.\n");
799 BIO_printf(bio_err,"-decrypt time decryption instead of encryption (only EVP).\n");
800 BIO_printf(bio_err,"-mr produce machine readable output.\n");
802 BIO_printf(bio_err,"-multi n run n benchmarks in parallel.\n");
812 if(multi && do_multi(multi))
818 for (i=0; i<ALGOR_NUM; i++)
823 for (i=0; i<RSA_NUM; i++)
825 for (i=0; i<DSA_NUM; i++)
828 for (i=0; i<ALGOR_NUM; i++)
829 if (doit[i]) pr_header++;
831 if (usertime == 0 && !mr)
832 BIO_printf(bio_err,"You have chosen to measure elapsed time instead of user CPU time.\n");
833 if (usertime <= 0 && !mr)
835 BIO_printf(bio_err,"To get the most accurate results, try to run this\n");
836 BIO_printf(bio_err,"program when this computer is idle.\n");
839 #ifndef OPENSSL_NO_RSA
840 for (i=0; i<RSA_NUM; i++)
842 const unsigned char *p;
845 rsa_key[i]=d2i_RSAPrivateKey(NULL,&p,rsa_data_length[i]);
846 if (rsa_key[i] == NULL)
848 BIO_printf(bio_err,"internal error loading RSA key number %d\n",i);
854 BIO_printf(bio_err,mr ? "+RK:%d:"
855 : "Loaded RSA key, %d bit modulus and e= 0x",
856 BN_num_bits(rsa_key[i]->n));
857 BN_print(bio_err,rsa_key[i]->e);
858 BIO_printf(bio_err,"\n");
864 #ifndef OPENSSL_NO_DSA
865 dsa_key[0]=get_dsa512();
866 dsa_key[1]=get_dsa1024();
867 dsa_key[2]=get_dsa2048();
870 #ifndef OPENSSL_NO_DES
871 DES_set_key_unchecked(&key,&sch);
872 DES_set_key_unchecked(&key2,&sch2);
873 DES_set_key_unchecked(&key3,&sch3);
875 #ifndef OPENSSL_NO_IDEA
876 idea_set_encrypt_key(key16,&idea_ks);
878 #ifndef OPENSSL_NO_RC4
879 RC4_set_key(&rc4_ks,16,key16);
881 #ifndef OPENSSL_NO_RC2
882 RC2_set_key(&rc2_ks,16,key16,128);
884 #ifndef OPENSSL_NO_RC5
885 RC5_32_set_key(&rc5_ks,16,key16,12);
887 #ifndef OPENSSL_NO_BF
888 BF_set_key(&bf_ks,16,key16);
890 #ifndef OPENSSL_NO_CAST
891 CAST_set_key(&cast_ks,16,key16);
893 #ifndef OPENSSL_NO_RSA
894 memset(rsa_c,0,sizeof(rsa_c));
897 #ifndef OPENSSL_NO_DES
898 BIO_printf(bio_err,"First we calculate the approximate speed ...\n");
904 for (i=count; i; i--)
905 DES_ecb_encrypt(buf_as_des_cblock,buf_as_des_cblock,
910 c[D_MD2][0]=count/10;
911 c[D_MDC2][0]=count/10;
916 c[D_RMD160][0]=count;
918 c[D_CBC_DES][0]=count;
919 c[D_EDE3_DES][0]=count/3;
920 c[D_CBC_IDEA][0]=count;
921 c[D_CBC_RC2][0]=count;
922 c[D_CBC_RC5][0]=count;
923 c[D_CBC_BF][0]=count;
924 c[D_CBC_CAST][0]=count;
926 for (i=1; i<SIZE_NUM; i++)
928 c[D_MD2][i]=c[D_MD2][0]*4*lengths[0]/lengths[i];
929 c[D_MDC2][i]=c[D_MDC2][0]*4*lengths[0]/lengths[i];
930 c[D_MD4][i]=c[D_MD4][0]*4*lengths[0]/lengths[i];
931 c[D_MD5][i]=c[D_MD5][0]*4*lengths[0]/lengths[i];
932 c[D_HMAC][i]=c[D_HMAC][0]*4*lengths[0]/lengths[i];
933 c[D_SHA1][i]=c[D_SHA1][0]*4*lengths[0]/lengths[i];
934 c[D_RMD160][i]=c[D_RMD160][0]*4*lengths[0]/lengths[i];
936 for (i=1; i<SIZE_NUM; i++)
940 l0=(long)lengths[i-1];
942 c[D_RC4][i]=c[D_RC4][i-1]*l0/l1;
943 c[D_CBC_DES][i]=c[D_CBC_DES][i-1]*l0/l1;
944 c[D_EDE3_DES][i]=c[D_EDE3_DES][i-1]*l0/l1;
945 c[D_CBC_IDEA][i]=c[D_CBC_IDEA][i-1]*l0/l1;
946 c[D_CBC_RC2][i]=c[D_CBC_RC2][i-1]*l0/l1;
947 c[D_CBC_RC5][i]=c[D_CBC_RC5][i-1]*l0/l1;
948 c[D_CBC_BF][i]=c[D_CBC_BF][i-1]*l0/l1;
949 c[D_CBC_CAST][i]=c[D_CBC_CAST][i-1]*l0/l1;
951 #ifndef OPENSSL_NO_RSA
952 rsa_c[R_RSA_512][0]=count/2000;
953 rsa_c[R_RSA_512][1]=count/400;
954 for (i=1; i<RSA_NUM; i++)
956 rsa_c[i][0]=rsa_c[i-1][0]/8;
957 rsa_c[i][1]=rsa_c[i-1][1]/4;
958 if ((rsa_doit[i] <= 1) && (rsa_c[i][0] == 0))
962 if (rsa_c[i][0] == 0)
971 #ifndef OPENSSL_NO_DSA
972 dsa_c[R_DSA_512][0]=count/1000;
973 dsa_c[R_DSA_512][1]=count/1000/2;
974 for (i=1; i<DSA_NUM; i++)
976 dsa_c[i][0]=dsa_c[i-1][0]/4;
977 dsa_c[i][1]=dsa_c[i-1][1]/4;
978 if ((dsa_doit[i] <= 1) && (dsa_c[i][0] == 0))
991 #define COND(d) (count < (d))
994 /* not worth fixing */
995 # error "You cannot disable DES on systems without SIGALRM."
996 #endif /* OPENSSL_NO_DES */
998 #define COND(c) (run)
999 #define COUNT(d) (count)
1000 signal(SIGALRM,sig_done);
1001 #endif /* SIGALRM */
1003 #ifndef OPENSSL_NO_MD2
1006 for (j=0; j<SIZE_NUM; j++)
1008 print_message(names[D_MD2],c[D_MD2][j],lengths[j]);
1010 for (count=0,run=1; COND(c[D_MD2][j]); count++)
1011 EVP_Digest(buf,(unsigned long)lengths[j],&(md2[0]),NULL,EVP_md2(),NULL);
1013 print_result(D_MD2,j,count,d);
1017 #ifndef OPENSSL_NO_MDC2
1020 for (j=0; j<SIZE_NUM; j++)
1022 print_message(names[D_MDC2],c[D_MDC2][j],lengths[j]);
1024 for (count=0,run=1; COND(c[D_MDC2][j]); count++)
1025 EVP_Digest(buf,(unsigned long)lengths[j],&(mdc2[0]),NULL,EVP_mdc2(),NULL);
1027 print_result(D_MDC2,j,count,d);
1032 #ifndef OPENSSL_NO_MD4
1035 for (j=0; j<SIZE_NUM; j++)
1037 print_message(names[D_MD4],c[D_MD4][j],lengths[j]);
1039 for (count=0,run=1; COND(c[D_MD4][j]); count++)
1040 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md4[0]),NULL,EVP_md4(),NULL);
1042 print_result(D_MD4,j,count,d);
1047 #ifndef OPENSSL_NO_MD5
1050 for (j=0; j<SIZE_NUM; j++)
1052 print_message(names[D_MD5],c[D_MD5][j],lengths[j]);
1054 for (count=0,run=1; COND(c[D_MD5][j]); count++)
1055 EVP_Digest(&(buf[0]),(unsigned long)lengths[j],&(md5[0]),NULL,EVP_get_digestbyname("md5"),NULL);
1057 print_result(D_MD5,j,count,d);
1062 #if !defined(OPENSSL_NO_MD5) && !defined(OPENSSL_NO_HMAC)
1067 HMAC_CTX_init(&hctx);
1068 HMAC_Init(&hctx,(unsigned char *)"This is a key...",
1071 for (j=0; j<SIZE_NUM; j++)
1073 print_message(names[D_HMAC],c[D_HMAC][j],lengths[j]);
1075 for (count=0,run=1; COND(c[D_HMAC][j]); count++)
1077 HMAC_Init(&hctx,NULL,0,NULL);
1078 HMAC_Update(&hctx,buf,lengths[j]);
1079 HMAC_Final(&hctx,&(hmac[0]),NULL);
1082 print_result(D_HMAC,j,count,d);
1084 HMAC_CTX_cleanup(&hctx);
1087 #ifndef OPENSSL_NO_SHA
1090 for (j=0; j<SIZE_NUM; j++)
1092 print_message(names[D_SHA1],c[D_SHA1][j],lengths[j]);
1094 for (count=0,run=1; COND(c[D_SHA1][j]); count++)
1095 EVP_Digest(buf,(unsigned long)lengths[j],&(sha[0]),NULL,EVP_sha1(),NULL);
1097 print_result(D_SHA1,j,count,d);
1101 #ifndef OPENSSL_NO_RIPEMD
1104 for (j=0; j<SIZE_NUM; j++)
1106 print_message(names[D_RMD160],c[D_RMD160][j],lengths[j]);
1108 for (count=0,run=1; COND(c[D_RMD160][j]); count++)
1109 EVP_Digest(buf,(unsigned long)lengths[j],&(rmd160[0]),NULL,EVP_ripemd160(),NULL);
1111 print_result(D_RMD160,j,count,d);
1115 #ifndef OPENSSL_NO_RC4
1118 for (j=0; j<SIZE_NUM; j++)
1120 print_message(names[D_RC4],c[D_RC4][j],lengths[j]);
1122 for (count=0,run=1; COND(c[D_RC4][j]); count++)
1123 RC4(&rc4_ks,(unsigned int)lengths[j],
1126 print_result(D_RC4,j,count,d);
1130 #ifndef OPENSSL_NO_DES
1131 if (doit[D_CBC_DES])
1133 for (j=0; j<SIZE_NUM; j++)
1135 print_message(names[D_CBC_DES],c[D_CBC_DES][j],lengths[j]);
1137 for (count=0,run=1; COND(c[D_CBC_DES][j]); count++)
1138 DES_ncbc_encrypt(buf,buf,lengths[j],&sch,
1141 print_result(D_CBC_DES,j,count,d);
1145 if (doit[D_EDE3_DES])
1147 for (j=0; j<SIZE_NUM; j++)
1149 print_message(names[D_EDE3_DES],c[D_EDE3_DES][j],lengths[j]);
1151 for (count=0,run=1; COND(c[D_EDE3_DES][j]); count++)
1152 DES_ede3_cbc_encrypt(buf,buf,lengths[j],
1156 print_result(D_EDE3_DES,j,count,d);
1160 #ifndef OPENSSL_NO_IDEA
1161 if (doit[D_CBC_IDEA])
1163 for (j=0; j<SIZE_NUM; j++)
1165 print_message(names[D_CBC_IDEA],c[D_CBC_IDEA][j],lengths[j]);
1167 for (count=0,run=1; COND(c[D_CBC_IDEA][j]); count++)
1168 idea_cbc_encrypt(buf,buf,
1169 (unsigned long)lengths[j],&idea_ks,
1172 print_result(D_CBC_IDEA,j,count,d);
1176 #ifndef OPENSSL_NO_RC2
1177 if (doit[D_CBC_RC2])
1179 for (j=0; j<SIZE_NUM; j++)
1181 print_message(names[D_CBC_RC2],c[D_CBC_RC2][j],lengths[j]);
1183 for (count=0,run=1; COND(c[D_CBC_RC2][j]); count++)
1184 RC2_cbc_encrypt(buf,buf,
1185 (unsigned long)lengths[j],&rc2_ks,
1188 print_result(D_CBC_RC2,j,count,d);
1192 #ifndef OPENSSL_NO_RC5
1193 if (doit[D_CBC_RC5])
1195 for (j=0; j<SIZE_NUM; j++)
1197 print_message(names[D_CBC_RC5],c[D_CBC_RC5][j],lengths[j]);
1199 for (count=0,run=1; COND(c[D_CBC_RC5][j]); count++)
1200 RC5_32_cbc_encrypt(buf,buf,
1201 (unsigned long)lengths[j],&rc5_ks,
1204 print_result(D_CBC_RC5,j,count,d);
1208 #ifndef OPENSSL_NO_BF
1211 for (j=0; j<SIZE_NUM; j++)
1213 print_message(names[D_CBC_BF],c[D_CBC_BF][j],lengths[j]);
1215 for (count=0,run=1; COND(c[D_CBC_BF][j]); count++)
1216 BF_cbc_encrypt(buf,buf,
1217 (unsigned long)lengths[j],&bf_ks,
1220 print_result(D_CBC_BF,j,count,d);
1224 #ifndef OPENSSL_NO_CAST
1225 if (doit[D_CBC_CAST])
1227 for (j=0; j<SIZE_NUM; j++)
1229 print_message(names[D_CBC_CAST],c[D_CBC_CAST][j],lengths[j]);
1231 for (count=0,run=1; COND(c[D_CBC_CAST][j]); count++)
1232 CAST_cbc_encrypt(buf,buf,
1233 (unsigned long)lengths[j],&cast_ks,
1236 print_result(D_CBC_CAST,j,count,d);
1243 for (j=0; j<SIZE_NUM; j++)
1250 names[D_EVP]=OBJ_nid2ln(evp_cipher->nid);
1251 print_message(names[D_EVP],save_count,
1254 EVP_CIPHER_CTX_init(&ctx);
1256 EVP_DecryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1258 EVP_EncryptInit_ex(&ctx,evp_cipher,NULL,key16,iv);
1262 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1263 EVP_DecryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1265 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1266 EVP_EncryptUpdate(&ctx,buf,&outl,buf,lengths[j]);
1268 EVP_DecryptFinal_ex(&ctx,buf,&outl);
1270 EVP_EncryptFinal_ex(&ctx,buf,&outl);
1275 names[D_EVP]=OBJ_nid2ln(evp_md->type);
1276 print_message(names[D_EVP],save_count,
1280 for (count=0,run=1; COND(save_count*4*lengths[0]/lengths[j]); count++)
1281 EVP_Digest(buf,lengths[j],&(md[0]),NULL,evp_md,NULL);
1285 print_result(D_EVP,j,count,d);
1289 RAND_pseudo_bytes(buf,36);
1290 #ifndef OPENSSL_NO_RSA
1291 for (j=0; j<RSA_NUM; j++)
1294 if (!rsa_doit[j]) continue;
1295 ret=RSA_sign(NID_md5_sha1, buf,36, buf2, &rsa_num, rsa_key[j]);
1298 BIO_printf(bio_err,"RSA sign failure. No RSA sign will be done.\n");
1299 ERR_print_errors(bio_err);
1304 pkey_print_message("private","rsa",
1305 rsa_c[j][0],rsa_bits[j],
1307 /* RSA_blinding_on(rsa_key[j],NULL); */
1309 for (count=0,run=1; COND(rsa_c[j][0]); count++)
1311 ret=RSA_sign(NID_md5_sha1, buf,36, buf2,
1312 &rsa_num, rsa_key[j]);
1316 "RSA sign failure\n");
1317 ERR_print_errors(bio_err);
1323 BIO_printf(bio_err,mr ? "+R1:%ld:%d:%.2f\n"
1324 : "%ld %d bit private RSA's in %.2fs\n",
1325 count,rsa_bits[j],d);
1326 rsa_results[j][0]=d/(double)count;
1331 ret=RSA_verify(NID_md5_sha1, buf,36, buf2, rsa_num, rsa_key[j]);
1334 BIO_printf(bio_err,"RSA verify failure. No RSA verify will be done.\n");
1335 ERR_print_errors(bio_err);
1340 pkey_print_message("public","rsa",
1341 rsa_c[j][1],rsa_bits[j],
1344 for (count=0,run=1; COND(rsa_c[j][1]); count++)
1346 ret=RSA_verify(NID_md5_sha1, buf,36, buf2,
1347 rsa_num, rsa_key[j]);
1351 "RSA verify failure\n");
1352 ERR_print_errors(bio_err);
1358 BIO_printf(bio_err,mr ? "+R2:%ld:%d:%.2f\n"
1359 : "%ld %d bit public RSA's in %.2fs\n",
1360 count,rsa_bits[j],d);
1361 rsa_results[j][1]=d/(double)count;
1367 /* if longer than 10s, don't do any more */
1368 for (j++; j<RSA_NUM; j++)
1374 RAND_pseudo_bytes(buf,20);
1375 #ifndef OPENSSL_NO_DSA
1376 if (RAND_status() != 1)
1378 RAND_seed(rnd_seed, sizeof rnd_seed);
1381 for (j=0; j<DSA_NUM; j++)
1386 if (!dsa_doit[j]) continue;
1387 /* DSA_generate_key(dsa_key[j]); */
1388 /* DSA_sign_setup(dsa_key[j],NULL); */
1389 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
1393 BIO_printf(bio_err,"DSA sign failure. No DSA sign will be done.\n");
1394 ERR_print_errors(bio_err);
1399 pkey_print_message("sign","dsa",
1400 dsa_c[j][0],dsa_bits[j],
1403 for (count=0,run=1; COND(dsa_c[j][0]); count++)
1405 ret=DSA_sign(EVP_PKEY_DSA,buf,20,buf2,
1410 "DSA sign failure\n");
1411 ERR_print_errors(bio_err);
1417 BIO_printf(bio_err,mr ? "+R3:%ld:%d:%.2f\n"
1418 : "%ld %d bit DSA signs in %.2fs\n",
1419 count,dsa_bits[j],d);
1420 dsa_results[j][0]=d/(double)count;
1424 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
1428 BIO_printf(bio_err,"DSA verify failure. No DSA verify will be done.\n");
1429 ERR_print_errors(bio_err);
1434 pkey_print_message("verify","dsa",
1435 dsa_c[j][1],dsa_bits[j],
1438 for (count=0,run=1; COND(dsa_c[j][1]); count++)
1440 ret=DSA_verify(EVP_PKEY_DSA,buf,20,buf2,
1445 "DSA verify failure\n");
1446 ERR_print_errors(bio_err);
1452 BIO_printf(bio_err,mr ? "+R4:%ld:%d:%.2f\n"
1453 : "%ld %d bit DSA verify in %.2fs\n",
1454 count,dsa_bits[j],d);
1455 dsa_results[j][1]=d/(double)count;
1460 /* if longer than 10s, don't do any more */
1461 for (j++; j<DSA_NUM; j++)
1465 if (rnd_fake) RAND_cleanup();
1472 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_VERSION));
1473 fprintf(stdout,"%s\n",SSLeay_version(SSLEAY_BUILT_ON));
1475 printf("%s ",BN_options());
1476 #ifndef OPENSSL_NO_MD2
1477 printf("%s ",MD2_options());
1479 #ifndef OPENSSL_NO_RC4
1480 printf("%s ",RC4_options());
1482 #ifndef OPENSSL_NO_DES
1483 printf("%s ",des_options());
1485 #ifndef OPENSSL_NO_IDEA
1486 printf("%s ",idea_options());
1488 #ifndef OPENSSL_NO_BF
1489 printf("%s ",BF_options());
1491 fprintf(stdout,"\n%s\n",SSLeay_version(SSLEAY_CFLAGS));
1492 printf("available timing options: ");
1503 #define as_string(s) (#s)
1504 printf("HZ=%g", HZ);
1506 printf(" [sysconf value]");
1510 printf("timing function used: %s%s%s%s%s%s%s\n",
1511 (ftime_used ? "ftime" : ""),
1512 (ftime_used + times_used > 1 ? "," : ""),
1513 (times_used ? "times" : ""),
1514 (ftime_used + times_used + gettimeofday_used > 1 ? "," : ""),
1515 (gettimeofday_used ? "gettimeofday" : ""),
1516 (ftime_used + times_used + gettimeofday_used + getrusage_used > 1 ? "," : ""),
1517 (getrusage_used ? "getrusage" : ""));
1523 fprintf(stdout,"+H");
1526 fprintf(stdout,"The 'numbers' are in 1000s of bytes per second processed.\n");
1527 fprintf(stdout,"type ");
1529 for (j=0; j<SIZE_NUM; j++)
1530 fprintf(stdout,mr ? ":%d" : "%7d bytes",lengths[j]);
1531 fprintf(stdout,"\n");
1534 for (k=0; k<ALGOR_NUM; k++)
1536 if (!doit[k]) continue;
1538 fprintf(stdout,"+F:%d:%s",k,names[k]);
1540 fprintf(stdout,"%-13s",names[k]);
1541 for (j=0; j<SIZE_NUM; j++)
1543 if (results[k][j] > 10000 && !mr)
1544 fprintf(stdout," %11.2fk",results[k][j]/1e3);
1546 fprintf(stdout,mr ? ":%.2f" : " %11.2f ",results[k][j]);
1548 fprintf(stdout,"\n");
1550 #ifndef OPENSSL_NO_RSA
1552 for (k=0; k<RSA_NUM; k++)
1554 if (!rsa_doit[k]) continue;
1557 printf("%18ssign verify sign/s verify/s\n"," ");
1561 fprintf(stdout,"+F2:%u:%u:%f:%f\n",
1562 k,rsa_bits[k],rsa_results[k][0],
1565 fprintf(stdout,"rsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\n",
1566 rsa_bits[k],rsa_results[k][0],rsa_results[k][1],
1567 1.0/rsa_results[k][0],1.0/rsa_results[k][1]);
1570 #ifndef OPENSSL_NO_DSA
1572 for (k=0; k<DSA_NUM; k++)
1574 if (!dsa_doit[k]) continue;
1577 printf("%18ssign verify sign/s verify/s\n"," ");
1581 fprintf(stdout,"+F3:%u:%u:%f:%f\n",
1582 k,dsa_bits[k],dsa_results[k][0],dsa_results[k][1]);
1584 fprintf(stdout,"dsa %4u bits %8.4fs %8.4fs %8.1f %8.1f\n",
1585 dsa_bits[k],dsa_results[k][0],dsa_results[k][1],
1586 1.0/dsa_results[k][0],1.0/dsa_results[k][1]);
1591 ERR_print_errors(bio_err);
1592 if (buf != NULL) OPENSSL_free(buf);
1593 if (buf2 != NULL) OPENSSL_free(buf2);
1594 #ifndef OPENSSL_NO_RSA
1595 for (i=0; i<RSA_NUM; i++)
1596 if (rsa_key[i] != NULL)
1597 RSA_free(rsa_key[i]);
1599 #ifndef OPENSSL_NO_DSA
1600 for (i=0; i<DSA_NUM; i++)
1601 if (dsa_key[i] != NULL)
1602 DSA_free(dsa_key[i]);
1608 static void print_message(const char *s, long num, int length)
1611 BIO_printf(bio_err,mr ? "+DT:%s:%d:%d\n"
1612 : "Doing %s for %ds on %d size blocks: ",s,SECONDS,length);
1613 (void)BIO_flush(bio_err);
1616 BIO_printf(bio_err,mr ? "+DN:%s:%ld:%d\n"
1617 : "Doing %s %ld times on %d size blocks: ",s,num,length);
1618 (void)BIO_flush(bio_err);
1625 static void pkey_print_message(char *str, char *str2, long num, int bits,
1629 BIO_printf(bio_err,mr ? "+DTP:%d:%s:%s:%d\n"
1630 : "Doing %d bit %s %s's for %ds: ",bits,str,str2,tm);
1631 (void)BIO_flush(bio_err);
1634 BIO_printf(bio_err,mr ? "+DNP:%ld:%d:%s:%s\n"
1635 : "Doing %ld %d bit %s %s's: ",num,bits,str,str2);
1636 (void)BIO_flush(bio_err);
1643 static void print_result(int alg,int run_no,int count,double time_used)
1645 BIO_printf(bio_err,mr ? "+R:%ld:%s:%f\n"
1646 : "%ld %s's in %.2fs\n",count,names[alg],time_used);
1647 results[alg][run_no]=((double)count)/time_used*lengths[run_no];
1650 static char *sstrsep(char **string, const char *delim)
1653 char *token = *string;
1658 memset(isdelim, 0, 256);
1663 isdelim[(unsigned char)(*delim)] = 1;
1667 while (!isdelim[(unsigned char)(**string)])
1682 static int do_multi(int multi)
1687 static char sep[]=":";
1689 fds=malloc(multi*sizeof *fds);
1690 for(n=0 ; n < multi ; ++n)
1708 printf("Forked child %d\n",n);
1711 /* for now, assume the pipe is long enough to take all the output */
1712 for(n=0 ; n < multi ; ++n)
1718 f=fdopen(fds[n],"r");
1719 while(fgets(buf,sizeof buf,f))
1726 fprintf(stderr,"Don't understand line '%s' from child %d\n",
1730 printf("Got: %s from %d\n",buf,n);
1731 if(!strncmp(buf,"+F:",3))
1737 alg=atoi(sstrsep(&p,sep));
1739 for(j=0 ; j < SIZE_NUM ; ++j)
1740 results[alg][j]+=atof(sstrsep(&p,sep));
1742 else if(!strncmp(buf,"+F2:",4))
1748 k=atoi(sstrsep(&p,sep));
1751 d=atof(sstrsep(&p,sep));
1753 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
1755 rsa_results[k][0]=d;
1757 d=atof(sstrsep(&p,sep));
1759 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
1761 rsa_results[k][1]=d;
1763 else if(!strncmp(buf,"+F2:",4))
1769 k=atoi(sstrsep(&p,sep));
1772 d=atof(sstrsep(&p,sep));
1774 rsa_results[k][0]=1/(1/rsa_results[k][0]+1/d);
1776 rsa_results[k][0]=d;
1778 d=atof(sstrsep(&p,sep));
1780 rsa_results[k][1]=1/(1/rsa_results[k][1]+1/d);
1782 rsa_results[k][1]=d;
1784 else if(!strncmp(buf,"+F3:",4))
1790 k=atoi(sstrsep(&p,sep));
1793 d=atof(sstrsep(&p,sep));
1795 dsa_results[k][0]=1/(1/dsa_results[k][0]+1/d);
1797 dsa_results[k][0]=d;
1799 d=atof(sstrsep(&p,sep));
1801 dsa_results[k][1]=1/(1/dsa_results[k][1]+1/d);
1803 dsa_results[k][1]=d;
1805 else if(!strncmp(buf,"+H:",3))
1809 fprintf(stderr,"Unknown type '%s' from child %d\n",buf,n);