Change logic to reduce indentation
Signed-off-by: Paul Elliott <paul.elliott@arm.com>
This commit is contained in:
parent
e2c788d480
commit
6108ee7c2d
@ -538,16 +538,16 @@ psa_status_t mbedtls_psa_aead_update_ad( mbedtls_psa_aead_operation_t
|
|||||||
|
|
||||||
/* Save the additional data for later, this will be passed in
|
/* Save the additional data for later, this will be passed in
|
||||||
when we have the body. */
|
when we have the body. */
|
||||||
operation->ad_buffer = ( uint8_t * ) mbedtls_calloc(1, input_length );
|
operation->ad_buffer = ( uint8_t * ) mbedtls_calloc( 1, input_length );
|
||||||
|
|
||||||
if( operation->ad_buffer )
|
if( operation->ad_buffer == NULL )
|
||||||
{
|
{
|
||||||
memcpy( operation->ad_buffer, input, input_length );
|
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||||
operation->ad_length = input_length;
|
|
||||||
status = PSA_SUCCESS;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
return ( PSA_ERROR_INSUFFICIENT_MEMORY );
|
memcpy( operation->ad_buffer, input, input_length );
|
||||||
|
operation->ad_length = input_length;
|
||||||
|
status = PSA_SUCCESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
||||||
@ -637,65 +637,65 @@ psa_status_t mbedtls_psa_aead_update( mbedtls_psa_aead_operation_t *operation,
|
|||||||
operation->tag_buffer =
|
operation->tag_buffer =
|
||||||
( uint8_t * ) mbedtls_calloc( 1, operation->tag_length );
|
( uint8_t * ) mbedtls_calloc( 1, operation->tag_length );
|
||||||
|
|
||||||
if( operation->tag_buffer )
|
if( operation->tag_buffer == NULL)
|
||||||
{
|
{
|
||||||
if( operation->is_encrypt )
|
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||||
{
|
}
|
||||||
/* Perform oneshot CCM encryption with additional data already
|
|
||||||
stored, as CCM does not support multipart yet.*/
|
|
||||||
status = mbedtls_to_psa_error(
|
|
||||||
mbedtls_ccm_encrypt_and_tag( &operation->ctx.ccm,
|
|
||||||
input_length,
|
|
||||||
operation->nonce,
|
|
||||||
operation->nonce_length,
|
|
||||||
operation->ad_buffer,
|
|
||||||
operation->ad_length,
|
|
||||||
input,
|
|
||||||
output,
|
|
||||||
operation->tag_buffer,
|
|
||||||
operation->tag_length ) );
|
|
||||||
|
|
||||||
/* Even if the above operation fails, we no longer need the
|
if( operation->is_encrypt )
|
||||||
additional data.*/
|
{
|
||||||
mbedtls_free( operation->ad_buffer );
|
/* Perform oneshot CCM encryption with additional data already
|
||||||
operation->ad_buffer = NULL;
|
stored, as CCM does not support multipart yet.*/
|
||||||
operation->ad_length = 0;
|
status = mbedtls_to_psa_error(
|
||||||
}
|
mbedtls_ccm_encrypt_and_tag( &operation->ctx.ccm,
|
||||||
else
|
input_length,
|
||||||
{
|
operation->nonce,
|
||||||
/* Need to back up the body data so we can do this again
|
operation->nonce_length,
|
||||||
later.*/
|
operation->ad_buffer,
|
||||||
operation->body_buffer =
|
operation->ad_length,
|
||||||
( uint8_t * ) mbedtls_calloc(1, input_length );
|
input,
|
||||||
|
output,
|
||||||
|
operation->tag_buffer,
|
||||||
|
operation->tag_length ) );
|
||||||
|
|
||||||
if( operation->body_buffer )
|
/* Even if the above operation fails, we no longer need the
|
||||||
{
|
additional data.*/
|
||||||
memcpy( operation->body_buffer, input, input_length );
|
mbedtls_free( operation->ad_buffer );
|
||||||
operation->body_length = input_length;
|
operation->ad_buffer = NULL;
|
||||||
|
operation->ad_length = 0;
|
||||||
/* this will fail, as the tag is clearly false, but will
|
|
||||||
write the decrypted data to the output buffer.*/
|
|
||||||
ret = mbedtls_ccm_auth_decrypt( &operation->ctx.ccm,
|
|
||||||
input_length,
|
|
||||||
operation->nonce,
|
|
||||||
operation->nonce_length,
|
|
||||||
operation->ad_buffer,
|
|
||||||
operation->ad_length,
|
|
||||||
input, output,
|
|
||||||
operation->tag_buffer,
|
|
||||||
operation->tag_length );
|
|
||||||
|
|
||||||
if( ret == MBEDTLS_ERR_CCM_AUTH_FAILED )
|
|
||||||
status = PSA_SUCCESS;
|
|
||||||
else
|
|
||||||
status = mbedtls_to_psa_error( ret );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
status = PSA_ERROR_INSUFFICIENT_MEMORY;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
status = PSA_ERROR_INSUFFICIENT_MEMORY;
|
{
|
||||||
|
/* Need to back up the body data so we can do this again
|
||||||
|
later.*/
|
||||||
|
operation->body_buffer =
|
||||||
|
( uint8_t * ) mbedtls_calloc(1, input_length );
|
||||||
|
|
||||||
|
if( operation->body_buffer == NULL)
|
||||||
|
{
|
||||||
|
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy( operation->body_buffer, input, input_length );
|
||||||
|
operation->body_length = input_length;
|
||||||
|
|
||||||
|
/* this will fail, as the tag is clearly false, but will
|
||||||
|
write the decrypted data to the output buffer.*/
|
||||||
|
ret = mbedtls_ccm_auth_decrypt( &operation->ctx.ccm,
|
||||||
|
input_length,
|
||||||
|
operation->nonce,
|
||||||
|
operation->nonce_length,
|
||||||
|
operation->ad_buffer,
|
||||||
|
operation->ad_length,
|
||||||
|
input, output,
|
||||||
|
operation->tag_buffer,
|
||||||
|
operation->tag_length );
|
||||||
|
|
||||||
|
if( ret == MBEDTLS_ERR_CCM_AUTH_FAILED )
|
||||||
|
status = PSA_SUCCESS;
|
||||||
|
else
|
||||||
|
status = mbedtls_to_psa_error( ret );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
#endif /* MBEDTLS_PSA_BUILTIN_ALG_CCM */
|
||||||
@ -871,27 +871,27 @@ psa_status_t mbedtls_psa_aead_verify( mbedtls_psa_aead_operation_t *operation,
|
|||||||
|
|
||||||
temp_buffer = ( uint8_t * ) mbedtls_calloc(1, temp_buffer_size );
|
temp_buffer = ( uint8_t * ) mbedtls_calloc(1, temp_buffer_size );
|
||||||
|
|
||||||
if( temp_buffer )
|
if( temp_buffer == NULL)
|
||||||
{
|
{
|
||||||
ret = mbedtls_ccm_auth_decrypt( &operation->ctx.ccm,
|
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||||
operation->body_length,
|
|
||||||
operation->nonce,
|
|
||||||
operation->nonce_length,
|
|
||||||
operation->ad_buffer,
|
|
||||||
operation->ad_length,
|
|
||||||
operation->body_buffer,
|
|
||||||
temp_buffer, tag, tag_length );
|
|
||||||
|
|
||||||
if( ret == MBEDTLS_ERR_CCM_AUTH_FAILED )
|
|
||||||
status = PSA_ERROR_INVALID_SIGNATURE;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
status = mbedtls_to_psa_error( ret );
|
|
||||||
do_tag_check = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = mbedtls_ccm_auth_decrypt( &operation->ctx.ccm,
|
||||||
|
operation->body_length,
|
||||||
|
operation->nonce,
|
||||||
|
operation->nonce_length,
|
||||||
|
operation->ad_buffer,
|
||||||
|
operation->ad_length,
|
||||||
|
operation->body_buffer,
|
||||||
|
temp_buffer, tag, tag_length );
|
||||||
|
|
||||||
|
if( ret == MBEDTLS_ERR_CCM_AUTH_FAILED )
|
||||||
|
status = PSA_ERROR_INVALID_SIGNATURE;
|
||||||
else
|
else
|
||||||
status = PSA_ERROR_INSUFFICIENT_MEMORY;
|
{
|
||||||
|
status = mbedtls_to_psa_error( ret );
|
||||||
|
do_tag_check = 0;
|
||||||
|
}
|
||||||
|
|
||||||
/* Even if the above operation fails, we no longer need the data */
|
/* Even if the above operation fails, we no longer need the data */
|
||||||
mbedtls_free(temp_buffer);
|
mbedtls_free(temp_buffer);
|
||||||
|
Loading…
Reference in New Issue
Block a user