mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-23 01:55:46 +01:00
Added return value checking for correctness in programs
This commit is contained in:
parent
4f42c11846
commit
cbe3d0d5cc
@ -164,7 +164,11 @@ int main( int argc, char *argv[] )
|
||||
fprintf( stderr, "Cipher '%s' not found\n", argv[4] );
|
||||
goto exit;
|
||||
}
|
||||
cipher_init_ctx( &cipher_ctx, cipher_info);
|
||||
if( ( ret = cipher_init_ctx( &cipher_ctx, cipher_info) ) != 0 )
|
||||
{
|
||||
fprintf( stderr, "cipher_init_ctx failed\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
md_info = md_info_from_string( argv[5] );
|
||||
if( md_info == NULL )
|
||||
@ -326,11 +330,16 @@ int main( int argc, char *argv[] )
|
||||
|
||||
if( fread( buffer, 1, ilen, fin ) != ilen )
|
||||
{
|
||||
fprintf( stderr, "fread(%ld bytes) failed\n", (long) n );
|
||||
fprintf( stderr, "fread(%ld bytes) failed\n", (long) ilen );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( cipher_update( &cipher_ctx, buffer, ilen, output, &olen ) != 0 )
|
||||
{
|
||||
fprintf( stderr, "cipher_update() returned error\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
cipher_update( &cipher_ctx, buffer, ilen, output, &olen );
|
||||
md_hmac_update( &md_ctx, output, olen );
|
||||
|
||||
if( fwrite( output, 1, olen, fout ) != olen )
|
||||
@ -424,10 +433,24 @@ int main( int argc, char *argv[] )
|
||||
|
||||
memset( key, 0, sizeof( key ) );
|
||||
|
||||
cipher_setkey( &cipher_ctx, digest, cipher_info->key_length,
|
||||
POLARSSL_DECRYPT );
|
||||
cipher_set_iv( &cipher_ctx, IV, 16 );
|
||||
cipher_reset( &cipher_ctx );
|
||||
if( cipher_setkey( &cipher_ctx, digest, cipher_info->key_length,
|
||||
POLARSSL_DECRYPT ) != 0 )
|
||||
{
|
||||
fprintf( stderr, "cipher_setkey() returned error\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( cipher_set_iv( &cipher_ctx, IV, 16 ) != 0 )
|
||||
{
|
||||
fprintf( stderr, "cipher_set_iv() returned error\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( cipher_reset( &cipher_ctx ) != 0 )
|
||||
{
|
||||
fprintf( stderr, "cipher_reset() returned error\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
md_hmac_starts( &md_ctx, digest, 32 );
|
||||
|
||||
@ -445,8 +468,13 @@ int main( int argc, char *argv[] )
|
||||
}
|
||||
|
||||
md_hmac_update( &md_ctx, buffer, cipher_get_block_size( &cipher_ctx ) );
|
||||
cipher_update( &cipher_ctx, buffer, cipher_get_block_size( &cipher_ctx ),
|
||||
output, &olen );
|
||||
if( cipher_update( &cipher_ctx, buffer,
|
||||
cipher_get_block_size( &cipher_ctx ),
|
||||
output, &olen ) != 0 )
|
||||
{
|
||||
fprintf( stderr, "cipher_update() returned error\n" );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( fwrite( output, 1, olen, fout ) != olen )
|
||||
{
|
||||
|
@ -65,7 +65,12 @@ int main( int argc, char *argv[] )
|
||||
((void) argv);
|
||||
|
||||
mpi_init( &G ); mpi_init( &P ); mpi_init( &Q );
|
||||
mpi_read_string( &G, 10, GENERATOR );
|
||||
|
||||
if( ( ret = mpi_read_string( &G, 10, GENERATOR ) ) != 0 )
|
||||
{
|
||||
printf( " failed\n ! mpi_read_string returned %d\n", ret );
|
||||
goto exit;
|
||||
}
|
||||
|
||||
printf( "\nWARNING: You should not generate and use your own DHM primes\n" );
|
||||
printf( " unless you are very certain of what you are doing!\n" );
|
||||
|
@ -483,11 +483,16 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
memset( &dhm, 0, sizeof( dhm_context ) );
|
||||
|
||||
mpi_read_string( &dhm.P, 16, dhm_P[i] );
|
||||
mpi_read_string( &dhm.G, 16, dhm_G[i] );
|
||||
if( mpi_read_string( &dhm.P, 16, dhm_P[i] ) != 0 ||
|
||||
mpi_read_string( &dhm.G, 16, dhm_G[i] ) != 0 )
|
||||
{
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
dhm.len = mpi_size( &dhm.P );
|
||||
dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, myrand, NULL );
|
||||
mpi_copy( &dhm.GY, &dhm.GX );
|
||||
if( mpi_copy( &dhm.GY, &dhm.GX ) != 0 )
|
||||
exit( 1 );
|
||||
|
||||
snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] );
|
||||
TIME_PUBLIC( title, "handshake",
|
||||
|
@ -273,7 +273,13 @@ static int ssl_test( struct options *opt )
|
||||
ssl_set_ciphersuites( &ssl, opt->force_ciphersuite );
|
||||
|
||||
if( opt->iomode == IOMODE_NONBLOCK )
|
||||
net_set_nonblock( client_fd );
|
||||
{
|
||||
if( ( ret = net_set_nonblock( client_fd ) ) != 0 )
|
||||
{
|
||||
printf( " ! net_set_nonblock returned %d\n\n", ret );
|
||||
return( ret );
|
||||
}
|
||||
}
|
||||
|
||||
read_buf = (unsigned char *) malloc( opt->buffer_size );
|
||||
write_buf = (unsigned char *) malloc( opt->buffer_size );
|
||||
|
Loading…
Reference in New Issue
Block a user