mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-24 10:35:12 +00:00
abort operation before return + fix error checks
This commit is contained in:
parent
5eb6e9ed60
commit
7cb22b8327
|
@ -1342,7 +1342,7 @@ static psa_status_t psa_cipher_setup( psa_cipher_operation_t *operation,
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
|
#if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING)
|
||||||
if( ( alg & PSA_ALG_CBC_BASE) == PSA_ALG_CBC_BASE )
|
if( ( alg & ~PSA_ALG_BLOCK_CIPHER_PADDING_MASK ) == PSA_ALG_CBC_BASE )
|
||||||
{
|
{
|
||||||
padding_mode = alg & PSA_ALG_BLOCK_CIPHER_PADDING_MASK;
|
padding_mode = alg & PSA_ALG_BLOCK_CIPHER_PADDING_MASK;
|
||||||
|
|
||||||
|
@ -1494,24 +1494,29 @@ psa_status_t psa_cipher_finish( psa_cipher_operation_t *operation,
|
||||||
uint8_t temp_output_buffer[MBEDTLS_MAX_BLOCK_LENGTH];
|
uint8_t temp_output_buffer[MBEDTLS_MAX_BLOCK_LENGTH];
|
||||||
|
|
||||||
if( ! operation->key_set )
|
if( ! operation->key_set )
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
if( operation->iv_required && ! operation->iv_set )
|
|
||||||
return( PSA_ERROR_BAD_STATE );
|
|
||||||
|
|
||||||
if( operation->ctx.cipher.operation == MBEDTLS_ENCRYPT )
|
|
||||||
{
|
{
|
||||||
if( operation->ctx.cipher.unprocessed_len > operation->block_size )
|
psa_cipher_abort( operation );
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
switch( operation->alg & PSA_ALG_BLOCK_CIPHER_PADDING_MASK )
|
}
|
||||||
|
if( operation->iv_required && ! operation->iv_set )
|
||||||
|
{
|
||||||
|
psa_cipher_abort( operation );
|
||||||
|
return( PSA_ERROR_BAD_STATE );
|
||||||
|
}
|
||||||
|
if( ( operation->ctx.cipher.operation == MBEDTLS_ENCRYPT ) && PSA_ALG_IS_BLOCK_CIPHER( operation->alg ) )
|
||||||
|
{
|
||||||
|
if( operation->ctx.cipher.unprocessed_len >= operation->block_size )
|
||||||
{
|
{
|
||||||
case PSA_ALG_BLOCK_CIPHER_PAD_NONE:
|
psa_cipher_abort( operation );
|
||||||
if( operation->ctx.cipher.unprocessed_len != 0 )
|
return( PSA_ERROR_TAMPERING_DETECTED );
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
}
|
||||||
break;
|
if( ( operation->alg & PSA_ALG_BLOCK_CIPHER_PADDING_MASK ) == PSA_ALG_BLOCK_CIPHER_PAD_NONE )
|
||||||
case PSA_ALG_BLOCK_CIPHER_PAD_PKCS7:
|
{
|
||||||
if( *output_length != operation->block_size )
|
if( operation->ctx.cipher.unprocessed_len != 0 )
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
{
|
||||||
break;
|
psa_cipher_abort( operation );
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue