From ec160c0f53db6095e959ba17ad5e325e44898160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 28 Apr 2015 22:52:30 +0200 Subject: [PATCH] Update ctr_drbg_init() usage in programs --- programs/pkey/dh_client.c | 5 +++-- programs/pkey/dh_genprime.c | 5 +++-- programs/pkey/dh_server.c | 5 +++-- programs/pkey/ecdsa.c | 5 +++-- programs/pkey/gen_key.c | 5 +++-- programs/pkey/pk_decrypt.c | 5 +++-- programs/pkey/pk_encrypt.c | 5 +++-- programs/pkey/pk_sign.c | 5 +++-- programs/pkey/rsa_decrypt.c | 5 +++-- programs/pkey/rsa_encrypt.c | 5 +++-- programs/pkey/rsa_genkey.c | 6 ++++-- programs/pkey/rsa_sign_pss.c | 5 +++-- programs/random/gen_random_ctr_drbg.c | 6 ++++-- programs/ssl/dtls_client.c | 5 +++-- programs/ssl/dtls_server.c | 5 +++-- programs/ssl/mini_client.c | 5 +++-- programs/ssl/ssl_client1.c | 5 +++-- programs/ssl/ssl_client2.c | 5 +++-- programs/ssl/ssl_fork_server.c | 5 +++-- programs/ssl/ssl_mail_client.c | 5 +++-- programs/ssl/ssl_pthread_server.c | 6 +++--- programs/ssl/ssl_server.c | 5 +++-- programs/ssl/ssl_server2.c | 5 +++-- programs/x509/cert_app.c | 5 +++-- programs/x509/cert_req.c | 5 +++-- programs/x509/cert_write.c | 5 +++-- 26 files changed, 80 insertions(+), 53 deletions(-) diff --git a/programs/pkey/dh_client.c b/programs/pkey/dh_client.c index 50b69159e..21c379633 100644 --- a/programs/pkey/dh_client.c +++ b/programs/pkey/dh_client.c @@ -87,6 +87,7 @@ int main( void ) memset( &rsa, 0, sizeof( rsa ) ); mbedtls_dhm_init( &dhm ); mbedtls_aes_init( &aes ); + mbedtls_ctr_drbg_init( &ctr_drbg ); /* * 1. Setup the RNG @@ -95,11 +96,11 @@ int main( void ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/pkey/dh_genprime.c b/programs/pkey/dh_genprime.c index d6ebca0ba..6169e916f 100644 --- a/programs/pkey/dh_genprime.c +++ b/programs/pkey/dh_genprime.c @@ -72,6 +72,7 @@ int main( void ) FILE *fout; mbedtls_mpi_init( &G ); mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q ); + mbedtls_ctr_drbg_init( &ctr_drbg ); mbedtls_entropy_init( &entropy ); if( ( ret = mbedtls_mpi_read_string( &G, 10, GENERATOR ) ) != 0 ) @@ -92,11 +93,11 @@ int main( void ) mbedtls_printf( "\n . Seeding the random number generator..." ); fflush( stdout ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/pkey/dh_server.c b/programs/pkey/dh_server.c index f2bf61b99..68a82e33f 100644 --- a/programs/pkey/dh_server.c +++ b/programs/pkey/dh_server.c @@ -88,6 +88,7 @@ int main( void ) memset( &rsa, 0, sizeof( rsa ) ); mbedtls_dhm_init( &dhm ); mbedtls_aes_init( &aes ); + mbedtls_ctr_drbg_init( &ctr_drbg ); /* * 1. Setup the RNG @@ -96,11 +97,11 @@ int main( void ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/pkey/ecdsa.c b/programs/pkey/ecdsa.c index 28acf37aa..22d2911c6 100644 --- a/programs/pkey/ecdsa.c +++ b/programs/pkey/ecdsa.c @@ -110,6 +110,7 @@ int main( int argc, char *argv[] ) mbedtls_ecdsa_init( &ctx_sign ); mbedtls_ecdsa_init( &ctx_verify ); + mbedtls_ctr_drbg_init( &ctr_drbg ); memset(sig, 0, sizeof( sig ) ); ret = 1; @@ -132,11 +133,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c index 17baabe6d..8aa193c3e 100644 --- a/programs/pkey/gen_key.c +++ b/programs/pkey/gen_key.c @@ -201,6 +201,7 @@ int main( int argc, char *argv[] ) * Set to sane values */ mbedtls_pk_init( &key ); + mbedtls_ctr_drbg_init( &ctr_drbg ); memset( buf, 0, sizeof( buf ) ); if( argc == 0 ) @@ -296,11 +297,11 @@ int main( int argc, char *argv[] ) } #endif /* !_WIN32 && MBEDTLS_FS_IO */ - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", -ret ); goto exit; } diff --git a/programs/pkey/pk_decrypt.c b/programs/pkey/pk_decrypt.c index a6c79adf4..f6c864ca1 100644 --- a/programs/pkey/pk_decrypt.c +++ b/programs/pkey/pk_decrypt.c @@ -70,6 +70,7 @@ int main( int argc, char *argv[] ) const char *pers = "mbedtls_pk_decrypt"; ((void) argv); + mbedtls_ctr_drbg_init( &ctr_drbg ); memset(result, 0, sizeof( result ) ); ret = 1; @@ -88,11 +89,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/pkey/pk_encrypt.c b/programs/pkey/pk_encrypt.c index bfef31c35..4e71be166 100644 --- a/programs/pkey/pk_encrypt.c +++ b/programs/pkey/pk_encrypt.c @@ -70,6 +70,7 @@ int main( int argc, char *argv[] ) const char *pers = "mbedtls_pk_encrypt"; ret = 1; + mbedtls_ctr_drbg_init( &ctr_drbg ); if( argc != 3 ) { @@ -86,11 +87,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", -ret ); goto exit; } diff --git a/programs/pkey/pk_sign.c b/programs/pkey/pk_sign.c index 150b09006..be8b5139b 100644 --- a/programs/pkey/pk_sign.c +++ b/programs/pkey/pk_sign.c @@ -81,6 +81,7 @@ int main( int argc, char *argv[] ) size_t olen = 0; mbedtls_entropy_init( &entropy ); + mbedtls_ctr_drbg_init( &ctr_drbg ); mbedtls_pk_init( &pk ); if( argc != 3 ) @@ -97,11 +98,11 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Seeding the random number generator..." ); fflush( stdout ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned -0x%04x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%04x\n", -ret ); goto exit; } diff --git a/programs/pkey/rsa_decrypt.c b/programs/pkey/rsa_decrypt.c index 24b7efbf7..de16de539 100644 --- a/programs/pkey/rsa_decrypt.c +++ b/programs/pkey/rsa_decrypt.c @@ -69,6 +69,7 @@ int main( int argc, char *argv[] ) ((void) argv); memset(result, 0, sizeof( result ) ); + mbedtls_ctr_drbg_init( &ctr_drbg ); ret = 1; if( argc != 1 ) @@ -86,11 +87,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/pkey/rsa_encrypt.c b/programs/pkey/rsa_encrypt.c index 106ce2b06..a3f9a6636 100644 --- a/programs/pkey/rsa_encrypt.c +++ b/programs/pkey/rsa_encrypt.c @@ -68,6 +68,7 @@ int main( int argc, char *argv[] ) unsigned char buf[512]; const char *pers = "rsa_encrypt"; + mbedtls_ctr_drbg_init( &ctr_drbg ); ret = 1; if( argc != 2 ) @@ -85,11 +86,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/pkey/rsa_genkey.c b/programs/pkey/rsa_genkey.c index d9b5b4b56..986a6ab05 100644 --- a/programs/pkey/rsa_genkey.c +++ b/programs/pkey/rsa_genkey.c @@ -70,15 +70,17 @@ int main( void ) FILE *fpriv = NULL; const char *pers = "rsa_genkey"; + mbedtls_ctr_drbg_init( &ctr_drbg ); + mbedtls_printf( "\n . Seeding the random number generator..." ); fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/pkey/rsa_sign_pss.c b/programs/pkey/rsa_sign_pss.c index 2bbba8c3d..c8b38f7f3 100644 --- a/programs/pkey/rsa_sign_pss.c +++ b/programs/pkey/rsa_sign_pss.c @@ -82,6 +82,7 @@ int main( int argc, char *argv[] ) mbedtls_entropy_init( &entropy ); mbedtls_pk_init( &pk ); + mbedtls_ctr_drbg_init( &ctr_drbg ); if( argc != 3 ) { @@ -97,11 +98,11 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Seeding the random number generator..." ); fflush( stdout ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/random/gen_random_ctr_drbg.c b/programs/random/gen_random_ctr_drbg.c index 67dc76642..ad086ccb6 100644 --- a/programs/random/gen_random_ctr_drbg.c +++ b/programs/random/gen_random_ctr_drbg.c @@ -58,6 +58,8 @@ int main( int argc, char *argv[] ) mbedtls_entropy_context entropy; unsigned char buf[1024]; + mbedtls_ctr_drbg_init( &ctr_drbg ); + if( argc < 2 ) { mbedtls_fprintf( stderr, "usage: %s \n", argv[0] ); @@ -71,10 +73,10 @@ int main( int argc, char *argv[] ) } mbedtls_entropy_init( &entropy ); - ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) "RANDOM_GEN", 10 ); + ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) "RANDOM_GEN", 10 ); if( ret != 0 ) { - mbedtls_printf( "failed in mbedtls_ctr_drbg_init: %d\n", ret ); + mbedtls_printf( "failed in mbedtls_ctr_drbg_seed: %d\n", ret ); goto cleanup; } mbedtls_ctr_drbg_set_prediction_resistance( &ctr_drbg, MBEDTLS_CTR_DRBG_PR_OFF ); diff --git a/programs/ssl/dtls_client.c b/programs/ssl/dtls_client.c index 580db829a..4a8642d5e 100644 --- a/programs/ssl/dtls_client.c +++ b/programs/ssl/dtls_client.c @@ -106,16 +106,17 @@ int main( int argc, char *argv[] ) */ memset( &ssl, 0, sizeof( mbedtls_ssl_context ) ); mbedtls_x509_crt_init( &cacert ); + mbedtls_ctr_drbg_init( &ctr_drbg ); mbedtls_printf( "\n . Seeding the random number generator..." ); fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/ssl/dtls_server.c b/programs/ssl/dtls_server.c index 689a0a741..92170ebb3 100644 --- a/programs/ssl/dtls_server.c +++ b/programs/ssl/dtls_server.c @@ -111,6 +111,7 @@ int main( void ) mbedtls_x509_crt_init( &srvcert ); mbedtls_pk_init( &pkey ); mbedtls_entropy_init( &entropy ); + mbedtls_ctr_drbg_init( &ctr_drbg ); #if defined(MBEDTLS_DEBUG_C) mbedtls_debug_set_threshold( DEBUG_LEVEL ); @@ -173,11 +174,11 @@ int main( void ) printf( " . Seeding the random number generator..." ); fflush( stdout ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/ssl/mini_client.c b/programs/ssl/mini_client.c index 903177c91..ad9e85191 100644 --- a/programs/ssl/mini_client.c +++ b/programs/ssl/mini_client.c @@ -146,7 +146,7 @@ const unsigned char ca_cert[] = { enum exit_codes { exit_ok = 0, - ctr_drbg_init_failed, + ctr_drbg_seed_failed, ssl_init_failed, socket_failed, connect_failed, @@ -167,6 +167,7 @@ int main( void ) mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; mbedtls_ssl_context ssl; + mbedtls_ctr_drbg_init( &ctr_drbg ); /* * 0. Initialize and setup stuff @@ -177,7 +178,7 @@ int main( void ) #endif mbedtls_entropy_init( &entropy ); - if( mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) != 0 ) { ret = ssl_init_failed; diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c index a039290d0..77a68e64c 100644 --- a/programs/ssl/ssl_client1.c +++ b/programs/ssl/ssl_client1.c @@ -94,16 +94,17 @@ int main( void ) */ memset( &ssl, 0, sizeof( mbedtls_ssl_context ) ); mbedtls_x509_crt_init( &cacert ); + mbedtls_ctr_drbg_init( &ctr_drbg ); mbedtls_printf( "\n . Seeding the random number generator..." ); fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index b6c776a5e..280b50d84 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -416,6 +416,7 @@ int main( int argc, char *argv[] ) server_fd = 0; memset( &ssl, 0, sizeof( mbedtls_ssl_context ) ); memset( &saved_session, 0, sizeof( mbedtls_ssl_session ) ); + mbedtls_ctr_drbg_init( &ctr_drbg ); #if defined(MBEDTLS_X509_CRT_PARSE_C) mbedtls_x509_crt_init( &cacert ); mbedtls_x509_crt_init( &clicert ); @@ -899,11 +900,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned -0x%x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", -ret ); goto exit; } diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c index 717d35bbc..9f00310d7 100644 --- a/programs/ssl/ssl_fork_server.c +++ b/programs/ssl/ssl_fork_server.c @@ -111,6 +111,7 @@ int main( void ) mbedtls_entropy_init( &entropy ); mbedtls_pk_init( &pkey ); mbedtls_x509_crt_init( &srvcert ); + mbedtls_ctr_drbg_init( &ctr_drbg ); signal( SIGCHLD, SIG_IGN ); @@ -120,11 +121,11 @@ int main( void ) mbedtls_printf( "\n . Initial seeding of the random generator..." ); fflush( stdout ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c index 371d9ad28..78abc2864 100644 --- a/programs/ssl/ssl_mail_client.c +++ b/programs/ssl/ssl_mail_client.c @@ -372,6 +372,7 @@ int main( int argc, char *argv[] ) mbedtls_x509_crt_init( &cacert ); mbedtls_x509_crt_init( &clicert ); mbedtls_pk_init( &pkey ); + mbedtls_ctr_drbg_init( &ctr_drbg ); if( argc == 0 ) { @@ -471,11 +472,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/ssl/ssl_pthread_server.c b/programs/ssl/ssl_pthread_server.c index 1ca6f1788..b32ceda01 100644 --- a/programs/ssl/ssl_pthread_server.c +++ b/programs/ssl/ssl_pthread_server.c @@ -134,7 +134,7 @@ static void *handle_ssl_connection( void *data ) /* Make sure memory references are valid */ memset( &ssl, 0, sizeof( mbedtls_ssl_context ) ); - memset( &ctr_drbg, 0, sizeof( mbedtls_ctr_drbg_context ) ); + mbedtls_ctr_drbg_init( &ctr_drbg ); mbedtls_snprintf( pers, sizeof(pers), "SSL Pthread Thread %d", thread_id ); mbedtls_printf( " [ #%d ] Client FD %d\n", thread_id, client_fd ); @@ -142,11 +142,11 @@ static void *handle_ssl_connection( void *data ) /* mbedtls_entropy_func() is thread-safe if MBEDTLS_THREADING_C is set */ - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, thread_info->entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, thread_info->entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " [ #%d ] failed: mbedtls_ctr_drbg_init returned -0x%04x\n", + mbedtls_printf( " [ #%d ] failed: mbedtls_ctr_drbg_seed returned -0x%04x\n", thread_id, -ret ); goto thread_exit; } diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c index 34dc2a1cb..e8f765e5f 100644 --- a/programs/ssl/ssl_server.c +++ b/programs/ssl/ssl_server.c @@ -110,6 +110,7 @@ int main( void ) mbedtls_x509_crt_init( &srvcert ); mbedtls_pk_init( &pkey ); mbedtls_entropy_init( &entropy ); + mbedtls_ctr_drbg_init( &ctr_drbg ); #if defined(MBEDTLS_DEBUG_C) mbedtls_debug_set_threshold( DEBUG_LEVEL ); @@ -172,11 +173,11 @@ int main( void ) mbedtls_printf( " . Seeding the random number generator..." ); fflush( stdout ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index b6d41c56e..f1dff6017 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -762,6 +762,7 @@ int main( int argc, char *argv[] ) */ listen_fd = 0; memset( &ssl, 0, sizeof( mbedtls_ssl_context ) ); + mbedtls_ctr_drbg_init( &ctr_drbg ); #if defined(MBEDTLS_X509_CRT_PARSE_C) mbedtls_x509_crt_init( &cacert ); mbedtls_x509_crt_init( &srvcert ); @@ -1296,11 +1297,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned -0x%x\n", -ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned -0x%x\n", -ret ); goto exit; } diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c index 04fd32549..ce58ab2c2 100644 --- a/programs/x509/cert_app.c +++ b/programs/x509/cert_app.c @@ -159,6 +159,7 @@ int main( int argc, char *argv[] ) * Set to sane values */ server_fd = 0; + mbedtls_ctr_drbg_init( &ctr_drbg ); mbedtls_x509_crt_init( &cacert ); mbedtls_x509_crt_init( &clicert ); #if defined(MBEDTLS_X509_CRL_PARSE_C) @@ -365,11 +366,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d\n", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", ret ); goto exit; } diff --git a/programs/x509/cert_req.c b/programs/x509/cert_req.c index 30594431a..9ea08bd6a 100644 --- a/programs/x509/cert_req.c +++ b/programs/x509/cert_req.c @@ -149,6 +149,7 @@ int main( int argc, char *argv[] ) mbedtls_x509write_csr_init( &req ); mbedtls_x509write_csr_set_md_alg( &req, MBEDTLS_MD_SHA256 ); mbedtls_pk_init( &key ); + mbedtls_ctr_drbg_init( &ctr_drbg ); memset( buf, 0, sizeof( buf ) ); if( argc == 0 ) @@ -259,11 +260,11 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d", ret ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d", ret ); goto exit; } diff --git a/programs/x509/cert_write.c b/programs/x509/cert_write.c index 20ee5b408..8c4e6da22 100644 --- a/programs/x509/cert_write.c +++ b/programs/x509/cert_write.c @@ -211,6 +211,7 @@ int main( int argc, char *argv[] ) mbedtls_pk_init( &loaded_issuer_key ); mbedtls_pk_init( &loaded_subject_key ); mbedtls_mpi_init( &serial ); + mbedtls_ctr_drbg_init( &ctr_drbg ); #if defined(MBEDTLS_X509_CSR_PARSE_C) mbedtls_x509_csr_init( &csr ); #endif @@ -371,12 +372,12 @@ int main( int argc, char *argv[] ) fflush( stdout ); mbedtls_entropy_init( &entropy ); - if( ( ret = mbedtls_ctr_drbg_init( &ctr_drbg, mbedtls_entropy_func, &entropy, + if( ( ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) ) != 0 ) { mbedtls_strerror( ret, buf, 1024 ); - mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_init returned %d - %s\n", ret, buf ); + mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d - %s\n", ret, buf ); goto exit; }