From 738153a0484fc3a403885e3c18f226ecc4ec8585 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Tue, 18 Jun 2019 20:16:43 +0200 Subject: [PATCH] Adding usage and removing dummy random --- programs/ssl/ssl_client2.c | 22 +++++----------------- programs/ssl/ssl_server2.c | 21 +++++---------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index a291013c9..67d23e2b9 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -312,6 +312,9 @@ int main( void ) #define USAGE_ETM "" #endif +#define USAGE_REPRODUCIBLE \ + " reproducible=0/1 default: 0 (disabled)\n" + #if defined(MBEDTLS_SSL_RENEGOTIATION) #define USAGE_RENEGO \ " renegotiation=%%d default: 0 (disabled)\n" \ @@ -383,6 +386,7 @@ int main( void ) USAGE_FALLBACK \ USAGE_EMS \ USAGE_ETM \ + USAGE_REPRODUCIBLE \ USAGE_CURVES \ USAGE_RECSPLIT \ USAGE_DHMLEN \ @@ -547,21 +551,6 @@ mbedtls_time_t dummy_constant_time( mbedtls_time_t* time ) return 0x5af2a056; } -int dummy_random( void *p_rng, unsigned char *output, size_t output_len ) -{ - int ret; - size_t i; - - //use mbedtls_ctr_drbg_random to find bugs in it - ret = mbedtls_ctr_drbg_random( p_rng, output, output_len ); - for ( i = 0; i < output_len; i++ ) - { - //replace result with pseudo random - output[i] = (unsigned char) rand(); - } - return( ret ); -} - int dummy_entropy( void *data, unsigned char *output, size_t len ) { size_t i; @@ -1709,6 +1698,7 @@ int main( int argc, char *argv[] ) mbedtls_entropy_init( &entropy ); if (opt.reproducible) { + srand( 1 ); if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, dummy_entropy, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) @@ -2009,8 +1999,6 @@ int main( int argc, char *argv[] ) if (opt.reproducible) { - srand( 1 ); - mbedtls_ssl_conf_rng( &conf, dummy_random, &ctr_drbg ); #if defined(MBEDTLS_HAVE_TIME) #if defined(MBEDTLS_PLATFORM_TIME_ALT) mbedtls_platform_set_time( dummy_constant_time ); diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index d5c0cae5b..776e555cd 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -402,6 +402,9 @@ int main( void ) #define USAGE_ETM "" #endif +#define USAGE_REPRODUCIBLE \ + " reproducible=0/1 default: 0 (disabled)\n" + #if defined(MBEDTLS_SSL_RENEGOTIATION) #define USAGE_RENEGO \ " renegotiation=%%d default: 0 (disabled)\n" \ @@ -470,6 +473,7 @@ int main( void ) "\n" \ USAGE_TICKETS \ USAGE_EAP_TLS \ + USAGE_REPRODUCIBLE \ USAGE_CACHE \ USAGE_MAX_FRAG_LEN \ USAGE_TRUNC_HMAC \ @@ -660,20 +664,6 @@ mbedtls_time_t dummy_constant_time( mbedtls_time_t* time ) return 0x5af2a056; } -int dummy_random( void *p_rng, unsigned char *output, size_t output_len ) -{ - int ret; - size_t i; - - //use mbedtls_ctr_drbg_random to find bugs in it - ret = mbedtls_ctr_drbg_random( p_rng, output, output_len ); - for ( i = 0; i < output_len; i++ ) { - //replace result with pseudo random - output[i] = (unsigned char) rand(); - } - return( ret ); -} - int dummy_entropy( void *data, unsigned char *output, size_t len ) { size_t i; @@ -2489,6 +2479,7 @@ int main( int argc, char *argv[] ) mbedtls_entropy_init( &entropy ); if (opt.reproducible) { + srand( 1 ); if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, dummy_entropy, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) @@ -2828,8 +2819,6 @@ int main( int argc, char *argv[] ) if (opt.reproducible) { - srand( 1 ); - mbedtls_ssl_conf_rng( &conf, dummy_random, &ctr_drbg ); #if defined(MBEDTLS_HAVE_TIME) #if defined(MBEDTLS_PLATFORM_TIME_ALT) mbedtls_platform_set_time( dummy_constant_time );