mirror of
https://git.suyu.dev/suyu/mbedtls.git
synced 2025-12-24 08:16:33 +01:00
Add additional parameter validation tests for the AES module
This adds additional tests to validate the AES module parameter validation checks which are enabled using the MBEDTLS_CHECK_PARAMS option.
This commit is contained in:
parent
5201e414aa
commit
a646345e3f
3 changed files with 213 additions and 11 deletions
|
|
@ -15,8 +15,8 @@ void aes_encrypt_ecb( data_t * key_str, data_t * src_str,
|
|||
mbedtls_aes_context ctx;
|
||||
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
TEST_FN( mbedtls_aes_init( &ctx ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
|
||||
if( setkey_result == 0 )
|
||||
|
|
@ -39,8 +39,8 @@ void aes_decrypt_ecb( data_t * key_str, data_t * src_str,
|
|||
mbedtls_aes_context ctx;
|
||||
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
TEST_FN( mbedtls_aes_init( &ctx ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == setkey_result );
|
||||
if( setkey_result == 0 )
|
||||
|
|
@ -64,8 +64,8 @@ void aes_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
|||
mbedtls_aes_context ctx;
|
||||
|
||||
memset(output, 0x00, 100);
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
TEST_FN( mbedtls_aes_init( &ctx ) );
|
||||
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
|
||||
|
|
@ -91,7 +91,6 @@ void aes_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
|||
memset(output, 0x00, 100);
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
|
||||
mbedtls_aes_setkey_dec( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
|
||||
if( cbc_result == 0)
|
||||
|
|
@ -372,6 +371,34 @@ exit:
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aes_invalid_param( )
|
||||
{
|
||||
mbedtls_aes_context dummy_ctx;
|
||||
const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
|
||||
|
||||
TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) );
|
||||
|
||||
/* mbedtls_aes_setkey_enc() */
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
|
||||
mbedtls_aes_setkey_enc( NULL, key, 128 ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
|
||||
mbedtls_aes_setkey_enc( &dummy_ctx, NULL, 128 ) );
|
||||
|
||||
/* mbedtls_aes_setkey_dec() */
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
|
||||
mbedtls_aes_setkey_dec( NULL, key, 128 ) );
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
|
||||
mbedtls_aes_setkey_dec( &dummy_ctx, NULL, 128 ) );
|
||||
|
||||
|
||||
exit:
|
||||
return;
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
|
||||
void aes_selftest( )
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue