mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-04-25 09:02:48 +00:00
tests: Improve incomplete then overflow tests
Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
83e4c1270a
commit
133740b74e
@ -646,16 +646,10 @@ void mbedtls_ccm_incomplete_ad_and_overflow( int cipher_id, int mode,
|
|||||||
data_t * add )
|
data_t * add )
|
||||||
{
|
{
|
||||||
mbedtls_ccm_context ctx;
|
mbedtls_ccm_context ctx;
|
||||||
|
uint8_t add_second_buffer[2];
|
||||||
|
|
||||||
/* New auth buffer containing same data as original one,
|
add_second_buffer[0] = add->x[ add->len - 1 ];
|
||||||
* with added extra byte at the end */
|
add_second_buffer[1] = 0xAB; // some magic value
|
||||||
uint8_t* add_extended = NULL;
|
|
||||||
ASSERT_ALLOC( add_extended, add->len + 1 );
|
|
||||||
if( add_extended )
|
|
||||||
{
|
|
||||||
memcpy( add_extended, add->x, add->len );
|
|
||||||
add_extended[add->len] = 0xAB; // some magic value
|
|
||||||
}
|
|
||||||
|
|
||||||
mbedtls_ccm_init( &ctx );
|
mbedtls_ccm_init( &ctx );
|
||||||
TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
|
TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
|
||||||
@ -664,11 +658,10 @@ void mbedtls_ccm_incomplete_ad_and_overflow( int cipher_id, int mode,
|
|||||||
TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, 16, 16 ) );
|
TEST_EQUAL( 0, mbedtls_ccm_set_lengths( &ctx, add->len, 16, 16 ) );
|
||||||
|
|
||||||
// pass incomplete auth data
|
// pass incomplete auth data
|
||||||
TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add_extended, add->len - 1) );
|
TEST_EQUAL( 0, mbedtls_ccm_update_ad( &ctx, add->x, add->len - 1) );
|
||||||
// pass 2 extra bytes (1 missing byte from previous incomplete pass, and 1 unexpected byte)
|
// pass 2 extra bytes (1 missing byte from previous incomplete pass, and 1 unexpected byte)
|
||||||
TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad( &ctx, add_extended + add->len - 1, 2) );
|
TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, mbedtls_ccm_update_ad( &ctx, add_second_buffer, 2) );
|
||||||
exit:
|
exit:
|
||||||
mbedtls_free( add_extended );
|
|
||||||
mbedtls_ccm_free( &ctx );
|
mbedtls_ccm_free( &ctx );
|
||||||
}
|
}
|
||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
@ -775,16 +768,10 @@ void mbedtls_ccm_incomplete_update_overflow( int cipher_id, int mode,
|
|||||||
mbedtls_ccm_context ctx;
|
mbedtls_ccm_context ctx;
|
||||||
uint8_t *output = NULL;
|
uint8_t *output = NULL;
|
||||||
size_t olen;
|
size_t olen;
|
||||||
|
uint8_t msg_second_buffer[2];
|
||||||
|
|
||||||
/* New plaintext/ciphertext buffer containing same data as original one,
|
msg_second_buffer[0] = msg->x[ msg->len - 1 ];
|
||||||
* with added extra byte at the end */
|
msg_second_buffer[1] = 0xAB; // some magic value
|
||||||
uint8_t* msg_extended = NULL;
|
|
||||||
ASSERT_ALLOC( msg_extended, msg->len + 1 );
|
|
||||||
if( msg_extended )
|
|
||||||
{
|
|
||||||
memcpy( msg_extended, msg->x, msg->len );
|
|
||||||
msg_extended[msg->len] = 0xAB; // some magic value
|
|
||||||
}
|
|
||||||
|
|
||||||
mbedtls_ccm_init( &ctx );
|
mbedtls_ccm_init( &ctx );
|
||||||
TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
|
TEST_EQUAL( mbedtls_ccm_setkey( &ctx, cipher_id, key->x, key->len * 8 ), 0 );
|
||||||
@ -796,12 +783,11 @@ void mbedtls_ccm_incomplete_update_overflow( int cipher_id, int mode,
|
|||||||
|
|
||||||
ASSERT_ALLOC( output, msg->len + 1 );
|
ASSERT_ALLOC( output, msg->len + 1 );
|
||||||
// pass incomplete text
|
// pass incomplete text
|
||||||
TEST_EQUAL( 0, mbedtls_ccm_update( &ctx, msg_extended, msg->len - 1, output, msg->len + 1, &olen ) );
|
TEST_EQUAL( 0, mbedtls_ccm_update( &ctx, msg->x, msg->len - 1, output, msg->len + 1, &olen ) );
|
||||||
// pass 2 extra bytes (1 missing byte from previous incomplete pass, and 1 unexpected byte)
|
// pass 2 extra bytes (1 missing byte from previous incomplete pass, and 1 unexpected byte)
|
||||||
TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, \
|
TEST_EQUAL( MBEDTLS_ERR_CCM_BAD_INPUT, \
|
||||||
mbedtls_ccm_update( &ctx, msg_extended + msg->len - 1, 2, output + msg->len - 1, 2, &olen ) );
|
mbedtls_ccm_update( &ctx, msg_second_buffer, 2, output + msg->len - 1, 2, &olen ) );
|
||||||
exit:
|
exit:
|
||||||
mbedtls_free( msg_extended );
|
|
||||||
mbedtls_free( output );
|
mbedtls_free( output );
|
||||||
mbedtls_ccm_free( &ctx );
|
mbedtls_ccm_free( &ctx );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user