mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-22 10:45:36 +01:00
Add parameter validation for mbedtls_aes_crypt_ecb()
This commit is contained in:
parent
68e3dff3f1
commit
1aca260571
@ -246,10 +246,13 @@ int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
|
||||
* call to this API with the same context.
|
||||
*
|
||||
* \param ctx The AES context to use for encryption or decryption.
|
||||
* It must be initialized and bound to a key.
|
||||
* \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
|
||||
* #MBEDTLS_AES_DECRYPT.
|
||||
* \param input The 16-Byte buffer holding the input data.
|
||||
* \param output The 16-Byte buffer holding the output data.
|
||||
* \param input The buffer holding the input data.
|
||||
* It must be readable and at least 16 Bytes long.
|
||||
* \param output The buffer where the output data will be written.
|
||||
* It must be writeable and at least 16 Bytes long.
|
||||
|
||||
* \return \c 0 on success.
|
||||
*/
|
||||
|
@ -1006,6 +1006,12 @@ int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
|
||||
const unsigned char input[16],
|
||||
unsigned char output[16] )
|
||||
{
|
||||
AES_VALIDATE_RET( ctx != NULL );
|
||||
AES_VALIDATE_RET( input != NULL );
|
||||
AES_VALIDATE_RET( output != NULL );
|
||||
AES_VALIDATE_RET( mode == MBEDTLS_AES_ENCRYPT ||
|
||||
mode == MBEDTLS_AES_DECRYPT );
|
||||
|
||||
#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
|
||||
if( mbedtls_aesni_has_support( MBEDTLS_AESNI_AES ) )
|
||||
return( mbedtls_aesni_crypt_ecb( ctx, mode, input, output ) );
|
||||
|
@ -379,6 +379,8 @@ void aes_invalid_param( )
|
||||
mbedtls_aes_xts_context xts_ctx;
|
||||
#endif
|
||||
const unsigned char key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 };
|
||||
const unsigned char in[16] = { 0 };
|
||||
unsigned char out[16];
|
||||
|
||||
TEST_INVALID_PARAM( mbedtls_aes_init( NULL ) );
|
||||
#if defined(MBEDTLS_CIPHER_MODE_XTS)
|
||||
@ -406,6 +408,20 @@ void aes_invalid_param( )
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
|
||||
mbedtls_aes_xts_setkey_dec( &xts_ctx, NULL, 128 ) );
|
||||
#endif
|
||||
|
||||
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
|
||||
mbedtls_aes_crypt_ecb( NULL,
|
||||
MBEDTLS_AES_ENCRYPT, in, out ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
|
||||
mbedtls_aes_crypt_ecb( &aes_ctx,
|
||||
42, in, out ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
|
||||
mbedtls_aes_crypt_ecb( &aes_ctx,
|
||||
MBEDTLS_AES_ENCRYPT, NULL, out ) );
|
||||
TEST_INVALID_PARAM_RET( MBEDTLS_ERR_AES_BAD_INPUT_DATA,
|
||||
mbedtls_aes_crypt_ecb( &aes_ctx,
|
||||
MBEDTLS_AES_ENCRYPT, in, NULL ) );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user