modify library/memory_buffer_alloc.c, benchmark.c and the tests main code to use polarssl_exit
This commit is contained in:
parent
c39cb4986b
commit
77d3638497
3 changed files with 42 additions and 26 deletions
|
@ -37,9 +37,11 @@
|
|||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#define polarssl_exit exit
|
||||
#define polarssl_fprintf fprintf
|
||||
#endif /* POLARSSL_PLATFORM_C */
|
||||
#endif /* POLARSSL_MEMORY_DEBUG */
|
||||
|
||||
#if defined(POLARSSL_MEMORY_BACKTRACE)
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
|
@ -273,7 +275,7 @@ static void *buffer_alloc_malloc( size_t len )
|
|||
polarssl_fprintf( stderr, "FATAL: block in free_list but allocated "
|
||||
"data\n" );
|
||||
#endif
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
}
|
||||
|
||||
#if defined(POLARSSL_MEMORY_DEBUG)
|
||||
|
@ -312,7 +314,7 @@ static void *buffer_alloc_malloc( size_t len )
|
|||
#endif
|
||||
|
||||
if( ( heap.verify & MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 )
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
|
||||
return( ( (unsigned char *) cur ) + sizeof(memory_header) );
|
||||
}
|
||||
|
@ -367,7 +369,7 @@ static void *buffer_alloc_malloc( size_t len )
|
|||
#endif
|
||||
|
||||
if( ( heap.verify & MEMORY_VERIFY_ALLOC ) && verify_chain() != 0 )
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
|
||||
return( ( (unsigned char *) cur ) + sizeof(memory_header) );
|
||||
}
|
||||
|
@ -386,14 +388,14 @@ static void buffer_alloc_free( void *ptr )
|
|||
polarssl_fprintf( stderr, "FATAL: polarssl_free() outside of managed "
|
||||
"space\n" );
|
||||
#endif
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
}
|
||||
|
||||
p -= sizeof(memory_header);
|
||||
hdr = (memory_header *) p;
|
||||
|
||||
if( verify_header( hdr ) != 0 )
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
|
||||
if( hdr->alloc != 1 )
|
||||
{
|
||||
|
@ -401,7 +403,7 @@ static void buffer_alloc_free( void *ptr )
|
|||
polarssl_fprintf( stderr, "FATAL: polarssl_free() on unallocated "
|
||||
"data\n" );
|
||||
#endif
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
}
|
||||
|
||||
hdr->alloc = 0;
|
||||
|
@ -491,7 +493,7 @@ static void buffer_alloc_free( void *ptr )
|
|||
#endif
|
||||
|
||||
if( ( heap.verify & MEMORY_VERIFY_FREE ) && verify_chain() != 0 )
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
}
|
||||
|
||||
void memory_buffer_set_verify( int verify )
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
#else
|
||||
#define polarssl_snprintf snprintf
|
||||
#define polarssl_printf printf
|
||||
#define polarssl_exit exit
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
|
@ -428,17 +429,17 @@ int main( int argc, char *argv[] )
|
|||
ctr_drbg_context ctr_drbg;
|
||||
|
||||
if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
||||
exit(1);
|
||||
polarssl_exit(1);
|
||||
TIME_AND_TSC( "CTR_DRBG (NOPR)",
|
||||
if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
|
||||
exit(1) );
|
||||
polarssl_exit(1) );
|
||||
|
||||
if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
||||
exit(1);
|
||||
polarssl_exit(1);
|
||||
ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON );
|
||||
TIME_AND_TSC( "CTR_DRBG (PR)",
|
||||
if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
|
||||
exit(1) );
|
||||
polarssl_exit(1) );
|
||||
ctr_drbg_free( &ctr_drbg );
|
||||
}
|
||||
#endif
|
||||
|
@ -451,43 +452,43 @@ int main( int argc, char *argv[] )
|
|||
|
||||
#if defined(POLARSSL_SHA1_C)
|
||||
if( ( md_info = md_info_from_type( POLARSSL_MD_SHA1 ) ) == NULL )
|
||||
exit(1);
|
||||
polarssl_exit(1);
|
||||
|
||||
if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
|
||||
exit(1);
|
||||
polarssl_exit(1);
|
||||
TIME_AND_TSC( "HMAC_DRBG SHA-1 (NOPR)",
|
||||
if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
|
||||
exit(1) );
|
||||
polarssl_exit(1) );
|
||||
hmac_drbg_free( &hmac_drbg );
|
||||
|
||||
if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
|
||||
exit(1);
|
||||
polarssl_exit(1);
|
||||
hmac_drbg_set_prediction_resistance( &hmac_drbg,
|
||||
POLARSSL_HMAC_DRBG_PR_ON );
|
||||
TIME_AND_TSC( "HMAC_DRBG SHA-1 (PR)",
|
||||
if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
|
||||
exit(1) );
|
||||
polarssl_exit(1) );
|
||||
hmac_drbg_free( &hmac_drbg );
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_SHA256_C)
|
||||
if( ( md_info = md_info_from_type( POLARSSL_MD_SHA256 ) ) == NULL )
|
||||
exit(1);
|
||||
polarssl_exit(1);
|
||||
|
||||
if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
|
||||
exit(1);
|
||||
polarssl_exit(1);
|
||||
TIME_AND_TSC( "HMAC_DRBG SHA-256 (NOPR)",
|
||||
if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
|
||||
exit(1) );
|
||||
polarssl_exit(1) );
|
||||
hmac_drbg_free( &hmac_drbg );
|
||||
|
||||
if( hmac_drbg_init( &hmac_drbg, md_info, myrand, NULL, NULL, 0 ) != 0 )
|
||||
exit(1);
|
||||
polarssl_exit(1);
|
||||
hmac_drbg_set_prediction_resistance( &hmac_drbg,
|
||||
POLARSSL_HMAC_DRBG_PR_ON );
|
||||
TIME_AND_TSC( "HMAC_DRBG SHA-256 (PR)",
|
||||
if( hmac_drbg_random( &hmac_drbg, buf, BUFSIZE ) != 0 )
|
||||
exit(1) );
|
||||
polarssl_exit(1) );
|
||||
hmac_drbg_free( &hmac_drbg );
|
||||
#endif
|
||||
}
|
||||
|
@ -542,13 +543,13 @@ int main( int argc, char *argv[] )
|
|||
if( mpi_read_string( &dhm.P, 16, dhm_P[i] ) != 0 ||
|
||||
mpi_read_string( &dhm.G, 16, dhm_G[i] ) != 0 )
|
||||
{
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
}
|
||||
|
||||
dhm.len = mpi_size( &dhm.P );
|
||||
dhm_make_public( &dhm, (int) dhm.len, buf, dhm.len, myrand, NULL );
|
||||
if( mpi_copy( &dhm.GY, &dhm.GX ) != 0 )
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
|
||||
polarssl_snprintf( title, sizeof( title ), "DHE-%d", dhm_sizes[i] );
|
||||
TIME_PUBLIC( title, "handshake",
|
||||
|
@ -583,7 +584,7 @@ int main( int argc, char *argv[] )
|
|||
ecdsa_init( &ecdsa );
|
||||
|
||||
if( ecdsa_genkey( &ecdsa, curve_info->grp_id, myrand, NULL ) != 0 )
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
|
||||
polarssl_snprintf( title, sizeof( title ), "ECDSA-%s",
|
||||
curve_info->name );
|
||||
|
@ -618,7 +619,7 @@ int main( int argc, char *argv[] )
|
|||
myrand, NULL ) != 0 ||
|
||||
ecp_copy( &ecdh.Qp, &ecdh.Q ) != 0 )
|
||||
{
|
||||
exit( 1 );
|
||||
polarssl_exit( 1 );
|
||||
}
|
||||
|
||||
polarssl_snprintf( title, sizeof( title ), "ECDHE-%s",
|
||||
|
|
|
@ -1,3 +1,16 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#if defined(POLARSSL_PLATFORM_C)
|
||||
#include "polarssl/platform.h"
|
||||
#else
|
||||
#define polarssl_exit exit
|
||||
#define polarssl_free free
|
||||
#define polarssl_malloc malloc
|
||||
#define polarssl_fprintf fprintf
|
||||
#define polarssl_printf printf
|
||||
#endif
|
||||
|
||||
#if defined(POLARSSL_MEMORY_BUFFER_ALLOC_C)
|
||||
#include "polarssl/memory_buffer_alloc.h"
|
||||
#endif
|
||||
|
@ -268,7 +281,7 @@ int main()
|
|||
{
|
||||
polarssl_fprintf( stderr, "FAILED: FATAL PARSE ERROR\n" );
|
||||
fclose(file);
|
||||
exit( 2 );
|
||||
polarssl_exit( 2 );
|
||||
}
|
||||
else
|
||||
total_errors++;
|
||||
|
|
Loading…
Reference in a new issue