mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-05-05 01:23:39 +02:00
Catch failures of AES or DES operations
A DES or AES block operation can fail in alternative implementations of
mbedtls_internal_aes_encrypt() (under MBEDTLS_AES_ENCRYPT_ALT),
mbedtls_internal_aes_decrypt() (under MBEDTLS_AES_DECRYPT_ALT),
mbedtls_des_crypt_ecb() (under MBEDTLS_DES_CRYPT_ECB_ALT),
mbedtls_des3_crypt_ecb() (under MBEDTLS_DES3_CRYPT_ECB_ALT).
A failure can happen if the accelerator peripheral is in a bad state.
Several block modes were not catching the error.
This commit does the following code changes:
* Fix DES and AES API calls which ignored the return values:
* In library code: on failure, goto exit and return ret.
* In pkey programs: goto exit.
* In the benchmark program: exit (not ideal since there's no error
message, but it's what the code currently does for failures).
* In test code: TEST_ASSERT.
* Changelog entry.
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
Signed-off-by: Mateusz Starzyk <mateusz.starzyk@mobica.com>
This commit is contained in:
committed by
Mateusz Starzyk
parent
8d2b7aaede
commit
621333f41b
7
check-return.txt
Normal file
7
check-return.txt
Normal file
@@ -0,0 +1,7 @@
|
||||
Bugfix
|
||||
* Failures of alternative implementations of AES or DES single-block
|
||||
functions enabled with MBEDTLS_AES_ENCRYPT_ALT, MBEDTLS_AES_DECRYPT_ALT,
|
||||
MBEDTLS_DES_CRYPT_ECB_ALT or MBEDTLS_DES3_CRYPT_ECB_ALT were ignored.
|
||||
This does not concern the implementation provided with Mbed TLS,
|
||||
where this function cannot fail, or full-module replacements with
|
||||
MBEDTLS_AES_ALT or MBEDTLS_DES_ALT. Reported by Armelle Duboc in #1092.
|
||||
@@ -1082,6 +1082,7 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
||||
unsigned char *output )
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
unsigned char temp[16];
|
||||
|
||||
AES_VALIDATE_RET( ctx != NULL );
|
||||
@@ -1111,7 +1112,9 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
||||
while( length > 0 )
|
||||
{
|
||||
memcpy( temp, input, 16 );
|
||||
mbedtls_aes_crypt_ecb( ctx, mode, input, output );
|
||||
ret = mbedtls_aes_crypt_ecb( ctx, mode, input, output );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
for( i = 0; i < 16; i++ )
|
||||
output[i] = (unsigned char)( output[i] ^ iv[i] );
|
||||
@@ -1130,7 +1133,9 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
||||
for( i = 0; i < 16; i++ )
|
||||
output[i] = (unsigned char)( input[i] ^ iv[i] );
|
||||
|
||||
mbedtls_aes_crypt_ecb( ctx, mode, output, output );
|
||||
ret = mbedtls_aes_crypt_ecb( ctx, mode, output, output );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
memcpy( iv, output, 16 );
|
||||
|
||||
input += 16;
|
||||
@@ -1138,8 +1143,10 @@ int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
|
||||
length -= 16;
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
return( 0 );
|
||||
exit:
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
@@ -1322,6 +1329,7 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
||||
unsigned char *output )
|
||||
{
|
||||
int c;
|
||||
int ret;
|
||||
size_t n;
|
||||
|
||||
AES_VALIDATE_RET( ctx != NULL );
|
||||
@@ -1342,7 +1350,11 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
||||
while( length-- )
|
||||
{
|
||||
if( n == 0 )
|
||||
mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
|
||||
{
|
||||
ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
c = *input++;
|
||||
*output++ = (unsigned char)( c ^ iv[n] );
|
||||
@@ -1356,7 +1368,11 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
||||
while( length-- )
|
||||
{
|
||||
if( n == 0 )
|
||||
mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
|
||||
{
|
||||
ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
iv[n] = *output++ = (unsigned char)( iv[n] ^ *input++ );
|
||||
|
||||
@@ -1365,8 +1381,10 @@ int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
|
||||
}
|
||||
|
||||
*iv_off = n;
|
||||
ret = 0;
|
||||
|
||||
return( 0 );
|
||||
exit:
|
||||
return( ret );
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1379,6 +1397,7 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
|
||||
const unsigned char *input,
|
||||
unsigned char *output )
|
||||
{
|
||||
int ret;
|
||||
unsigned char c;
|
||||
unsigned char ov[17];
|
||||
|
||||
@@ -1391,7 +1410,9 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
|
||||
while( length-- )
|
||||
{
|
||||
memcpy( ov, iv, 16 );
|
||||
mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
|
||||
ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, iv, iv );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
if( mode == MBEDTLS_AES_DECRYPT )
|
||||
ov[16] = *input;
|
||||
@@ -1403,8 +1424,10 @@ int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
|
||||
|
||||
memcpy( iv, ov + 1, 16 );
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
return( 0 );
|
||||
exit:
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CFB */
|
||||
|
||||
@@ -1466,6 +1489,7 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
||||
unsigned char *output )
|
||||
{
|
||||
int c, i;
|
||||
int ret;
|
||||
size_t n;
|
||||
|
||||
AES_VALIDATE_RET( ctx != NULL );
|
||||
@@ -1483,7 +1507,9 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
||||
while( length-- )
|
||||
{
|
||||
if( n == 0 ) {
|
||||
mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block );
|
||||
ret = mbedtls_aes_crypt_ecb( ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
for( i = 16; i > 0; i-- )
|
||||
if( ++nonce_counter[i - 1] != 0 )
|
||||
@@ -1496,8 +1522,10 @@ int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
|
||||
}
|
||||
|
||||
*nc_off = n;
|
||||
ret = 0;
|
||||
|
||||
return( 0 );
|
||||
exit:
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#if defined(MBEDTLS_DES_C)
|
||||
|
||||
#include "mbedtls/des.h"
|
||||
#include "mbedtls/error.h"
|
||||
#include "mbedtls/platform_util.h"
|
||||
|
||||
#include <string.h>
|
||||
@@ -696,6 +697,7 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
|
||||
unsigned char *output )
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
unsigned char temp[8];
|
||||
|
||||
if( length % 8 )
|
||||
@@ -708,7 +710,9 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
|
||||
for( i = 0; i < 8; i++ )
|
||||
output[i] = (unsigned char)( input[i] ^ iv[i] );
|
||||
|
||||
mbedtls_des_crypt_ecb( ctx, output, output );
|
||||
ret = mbedtls_des_crypt_ecb( ctx, output, output );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
memcpy( iv, output, 8 );
|
||||
|
||||
input += 8;
|
||||
@@ -721,7 +725,9 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
|
||||
while( length > 0 )
|
||||
{
|
||||
memcpy( temp, input, 8 );
|
||||
mbedtls_des_crypt_ecb( ctx, input, output );
|
||||
ret = mbedtls_des_crypt_ecb( ctx, input, output );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
output[i] = (unsigned char)( output[i] ^ iv[i] );
|
||||
@@ -733,8 +739,10 @@ int mbedtls_des_crypt_cbc( mbedtls_des_context *ctx,
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
return( 0 );
|
||||
exit:
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
@@ -795,6 +803,7 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
|
||||
unsigned char *output )
|
||||
{
|
||||
int i;
|
||||
int ret;
|
||||
unsigned char temp[8];
|
||||
|
||||
if( length % 8 )
|
||||
@@ -807,7 +816,9 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
|
||||
for( i = 0; i < 8; i++ )
|
||||
output[i] = (unsigned char)( input[i] ^ iv[i] );
|
||||
|
||||
mbedtls_des3_crypt_ecb( ctx, output, output );
|
||||
ret = mbedtls_des3_crypt_ecb( ctx, output, output );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
memcpy( iv, output, 8 );
|
||||
|
||||
input += 8;
|
||||
@@ -820,7 +831,9 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
|
||||
while( length > 0 )
|
||||
{
|
||||
memcpy( temp, input, 8 );
|
||||
mbedtls_des3_crypt_ecb( ctx, input, output );
|
||||
ret = mbedtls_des3_crypt_ecb( ctx, input, output );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
for( i = 0; i < 8; i++ )
|
||||
output[i] = (unsigned char)( output[i] ^ iv[i] );
|
||||
@@ -832,8 +845,10 @@ int mbedtls_des3_crypt_cbc( mbedtls_des3_context *ctx,
|
||||
length -= 8;
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
return( 0 );
|
||||
exit:
|
||||
return( ret );
|
||||
}
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
@@ -926,39 +941,43 @@ int mbedtls_des_self_test( int verbose )
|
||||
switch( i )
|
||||
{
|
||||
case 0:
|
||||
mbedtls_des_setkey_dec( &ctx, des3_test_keys );
|
||||
ret = mbedtls_des_setkey_dec( &ctx, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mbedtls_des_setkey_enc( &ctx, des3_test_keys );
|
||||
ret = mbedtls_des_setkey_enc( &ctx, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
|
||||
ret = mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
|
||||
ret = mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 4:
|
||||
mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
|
||||
ret = mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 5:
|
||||
mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
|
||||
ret = mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
default:
|
||||
return( 1 );
|
||||
}
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
for( j = 0; j < 10000; j++ )
|
||||
{
|
||||
if( u == 0 )
|
||||
mbedtls_des_crypt_ecb( &ctx, buf, buf );
|
||||
ret = mbedtls_des_crypt_ecb( &ctx, buf, buf );
|
||||
else
|
||||
mbedtls_des3_crypt_ecb( &ctx3, buf, buf );
|
||||
ret = mbedtls_des3_crypt_ecb( &ctx3, buf, buf );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( ( v == MBEDTLS_DES_DECRYPT &&
|
||||
@@ -1001,41 +1020,45 @@ int mbedtls_des_self_test( int verbose )
|
||||
switch( i )
|
||||
{
|
||||
case 0:
|
||||
mbedtls_des_setkey_dec( &ctx, des3_test_keys );
|
||||
ret = mbedtls_des_setkey_dec( &ctx, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 1:
|
||||
mbedtls_des_setkey_enc( &ctx, des3_test_keys );
|
||||
ret = mbedtls_des_setkey_enc( &ctx, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 2:
|
||||
mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
|
||||
ret = mbedtls_des3_set2key_dec( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 3:
|
||||
mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
|
||||
ret = mbedtls_des3_set2key_enc( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 4:
|
||||
mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
|
||||
ret = mbedtls_des3_set3key_dec( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
case 5:
|
||||
mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
|
||||
ret = mbedtls_des3_set3key_enc( &ctx3, des3_test_keys );
|
||||
break;
|
||||
|
||||
default:
|
||||
return( 1 );
|
||||
}
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
if( v == MBEDTLS_DES_DECRYPT )
|
||||
{
|
||||
for( j = 0; j < 10000; j++ )
|
||||
{
|
||||
if( u == 0 )
|
||||
mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
|
||||
ret = mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
|
||||
else
|
||||
mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
|
||||
ret = mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1045,9 +1068,11 @@ int mbedtls_des_self_test( int verbose )
|
||||
unsigned char tmp[8];
|
||||
|
||||
if( u == 0 )
|
||||
mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
|
||||
ret = mbedtls_des_crypt_cbc( &ctx, v, 8, iv, buf, buf );
|
||||
else
|
||||
mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
|
||||
ret = mbedtls_des3_crypt_cbc( &ctx3, v, 8, iv, buf, buf );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
memcpy( tmp, prv, 8 );
|
||||
memcpy( prv, buf, 8 );
|
||||
@@ -1081,6 +1106,8 @@ exit:
|
||||
mbedtls_des_free( &ctx );
|
||||
mbedtls_des3_free( &ctx3 );
|
||||
|
||||
if( ret != 0 )
|
||||
ret = 1;
|
||||
return( ret );
|
||||
}
|
||||
|
||||
|
||||
@@ -301,7 +301,9 @@ int main( void )
|
||||
mbedtls_printf( "...\n . Receiving and decrypting the ciphertext" );
|
||||
fflush( stdout );
|
||||
|
||||
mbedtls_aes_setkey_dec( &aes, buf, 256 );
|
||||
ret = mbedtls_aes_setkey_dec( &aes, buf, 256 );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
|
||||
@@ -311,7 +313,9 @@ int main( void )
|
||||
goto exit;
|
||||
}
|
||||
|
||||
mbedtls_aes_crypt_ecb( &aes, MBEDTLS_AES_DECRYPT, buf, buf );
|
||||
ret = mbedtls_aes_crypt_ecb( &aes, MBEDTLS_AES_DECRYPT, buf, buf );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
buf[16] = '\0';
|
||||
mbedtls_printf( "\n . Plaintext is \"%s\"\n\n", (char *) buf );
|
||||
|
||||
|
||||
@@ -322,9 +322,13 @@ int main( void )
|
||||
mbedtls_printf( "...\n . Encrypting and sending the ciphertext" );
|
||||
fflush( stdout );
|
||||
|
||||
mbedtls_aes_setkey_enc( &aes, buf, 256 );
|
||||
ret = mbedtls_aes_setkey_enc( &aes, buf, 256 );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
memcpy( buf, PLAINTEXT, 16 );
|
||||
mbedtls_aes_crypt_ecb( &aes, MBEDTLS_AES_ENCRYPT, buf, buf );
|
||||
ret = mbedtls_aes_crypt_ecb( &aes, MBEDTLS_AES_ENCRYPT, buf, buf );
|
||||
if( ret != 0 )
|
||||
goto exit;
|
||||
|
||||
if( ( ret = mbedtls_net_send( &client_fd, buf, 16 ) ) != 16 )
|
||||
{
|
||||
|
||||
@@ -178,6 +178,18 @@ do { \
|
||||
} \
|
||||
} while( 0 )
|
||||
|
||||
#define CHECK_AND_CONTINUE( R ) \
|
||||
{ \
|
||||
int CHECK_AND_CONTINUE_ret = ( R ); \
|
||||
if( CHECK_AND_CONTINUE_ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED ) { \
|
||||
mbedtls_printf( "Feature not supported. Skipping.\n" ); \
|
||||
continue; \
|
||||
} \
|
||||
else if( CHECK_AND_CONTINUE_ret != 0 ) { \
|
||||
mbedtls_exit( 1 ); \
|
||||
} \
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_MEMORY_BUFFER_ALLOC_C) && defined(MBEDTLS_MEMORY_DEBUG)
|
||||
|
||||
/* How much space to reserve for the title when printing heap usage results.
|
||||
@@ -434,7 +446,8 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
mbedtls_des3_context des3;
|
||||
mbedtls_des3_init( &des3 );
|
||||
mbedtls_des3_set3key_enc( &des3, tmp );
|
||||
if( mbedtls_des3_set3key_enc( &des3, tmp ) != 0 )
|
||||
mbedtls_exit( 1 );
|
||||
TIME_AND_TSC( "3DES",
|
||||
mbedtls_des3_crypt_cbc( &des3, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
|
||||
mbedtls_des3_free( &des3 );
|
||||
@@ -444,7 +457,8 @@ int main( int argc, char *argv[] )
|
||||
{
|
||||
mbedtls_des_context des;
|
||||
mbedtls_des_init( &des );
|
||||
mbedtls_des_setkey_enc( &des, tmp );
|
||||
if( mbedtls_des_setkey_enc( &des, tmp ) != 0 )
|
||||
mbedtls_exit( 1 );
|
||||
TIME_AND_TSC( "DES",
|
||||
mbedtls_des_crypt_cbc( &des, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
|
||||
mbedtls_des_free( &des );
|
||||
@@ -482,7 +496,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
memset( tmp, 0, sizeof( tmp ) );
|
||||
mbedtls_aes_setkey_enc( &aes, tmp, keysize );
|
||||
CHECK_AND_CONTINUE( mbedtls_aes_setkey_enc( &aes, tmp, keysize ) );
|
||||
|
||||
TIME_AND_TSC( title,
|
||||
mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
|
||||
@@ -503,7 +517,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
memset( buf, 0, sizeof( buf ) );
|
||||
memset( tmp, 0, sizeof( tmp ) );
|
||||
mbedtls_aes_xts_setkey_enc( &ctx, tmp, keysize * 2 );
|
||||
CHECK_AND_CONTINUE( mbedtls_aes_xts_setkey_enc( &ctx, tmp, keysize * 2 ) );
|
||||
|
||||
TIME_AND_TSC( title,
|
||||
mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, BUFSIZE,
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
@@ -240,7 +240,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 );
|
||||
@@ -262,7 +262,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 );
|
||||
@@ -283,7 +283,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,
|
||||
@@ -305,7 +305,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