From fb3a83f9e39259d11959cb4f4c2f6665e5ab25d7 Mon Sep 17 00:00:00 2001 From: Paul Bakker Date: Thu, 15 Dec 2011 20:05:53 +0000 Subject: [PATCH] - Added appropriate error handling to ctr_drbg_init() --- programs/random/gen_random_ctr_drbg.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/programs/random/gen_random_ctr_drbg.c b/programs/random/gen_random_ctr_drbg.c index ead9bb2483..cb46593596 100644 --- a/programs/random/gen_random_ctr_drbg.c +++ b/programs/random/gen_random_ctr_drbg.c @@ -61,7 +61,12 @@ int main( int argc, char *argv[] ) } entropy_init( &entropy ); - ctr_drbg_init( &ctr_drbg, entropy_func, &entropy, (unsigned char *) "RANDOM_GEN", 10 ); + ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy, (unsigned char *) "RANDOM_GEN", 10 ); + if( ret != 0 ) + { + printf( "failed in ctr_drbg_init: %d\n", ret ); + goto cleanup; + } ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_OFF ); #if defined(POLARSSL_FS_IO) @@ -69,17 +74,17 @@ int main( int argc, char *argv[] ) if( ret == POLARSSL_ERR_CTR_DRBG_FILE_IO_ERROR ) { - printf("Failed to open seedfile. Generating one.\n"); + printf( "Failed to open seedfile. Generating one.\n" ); ret = ctr_drbg_write_seed_file( &ctr_drbg, "seedfile" ); if( ret != 0 ) { - printf("failed in ctr_drbg_write_seed_file: %d\n", ret ); + printf( "failed in ctr_drbg_write_seed_file: %d\n", ret ); goto cleanup; } } else if( ret != 0 ) { - printf("failed in ctr_drbg_update_seed_file: %d\n", ret ); + printf( "failed in ctr_drbg_update_seed_file: %d\n", ret ); goto cleanup; } #endif