From 942f1af93b1cafbb4439aec0018da099af09a934 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Thu, 3 Jun 2010 09:02:13 +0300 Subject: [PATCH 2/3] apps/speed: fix digest speed measurement and add hmac-sha1 test Merge the common code of testing digest speed, and make it reuse existing context. Context creation can be heavy operation, and it's speed depends on if engine is used or not. As we are measuring the digest speed, the context creation overhead should not be included like hmac tests do. This also adds test for hmac-sha1 speed. --- apps/speed.c | 232 ++++++++++++++++++++++------------------------------------- 1 file changed, 87 insertions(+), 145 deletions(-) diff --git a/apps/speed.c b/apps/speed.c index 84ce35d..116cf82 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -285,7 +285,7 @@ static void print_result(int alg,int run_no,int count,double time_used); static int do_multi(int multi); #endif -#define ALGOR_NUM 28 +#define ALGOR_NUM 29 #define SIZE_NUM 5 #define RSA_NUM 4 #define DSA_NUM 3 @@ -300,9 +300,11 @@ static const char *names[ALGOR_NUM]={ "aes-128 cbc","aes-192 cbc","aes-256 cbc", "camellia-128 cbc","camellia-192 cbc","camellia-256 cbc", "evp","sha256","sha512", - "aes-128 ige","aes-192 ige","aes-256 ige"}; + "aes-128 ige","aes-192 ige","aes-256 ige", "hmac(sha1)" }; static double results[ALGOR_NUM][SIZE_NUM]; static int lengths[SIZE_NUM]={16,64,256,1024,8*1024}; +static unsigned char *buf=NULL,*buf2=NULL; +static long c[ALGOR_NUM][SIZE_NUM]; #ifndef OPENSSL_NO_RSA static double rsa_results[RSA_NUM][2]; #endif @@ -478,6 +480,66 @@ static double Time_F(int s) } #endif /* if defined(OPENSSL_SYS_NETWARE) */ +#ifndef SIGALRM +#define COND(d) (count < (d)) +#else +#define COND(c) (run) +#endif /* SIGALRM */ + +static void Test_Digest(int digest, const EVP_MD *type) +{ + unsigned char md[EVP_MAX_MD_SIZE]; + int j, count; + double d=0.0; + EVP_MD_CTX ctx; + + EVP_MD_CTX_init(&ctx); + EVP_MD_CTX_set_flags(&ctx,EVP_MD_CTX_FLAG_ONESHOT); + + for (j=0; j