Change logic to reduce indentation
@@ -540,15 +540,15 @@ psa_status_t mbedtls_psa_aead_update_ad( mbedtls_psa_aead_operation_t
when we have the body. */
operation->ad_buffer = ( uint8_t * ) mbedtls_calloc( 1, input_length );
- if( operation->ad_buffer )
+ if( operation->ad_buffer == NULL )
{
+ return( PSA_ERROR_INSUFFICIENT_MEMORY );
+ }
+
memcpy( operation->ad_buffer, input, input_length );
operation->ad_length = input_length;
status = PSA_SUCCESS;
}
- else
- return ( PSA_ERROR_INSUFFICIENT_MEMORY );
- }
else
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
#if defined(MBEDTLS_PSA_BUILTIN_ALG_CHACHA20_POLY1305)
@@ -637,8 +637,11 @@ psa_status_t mbedtls_psa_aead_update( mbedtls_psa_aead_operation_t *operation,
operation->tag_buffer =
( uint8_t * ) mbedtls_calloc( 1, operation->tag_length );
- if( operation->tag_buffer )
+ if( operation->tag_buffer == NULL)
{
+ return( PSA_ERROR_INSUFFICIENT_MEMORY );
+ }
+
if( operation->is_encrypt )
{
/* Perform oneshot CCM encryption with additional data already
@@ -668,8 +671,11 @@ psa_status_t mbedtls_psa_aead_update( mbedtls_psa_aead_operation_t *operation,
operation->body_buffer =
( uint8_t * ) mbedtls_calloc(1, input_length );
- if( operation->body_buffer )
+ if( operation->body_buffer == NULL)
{
+ return( PSA_ERROR_INSUFFICIENT_MEMORY );
+ }
+
memcpy( operation->body_buffer, input, input_length );
operation->body_length = input_length;
@@ -690,12 +696,6 @@ psa_status_t mbedtls_psa_aead_update( mbedtls_psa_aead_operation_t *operation,
else
status = mbedtls_to_psa_error( ret );
}
- else
- status = PSA_ERROR_INSUFFICIENT_MEMORY;
- }
- }
- else
- status = PSA_ERROR_INSUFFICIENT_MEMORY;
}
else
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
@@ -871,8 +871,11 @@ psa_status_t mbedtls_psa_aead_verify( mbedtls_psa_aead_operation_t *operation,
temp_buffer = ( uint8_t * ) mbedtls_calloc(1, temp_buffer_size );
- if( temp_buffer )
+ if( temp_buffer == NULL)
{
+ return( PSA_ERROR_INSUFFICIENT_MEMORY );
+ }
+
ret = mbedtls_ccm_auth_decrypt( &operation->ctx.ccm,
operation->body_length,
operation->nonce,
@@ -889,9 +892,6 @@ psa_status_t mbedtls_psa_aead_verify( mbedtls_psa_aead_operation_t *operation,
status = mbedtls_to_psa_error( ret );
do_tag_check = 0;
}
- }
- else
- status = PSA_ERROR_INSUFFICIENT_MEMORY;
/* Even if the above operation fails, we no longer need the data */
mbedtls_free(temp_buffer);
