From ca1f332fbadc20d53d807d542fb37988a5508d32 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/5] 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 | 243 +++++++++++++++++++++------------------------------------- 1 files changed, 86 insertions(+), 157 deletions(-) diff --git a/apps/speed.c b/apps/speed.c index 539bfff..f64289e 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -214,7 +214,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 29 +#define ALGOR_NUM 30 #define SIZE_NUM 5 #define RSA_NUM 4 #define DSA_NUM 3 @@ -229,9 +229,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","whirlpool", - "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 @@ -329,6 +331,66 @@ static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen) } #endif /* OPENSSL_NO_ECDH */ +#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