Fix ret code in rsa_genkey.c

This commit is contained in:
Andres Amaya Garcia 2018-04-29 20:12:43 +01:00 committed by Simon Butcher
parent aa3291e1fb
commit a8a96ae42f

View file

@ -29,8 +29,11 @@
#include "mbedtls/platform.h" #include "mbedtls/platform.h"
#else #else
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#define mbedtls_printf printf #define mbedtls_printf printf
#endif #define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS
#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE
#endif /* MBEDTLS_PLATFORM_C */
#if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_ENTROPY_C) && \ #if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_ENTROPY_C) && \
defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME) && \ defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME) && \
@ -61,7 +64,8 @@ int main( void )
#else #else
int main( void ) int main( void )
{ {
int ret; int ret = 1;
int exit_code = MBEDTLS_EXIT_FAILURE;
mbedtls_rsa_context rsa; mbedtls_rsa_context rsa;
mbedtls_entropy_context entropy; mbedtls_entropy_context entropy;
mbedtls_ctr_drbg_context ctr_drbg; mbedtls_ctr_drbg_context ctr_drbg;
@ -105,14 +109,12 @@ int main( void )
( ret = mbedtls_rsa_export_crt( &rsa, &DP, &DQ, &QP ) ) != 0 ) ( ret = mbedtls_rsa_export_crt( &rsa, &DP, &DQ, &QP ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! could not export RSA parameters\n\n" ); mbedtls_printf( " failed\n ! could not export RSA parameters\n\n" );
ret = 1;
goto exit; goto exit;
} }
if( ( fpub = fopen( "rsa_pub.txt", "wb+" ) ) == NULL ) if( ( fpub = fopen( "rsa_pub.txt", "wb+" ) ) == NULL )
{ {
mbedtls_printf( " failed\n ! could not open rsa_pub.txt for writing\n\n" ); mbedtls_printf( " failed\n ! could not open rsa_pub.txt for writing\n\n" );
ret = 1;
goto exit; goto exit;
} }
@ -129,7 +131,6 @@ int main( void )
if( ( fpriv = fopen( "rsa_priv.txt", "wb+" ) ) == NULL ) if( ( fpriv = fopen( "rsa_priv.txt", "wb+" ) ) == NULL )
{ {
mbedtls_printf( " failed\n ! could not open rsa_priv.txt for writing\n" ); mbedtls_printf( " failed\n ! could not open rsa_priv.txt for writing\n" );
ret = 1;
goto exit; goto exit;
} }
@ -160,6 +161,8 @@ int main( void )
*/ */
mbedtls_printf( " ok\n\n" ); mbedtls_printf( " ok\n\n" );
exit_code = MBEDTLS_EXIT_SUCCESS;
exit: exit:
if( fpub != NULL ) if( fpub != NULL )
@ -180,7 +183,7 @@ exit:
fflush( stdout ); getchar(); fflush( stdout ); getchar();
#endif #endif
return( ret ); return( exit_code );
} }
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_RSA_C && #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_RSA_C &&
MBEDTLS_GENPRIME && MBEDTLS_FS_IO && MBEDTLS_CTR_DRBG_C */ MBEDTLS_GENPRIME && MBEDTLS_FS_IO && MBEDTLS_CTR_DRBG_C */