2020# include "perflib/basename.h"
2121#endif /* _WIN32 */
2222#include <openssl/ssl.h>
23+ #include <openssl/err.h>
2324#include "perflib/perflib.h"
2425
2526#define RUN_TIME 5
@@ -79,7 +80,8 @@ static void do_handshake(size_t num)
7980 TLS_client_method (),
8081 0 , 0 , & lsctx , & lcctx , cert ,
8182 privkey )) {
82- printf ("Failed to create SSL_CTX pair\n" );
83+ ERR_print_errors_fp (stderr );
84+ fprintf (stderr , "%s:%d: Failed to create SSL_CTX pair\n" , __FILE__ , __LINE__ );
8385 break ;
8486 }
8587 }
@@ -127,6 +129,7 @@ static void do_handshake_ossl_lib_ctx_per_thread(size_t num)
127129 TLS_client_method (),
128130 0 , 0 , & lsctx , & lcctx , cert ,
129131 privkey )) {
132+ ERR_print_errors_fp (stderr );
130133 fprintf (stderr , "%s:%d: Failed to create SSL_CTX pair\n" , __FILE__ , __LINE__ );
131134 err = 1 ;
132135 return ;
@@ -175,6 +178,7 @@ static void do_handshake_ctx_pool(size_t num)
175178 TLS_client_method (),
176179 0 , 0 , & lsctx , & lcctx , cert ,
177180 privkey )) {
181+ ERR_print_errors_fp (stderr );
178182 fprintf (stderr , "%s:%d: Failed to create SSL_CTX pair\n" , __FILE__ , __LINE__ );
179183 err = 1 ;
180184 return ;
@@ -190,6 +194,7 @@ static void do_handshake_ctx_pool(size_t num)
190194 TLS_client_method (),
191195 0 , 0 , & lsctx , & lcctx , cert ,
192196 privkey )) {
197+ ERR_print_errors_fp (stderr );
193198 fprintf (stderr , "%s:%d: Failed to create SSL_CTX pair\n" , __FILE__ , __LINE__ );
194199 err = 1 ;
195200 return ;
@@ -314,6 +319,7 @@ void usage(const char *progname)
314319 printf ("-P - use ossl_lib_ctx pool\n" );
315320 printf ("-l - use ssl ctx pool\n" );
316321 printf ("-o - set ossl_lib_ctx pool size\n" );
322+ printf ("-S [n] - use secure memory\n" );
317323}
318324
319325int main (int argc , char * const argv [])
@@ -329,7 +335,7 @@ int main(int argc, char * const argv[])
329335 int p_flag = 0 , P_flag = 0 , l_flag = 0 ;
330336 char * endptr = NULL ;
331337
332- while ((opt = getopt (argc , argv , "tspPo:l " )) != -1 ) {
338+ while ((opt = getopt (argc , argv , "tspPo:lS: " )) != -1 ) {
333339 switch (opt ) {
334340 case 't' :
335341 terse = 1 ;
@@ -368,6 +374,27 @@ int main(int argc, char * const argv[])
368374 l_flag = 1 ;
369375 test_case = TC_SSL_CTX_POOL ;
370376 break ;
377+ case 'S' : {
378+ char * end = NULL ;
379+ int sec_mem_size ;
380+
381+ errno = 0 ;
382+ sec_mem_size = (int )strtol (optarg , & end , 10 );
383+ if (errno || end == NULL || * end || sec_mem_size <= 0 ) {
384+ fprintf (stderr , "Invalid secure memory size: '%s'\n" , optarg );
385+ usage (basename (argv [0 ]));
386+ return EXIT_FAILURE ;
387+ }
388+ if (CRYPTO_secure_malloc_init (sec_mem_size , 16 ) == 0 ) {
389+ fprintf (stderr , "Secure heap not available\n" );
390+ return EXIT_FAILURE ;
391+ }
392+ if (CRYPTO_secure_malloc_initialized () == 0 ) {
393+ fprintf (stderr , "Secure heap not initialized\n" );
394+ return EXIT_FAILURE ;
395+ }
396+ break ;
397+ }
371398 default :
372399 usage (basename (argv [0 ]));
373400 return EXIT_FAILURE ;
@@ -415,7 +442,8 @@ int main(int argc, char * const argv[])
415442 if (share_ctx == 1 ) {
416443 if (!perflib_create_ssl_ctx_pair (TLS_server_method (), TLS_client_method (),
417444 0 , 0 , & sctx , & cctx , cert , privkey )) {
418- printf ("Failed to create SSL_CTX pair\n" );
445+ ERR_print_errors_fp (stderr );
446+ fprintf (stderr , "%s:%d: Failed to create SSL_CTX pair\n" , __FILE__ , __LINE__ );
419447 goto err ;
420448 }
421449 }
0 commit comments