poly1305: add test with multiple small fragments

This exercises the code path where data is just appended to the waiting queue
while it isn't empty.
This commit is contained in:
Manuel Pégourié-Gonnard 2018-05-10 11:06:46 +02:00
parent 59d2c30eba
commit 444f711216

View file

@ -54,15 +54,35 @@ void mbedtls_poly1305( char *hex_key_string, char *hex_mac_string, char *hex_src
/* Don't free/init the context, in order to test that starts() does the
* right thing. */
TEST_ASSERT( mbedtls_poly1305_starts( &ctx, key ) == 0 );
if( src_len >= 1 )
{
TEST_ASSERT( mbedtls_poly1305_starts( &ctx, key ) == 0 );
TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str, 1 ) == 0 );
TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str + 1, src_len - 1) == 0 );
TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str, 1 ) == 0 );
TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str + 1, src_len - 1 ) == 0 );
TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
hexify( mac_str, mac, 16 );
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );
hexify( mac_str, mac, 16 );
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );
}
/*
* Again with more pieces
*/
if( src_len >= 2 )
{
TEST_ASSERT( mbedtls_poly1305_starts( &ctx, key ) == 0 );
TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str, 1 ) == 0 );
TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str + 1, 1 ) == 0 );
TEST_ASSERT( mbedtls_poly1305_update( &ctx, src_str + 2, src_len - 2 ) == 0 );
TEST_ASSERT( mbedtls_poly1305_finish( &ctx, mac ) == 0 );
hexify( mac_str, mac, 16 );
TEST_ASSERT( strcmp( (char *) mac_str, hex_mac_string ) == 0 );
}
mbedtls_poly1305_free( &ctx );
}