From 15cbf6180558109e8fe1d7b8b5c1925e1f90f591 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 19:01:34 +0100 Subject: [PATCH 01/41] Fix ret code in aescrypt2.c --- programs/aes/aescrypt2.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/programs/aes/aescrypt2.c b/programs/aes/aescrypt2.c index 4acf38dd7..31daf1e2c 100644 --- a/programs/aes/aescrypt2.c +++ b/programs/aes/aescrypt2.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#include +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #include "mbedtls/aes.h" #include "mbedtls/md.h" @@ -71,7 +74,8 @@ int main( void ) #else int main( int argc, char *argv[] ) { - int ret = 1; + int ret = 0; + int exit_code = MBEDTLS_EXIT_FAILURE; unsigned int i, n; int mode, lastn; @@ -429,7 +433,7 @@ int main( int argc, char *argv[] ) } } - ret = 0; + exit_code = MBEDTLS_EXIT_SUCCESS; exit: if( fin ) @@ -452,6 +456,6 @@ exit: mbedtls_aes_free( &aes_ctx ); mbedtls_md_free( &sha_ctx ); - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_AES_C && MBEDTLS_SHA256_C && MBEDTLS_FS_IO */ From 990900ff409428ae67889b4ba9ce5996ebbaabc8 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 19:11:26 +0100 Subject: [PATCH 02/41] Fix ret code in crypt_and_hash.c --- programs/aes/crypt_and_hash.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/programs/aes/crypt_and_hash.c b/programs/aes/crypt_and_hash.c index 0e272ebe4..9e234e672 100644 --- a/programs/aes/crypt_and_hash.c +++ b/programs/aes/crypt_and_hash.c @@ -30,9 +30,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#include +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_CIPHER_C) && defined(MBEDTLS_MD_C) && \ defined(MBEDTLS_FS_IO) @@ -74,6 +77,7 @@ int main( void ) int main( int argc, char *argv[] ) { int ret = 1, i, n; + int exit_code = MBEDTLS_EXIT_FAILURE; int mode; size_t keylen, ilen, olen; FILE *fkey, *fin = NULL, *fout = NULL; @@ -526,7 +530,7 @@ int main( int argc, char *argv[] ) } } - ret = 0; + exit_code = MBEDTLS_EXIT_SUCCESS; exit: if( fin ) @@ -549,6 +553,6 @@ exit: mbedtls_cipher_free( &cipher_ctx ); mbedtls_md_free( &md_ctx ); - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_CIPHER_C && MBEDTLS_MD_C && MBEDTLS_FS_IO */ From f842345ac3e01a43a9d243b63aade8aa7c973b9a Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 19:23:39 +0100 Subject: [PATCH 03/41] Fix ret code in dh_client.c --- programs/pkey/dh_client.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/programs/pkey/dh_client.c b/programs/pkey/dh_client.c index 0978408c1..68f0df58e 100644 --- a/programs/pkey/dh_client.c +++ b/programs/pkey/dh_client.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#define mbedtls_time_t time_t -#endif +#include +#define mbedtls_printf printf +#define mbedtls_time_t time_t +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_AES_C) && defined(MBEDTLS_DHM_C) && \ defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_NET_C) && \ @@ -71,7 +74,8 @@ int main( void ) { FILE *f; - int ret; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; size_t n, buflen; mbedtls_net_context server_fd; @@ -115,7 +119,6 @@ int main( void ) if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL ) { - ret = 1; mbedtls_printf( " failed\n ! Could not open rsa_pub.txt\n" \ " ! Please run rsa_genkey first\n\n" ); goto exit; @@ -191,7 +194,6 @@ int main( void ) if( dhm.len < 64 || dhm.len > 512 ) { - ret = 1; mbedtls_printf( " failed\n ! Invalid DHM modulus size\n\n" ); goto exit; } @@ -286,6 +288,8 @@ int main( void ) buf[16] = '\0'; mbedtls_printf( "\n . Plaintext is \"%s\"\n\n", (char *) buf ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_net_free( &server_fd ); @@ -301,7 +305,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_AES_C && MBEDTLS_DHM_C && MBEDTLS_ENTROPY_C && MBEDTLS_NET_C && MBEDTLS_RSA_C && MBEDTLS_SHA256_C && From 74c51e6e6433eeed0404a26791dc44bf26ae03dd Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 19:34:09 +0100 Subject: [PATCH 04/41] Fix ret code in dh_genprime.c --- programs/pkey/dh_genprime.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/programs/pkey/dh_genprime.c b/programs/pkey/dh_genprime.c index 84a94a18b..7884ea668 100644 --- a/programs/pkey/dh_genprime.c +++ b/programs/pkey/dh_genprime.c @@ -30,9 +30,11 @@ #else #include #include -#define mbedtls_printf printf -#define mbedtls_time_t time_t -#endif +#define mbedtls_printf printf +#define mbedtls_time_t time_t +#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) || \ !defined(MBEDTLS_FS_IO) || !defined(MBEDTLS_CTR_DRBG_C) || \ @@ -69,6 +71,7 @@ int main( void ) int main( int argc, char **argv ) { int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_mpi G, P, Q; mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; @@ -86,7 +89,7 @@ int main( int argc, char **argv ) { usage: mbedtls_printf( USAGE ); - return( 1 ); + return( exit_code ); } for( i = 1; i < argc; i++ ) @@ -164,7 +167,6 @@ int main( int argc, char **argv ) if( ( fout = fopen( "dh_prime.txt", "wb+" ) ) == NULL ) { - ret = 1; mbedtls_printf( " failed\n ! Could not create dh_prime.txt\n\n" ); goto exit; } @@ -180,6 +182,8 @@ int main( int argc, char **argv ) mbedtls_printf( " ok\n\n" ); fclose( fout ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_mpi_free( &G ); mbedtls_mpi_free( &P ); mbedtls_mpi_free( &Q ); @@ -191,7 +195,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_FS_IO && MBEDTLS_CTR_DRBG_C && MBEDTLS_GENPRIME */ From 114ba1955eb7496a1f824682a82d55b37d6204c5 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 19:40:45 +0100 Subject: [PATCH 05/41] Fix ret code in dh_server.c --- programs/pkey/dh_server.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/programs/pkey/dh_server.c b/programs/pkey/dh_server.c index 430423154..d7765e332 100644 --- a/programs/pkey/dh_server.c +++ b/programs/pkey/dh_server.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#define mbedtls_time_t time_t -#endif +#include +#define mbedtls_printf printf +#define mbedtls_time_t time_t +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_AES_C) && defined(MBEDTLS_DHM_C) && \ defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_NET_C) && \ @@ -71,7 +74,8 @@ int main( void ) { FILE *f; - int ret; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; size_t n, buflen; mbedtls_net_context listen_fd, client_fd; @@ -121,7 +125,6 @@ int main( void ) if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL ) { - ret = 1; mbedtls_printf( " failed\n ! Could not open rsa_priv.txt\n" \ " ! Please run rsa_genkey first\n\n" ); goto exit; @@ -164,7 +167,6 @@ int main( void ) if( ( f = fopen( "dh_prime.txt", "rb" ) ) == NULL ) { - ret = 1; mbedtls_printf( " failed\n ! Could not open dh_prime.txt\n" \ " ! Please run dh_genprime first\n\n" ); goto exit; @@ -304,6 +306,8 @@ int main( void ) mbedtls_printf( "\n\n" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_mpi_free( &N ); mbedtls_mpi_free( &P ); mbedtls_mpi_free( &Q ); @@ -323,7 +327,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_AES_C && MBEDTLS_DHM_C && MBEDTLS_ENTROPY_C && MBEDTLS_NET_C && MBEDTLS_RSA_C && MBEDTLS_SHA256_C && From 47c041190caadd945b05272c5fb49965dd01cdc9 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 19:45:25 +0100 Subject: [PATCH 06/41] Fix ret code in ecdsa.c --- programs/pkey/ecdsa.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/programs/pkey/ecdsa.c b/programs/pkey/ecdsa.c index b47406010..8455bb52b 100644 --- a/programs/pkey/ecdsa.c +++ b/programs/pkey/ecdsa.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_ECDSA_C) && \ defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_CTR_DRBG_C) @@ -98,7 +101,8 @@ static void dump_pubkey( const char *title, mbedtls_ecdsa_context *key ) int main( int argc, char *argv[] ) { - int ret; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_ecdsa_context ctx_sign, ctx_verify; mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; @@ -115,7 +119,6 @@ int main( int argc, char *argv[] ) memset( sig, 0, sizeof( sig ) ); memset( message, 0x25, sizeof( message ) ); - ret = 1; if( argc != 1 ) { @@ -213,8 +216,6 @@ int main( int argc, char *argv[] ) goto exit; } - ret = 0; - /* * Verify signature */ @@ -231,6 +232,8 @@ int main( int argc, char *argv[] ) mbedtls_printf( " ok\n" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: #if defined(_WIN32) @@ -243,7 +246,7 @@ exit: mbedtls_ctr_drbg_free( &ctr_drbg ); mbedtls_entropy_free( &entropy ); - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C && ECPARAMS */ From 7c55e79f5495137209ee1f1dcd4c1b3f8abe2d46 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 19:51:56 +0100 Subject: [PATCH 07/41] Fix ret code in gen_key.c --- programs/pkey/gen_key.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c index a7f5c90a6..9a98fda56 100644 --- a/programs/pkey/gen_key.c +++ b/programs/pkey/gen_key.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_PK_WRITE_C) && defined(MBEDTLS_FS_IO) && \ defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_CTR_DRBG_C) @@ -186,7 +189,8 @@ static int write_private_key( mbedtls_pk_context *key, const char *output_file ) int main( int argc, char *argv[] ) { - int ret = 0; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_pk_context key; char buf[1024]; int i; @@ -214,7 +218,6 @@ int main( int argc, char *argv[] ) if( argc == 0 ) { usage: - ret = 1; mbedtls_printf( USAGE ); #if defined(MBEDTLS_ECP_C) mbedtls_printf( " available ec_curve values:\n" ); @@ -222,7 +225,7 @@ int main( int argc, char *argv[] ) mbedtls_printf( " %s (default)\n", curve_info->name ); while( ( ++curve_info )->name != NULL ) mbedtls_printf( " %s\n", curve_info->name ); -#endif +#endif /* MBEDTLS_ECP_C */ goto exit; } @@ -411,9 +414,11 @@ int main( int argc, char *argv[] ) mbedtls_printf( " ok\n" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: - if( ret != 0 && ret != 1) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { #ifdef MBEDTLS_ERROR_C mbedtls_strerror( ret, buf, sizeof( buf ) ); @@ -436,7 +441,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_PK_WRITE_C && MBEDTLS_PEM_WRITE_C && MBEDTLS_FS_IO && * MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ From f57bccf83915eca6ae544a6b5c6bfebbd3cc8433 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:02:18 +0100 Subject: [PATCH 08/41] Fix ret code in key_app.c --- programs/pkey/key_app.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/programs/pkey/key_app.c b/programs/pkey/key_app.c index f1b548d05..56930781f 100644 --- a/programs/pkey/key_app.c +++ b/programs/pkey/key_app.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_BIGNUM_C) && \ defined(MBEDTLS_PK_PARSE_C) && defined(MBEDTLS_FS_IO) @@ -83,7 +86,8 @@ struct options int main( int argc, char *argv[] ) { - int ret = 0; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; char buf[1024]; int i; char *p, *q; @@ -283,10 +287,12 @@ int main( int argc, char *argv[] ) else goto usage; + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: #if defined(MBEDTLS_ERROR_C) - if( ret != 0 ) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { mbedtls_strerror( ret, buf, sizeof(buf) ); mbedtls_printf( " ! Last error was: %s\n", buf ); @@ -303,6 +309,6 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO */ From aa3291e1fbbcb63b5e05a9e298d08aaf97b7d27a Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:07:30 +0100 Subject: [PATCH 09/41] Fix ret code in key_app_writer.c --- programs/pkey/key_app_writer.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/programs/pkey/key_app_writer.c b/programs/pkey/key_app_writer.c index 5f7d2ddb5..0292a1d63 100644 --- a/programs/pkey/key_app_writer.c +++ b/programs/pkey/key_app_writer.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_PK_WRITE_C) && defined(MBEDTLS_FS_IO) #include "mbedtls/error.h" @@ -189,7 +192,8 @@ static int write_private_key( mbedtls_pk_context *key, const char *output_file ) int main( int argc, char *argv[] ) { - int ret = 0; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; char buf[1024]; int i; char *p, *q; @@ -210,7 +214,6 @@ int main( int argc, char *argv[] ) if( argc == 0 ) { usage: - ret = 1; mbedtls_printf( USAGE ); goto exit; } @@ -403,9 +406,11 @@ int main( int argc, char *argv[] ) write_private_key( &key, opt.output_file ); } + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: - if( ret != 0 && ret != 1) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { #ifdef MBEDTLS_ERROR_C mbedtls_strerror( ret, buf, sizeof( buf ) ); @@ -426,6 +431,6 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_PK_WRITE_C && MBEDTLS_FS_IO */ From a8a96ae42fb6599217108293b9cf70ce4e3d6e9e Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:12:43 +0100 Subject: [PATCH 10/41] Fix ret code in rsa_genkey.c --- programs/pkey/rsa_genkey.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/programs/pkey/rsa_genkey.c b/programs/pkey/rsa_genkey.c index 939921761..1afec559b 100644 --- a/programs/pkey/rsa_genkey.c +++ b/programs/pkey/rsa_genkey.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#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) && \ defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME) && \ @@ -61,7 +64,8 @@ int main( void ) #else int main( void ) { - int ret; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_rsa_context rsa; mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; @@ -105,14 +109,12 @@ int main( void ) ( ret = mbedtls_rsa_export_crt( &rsa, &DP, &DQ, &QP ) ) != 0 ) { mbedtls_printf( " failed\n ! could not export RSA parameters\n\n" ); - ret = 1; goto exit; } if( ( fpub = fopen( "rsa_pub.txt", "wb+" ) ) == NULL ) { mbedtls_printf( " failed\n ! could not open rsa_pub.txt for writing\n\n" ); - ret = 1; goto exit; } @@ -129,7 +131,6 @@ int main( void ) if( ( fpriv = fopen( "rsa_priv.txt", "wb+" ) ) == NULL ) { mbedtls_printf( " failed\n ! could not open rsa_priv.txt for writing\n" ); - ret = 1; goto exit; } @@ -160,6 +161,8 @@ int main( void ) */ mbedtls_printf( " ok\n\n" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: if( fpub != NULL ) @@ -180,7 +183,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_RSA_C && MBEDTLS_GENPRIME && MBEDTLS_FS_IO && MBEDTLS_CTR_DRBG_C */ From 39e1964960bfef1866ae8216be64f29a7fc2d0e9 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:16:46 +0100 Subject: [PATCH 11/41] Fix ret code in rsa_sign.c --- programs/pkey/rsa_sign.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/programs/pkey/rsa_sign.c b/programs/pkey/rsa_sign.c index 89018cb76..c6c790519 100644 --- a/programs/pkey/rsa_sign.c +++ b/programs/pkey/rsa_sign.c @@ -29,10 +29,13 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#define mbedtls_snprintf snprintf -#endif +#include +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define mbedtls_snprintf snprintf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \ !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_MD_C) || \ @@ -55,7 +58,8 @@ int main( void ) int main( int argc, char *argv[] ) { FILE *f; - int ret; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; size_t i; mbedtls_rsa_context rsa; unsigned char hash[32]; @@ -69,8 +73,6 @@ int main( int argc, char *argv[] ) mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &DP ); mbedtls_mpi_init( &DQ ); mbedtls_mpi_init( &QP ); - ret = 1; - if( argc != 2 ) { mbedtls_printf( "usage: rsa_sign \n" ); @@ -87,7 +89,6 @@ int main( int argc, char *argv[] ) if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL ) { - ret = 1; mbedtls_printf( " failed\n ! Could not open rsa_priv.txt\n" \ " ! Please run rsa_genkey first\n\n" ); goto exit; @@ -159,7 +160,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", argv[1] ); goto exit; } @@ -172,6 +172,8 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Done (created \"%s\")\n\n", filename ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_rsa_free( &rsa ); @@ -184,7 +186,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_SHA256_C && MBEDTLS_FS_IO */ From 0b20b4e4cddc7dc63195f031808b2650e8d962e0 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:23:38 +0100 Subject: [PATCH 12/41] 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 && From 1e36af911beb285233262d3641e9667c6045c82e Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:27:09 +0100 Subject: [PATCH 13/41] Fix ret code in rsa_verify.c --- programs/pkey/rsa_verify.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/programs/pkey/rsa_verify.c b/programs/pkey/rsa_verify.c index 1f827aa07..5625abacf 100644 --- a/programs/pkey/rsa_verify.c +++ b/programs/pkey/rsa_verify.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#define mbedtls_snprintf snprintf -#endif +#include +#define mbedtls_printf printf +#define mbedtls_snprintf snprintf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \ !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_MD_C) || \ @@ -54,7 +57,8 @@ int main( void ) int main( int argc, char *argv[] ) { FILE *f; - int ret, c; + int ret = 1, c; + int exit_code = MBEDTLS_EXIT_FAILURE; size_t i; mbedtls_rsa_context rsa; unsigned char hash[32]; @@ -62,7 +66,6 @@ int main( int argc, char *argv[] ) char filename[512]; mbedtls_rsa_init( &rsa, MBEDTLS_RSA_PKCS_V15, 0 ); - ret = 1; if( argc != 2 ) { @@ -100,7 +103,6 @@ int main( int argc, char *argv[] ) /* * Extract the RSA signature from the text file */ - ret = 1; mbedtls_snprintf( filename, sizeof(filename), "%s.sig", argv[1] ); if( ( f = fopen( filename, "rb" ) ) == NULL ) @@ -146,7 +148,7 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . OK (the signature is valid)\n\n" ); - ret = 0; + exit_code = MBEDTLS_EXIT_SUCCESS; exit: @@ -157,7 +159,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_SHA256_C && MBEDTLS_FS_IO */ From 1b04390e4f16ffa295b026570c89dd3d53f85578 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:33:22 +0100 Subject: [PATCH 14/41] Fix ret code in rsa_verify_pss.c --- programs/pkey/rsa_verify_pss.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/programs/pkey/rsa_verify_pss.c b/programs/pkey/rsa_verify_pss.c index 31b720f36..d681e2c5e 100644 --- a/programs/pkey/rsa_verify_pss.c +++ b/programs/pkey/rsa_verify_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) || \ @@ -60,6 +63,7 @@ int main( int argc, char *argv[] ) { FILE *f; int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; size_t i; mbedtls_pk_context pk; unsigned char hash[32]; @@ -91,7 +95,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; } @@ -101,7 +104,6 @@ int main( int argc, char *argv[] ) /* * Extract the RSA signature from the file */ - ret = 1; mbedtls_snprintf( filename, 512, "%s.sig", argv[2] ); if( ( f = fopen( filename, "rb" ) ) == NULL ) @@ -139,7 +141,7 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . OK (the signature is valid)\n\n" ); - ret = 0; + exit_code = MBEDTLS_EXIT_SUCCESS; exit: mbedtls_pk_free( &pk ); @@ -149,7 +151,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_SHA256_C && MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO */ From 43e65fbbca1631f16a440217a70a24ce6451b1e4 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:40:36 +0100 Subject: [PATCH 15/41] Fix ret code in gen_entropy.c --- programs/random/gen_entropy.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/programs/random/gen_entropy.c b/programs/random/gen_entropy.c index 792d3818a..bca36e0ac 100644 --- a/programs/random/gen_entropy.c +++ b/programs/random/gen_entropy.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#include +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_FS_IO) #include "mbedtls/entropy.h" @@ -49,20 +52,21 @@ int main( void ) int main( int argc, char *argv[] ) { FILE *f; - int i, k, ret; + int i, k, ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_entropy_context entropy; unsigned char buf[MBEDTLS_ENTROPY_BLOCK_SIZE]; if( argc < 2 ) { mbedtls_fprintf( stderr, "usage: %s \n", argv[0] ); - return( 1 ); + return( exit_code ); } if( ( f = fopen( argv[1], "wb+" ) ) == NULL ) { mbedtls_printf( "failed to open '%s' for writing.\n", argv[1] ); - return( 1 ); + return( exit_code ); } mbedtls_entropy_init( &entropy ); @@ -72,7 +76,8 @@ int main( int argc, char *argv[] ) ret = mbedtls_entropy_func( &entropy, buf, sizeof( buf ) ); if( ret != 0 ) { - mbedtls_printf("failed!\n"); + mbedtls_printf( " failed\n ! mbedtls_entropy_func returned -%04X\n", + ret ); goto cleanup; } @@ -83,7 +88,7 @@ int main( int argc, char *argv[] ) fflush( stdout ); } - ret = 0; + exit_code = MBEDTLS_EXIT_SUCCESS; cleanup: mbedtls_printf( "\n" ); @@ -91,6 +96,6 @@ cleanup: fclose( f ); mbedtls_entropy_free( &entropy ); - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_ENTROPY_C */ From ac0e3e7b114f60ece05230e0aef98c47cbe8f113 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:46:55 +0100 Subject: [PATCH 16/41] Fix ret code in gen_random_ctr_drbg.c --- programs/random/gen_random_ctr_drbg.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/programs/random/gen_random_ctr_drbg.c b/programs/random/gen_random_ctr_drbg.c index c76f99d09..76d4092de 100644 --- a/programs/random/gen_random_ctr_drbg.c +++ b/programs/random/gen_random_ctr_drbg.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#include +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_CTR_DRBG_C) && defined(MBEDTLS_ENTROPY_C) && \ defined(MBEDTLS_FS_IO) @@ -52,7 +55,8 @@ int main( void ) int main( int argc, char *argv[] ) { FILE *f; - int i, k, ret; + int i, k, ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_ctr_drbg_context ctr_drbg; mbedtls_entropy_context entropy; unsigned char buf[1024]; @@ -62,13 +66,13 @@ int main( int argc, char *argv[] ) if( argc < 2 ) { mbedtls_fprintf( stderr, "usage: %s \n", argv[0] ); - return( 1 ); + return( exit_code ); } if( ( f = fopen( argv[1], "wb+" ) ) == NULL ) { mbedtls_printf( "failed to open '%s' for writing.\n", argv[1] ); - return( 1 ); + return( exit_code ); } mbedtls_entropy_init( &entropy ); @@ -116,7 +120,7 @@ int main( int argc, char *argv[] ) fflush( stdout ); } - ret = 0; + exit_code = MBEDTLS_EXIT_SUCCESS; cleanup: mbedtls_printf("\n"); @@ -125,6 +129,6 @@ cleanup: mbedtls_ctr_drbg_free( &ctr_drbg ); mbedtls_entropy_free( &entropy ); - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_CTR_DRBG_C && MBEDTLS_ENTROPY_C */ From bc1af79add43f52b6b9a0c404e85505fe0213af1 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:53:53 +0100 Subject: [PATCH 17/41] Fix ret code in ssl_client1.c --- programs/ssl/ssl_client1.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c index 01cee1354..0e49c49aa 100644 --- a/programs/ssl/ssl_client1.c +++ b/programs/ssl/ssl_client1.c @@ -30,11 +30,13 @@ #else #include #include -#define mbedtls_time time -#define mbedtls_time_t time_t -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#define mbedtls_time time +#define mbedtls_time_t time_t +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#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) || \ !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \ @@ -80,7 +82,8 @@ static void my_debug( void *ctx, int level, int main( void ) { - int ret, len; + int ret = 1, len; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_net_context server_fd; uint32_t flags; unsigned char buf[1024]; @@ -281,10 +284,12 @@ int main( void ) mbedtls_ssl_close_notify( &ssl ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: #ifdef MBEDTLS_ERROR_C - if( ret != 0 ) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { char error_buf[100]; mbedtls_strerror( ret, error_buf, 100 ); @@ -305,7 +310,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C && From e4f79e1902f1a17a490d53a71012c65b6d2828d3 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 20:57:21 +0100 Subject: [PATCH 18/41] Fix ret code in ssl_fork_server.c --- programs/ssl/ssl_fork_server.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c index 7624896a3..29a297c40 100644 --- a/programs/ssl/ssl_fork_server.c +++ b/programs/ssl/ssl_fork_server.c @@ -29,10 +29,13 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#define mbedtls_time_t time_t -#endif +#include +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define mbedtls_time_t time_t +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_CERTS_C) || \ !defined(MBEDTLS_ENTROPY_C) || !defined(MBEDTLS_SSL_TLS_C) || \ @@ -95,7 +98,8 @@ static void my_debug( void *ctx, int level, int main( void ) { - int ret, len, cnt = 0, pid; + int ret = 1, len, cnt = 0, pid; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_net_context listen_fd, client_fd; unsigned char buf[1024]; const char *pers = "ssl_fork_server"; @@ -392,6 +396,8 @@ int main( void ) goto exit; } + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_net_free( &client_fd ); mbedtls_net_free( &listen_fd ); @@ -408,7 +414,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_CERTS_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_SRV_C && MBEDTLS_NET_C && From ea14fe76d52b870756d975e5807bb8e73317ed80 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 21:04:29 +0100 Subject: [PATCH 19/41] Fix ret code in ssl_mail_client.c --- programs/ssl/ssl_mail_client.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c index 04b847a69..a41486443 100644 --- a/programs/ssl/ssl_mail_client.c +++ b/programs/ssl/ssl_mail_client.c @@ -30,11 +30,13 @@ #else #include #include -#define mbedtls_time time -#define mbedtls_time_t time_t -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#define mbedtls_time time +#define mbedtls_time_t time_t +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#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) || \ !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \ @@ -346,7 +348,8 @@ static int write_and_get_response( mbedtls_net_context *sock_fd, unsigned char * int main( int argc, char *argv[] ) { - int ret = 0, len; + int ret = 1, len; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_net_context server_fd; unsigned char buf[1024]; #if defined(MBEDTLS_BASE64_C) @@ -499,8 +502,8 @@ int main( int argc, char *argv[] ) mbedtls_test_cas_pem_len ); #else { - ret = 1; mbedtls_printf("MBEDTLS_CERTS_C and/or MBEDTLS_PEM_PARSE_C not defined."); + goto exit; } #endif if( ret < 0 ) @@ -529,8 +532,8 @@ int main( int argc, char *argv[] ) mbedtls_test_cli_crt_len ); #else { - ret = -1; mbedtls_printf("MBEDTLS_CERTS_C not defined."); + goto exit; } #endif if( ret != 0 ) @@ -549,8 +552,8 @@ int main( int argc, char *argv[] ) mbedtls_test_cli_key_len, NULL, 0 ); #else { - ret = -1; mbedtls_printf("MBEDTLS_CERTS_C or MBEDTLS_PEM_PARSE_C not defined."); + goto exit; } #endif if( ret != 0 ) @@ -819,6 +822,8 @@ int main( int argc, char *argv[] ) mbedtls_ssl_close_notify( &ssl ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_net_free( &server_fd ); @@ -835,7 +840,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C ** From 7bd88dc44cc386287f9add2612ef4e842ecf08f9 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 21:36:13 +0100 Subject: [PATCH 20/41] Fix ret code in cert_req.c --- programs/x509/cert_req.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/programs/x509/cert_req.c b/programs/x509/cert_req.c index 30df2162a..8b47138a5 100644 --- a/programs/x509/cert_req.c +++ b/programs/x509/cert_req.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_X509_CSR_WRITE_C) || !defined(MBEDTLS_FS_IO) || \ !defined(MBEDTLS_PK_PARSE_C) || !defined(MBEDTLS_SHA256_C) || \ @@ -133,7 +136,8 @@ int write_certificate_request( mbedtls_x509write_csr *req, const char *output_fi int main( int argc, char *argv[] ) { - int ret = 0; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_pk_context key; char buf[1024]; int i; @@ -156,7 +160,6 @@ int main( int argc, char *argv[] ) { usage: mbedtls_printf( USAGE ); - ret = 1; goto exit; } @@ -317,9 +320,11 @@ int main( int argc, char *argv[] ) mbedtls_printf( " ok\n" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: - if( ret != 0 && ret != 1) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { #ifdef MBEDTLS_ERROR_C mbedtls_strerror( ret, buf, sizeof( buf ) ); @@ -339,7 +344,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_X509_CSR_WRITE_C && MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C && MBEDTLS_PEM_WRITE_C */ From a7ac5ab2ee1d29dd2c90bb13081aede6442a99ed Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 21:42:45 +0100 Subject: [PATCH 21/41] Fix ret code in cert_write.c --- programs/x509/cert_write.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/programs/x509/cert_write.c b/programs/x509/cert_write.c index 9cc582d61..03f36487e 100644 --- a/programs/x509/cert_write.c +++ b/programs/x509/cert_write.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_X509_CRT_WRITE_C) || \ !defined(MBEDTLS_X509_CRT_PARSE_C) || !defined(MBEDTLS_FS_IO) || \ @@ -211,7 +214,8 @@ int write_certificate( mbedtls_x509write_cert *crt, const char *output_file, int main( int argc, char *argv[] ) { - int ret = 0; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_x509_crt issuer_crt; mbedtls_pk_context loaded_issuer_key, loaded_subject_key; mbedtls_pk_context *issuer_key = &loaded_issuer_key, @@ -248,7 +252,6 @@ int main( int argc, char *argv[] ) { usage: mbedtls_printf( USAGE ); - ret = 1; goto exit; } @@ -615,7 +618,6 @@ int main( int argc, char *argv[] ) { mbedtls_printf( " failed\n ! issuer_key does not match " "issuer certificate\n\n" ); - ret = -1; goto exit; } } @@ -788,6 +790,8 @@ int main( int argc, char *argv[] ) mbedtls_printf( " ok\n" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_x509write_crt_free( &crt ); mbedtls_pk_free( &loaded_subject_key ); @@ -801,7 +805,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_X509_CRT_WRITE_C && MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_FS_IO && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C && From 8fe4d917f78da81dee40b5f4ef10a5af270aa9bc Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 21:47:51 +0100 Subject: [PATCH 22/41] Fix ret code in crl_app.c --- programs/x509/crl_app.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/programs/x509/crl_app.c b/programs/x509/crl_app.c index 210d19e96..687752fc6 100644 --- a/programs/x509/crl_app.c +++ b/programs/x509/crl_app.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \ !defined(MBEDTLS_X509_CRL_PARSE_C) || !defined(MBEDTLS_FS_IO) @@ -67,7 +70,8 @@ struct options int main( int argc, char *argv[] ) { - int ret = 0; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; unsigned char buf[100000]; mbedtls_x509_crl crl; int i; @@ -131,6 +135,8 @@ int main( int argc, char *argv[] ) mbedtls_printf( "%s\n", buf ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_x509_crl_free( &crl ); @@ -139,7 +145,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_X509_CRL_PARSE_C && MBEDTLS_FS_IO */ From 12ab7a6884167d763e6a12fca18a61d92aab60f9 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 21:51:47 +0100 Subject: [PATCH 23/41] Fix ret code in req_app.c --- programs/x509/req_app.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/programs/x509/req_app.c b/programs/x509/req_app.c index 8410a5371..131cc293f 100644 --- a/programs/x509/req_app.c +++ b/programs/x509/req_app.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \ !defined(MBEDTLS_X509_CSR_PARSE_C) || !defined(MBEDTLS_FS_IO) @@ -67,7 +70,8 @@ struct options int main( int argc, char *argv[] ) { - int ret = 0; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; unsigned char buf[100000]; mbedtls_x509_csr csr; int i; @@ -131,6 +135,8 @@ int main( int argc, char *argv[] ) mbedtls_printf( "%s\n", buf ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_x509_csr_free( &csr ); @@ -139,7 +145,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_X509_CSR_PARSE_C && MBEDTLS_FS_IO */ From 01e3d21350265b1b0236d79c0f6854572c8e8fae Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 21:58:53 +0100 Subject: [PATCH 24/41] Fix ret code in udp_proxy.c --- programs/test/udp_proxy.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/programs/test/udp_proxy.c b/programs/test/udp_proxy.c index 20624d227..b56bd2110 100644 --- a/programs/test/udp_proxy.c +++ b/programs/test/udp_proxy.c @@ -37,10 +37,12 @@ #include #include #include -#define mbedtls_time time -#define mbedtls_time_t time_t -#define mbedtls_printf printf -#endif +#define mbedtls_time time +#define mbedtls_time_t time_t +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_NET_C) int main( void ) @@ -468,7 +470,8 @@ int handle_message( const char *way, int main( int argc, char *argv[] ) { - int ret; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_net_context listen_fd, client_fd, server_fd; @@ -591,10 +594,12 @@ accept: } } + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: #ifdef MBEDTLS_ERROR_C - if( ret != 0 ) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { char error_buf[100]; mbedtls_strerror( ret, error_buf, 100 ); @@ -612,7 +617,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret != 0 ); + return( exit_code ); } #endif /* MBEDTLS_NET_C */ From 73081c3e2f5717472dc6dc50b901d1ec83319100 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 22:04:03 +0100 Subject: [PATCH 25/41] Fix ret code in ssl_cert_test.c --- programs/test/ssl_cert_test.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/programs/test/ssl_cert_test.c b/programs/test/ssl_cert_test.c index 9cfcd2d55..7e5ed384b 100644 --- a/programs/test/ssl_cert_test.c +++ b/programs/test/ssl_cert_test.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_RSA_C) && defined(MBEDTLS_X509_CRT_PARSE_C) && \ defined(MBEDTLS_FS_IO) && defined(MBEDTLS_X509_CRL_PARSE_C) @@ -80,7 +83,8 @@ const char *client_private_keys[MAX_CLIENT_CERTS] = int main( void ) { - int ret, i; + int ret = 1, i; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_x509_crt cacert; mbedtls_x509_crl crl; char buf[10240]; @@ -210,7 +214,6 @@ int main( void ) if( ! mbedtls_pk_can_do( &clicert.pk, MBEDTLS_PK_RSA ) ) { mbedtls_printf( " failed\n ! certificate's key is not RSA\n\n" ); - ret = MBEDTLS_ERR_X509_FEATURE_UNAVAILABLE; goto exit; } @@ -241,6 +244,8 @@ int main( void ) mbedtls_pk_free( &pk ); } + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_x509_crt_free( &cacert ); mbedtls_x509_crl_free( &crl ); @@ -250,7 +255,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_RSA_C && MBEDTLS_X509_CRT_PARSE_C && MBEDTLS_FS_IO && MBEDTLS_X509_CRL_PARSE_C */ From 6118adab095337cdf91944342a5892ba87cc0d6a Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 22:08:41 +0100 Subject: [PATCH 26/41] Fix ret code in pem2der.c --- programs/util/pem2der.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/programs/util/pem2der.c b/programs/util/pem2der.c index ad2c6ac13..fda5f5781 100644 --- a/programs/util/pem2der.c +++ b/programs/util/pem2der.c @@ -29,10 +29,13 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_free free -#define mbedtls_calloc calloc -#define mbedtls_printf printf -#endif +#include +#define mbedtls_free free +#define mbedtls_calloc calloc +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_BASE64_C) && defined(MBEDTLS_FS_IO) #include "mbedtls/error.h" @@ -178,7 +181,8 @@ static int write_file( const char *path, unsigned char *buf, size_t n ) int main( int argc, char *argv[] ) { - int ret = 0; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; unsigned char *pem_buffer = NULL; unsigned char der_buffer[4096]; char buf[1024]; @@ -273,6 +277,8 @@ int main( int argc, char *argv[] ) mbedtls_printf( " ok\n" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: free( pem_buffer ); @@ -281,6 +287,6 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BASE64_C && MBEDTLS_FS_IO */ From c899c464f6a965aa4048da19f3b8e422eb8aba4c Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 22:12:21 +0100 Subject: [PATCH 27/41] Fix ret code in mpi_demo.c --- programs/pkey/mpi_demo.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/programs/pkey/mpi_demo.c b/programs/pkey/mpi_demo.c index afe8957e7..5b40c5185 100644 --- a/programs/pkey/mpi_demo.c +++ b/programs/pkey/mpi_demo.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_FS_IO) #include "mbedtls/bignum.h" @@ -47,7 +50,8 @@ int main( void ) #else int main( void ) { - int ret; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_mpi E, P, Q, N, H, D, X, Y, Z; mbedtls_mpi_init( &E ); mbedtls_mpi_init( &P ); mbedtls_mpi_init( &Q ); mbedtls_mpi_init( &N ); @@ -88,15 +92,16 @@ int main( void ) MBEDTLS_MPI_CHK( mbedtls_mpi_write_file( " Z (decrypted) = Y^D mod N = ", &Z, 10, NULL ) ); mbedtls_printf( "\n" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + cleanup: mbedtls_mpi_free( &E ); mbedtls_mpi_free( &P ); mbedtls_mpi_free( &Q ); mbedtls_mpi_free( &N ); mbedtls_mpi_free( &H ); mbedtls_mpi_free( &D ); mbedtls_mpi_free( &X ); mbedtls_mpi_free( &Y ); mbedtls_mpi_free( &Z ); - if( ret != 0 ) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { mbedtls_printf( "\nAn error occurred.\n" ); - ret = 1; } #if defined(_WIN32) @@ -104,6 +109,6 @@ cleanup: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_FS_IO */ From 81982c84d4f45bbb993779f7c98e4c9d2009b3ce Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 22:16:23 +0100 Subject: [PATCH 28/41] Fix ret code in ecdh_curve25519.c --- programs/pkey/ecdh_curve25519.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/programs/pkey/ecdh_curve25519.c b/programs/pkey/ecdh_curve25519.c index e7ead9a93..1f52126af 100644 --- a/programs/pkey/ecdh_curve25519.c +++ b/programs/pkey/ecdh_curve25519.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_ECDH_C) || \ !defined(MBEDTLS_ECP_DP_CURVE25519_ENABLED) || \ @@ -51,7 +54,8 @@ int main( void ) int main( int argc, char *argv[] ) { - int ret; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_ecdh_context ctx_cli, ctx_srv; mbedtls_entropy_context entropy; mbedtls_ctr_drbg_context ctr_drbg; @@ -218,6 +222,7 @@ int main( int argc, char *argv[] ) mbedtls_printf( " ok\n" ); + exit_code = MBEDTLS_EXIT_SUCCESS; exit: @@ -231,7 +236,7 @@ exit: mbedtls_ctr_drbg_free( &ctr_drbg ); mbedtls_entropy_free( &entropy ); - return( ret != 0 ); + return( exit_code ); } #endif /* MBEDTLS_ECDH_C && MBEDTLS_ECP_DP_CURVE25519_ENABLED && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ From 141b4f4526cb8600a2152c8749987029a1528fd2 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 22:19:26 +0100 Subject: [PATCH 29/41] Fix ret code in pk_encrypt.c --- programs/pkey/pk_encrypt.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/programs/pkey/pk_encrypt.c b/programs/pkey/pk_encrypt.c index 7ca9d5ad9..b4b7107dd 100644 --- a/programs/pkey/pk_encrypt.c +++ b/programs/pkey/pk_encrypt.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#include +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_PK_PARSE_C) && \ defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_FS_IO) && \ @@ -59,7 +62,8 @@ int main( void ) int main( int argc, char *argv[] ) { FILE *f; - int ret; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; size_t i, olen = 0; mbedtls_pk_context pk; mbedtls_entropy_context entropy; @@ -68,7 +72,6 @@ int main( int argc, char *argv[] ) unsigned char buf[512]; const char *pers = "mbedtls_pk_encrypt"; - ret = 1; mbedtls_ctr_drbg_init( &ctr_drbg ); if( argc != 3 ) @@ -132,7 +135,6 @@ int main( int argc, char *argv[] ) */ if( ( f = fopen( "result-enc.txt", "wb+" ) ) == NULL ) { - ret = 1; mbedtls_printf( " failed\n ! Could not create %s\n\n", "result-enc.txt" ); goto exit; } @@ -145,12 +147,14 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_ctr_drbg_free( &ctr_drbg ); mbedtls_entropy_free( &entropy ); #if defined(MBEDTLS_ERROR_C) - if( ret != 0 ) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); mbedtls_printf( " ! Last error was: %s\n", buf ); @@ -162,7 +166,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_PK_PARSE_C && MBEDTLS_ENTROPY_C && MBEDTLS_FS_IO && MBEDTLS_CTR_DRBG_C */ From a0ea01d27342b80fc2f9c84edeac00ecdb5586ad Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 22:23:22 +0100 Subject: [PATCH 30/41] Fix ret code in pk_encrypt.c --- programs/pkey/pk_decrypt.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/programs/pkey/pk_decrypt.c b/programs/pkey/pk_decrypt.c index 32fbc7545..b60f6caee 100644 --- a/programs/pkey/pk_decrypt.c +++ b/programs/pkey/pk_decrypt.c @@ -59,7 +59,8 @@ int main( void ) int main( int argc, char *argv[] ) { FILE *f; - int ret, c; + int ret = 1, c; + int exit_code = MBEDTLS_EXIT_FAILURE; size_t i, olen = 0; mbedtls_pk_context pk; mbedtls_entropy_context entropy; @@ -71,7 +72,6 @@ int main( int argc, char *argv[] ) mbedtls_ctr_drbg_init( &ctr_drbg ); memset(result, 0, sizeof( result ) ); - ret = 1; if( argc != 2 ) { @@ -110,8 +110,6 @@ int main( int argc, char *argv[] ) /* * Extract the RSA encrypted value from the text file */ - ret = 1; - if( ( f = fopen( "result-enc.txt", "rb" ) ) == NULL ) { mbedtls_printf( "\n ! Could not open %s\n\n", "result-enc.txt" ); @@ -143,14 +141,14 @@ int main( int argc, char *argv[] ) mbedtls_printf( "The decrypted result is: '%s'\n\n", result ); - ret = 0; + exit_code = MBEDTLS_EXIT_SUCCESS; exit: mbedtls_ctr_drbg_free( &ctr_drbg ); mbedtls_entropy_free( &entropy ); #if defined(MBEDTLS_ERROR_C) - if( ret != 0 ) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); mbedtls_printf( " ! Last error was: %s\n", buf ); @@ -162,7 +160,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO && MBEDTLS_ENTROPY_C && MBEDTLS_CTR_DRBG_C */ From a5236b1dd38167beca77f78088818e6987659742 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 22:26:25 +0100 Subject: [PATCH 31/41] Fix ret code in pk_sign.c --- programs/pkey/pk_sign.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/programs/pkey/pk_sign.c b/programs/pkey/pk_sign.c index 55df95e49..240be6b92 100644 --- a/programs/pkey/pk_sign.c +++ b/programs/pkey/pk_sign.c @@ -30,9 +30,11 @@ #else #include #include -#define mbedtls_snprintf snprintf -#define mbedtls_printf printf -#endif +#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_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \ !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_MD_C) || \ @@ -61,6 +63,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; @@ -134,14 +137,12 @@ 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; } if( fwrite( buf, 1, olen, f ) != olen ) { - ret = 1; mbedtls_printf( "failed\n ! fwrite failed\n\n" ); fclose( f ); goto exit; @@ -151,13 +152,15 @@ 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 ); mbedtls_entropy_free( &entropy ); #if defined(MBEDTLS_ERROR_C) - if( ret != 0 ) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); mbedtls_printf( " ! Last error was: %s\n", buf ); @@ -169,7 +172,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ? EXIT_FAILURE : EXIT_SUCCESS ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SHA256_C && MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO && From 2702000d2ce29b9eac5d68a8747620e63ea0c9a1 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 22:30:05 +0100 Subject: [PATCH 32/41] Fix ret code in pk_verify.c --- programs/pkey/pk_verify.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/programs/pkey/pk_verify.c b/programs/pkey/pk_verify.c index d35d17f69..24fcd3761 100644 --- a/programs/pkey/pk_verify.c +++ b/programs/pkey/pk_verify.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_BIGNUM_C) || !defined(MBEDTLS_MD_C) || \ !defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_PK_PARSE_C) || \ @@ -56,6 +59,7 @@ int main( int argc, char *argv[] ) { FILE *f; int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; size_t i; mbedtls_pk_context pk; unsigned char hash[32]; @@ -87,7 +91,6 @@ int main( int argc, char *argv[] ) /* * Extract the signature from the file */ - ret = 1; mbedtls_snprintf( filename, sizeof(filename), "%s.sig", argv[2] ); if( ( f = fopen( filename, "rb" ) ) == NULL ) @@ -125,13 +128,13 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . OK (the signature is valid)\n\n" ); - ret = 0; + exit_code = MBEDTLS_EXIT_SUCCESS; exit: mbedtls_pk_free( &pk ); #if defined(MBEDTLS_ERROR_C) - if( ret != 0 ) + if( exit_code != MBEDTLS_EXIT_SUCCESS ) { mbedtls_strerror( ret, (char *) buf, sizeof(buf) ); mbedtls_printf( " ! Last error was: %s\n", buf ); @@ -143,7 +146,7 @@ exit: fflush( stdout ); getchar(); #endif - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_SHA256_C && MBEDTLS_PK_PARSE_C && MBEDTLS_FS_IO */ From 77d2de223c296f1b17036aa1eb70f06f29640882 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Sun, 29 Apr 2018 22:35:36 +0100 Subject: [PATCH 33/41] Fix ret code in generic_sum.c --- programs/hash/generic_sum.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/programs/hash/generic_sum.c b/programs/hash/generic_sum.c index d1e81d491..3fb215b22 100644 --- a/programs/hash/generic_sum.c +++ b/programs/hash/generic_sum.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#include +#define mbedtls_fprintf fprintf +#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_FS_IO) #include "mbedtls/md.h" @@ -169,7 +172,8 @@ static int generic_check( const mbedtls_md_info_t *md_info, char *filename ) int main( int argc, char *argv[] ) { - int ret, i; + int ret = 1, i; + int exit_code = MBEDTLS_EXIT_FAILURE; const mbedtls_md_info_t *md_info; mbedtls_md_context_t md_ctx; @@ -196,7 +200,7 @@ int main( int argc, char *argv[] ) fflush( stdout ); getchar(); #endif - return( 1 ); + return( exit_code ); } /* @@ -206,12 +210,12 @@ int main( int argc, char *argv[] ) if( md_info == NULL ) { mbedtls_fprintf( stderr, "Message Digest '%s' not found\n", argv[1] ); - return( 1 ); + return( exit_code ); } if( mbedtls_md_setup( &md_ctx, md_info, 0 ) ) { mbedtls_fprintf( stderr, "Failed to initialize context.\n" ); - return( 1 ); + return( exit_code ); } ret = 0; @@ -224,9 +228,12 @@ int main( int argc, char *argv[] ) for( i = 2; i < argc; i++ ) ret |= generic_print( md_info, argv[i] ); + if ( ret == 0 ) + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_md_free( &md_ctx ); - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_MD_C && MBEDTLS_FS_IO */ From 8ec767c042271cd3f916b2318273125240ce883d Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Mon, 30 Apr 2018 20:05:57 +0100 Subject: [PATCH 34/41] Fix ret code in cert_app.c --- programs/x509/cert_app.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c index c893ca8de..7ad4e86ff 100644 --- a/programs/x509/cert_app.c +++ b/programs/x509/cert_app.c @@ -145,7 +145,8 @@ static int my_verify( void *data, mbedtls_x509_crt *crt, int depth, uint32_t *fl int main( int argc, char *argv[] ) { - int ret = 0; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_net_context server_fd; unsigned char buf[1024]; mbedtls_entropy_context entropy; @@ -180,7 +181,6 @@ int main( int argc, char *argv[] ) { usage: mbedtls_printf( USAGE ); - ret = 2; goto exit; } @@ -252,19 +252,23 @@ int main( int argc, char *argv[] ) if( strlen( opt.ca_path ) ) { - ret = mbedtls_x509_crt_parse_path( &cacert, opt.ca_path ); + if( ( ret = mbedtls_x509_crt_parse_path( &cacert, opt.ca_path ) ) < 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_path returned -0x%x\n\n", -ret ); + goto exit; + } + verify = 1; } else if( strlen( opt.ca_file ) ) { - ret = mbedtls_x509_crt_parse_file( &cacert, opt.ca_file ); - verify = 1; - } + if( ( ret = mbedtls_x509_crt_parse_file( &cacert, opt.ca_file ) ) < 0 ) + { + mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse_file returned -0x%x\n\n", -ret ); + goto exit; + } - if( ret < 0 ) - { - mbedtls_printf( " failed\n ! mbedtls_x509_crt_parse returned -0x%x\n\n", -ret ); - goto exit; + verify = 1; } mbedtls_printf( " ok (%d skipped)\n", ret ); @@ -332,8 +336,6 @@ int main( int argc, char *argv[] ) cur = cur->next; } - ret = 0; - /* * 1.3 Verify the certificate */ @@ -470,6 +472,8 @@ ssl_exit: else goto usage; + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_net_free( &server_fd ); @@ -485,10 +489,7 @@ exit: fflush( stdout ); getchar(); #endif - if( ret < 0 ) - ret = 1; - - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_ENTROPY_C && MBEDTLS_SSL_TLS_C && MBEDTLS_SSL_CLI_C && MBEDTLS_NET_C && MBEDTLS_RSA_C && From 156099b76fd16e2ca11f40d5734786ee53124035 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Mon, 30 Apr 2018 22:07:15 +0100 Subject: [PATCH 35/41] Fix ret code in rsa_decrypt.c --- programs/pkey/rsa_decrypt.c | 61 ++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 32 deletions(-) diff --git a/programs/pkey/rsa_decrypt.c b/programs/pkey/rsa_decrypt.c index 2da3fbf11..0a252d2ad 100644 --- a/programs/pkey/rsa_decrypt.c +++ b/programs/pkey/rsa_decrypt.c @@ -30,11 +30,11 @@ #else #include #include -#define mbedtls_printf printf -#define mbedtls_exit exit +#define mbedtls_printf printf +#define mbedtls_exit exit #define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE -#endif +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_RSA_C) && \ defined(MBEDTLS_FS_IO) && defined(MBEDTLS_ENTROPY_C) && \ @@ -61,7 +61,9 @@ int main( void ) int main( int argc, char *argv[] ) { FILE *f; - int return_val, exit_val, c; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; + int c; size_t i; mbedtls_rsa_context rsa; mbedtls_mpi N, P, Q, D, E, DP, DQ, QP; @@ -73,7 +75,6 @@ int main( int argc, char *argv[] ) ((void) argv); memset(result, 0, sizeof( result ) ); - exit_val = MBEDTLS_EXIT_SUCCESS; if( argc != 1 ) { @@ -83,7 +84,7 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n" ); #endif - mbedtls_exit( MBEDTLS_EXIT_FAILURE ); + mbedtls_exit( exit_code ); } mbedtls_printf( "\n . Seeding the random number generator..." ); @@ -96,14 +97,13 @@ int main( int argc, char *argv[] ) mbedtls_mpi_init( &D ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &DP ); mbedtls_mpi_init( &DQ ); mbedtls_mpi_init( &QP ); - return_val = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, + ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ); - if( return_val != 0 ) + if( ret != 0 ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", - return_val ); + ret ); goto exit; } @@ -112,40 +112,38 @@ int main( int argc, char *argv[] ) if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! Could not open rsa_priv.txt\n" \ " ! Please run rsa_genkey first\n\n" ); goto exit; } - if( ( return_val = mbedtls_mpi_read_file( &N , 16, f ) ) != 0 || - ( return_val = mbedtls_mpi_read_file( &E , 16, f ) ) != 0 || - ( return_val = mbedtls_mpi_read_file( &D , 16, f ) ) != 0 || - ( return_val = mbedtls_mpi_read_file( &P , 16, f ) ) != 0 || - ( return_val = mbedtls_mpi_read_file( &Q , 16, f ) ) != 0 || - ( return_val = mbedtls_mpi_read_file( &DP , 16, f ) ) != 0 || - ( return_val = mbedtls_mpi_read_file( &DQ , 16, f ) ) != 0 || - ( return_val = mbedtls_mpi_read_file( &QP , 16, f ) ) != 0 ) + if( ( ret = mbedtls_mpi_read_file( &N , 16, f ) ) != 0 || + ( ret = mbedtls_mpi_read_file( &E , 16, f ) ) != 0 || + ( ret = mbedtls_mpi_read_file( &D , 16, f ) ) != 0 || + ( ret = mbedtls_mpi_read_file( &P , 16, f ) ) != 0 || + ( ret = mbedtls_mpi_read_file( &Q , 16, f ) ) != 0 || + ( ret = mbedtls_mpi_read_file( &DP , 16, f ) ) != 0 || + ( ret = mbedtls_mpi_read_file( &DQ , 16, f ) ) != 0 || + ( ret = mbedtls_mpi_read_file( &QP , 16, f ) ) != 0 ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n", - return_val ); + ret ); fclose( f ); goto exit; } fclose( f ); - if( ( return_val = mbedtls_rsa_import( &rsa, &N, &P, &Q, &D, &E ) ) != 0 ) + if( ( ret = mbedtls_rsa_import( &rsa, &N, &P, &Q, &D, &E ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_rsa_import returned %d\n\n", - return_val ); + ret ); goto exit; } - if( ( return_val = mbedtls_rsa_complete( &rsa ) ) != 0 ) + if( ( ret = mbedtls_rsa_complete( &rsa ) ) != 0 ) { mbedtls_printf( " failed\n ! mbedtls_rsa_complete returned %d\n\n", - return_val ); + ret ); goto exit; } @@ -154,7 +152,6 @@ int main( int argc, char *argv[] ) */ if( ( f = fopen( "result-enc.txt", "rb" ) ) == NULL ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( "\n ! Could not open %s\n\n", "result-enc.txt" ); goto exit; } @@ -169,7 +166,6 @@ int main( int argc, char *argv[] ) if( i != rsa.len ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( "\n ! Invalid RSA signature format\n\n" ); goto exit; } @@ -180,14 +176,13 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Decrypting the encrypted data" ); fflush( stdout ); - return_val = mbedtls_rsa_pkcs1_decrypt( &rsa, mbedtls_ctr_drbg_random, + ret = mbedtls_rsa_pkcs1_decrypt( &rsa, mbedtls_ctr_drbg_random, &ctr_drbg, MBEDTLS_RSA_PRIVATE, &i, buf, result, 1024 ); - if( return_val != 0 ) + if( ret != 0 ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! mbedtls_rsa_pkcs1_decrypt returned %d\n\n", - return_val ); + ret ); goto exit; } @@ -195,6 +190,8 @@ int main( int argc, char *argv[] ) mbedtls_printf( "The decrypted result is: '%s'\n\n", result ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_ctr_drbg_free( &ctr_drbg ); mbedtls_entropy_free( &entropy ); @@ -208,6 +205,6 @@ exit: fflush( stdout ); getchar(); #endif - return( exit_val ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_FS_IO */ From 053e1cd7abfc45a7f1f28c51c39b4704fc5606d3 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Mon, 30 Apr 2018 22:08:36 +0100 Subject: [PATCH 36/41] Fix ret code in rsa_encrypt.c --- programs/pkey/rsa_encrypt.c | 61 ++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 34 deletions(-) diff --git a/programs/pkey/rsa_encrypt.c b/programs/pkey/rsa_encrypt.c index 81c27d888..411657a07 100644 --- a/programs/pkey/rsa_encrypt.c +++ b/programs/pkey/rsa_encrypt.c @@ -30,12 +30,12 @@ #else #include #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#define mbedtls_exit exit -#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS -#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE -#endif +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define mbedtls_exit exit +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_RSA_C) && \ defined(MBEDTLS_ENTROPY_C) && defined(MBEDTLS_FS_IO) && \ @@ -61,7 +61,8 @@ int main( void ) int main( int argc, char *argv[] ) { FILE *f; - int return_val, exit_val; + int ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; size_t i; mbedtls_rsa_context rsa; mbedtls_entropy_context entropy; @@ -71,8 +72,6 @@ int main( int argc, char *argv[] ) const char *pers = "rsa_encrypt"; mbedtls_mpi N, E; - exit_val = MBEDTLS_EXIT_SUCCESS; - if( argc != 2 ) { mbedtls_printf( "usage: rsa_encrypt \n" ); @@ -81,7 +80,7 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n" ); #endif - mbedtls_exit( MBEDTLS_EXIT_FAILURE ); + mbedtls_exit( exit_code ); } mbedtls_printf( "\n . Seeding the random number generator..." ); @@ -92,14 +91,13 @@ int main( int argc, char *argv[] ) mbedtls_ctr_drbg_init( &ctr_drbg ); mbedtls_entropy_init( &entropy ); - return_val = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, - &entropy, (const unsigned char *) pers, - strlen( pers ) ); - if( return_val != 0 ) + ret = mbedtls_ctr_drbg_seed( &ctr_drbg, mbedtls_entropy_func, + &entropy, (const unsigned char *) pers, + strlen( pers ) ); + if( ret != 0 ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! mbedtls_ctr_drbg_seed returned %d\n", - return_val ); + ret ); goto exit; } @@ -108,35 +106,30 @@ int main( int argc, char *argv[] ) if( ( f = fopen( "rsa_pub.txt", "rb" ) ) == NULL ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! Could not open rsa_pub.txt\n" \ " ! Please run rsa_genkey first\n\n" ); goto exit; } - if( ( return_val = mbedtls_mpi_read_file( &N, 16, f ) ) != 0 || - ( return_val = mbedtls_mpi_read_file( &E, 16, f ) ) != 0 ) + if( ( ret = mbedtls_mpi_read_file( &N, 16, f ) ) != 0 || + ( ret = mbedtls_mpi_read_file( &E, 16, f ) ) != 0 ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! mbedtls_mpi_read_file returned %d\n\n", - return_val ); + ret ); fclose( f ); goto exit; } fclose( f ); - if( ( return_val = mbedtls_rsa_import( &rsa, &N, NULL, - NULL, NULL, &E ) ) != 0 ) + if( ( ret = mbedtls_rsa_import( &rsa, &N, NULL, NULL, NULL, &E ) ) != 0 ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! mbedtls_rsa_import returned %d\n\n", - return_val ); + ret ); goto exit; } if( strlen( argv[1] ) > 100 ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " Input data larger than 100 characters.\n\n" ); goto exit; } @@ -149,14 +142,13 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Generating the RSA encrypted value" ); fflush( stdout ); - return_val = mbedtls_rsa_pkcs1_encrypt( &rsa, mbedtls_ctr_drbg_random, - &ctr_drbg, MBEDTLS_RSA_PUBLIC, - strlen( argv[1] ), input, buf ); - if( return_val != 0 ) + ret = mbedtls_rsa_pkcs1_encrypt( &rsa, mbedtls_ctr_drbg_random, + &ctr_drbg, MBEDTLS_RSA_PUBLIC, + strlen( argv[1] ), input, buf ); + if( ret != 0 ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! mbedtls_rsa_pkcs1_encrypt returned %d\n\n", - return_val ); + ret ); goto exit; } @@ -165,7 +157,6 @@ int main( int argc, char *argv[] ) */ if( ( f = fopen( "result-enc.txt", "wb+" ) ) == NULL ) { - exit_val = MBEDTLS_EXIT_FAILURE; mbedtls_printf( " failed\n ! Could not create %s\n\n", "result-enc.txt" ); goto exit; } @@ -178,6 +169,8 @@ int main( int argc, char *argv[] ) mbedtls_printf( "\n . Done (created \"%s\")\n\n", "result-enc.txt" ); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_mpi_free( &N ); mbedtls_mpi_free( &E ); mbedtls_ctr_drbg_free( &ctr_drbg ); @@ -189,7 +182,7 @@ exit: fflush( stdout ); getchar(); #endif - return( exit_val ); + return( exit_code ); } #endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_ENTROPY_C && MBEDTLS_FS_IO && MBEDTLS_CTR_DRBG_C */ From 0dcc6a9f7d40dc379ba8f00e8893a70097abdfca Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Mon, 30 Apr 2018 22:09:18 +0100 Subject: [PATCH 37/41] Fix ret code in gen_random_havege.c --- programs/random/gen_random_havege.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/programs/random/gen_random_havege.c b/programs/random/gen_random_havege.c index 6c3146265..3fb3f0196 100644 --- a/programs/random/gen_random_havege.c +++ b/programs/random/gen_random_havege.c @@ -29,9 +29,12 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#include +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_HAVEGE_C) && defined(MBEDTLS_FS_IO) #include "mbedtls/havege.h" @@ -51,20 +54,21 @@ int main( int argc, char *argv[] ) { FILE *f; time_t t; - int i, k, ret = 0; + int i, k, ret = 1; + int exit_code = MBEDTLS_EXIT_FAILURE; mbedtls_havege_state hs; unsigned char buf[1024]; if( argc < 2 ) { mbedtls_fprintf( stderr, "usage: %s \n", argv[0] ); - return( 1 ); + return( exit_code ); } if( ( f = fopen( argv[1], "wb+" ) ) == NULL ) { mbedtls_printf( "failed to open '%s' for writing.\n", argv[1] ); - return( 1 ); + return( exit_code ); } mbedtls_havege_init( &hs ); @@ -73,11 +77,10 @@ int main( int argc, char *argv[] ) for( i = 0, k = 768; i < k; i++ ) { - if( mbedtls_havege_random( &hs, buf, sizeof( buf ) ) != 0 ) + if( ( ret = mbedtls_havege_random( &hs, buf, sizeof( buf ) ) ) != 0 ) { - mbedtls_printf( "Failed to get random from source.\n" ); - - ret = 1; + mbedtls_printf( " failed\n ! mbedtls_havege_random returned -0x%04X", + -ret ); goto exit; } @@ -93,9 +96,11 @@ int main( int argc, char *argv[] ) mbedtls_printf(" \n "); + exit_code = MBEDTLS_EXIT_SUCCESS; + exit: mbedtls_havege_free( &hs ); fclose( f ); - return( ret ); + return( exit_code ); } #endif /* MBEDTLS_HAVEGE_C */ From 2b0599bc9140dbc4bdafc401618767ecca66fc32 Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Mon, 30 Apr 2018 22:42:33 +0100 Subject: [PATCH 38/41] Fix typo in platform macro defines for examples --- programs/aes/aescrypt2.c | 2 +- programs/aes/crypt_and_hash.c | 2 +- programs/hash/generic_sum.c | 2 +- programs/pkey/dh_client.c | 2 +- programs/pkey/dh_genprime.c | 2 +- programs/pkey/dh_server.c | 2 +- programs/pkey/ecdh_curve25519.c | 2 +- programs/pkey/ecdsa.c | 2 +- programs/pkey/gen_key.c | 2 +- programs/pkey/key_app.c | 2 +- programs/pkey/key_app_writer.c | 2 +- programs/pkey/mpi_demo.c | 2 +- programs/pkey/pk_encrypt.c | 2 +- programs/pkey/pk_sign.c | 2 +- programs/pkey/pk_verify.c | 2 +- programs/pkey/rsa_genkey.c | 2 +- programs/pkey/rsa_sign.c | 2 +- programs/pkey/rsa_sign_pss.c | 2 +- programs/pkey/rsa_verify.c | 2 +- programs/pkey/rsa_verify_pss.c | 2 +- programs/random/gen_entropy.c | 2 +- programs/random/gen_random_ctr_drbg.c | 2 +- programs/ssl/ssl_client1.c | 2 +- programs/ssl/ssl_fork_server.c | 2 +- programs/ssl/ssl_mail_client.c | 2 +- programs/test/ssl_cert_test.c | 2 +- programs/test/udp_proxy.c | 2 +- programs/util/pem2der.c | 2 +- programs/x509/cert_req.c | 2 +- programs/x509/cert_write.c | 2 +- programs/x509/crl_app.c | 2 +- programs/x509/req_app.c | 2 +- 32 files changed, 32 insertions(+), 32 deletions(-) diff --git a/programs/aes/aescrypt2.c b/programs/aes/aescrypt2.c index 31daf1e2c..c727f936e 100644 --- a/programs/aes/aescrypt2.c +++ b/programs/aes/aescrypt2.c @@ -32,7 +32,7 @@ #include #define mbedtls_fprintf fprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/aes/crypt_and_hash.c b/programs/aes/crypt_and_hash.c index 9e234e672..99d30c9a9 100644 --- a/programs/aes/crypt_and_hash.c +++ b/programs/aes/crypt_and_hash.c @@ -33,7 +33,7 @@ #include #define mbedtls_fprintf fprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/hash/generic_sum.c b/programs/hash/generic_sum.c index 3fb215b22..bbe8d92a2 100644 --- a/programs/hash/generic_sum.c +++ b/programs/hash/generic_sum.c @@ -32,7 +32,7 @@ #include #define mbedtls_fprintf fprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/dh_client.c b/programs/pkey/dh_client.c index 68f0df58e..7ec47acab 100644 --- a/programs/pkey/dh_client.c +++ b/programs/pkey/dh_client.c @@ -32,7 +32,7 @@ #include #define mbedtls_printf printf #define mbedtls_time_t time_t -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/dh_genprime.c b/programs/pkey/dh_genprime.c index 7884ea668..dbe915338 100644 --- a/programs/pkey/dh_genprime.c +++ b/programs/pkey/dh_genprime.c @@ -32,7 +32,7 @@ #include #define mbedtls_printf printf #define mbedtls_time_t time_t -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/dh_server.c b/programs/pkey/dh_server.c index d7765e332..c4e2c391e 100644 --- a/programs/pkey/dh_server.c +++ b/programs/pkey/dh_server.c @@ -32,7 +32,7 @@ #include #define mbedtls_printf printf #define mbedtls_time_t time_t -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/ecdh_curve25519.c b/programs/pkey/ecdh_curve25519.c index 1f52126af..5db04088f 100644 --- a/programs/pkey/ecdh_curve25519.c +++ b/programs/pkey/ecdh_curve25519.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/ecdsa.c b/programs/pkey/ecdsa.c index 8455bb52b..c653df9e4 100644 --- a/programs/pkey/ecdsa.c +++ b/programs/pkey/ecdsa.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/gen_key.c b/programs/pkey/gen_key.c index 9a98fda56..f01bf5fcd 100644 --- a/programs/pkey/gen_key.c +++ b/programs/pkey/gen_key.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/key_app.c b/programs/pkey/key_app.c index 56930781f..7a4cb3976 100644 --- a/programs/pkey/key_app.c +++ b/programs/pkey/key_app.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/key_app_writer.c b/programs/pkey/key_app_writer.c index 0292a1d63..13602c2e5 100644 --- a/programs/pkey/key_app_writer.c +++ b/programs/pkey/key_app_writer.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/mpi_demo.c b/programs/pkey/mpi_demo.c index 5b40c5185..365bdc480 100644 --- a/programs/pkey/mpi_demo.c +++ b/programs/pkey/mpi_demo.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/pk_encrypt.c b/programs/pkey/pk_encrypt.c index b4b7107dd..400619c5c 100644 --- a/programs/pkey/pk_encrypt.c +++ b/programs/pkey/pk_encrypt.c @@ -32,7 +32,7 @@ #include #define mbedtls_fprintf fprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/pk_sign.c b/programs/pkey/pk_sign.c index 240be6b92..7ec46752a 100644 --- a/programs/pkey/pk_sign.c +++ b/programs/pkey/pk_sign.c @@ -32,7 +32,7 @@ #include #define mbedtls_snprintf snprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/pk_verify.c b/programs/pkey/pk_verify.c index 24fcd3761..3c7709f9d 100644 --- a/programs/pkey/pk_verify.c +++ b/programs/pkey/pk_verify.c @@ -32,7 +32,7 @@ #include #define mbedtls_snprintf snprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/rsa_genkey.c b/programs/pkey/rsa_genkey.c index 1afec559b..3359e1407 100644 --- a/programs/pkey/rsa_genkey.c +++ b/programs/pkey/rsa_genkey.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/rsa_sign.c b/programs/pkey/rsa_sign.c index c6c790519..b16fe5d22 100644 --- a/programs/pkey/rsa_sign.c +++ b/programs/pkey/rsa_sign.c @@ -33,7 +33,7 @@ #define mbedtls_fprintf fprintf #define mbedtls_printf printf #define mbedtls_snprintf snprintf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/rsa_sign_pss.c b/programs/pkey/rsa_sign_pss.c index 3b58c297b..b0b0f7ecf 100644 --- a/programs/pkey/rsa_sign_pss.c +++ b/programs/pkey/rsa_sign_pss.c @@ -32,7 +32,7 @@ #include #define mbedtls_snprintf snprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/rsa_verify.c b/programs/pkey/rsa_verify.c index 5625abacf..6f88345f2 100644 --- a/programs/pkey/rsa_verify.c +++ b/programs/pkey/rsa_verify.c @@ -32,7 +32,7 @@ #include #define mbedtls_printf printf #define mbedtls_snprintf snprintf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/pkey/rsa_verify_pss.c b/programs/pkey/rsa_verify_pss.c index d681e2c5e..7c9c68f22 100644 --- a/programs/pkey/rsa_verify_pss.c +++ b/programs/pkey/rsa_verify_pss.c @@ -32,7 +32,7 @@ #include #define mbedtls_snprintf snprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/random/gen_entropy.c b/programs/random/gen_entropy.c index bca36e0ac..a1eb3868a 100644 --- a/programs/random/gen_entropy.c +++ b/programs/random/gen_entropy.c @@ -32,7 +32,7 @@ #include #define mbedtls_fprintf fprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/random/gen_random_ctr_drbg.c b/programs/random/gen_random_ctr_drbg.c index 76d4092de..5ade946a7 100644 --- a/programs/random/gen_random_ctr_drbg.c +++ b/programs/random/gen_random_ctr_drbg.c @@ -32,7 +32,7 @@ #include #define mbedtls_fprintf fprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/ssl/ssl_client1.c b/programs/ssl/ssl_client1.c index 0e49c49aa..bf7c0132a 100644 --- a/programs/ssl/ssl_client1.c +++ b/programs/ssl/ssl_client1.c @@ -34,7 +34,7 @@ #define mbedtls_time_t time_t #define mbedtls_fprintf fprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c index 29a297c40..1c3a80600 100644 --- a/programs/ssl/ssl_fork_server.c +++ b/programs/ssl/ssl_fork_server.c @@ -33,7 +33,7 @@ #define mbedtls_fprintf fprintf #define mbedtls_printf printf #define mbedtls_time_t time_t -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/ssl/ssl_mail_client.c b/programs/ssl/ssl_mail_client.c index a41486443..04f891081 100644 --- a/programs/ssl/ssl_mail_client.c +++ b/programs/ssl/ssl_mail_client.c @@ -34,7 +34,7 @@ #define mbedtls_time_t time_t #define mbedtls_fprintf fprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/test/ssl_cert_test.c b/programs/test/ssl_cert_test.c index 7e5ed384b..fd3526f7f 100644 --- a/programs/test/ssl_cert_test.c +++ b/programs/test/ssl_cert_test.c @@ -32,7 +32,7 @@ #include #define mbedtls_snprintf snprintf #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/test/udp_proxy.c b/programs/test/udp_proxy.c index b56bd2110..1865b0f1b 100644 --- a/programs/test/udp_proxy.c +++ b/programs/test/udp_proxy.c @@ -40,7 +40,7 @@ #define mbedtls_time time #define mbedtls_time_t time_t #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/util/pem2der.c b/programs/util/pem2der.c index fda5f5781..73a9fb5e0 100644 --- a/programs/util/pem2der.c +++ b/programs/util/pem2der.c @@ -33,7 +33,7 @@ #define mbedtls_free free #define mbedtls_calloc calloc #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/x509/cert_req.c b/programs/x509/cert_req.c index 8b47138a5..a32ac505f 100644 --- a/programs/x509/cert_req.c +++ b/programs/x509/cert_req.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/x509/cert_write.c b/programs/x509/cert_write.c index 03f36487e..26ab88af9 100644 --- a/programs/x509/cert_write.c +++ b/programs/x509/cert_write.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/x509/crl_app.c b/programs/x509/crl_app.c index 687752fc6..f8316835f 100644 --- a/programs/x509/crl_app.c +++ b/programs/x509/crl_app.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ diff --git a/programs/x509/req_app.c b/programs/x509/req_app.c index 131cc293f..0f20c85f5 100644 --- a/programs/x509/req_app.c +++ b/programs/x509/req_app.c @@ -31,7 +31,7 @@ #include #include #define mbedtls_printf printf -#define MBEDTLS_EXTI_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS #define MBEDTLS_EXIT_FAILURE EXIT_FAILURE #endif /* MBEDTLS_PLATFORM_C */ From 9f92a805e92163db59aed6c19446da4ea74334cb Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Mon, 30 Apr 2018 22:43:11 +0100 Subject: [PATCH 39/41] Add missing platform macro defines in pk_decrypt.c --- programs/pkey/pk_decrypt.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/programs/pkey/pk_decrypt.c b/programs/pkey/pk_decrypt.c index b60f6caee..00bd71ed3 100644 --- a/programs/pkey/pk_decrypt.c +++ b/programs/pkey/pk_decrypt.c @@ -29,8 +29,11 @@ #include "mbedtls/platform.h" #else #include -#define mbedtls_printf printf -#endif +#include +#define mbedtls_printf printf +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if defined(MBEDTLS_BIGNUM_C) && defined(MBEDTLS_PK_PARSE_C) && \ defined(MBEDTLS_FS_IO) && defined(MBEDTLS_ENTROPY_C) && \ From cfb61b33cfce2737f8f28b7a289c8bebf86b7bec Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Mon, 30 Apr 2018 22:43:29 +0100 Subject: [PATCH 40/41] Add missing platform macro defines in cert_app.c --- programs/x509/cert_app.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/programs/x509/cert_app.c b/programs/x509/cert_app.c index 7ad4e86ff..c57ecca03 100644 --- a/programs/x509/cert_app.c +++ b/programs/x509/cert_app.c @@ -30,11 +30,13 @@ #else #include #include -#define mbedtls_time time -#define mbedtls_time_t time_t -#define mbedtls_fprintf fprintf -#define mbedtls_printf printf -#endif +#define mbedtls_time time +#define mbedtls_time_t time_t +#define mbedtls_fprintf fprintf +#define mbedtls_printf printf +#define MBEDTLS_EXIT_SUCCESS EXIT_SUCCESS +#define MBEDTLS_EXIT_FAILURE EXIT_FAILURE +#endif /* MBEDTLS_PLATFORM_C */ #if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_ENTROPY_C) || \ !defined(MBEDTLS_SSL_TLS_C) || !defined(MBEDTLS_SSL_CLI_C) || \ From 808a09ca851d97dc6f0bb0a04bf843a8ebd4a9ed Mon Sep 17 00:00:00 2001 From: Andres Amaya Garcia Date: Tue, 1 May 2018 19:29:14 +0100 Subject: [PATCH 41/41] Remove redundant ret = 1 in dh_client.c --- programs/pkey/dh_client.c | 1 - 1 file changed, 1 deletion(-) diff --git a/programs/pkey/dh_client.c b/programs/pkey/dh_client.c index 7ec47acab..3dadf48e6 100644 --- a/programs/pkey/dh_client.c +++ b/programs/pkey/dh_client.c @@ -209,7 +209,6 @@ int main( void ) if( ( n = (size_t) ( end - p ) ) != rsa.len ) { - ret = 1; mbedtls_printf( " failed\n ! Invalid RSA signature size\n\n" ); goto exit; }