From 287f4938225be161f8844308404796bfb27dbdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Teppo=20J=C3=A4rvelin?= Date: Thu, 17 Oct 2019 10:09:01 +0300 Subject: [PATCH] Entropy changed back to non-pointer in ssl_server2.c Changed because CI failures. Also some minor improvements. --- programs/ssl/ssl_server2.c | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index 15824250a59d..9a99582f51a3 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -1561,16 +1561,16 @@ int main( int argc, char *argv[] ) #if defined(MBEDTLS_X509_CRT_PARSE_C) mbedtls_x509_crt_profile crt_profile_for_test = mbedtls_x509_crt_profile_default; #endif - mbedtls_entropy_context *entropy; + mbedtls_entropy_context entropy; #if defined(MBEDTLS_CTR_DRBG_C) - mbedtls_ctr_drbg_context *ctr_drbg; + mbedtls_ctr_drbg_context *ctr_drbg = NULL; #else - mbedtls_hmac_drbg_context *hmac_drbg; + mbedtls_hmac_drbg_context *hmac_drbg = NULL; #endif mbedtls_ssl_context *ssl = NULL; mbedtls_ssl_config *conf = NULL; #if defined(MBEDTLS_TIMING_C) - mbedtls_timing_delay_context *timer; + mbedtls_timing_delay_context *timer = NULL; #endif #if defined(MBEDTLS_SSL_RENEGOTIATION) unsigned char renego_period[8] = { 0 }; @@ -1594,7 +1594,7 @@ int main( int argc, char *argv[] ) mbedtls_ssl_cache_context *cache = NULL; #endif #if defined(MBEDTLS_SSL_SESSION_TICKETS) - mbedtls_ssl_ticket_context *ticket_ctx; + mbedtls_ssl_ticket_context *ticket_ctx = NULL; #endif #if defined(SNI_OPTION) sni_entry *sni_info = NULL; @@ -2292,7 +2292,7 @@ int main( int argc, char *argv[] ) #if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) mbedtls_memory_buffer_alloc_init( alloc_buf, sizeof(alloc_buf) ); #endif - +#if defined(MBEDTLS_X509_CRT_PARSE_C) ssl = mbedtls_calloc( 1, sizeof( *ssl ) ); conf = mbedtls_calloc( 1, sizeof( *conf ) ); cacert = mbedtls_calloc( 1, sizeof( *cacert ) ); @@ -2300,6 +2300,7 @@ int main( int argc, char *argv[] ) pkey = mbedtls_calloc( 1, sizeof( *pkey ) ); srvcert2 = mbedtls_calloc( 1, sizeof( *srvcert2 ) ); pkey2 = mbedtls_calloc( 1, sizeof( *pkey2 ) ); +#endif #if defined(MBEDTLS_SSL_CACHE_C) cache = mbedtls_calloc( 1, sizeof( *cache ) ); #endif @@ -2309,17 +2310,20 @@ int main( int argc, char *argv[] ) #if defined(MBEDTLS_SSL_SESSION_TICKETS) ticket_ctx = mbedtls_calloc( 1, sizeof( *ticket_ctx ) ); #endif - entropy = mbedtls_calloc( 1, sizeof( *entropy ) ); + #if defined(MBEDTLS_CTR_DRBG_C) ctr_drbg = mbedtls_calloc( 1, sizeof( *ctr_drbg ) ); #else hmac_drbg = mbedtls_calloc( 1, sizeof( *hmac_drbg ) ); #endif - if( ssl == NULL || conf == NULL || + if( +#if defined(MBEDTLS_X509_CRT_PARSE_C) + ssl == NULL || conf == NULL || cacert == NULL || srvcert == NULL || pkey == NULL || srvcert2 == NULL || pkey2 == NULL || +#endif #if defined(MBEDTLS_SSL_CACHE_C) cache == NULL || #endif @@ -2334,7 +2338,7 @@ int main( int argc, char *argv[] ) #else hmac_drbg == NULL || #endif - entropy == NULL ) + 1 == 0) // just to please compiler { goto exit; } @@ -2380,7 +2384,6 @@ int main( int argc, char *argv[] ) - #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) if( unhexify( cid, opt.cid_val, &cid_len ) != 0 ) { @@ -2504,10 +2507,10 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Seeding the random number generator..." ); fflush( stdout ); - mbedtls_entropy_init( entropy ); + mbedtls_entropy_init( &entropy ); #if defined(MBEDTLS_CTR_DRBG_C) if( ( ret = mbedtls_ctr_drbg_seed( ctr_drbg, mbedtls_entropy_func, - entropy, (const unsigned char *) pers, + &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", @@ -2519,7 +2522,7 @@ int main( int argc, char *argv[] ) mbedtls_md_info_from_type( available_hashes[0] ), mbedtls_entropy_func, - entropy, (const unsigned char *) pers, + &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", @@ -3976,7 +3979,7 @@ int main( int argc, char *argv[] ) #else mbedtls_hmac_drbg_free( hmac_drbg ); #endif - mbedtls_entropy_free( entropy ); + mbedtls_entropy_free( &entropy ); #if defined(MBEDTLS_SSL_CACHE_C) mbedtls_ssl_cache_free( cache ); @@ -4000,15 +4003,17 @@ int main( int argc, char *argv[] ) mbedtls_free( ssl ); mbedtls_free( conf ); +#if defined(MBEDTLS_X509_CRT_PARSE_C) mbedtls_free( cacert ); mbedtls_free( srvcert ); mbedtls_free( pkey ); mbedtls_free( srvcert2 ); mbedtls_free( pkey2 ); +#endif #if defined(MBEDTLS_TIMING_C) mbedtls_free( timer ); #endif - mbedtls_free( entropy ); + #if defined(MBEDTLS_CTR_DRBG_C) mbedtls_free( ctr_drbg ); #else