mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-03-24 22:25:11 +00:00
Add missing calls to psa_cipher_abort in cipher functions
This commit is contained in:
parent
40835d4e56
commit
534bd7c33b
|
@ -2478,53 +2478,59 @@ psa_status_t psa_cipher_generate_iv( psa_cipher_operation_t *operation,
|
||||||
size_t iv_size,
|
size_t iv_size,
|
||||||
size_t *iv_length )
|
size_t *iv_length )
|
||||||
{
|
{
|
||||||
int ret = PSA_SUCCESS;
|
psa_status_t status;
|
||||||
|
int ret;
|
||||||
if( operation->iv_set || ! operation->iv_required )
|
if( operation->iv_set || ! operation->iv_required )
|
||||||
return( PSA_ERROR_BAD_STATE );
|
{
|
||||||
|
status = PSA_ERROR_BAD_STATE;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
if( iv_size < operation->iv_size )
|
if( iv_size < operation->iv_size )
|
||||||
{
|
{
|
||||||
ret = PSA_ERROR_BUFFER_TOO_SMALL;
|
status = PSA_ERROR_BUFFER_TOO_SMALL;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
ret = mbedtls_ctr_drbg_random( &global_data.ctr_drbg,
|
ret = mbedtls_ctr_drbg_random( &global_data.ctr_drbg,
|
||||||
iv, operation->iv_size );
|
iv, operation->iv_size );
|
||||||
if( ret != 0 )
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
ret = mbedtls_to_psa_error( ret );
|
status = mbedtls_to_psa_error( ret );
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
*iv_length = operation->iv_size;
|
*iv_length = operation->iv_size;
|
||||||
ret = psa_cipher_set_iv( operation, iv, *iv_length );
|
status = psa_cipher_set_iv( operation, iv, *iv_length );
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
if( ret != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
psa_cipher_abort( operation );
|
psa_cipher_abort( operation );
|
||||||
return( ret );
|
return( status );
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_cipher_set_iv( psa_cipher_operation_t *operation,
|
psa_status_t psa_cipher_set_iv( psa_cipher_operation_t *operation,
|
||||||
const unsigned char *iv,
|
const unsigned char *iv,
|
||||||
size_t iv_length )
|
size_t iv_length )
|
||||||
{
|
{
|
||||||
int ret = PSA_SUCCESS;
|
psa_status_t status;
|
||||||
|
int ret;
|
||||||
if( operation->iv_set || ! operation->iv_required )
|
if( operation->iv_set || ! operation->iv_required )
|
||||||
return( PSA_ERROR_BAD_STATE );
|
{
|
||||||
|
status = PSA_ERROR_BAD_STATE;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
if( iv_length != operation->iv_size )
|
if( iv_length != operation->iv_size )
|
||||||
{
|
{
|
||||||
psa_cipher_abort( operation );
|
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
goto exit;
|
||||||
}
|
}
|
||||||
ret = mbedtls_cipher_set_iv( &operation->ctx.cipher, iv, iv_length );
|
ret = mbedtls_cipher_set_iv( &operation->ctx.cipher, iv, iv_length );
|
||||||
if( ret != 0 )
|
status = mbedtls_to_psa_error( ret );
|
||||||
{
|
exit:
|
||||||
|
if( status == PSA_SUCCESS )
|
||||||
|
operation->iv_set = 1;
|
||||||
|
else
|
||||||
psa_cipher_abort( operation );
|
psa_cipher_abort( operation );
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( status );
|
||||||
}
|
|
||||||
|
|
||||||
operation->iv_set = 1;
|
|
||||||
|
|
||||||
return( PSA_SUCCESS );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_cipher_update( psa_cipher_operation_t *operation,
|
psa_status_t psa_cipher_update( psa_cipher_operation_t *operation,
|
||||||
|
@ -2534,7 +2540,8 @@ psa_status_t psa_cipher_update( psa_cipher_operation_t *operation,
|
||||||
size_t output_size,
|
size_t output_size,
|
||||||
size_t *output_length )
|
size_t *output_length )
|
||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_CIPHER_FEATURE_UNAVAILABLE;
|
psa_status_t status;
|
||||||
|
int ret;
|
||||||
size_t expected_output_size;
|
size_t expected_output_size;
|
||||||
if( PSA_ALG_IS_BLOCK_CIPHER( operation->alg ) )
|
if( PSA_ALG_IS_BLOCK_CIPHER( operation->alg ) )
|
||||||
{
|
{
|
||||||
|
@ -2550,18 +2557,20 @@ psa_status_t psa_cipher_update( psa_cipher_operation_t *operation,
|
||||||
{
|
{
|
||||||
expected_output_size = input_length;
|
expected_output_size = input_length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( output_size < expected_output_size )
|
if( output_size < expected_output_size )
|
||||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
{
|
||||||
|
status = PSA_ERROR_BUFFER_TOO_SMALL;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
ret = mbedtls_cipher_update( &operation->ctx.cipher, input,
|
ret = mbedtls_cipher_update( &operation->ctx.cipher, input,
|
||||||
input_length, output, output_length );
|
input_length, output, output_length );
|
||||||
if( ret != 0 )
|
status = mbedtls_to_psa_error( ret );
|
||||||
{
|
exit:
|
||||||
|
if( status != PSA_SUCCESS )
|
||||||
psa_cipher_abort( operation );
|
psa_cipher_abort( operation );
|
||||||
return( mbedtls_to_psa_error( ret ) );
|
return( status );
|
||||||
}
|
|
||||||
|
|
||||||
return( PSA_SUCCESS );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
psa_status_t psa_cipher_finish( psa_cipher_operation_t *operation,
|
psa_status_t psa_cipher_finish( psa_cipher_operation_t *operation,
|
||||||
|
|
Loading…
Reference in a new issue