mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-01-30 15:32:58 +00:00
Fix ret code in rsa_sign.c
This commit is contained in:
parent
70e1ffdacd
commit
1a66056c77
@ -29,10 +29,13 @@
|
|||||||
#include "mbedtls/platform.h"
|
#include "mbedtls/platform.h"
|
||||||
#else
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#define mbedtls_fprintf fprintf
|
#include <stdlib.h>
|
||||||
#define mbedtls_printf printf
|
#define mbedtls_fprintf fprintf
|
||||||
#define mbedtls_snprintf snprintf
|
#define mbedtls_printf printf
|
||||||
#endif
|
#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) || \
|
#if !defined(MBEDTLS_BIGNUM_C) || !defined(MBEDTLS_RSA_C) || \
|
||||||
!defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_MD_C) || \
|
!defined(MBEDTLS_SHA256_C) || !defined(MBEDTLS_MD_C) || \
|
||||||
@ -55,7 +58,8 @@ int main( void )
|
|||||||
int main( int argc, char *argv[] )
|
int main( int argc, char *argv[] )
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int ret;
|
int ret = 1;
|
||||||
|
int exit_code = MBEDTLS_EXIT_FAILURE;
|
||||||
size_t i;
|
size_t i;
|
||||||
mbedtls_rsa_context rsa;
|
mbedtls_rsa_context rsa;
|
||||||
unsigned char hash[32];
|
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( &D ); mbedtls_mpi_init( &E ); mbedtls_mpi_init( &DP );
|
||||||
mbedtls_mpi_init( &DQ ); mbedtls_mpi_init( &QP );
|
mbedtls_mpi_init( &DQ ); mbedtls_mpi_init( &QP );
|
||||||
|
|
||||||
ret = 1;
|
|
||||||
|
|
||||||
if( argc != 2 )
|
if( argc != 2 )
|
||||||
{
|
{
|
||||||
mbedtls_printf( "usage: rsa_sign <filename>\n" );
|
mbedtls_printf( "usage: rsa_sign <filename>\n" );
|
||||||
@ -87,7 +89,6 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL )
|
if( ( f = fopen( "rsa_priv.txt", "rb" ) ) == NULL )
|
||||||
{
|
{
|
||||||
ret = 1;
|
|
||||||
mbedtls_printf( " failed\n ! Could not open rsa_priv.txt\n" \
|
mbedtls_printf( " failed\n ! Could not open rsa_priv.txt\n" \
|
||||||
" ! Please run rsa_genkey first\n\n" );
|
" ! Please run rsa_genkey first\n\n" );
|
||||||
goto exit;
|
goto exit;
|
||||||
@ -159,7 +160,6 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
if( ( f = fopen( filename, "wb+" ) ) == NULL )
|
if( ( f = fopen( filename, "wb+" ) ) == NULL )
|
||||||
{
|
{
|
||||||
ret = 1;
|
|
||||||
mbedtls_printf( " failed\n ! Could not create %s\n\n", argv[1] );
|
mbedtls_printf( " failed\n ! Could not create %s\n\n", argv[1] );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
@ -172,6 +172,8 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
mbedtls_printf( "\n . Done (created \"%s\")\n\n", filename );
|
mbedtls_printf( "\n . Done (created \"%s\")\n\n", filename );
|
||||||
|
|
||||||
|
exit_code = MBEDTLS_EXIT_SUCCESS;
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
mbedtls_rsa_free( &rsa );
|
mbedtls_rsa_free( &rsa );
|
||||||
@ -184,7 +186,7 @@ exit:
|
|||||||
fflush( stdout ); getchar();
|
fflush( stdout ); getchar();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return( ret );
|
return( exit_code );
|
||||||
}
|
}
|
||||||
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_SHA256_C &&
|
#endif /* MBEDTLS_BIGNUM_C && MBEDTLS_RSA_C && MBEDTLS_SHA256_C &&
|
||||||
MBEDTLS_FS_IO */
|
MBEDTLS_FS_IO */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user