@@ -45,9 +45,9 @@ typedef enum {
4545} hash_algorithm_type ;
4646
4747static unsigned char data [DATA_SIZE ];
48- static int deprecated_api = 0 ;
4948static int update_times = 1 ;
5049static int hash_algorithm = -1 ;
50+ static const EVP_MD * evp_md = NULL ;
5151
5252int hash_deprecated ()
5353{
@@ -128,50 +128,34 @@ int hash_evp(EVP_MD_CTX *mctx, const EVP_MD *evp_md)
128128 return 1 ;
129129}
130130
131- void do_hash (size_t num )
131+ void do_hash_deprecated (size_t num )
132132{
133133 OSSL_TIME time ;
134- EVP_MD_CTX * mctx = NULL ;
135- const EVP_MD * evp_md = NULL ;
136134
137- counts [num ] = 0 ;
138-
139- if (!deprecated_api ) {
140- switch (hash_algorithm ) {
141- case SHA1_ALG :
142- evp_md = EVP_sha1 ();
143- break ;
144- case SHA224_ALG :
145- evp_md = EVP_sha224 ();
146- break ;
147- case SHA256_ALG :
148- evp_md = EVP_sha256 ();
149- break ;
150- case SHA384_ALG :
151- evp_md = EVP_sha384 ();
152- break ;
153- case SHA512_ALG :
154- evp_md = EVP_sha512 ();
155- break ;
156- default :
135+ do {
136+ if (!hash_deprecated ()) {
157137 err = 1 ;
158138 return ;
159139 }
160140
161- if ((mctx = EVP_MD_CTX_new ()) == NULL )
162- return ;
163- }
141+ counts [num ]++ ;
142+ time = ossl_time_now ();
143+ } while (time .t < max_time .t );
144+ }
145+
146+ void do_hash_evp (size_t num )
147+ {
148+ OSSL_TIME time ;
149+ EVP_MD_CTX * mctx = EVP_MD_CTX_new ();
150+
151+ if (mctx == NULL )
152+ return ;
164153
165154 do {
166- if (deprecated_api ) {
167- if (!hash_deprecated ())
168- err = 1 ;
169- } else if (!hash_evp (mctx , evp_md )) {
155+ if (!hash_evp (mctx , evp_md )) {
170156 err = 1 ;
171- }
172-
173- if (err )
174157 goto err ;
158+ }
175159
176160 counts [num ]++ ;
177161 time = ossl_time_now ();
@@ -197,7 +181,7 @@ int main(int argc, char *argv[])
197181 OSSL_TIME duration ;
198182 size_t total_count = 0 ;
199183 double av ;
200- int terse = 0 ;
184+ int terse = 0 , deprecated_api = 0 ;
201185 int j , opt , rc = EXIT_FAILURE ;
202186
203187 while ((opt = getopt (argc , argv , "htx" )) != -1 ) {
@@ -258,15 +242,37 @@ int main(int argc, char *argv[])
258242
259243 max_time = ossl_time_add (ossl_time_now (), ossl_seconds2time (RUN_TIME ));
260244
261- counts = OPENSSL_malloc (sizeof (size_t ) * threadcount );
245+ counts = OPENSSL_zalloc (sizeof (size_t ) * threadcount );
262246 if (counts == NULL ) {
263247 fprintf (stderr , "Failed to create counts array\n" );
264248 goto out ;
265249 }
266250
267- if (!perflib_run_multi_thread_test (do_hash , threadcount , & duration )) {
268- fprintf (stderr , "Failed to run the test\n" );
269- goto out ;
251+ if (deprecated_api ) {
252+ err = !perflib_run_multi_thread_test (do_hash_deprecated , threadcount , & duration ) || err ;
253+ } else {
254+ switch (hash_algorithm ) {
255+ case SHA1_ALG :
256+ evp_md = EVP_sha1 ();
257+ break ;
258+ case SHA224_ALG :
259+ evp_md = EVP_sha224 ();
260+ break ;
261+ case SHA256_ALG :
262+ evp_md = EVP_sha256 ();
263+ break ;
264+ case SHA384_ALG :
265+ evp_md = EVP_sha384 ();
266+ break ;
267+ case SHA512_ALG :
268+ evp_md = EVP_sha512 ();
269+ break ;
270+ default :
271+ err = 1 ;
272+ goto out ;
273+ }
274+
275+ err = !perflib_run_multi_thread_test (do_hash_evp , threadcount , & duration ) || err ;
270276 }
271277
272278 if (err ) {
0 commit comments