mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
Merge pull request #4845 from mstarzyk-mobica/ecb-alt-ret-2.2x
Backport 2.2x: Catch failures of mbedtls_aes_crypt_ecb and its DES equivalents
This commit is contained in:
@ -67,7 +67,7 @@ void aes_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cbc( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
@ -92,7 +92,7 @@ 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_setkey_dec( &ctx, key_str->x, key_str->len * 8 ) == 0 );
|
||||
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)
|
||||
{
|
||||
@ -244,7 +244,7 @@ void aes_encrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_ENCRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
@ -266,7 +266,7 @@ void aes_decrypt_cfb128( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cfb128( &ctx, MBEDTLS_AES_DECRYPT, 16, &iv_offset, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 16, dst->len ) == 0 );
|
||||
@ -287,7 +287,7 @@ void aes_encrypt_cfb8( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
@ -309,7 +309,7 @@ void aes_decrypt_cfb8( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_aes_init( &ctx );
|
||||
|
||||
|
||||
mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 );
|
||||
TEST_ASSERT( mbedtls_aes_setkey_enc( &ctx, key_str->x, key_str->len * 8 ) == 0 );
|
||||
TEST_ASSERT( mbedtls_aes_crypt_cfb8( &ctx, MBEDTLS_AES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x,
|
||||
|
@ -24,7 +24,7 @@ void des_encrypt_ecb( data_t * key_str, data_t * src_str, data_t * dst )
|
||||
mbedtls_des_init( &ctx );
|
||||
|
||||
|
||||
mbedtls_des_setkey_enc( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des_setkey_enc( &ctx, key_str->x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
@ -44,7 +44,7 @@ void des_decrypt_ecb( data_t * key_str, data_t * src_str, data_t * dst )
|
||||
mbedtls_des_init( &ctx );
|
||||
|
||||
|
||||
mbedtls_des_setkey_dec( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des_setkey_dec( &ctx, key_str->x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str->x, output ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_test_hexcmp( output, dst->x, 8, dst->len ) == 0 );
|
||||
@ -65,7 +65,7 @@ void des_encrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_des_init( &ctx );
|
||||
|
||||
|
||||
mbedtls_des_setkey_enc( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des_setkey_enc( &ctx, key_str->x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_ENCRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
@ -91,7 +91,7 @@ void des_decrypt_cbc( data_t * key_str, data_t * iv_str,
|
||||
mbedtls_des_init( &ctx );
|
||||
|
||||
|
||||
mbedtls_des_setkey_dec( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des_setkey_dec( &ctx, key_str->x ) == 0 );
|
||||
TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_DECRYPT, src_str->len, iv_str->x, src_str->x, output ) == cbc_result );
|
||||
if( cbc_result == 0 )
|
||||
{
|
||||
@ -117,9 +117,9 @@ void des3_encrypt_ecb( int key_count, data_t * key_str,
|
||||
|
||||
|
||||
if( key_count == 2 )
|
||||
mbedtls_des3_set2key_enc( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des3_set2key_enc( &ctx, key_str->x ) == 0 );
|
||||
else if( key_count == 3 )
|
||||
mbedtls_des3_set3key_enc( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des3_set3key_enc( &ctx, key_str->x ) == 0 );
|
||||
else
|
||||
TEST_ASSERT( 0 );
|
||||
|
||||
@ -144,9 +144,9 @@ void des3_decrypt_ecb( int key_count, data_t * key_str,
|
||||
|
||||
|
||||
if( key_count == 2 )
|
||||
mbedtls_des3_set2key_dec( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des3_set2key_dec( &ctx, key_str->x ) == 0 );
|
||||
else if( key_count == 3 )
|
||||
mbedtls_des3_set3key_dec( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des3_set3key_dec( &ctx, key_str->x ) == 0 );
|
||||
else
|
||||
TEST_ASSERT( 0 );
|
||||
|
||||
@ -172,9 +172,9 @@ void des3_encrypt_cbc( int key_count, data_t * key_str,
|
||||
|
||||
|
||||
if( key_count == 2 )
|
||||
mbedtls_des3_set2key_enc( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des3_set2key_enc( &ctx, key_str->x ) == 0 );
|
||||
else if( key_count == 3 )
|
||||
mbedtls_des3_set3key_enc( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des3_set3key_enc( &ctx, key_str->x ) == 0 );
|
||||
else
|
||||
TEST_ASSERT( 0 );
|
||||
|
||||
@ -205,9 +205,9 @@ void des3_decrypt_cbc( int key_count, data_t * key_str,
|
||||
|
||||
|
||||
if( key_count == 2 )
|
||||
mbedtls_des3_set2key_dec( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des3_set2key_dec( &ctx, key_str->x ) == 0 );
|
||||
else if( key_count == 3 )
|
||||
mbedtls_des3_set3key_dec( &ctx, key_str->x );
|
||||
TEST_ASSERT( mbedtls_des3_set3key_dec( &ctx, key_str->x ) == 0 );
|
||||
else
|
||||
TEST_ASSERT( 0 );
|
||||
|
||||
|
Reference in New Issue
Block a user