mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2025-12-21 21:36:21 +01:00
Simplify selftest functions using macros
This reduces clutter, making the functions more readable. Also, it makes lcov see each line as covered. This is not cheating, as the lines that were previously seen as not covered are not supposed to be reached anyway (failing branches of the selftests). Thanks to this and previous test suite enhancements, lcov now sees chacha20.c and poly1305.c at 100% line coverage, and for chachapoly.c only two lines are not covered (error returns from lower-level module that should never happen except perhaps if an alternative implementation returns an unexpected error).
This commit is contained in:
parent
ceb1225d46
commit
c0dfcd4bf1
3 changed files with 60 additions and 94 deletions
|
|
@ -487,53 +487,44 @@ static const unsigned char test_mac[2][16] =
|
|||
}
|
||||
};
|
||||
|
||||
#define ASSERT( cond, args ) \
|
||||
do \
|
||||
{ \
|
||||
if( ! ( cond ) ) \
|
||||
{ \
|
||||
if( verbose != 0 ) \
|
||||
mbedtls_printf args; \
|
||||
\
|
||||
return( -1 ); \
|
||||
} \
|
||||
} \
|
||||
while( 0 )
|
||||
|
||||
int mbedtls_poly1305_self_test( int verbose )
|
||||
{
|
||||
unsigned char mac[16];
|
||||
unsigned i;
|
||||
int result;
|
||||
|
||||
for ( i = 0U; i < 2U; i++ )
|
||||
for( i = 0U; i < 2U; i++ )
|
||||
{
|
||||
if ( verbose != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( " Poly1305 test %u ", i );
|
||||
}
|
||||
|
||||
result = mbedtls_poly1305_mac( test_keys[i],
|
||||
test_data[i],
|
||||
test_data_len[i],
|
||||
mac );
|
||||
if ( result != 0 )
|
||||
{
|
||||
if ( verbose != 0 )
|
||||
{
|
||||
mbedtls_printf( "error code: %i\n", result );
|
||||
}
|
||||
ASSERT( 0 == result, ( "error code: %i\n", result ) );
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
ASSERT( 0 == memcmp( mac, test_mac[i], 16U ), ( "failed (mac)\n" ) );
|
||||
|
||||
if ( memcmp( mac, test_mac[i], 16U ) != 0 )
|
||||
{
|
||||
if ( verbose != 0 )
|
||||
{
|
||||
mbedtls_printf( "failed\n" );
|
||||
}
|
||||
|
||||
return( -1 );
|
||||
}
|
||||
|
||||
if ( verbose != 0 )
|
||||
{
|
||||
if( verbose != 0 )
|
||||
mbedtls_printf( "passed\n" );
|
||||
}
|
||||
}
|
||||
|
||||
if( verbose != 0 )
|
||||
{
|
||||
mbedtls_printf( "\n" );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue