From 3c41e564f8eeb5012df5877efbbbba2b68914a6f Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:23:38 +0100 Subject: [PATCH] Fix ret code in rsa_sign_pss.c --- programs/pkey/rsa_sign_pss.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/programs/pkey/rsa_sign_pss.c b/programs/pkey/rsa_sign_pss.c index 7b6f14dd8..3b58c297b 100644 --- a/programs/pkey/rsa_sign_pss.c +++ b/programs/pkey/rsa_sign_pss.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_snprintf snprintf -#define mbedtls_printf printf -#endif +#include +#define mbedtls_snprintf snprintf +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_MD_C) || !defined(MBEDTLS_ENTROPY_C) || \ !defined(MBEDTLS_RSA_C) || !defined(MBEDTLS_SHA256_C) || \ @@ -61,6 +64,7 @@ int main( int argc, char *argv[] ) { FILE *f; int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_pk_context pk; mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; @@ -101,7 +105,6 @@ int main( int argc, char *argv[] ) if( ( ret = mbedtls_pk_parse_keyfile( &pk, argv[1], "" ) ) != 0 ) { - ret = 1; mbedtls_printf( " failed\n ! Could not read key from '%s'\n", argv[1] ); mbedtls_printf( " ! mbedtls_pk_parse_public_keyfile returned %d\n\n", ret ); goto exit; @@ -109,7 +112,6 @@ int main( int argc, char *argv[] ) if( !mbedtls_pk_can_do( &pk, MBEDTLS_PK_RSA ) ) { - ret = 1; mbedtls_printf( " failed\n ! Key is not an RSA key\n" ); goto exit; } @@ -145,7 +147,6 @@ int main( int argc, char *argv[] ) if( ( f = fopen( filename, "wb+" ) ) == NULL ) { - ret = 1; mbedtls_printf( " failed\n ! Could not create %s\n\n", filename ); goto exit; } @@ -161,6 +162,8 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Done (created \"%s\")\n\n", filename ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_pk_free( &pk ); mbedtls_ctr_drbg_free( &ctr_drbg ); @@ -171,7 +174,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_RSA_C && MBEDTLS_SHA256_C && MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO &&