mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 19:35:38 +01:00
Code flow/readability improvements after review
* Early return since there's nothing to clean up * Get rid of unnecessary local variable * Check algorithm validity for MAC in the PSA core instead of in the driver Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
parent
5c85ef0a56
commit
6e6451ec01
@ -2318,18 +2318,22 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
|
|||||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
psa_key_slot_t *slot;
|
psa_key_slot_t *slot;
|
||||||
psa_key_usage_t usage =
|
size_t mac_size;
|
||||||
is_sign ? PSA_KEY_USAGE_SIGN_HASH : PSA_KEY_USAGE_VERIFY_HASH;
|
|
||||||
size_t mac_size = 0;
|
|
||||||
|
|
||||||
/* A context must be freshly initialized before it can be set up. */
|
/* A context must be freshly initialized before it can be set up. */
|
||||||
if( operation->id != 0 )
|
if( operation->id != 0 )
|
||||||
return( PSA_ERROR_BAD_STATE );
|
return( PSA_ERROR_BAD_STATE );
|
||||||
|
|
||||||
|
if( ! PSA_ALG_IS_MAC( alg ) )
|
||||||
|
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||||
|
|
||||||
status = psa_get_and_lock_key_slot_with_policy(
|
status = psa_get_and_lock_key_slot_with_policy(
|
||||||
key, &slot, usage, alg );
|
key,
|
||||||
|
&slot,
|
||||||
|
is_sign ? PSA_KEY_USAGE_SIGN_HASH : PSA_KEY_USAGE_VERIFY_HASH,
|
||||||
|
alg );
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
goto exit;
|
return( status );
|
||||||
|
|
||||||
psa_key_attributes_t attributes = {
|
psa_key_attributes_t attributes = {
|
||||||
.core = slot->attr
|
.core = slot->attr
|
||||||
|
@ -243,7 +243,7 @@ static psa_status_t mac_init(
|
|||||||
mbedtls_psa_mac_operation_t *operation,
|
mbedtls_psa_mac_operation_t *operation,
|
||||||
psa_algorithm_t alg )
|
psa_algorithm_t alg )
|
||||||
{
|
{
|
||||||
psa_status_t status = PSA_ERROR_NOT_SUPPORTED;
|
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
operation->alg = PSA_ALG_FULL_LENGTH_MAC( alg );
|
operation->alg = PSA_ALG_FULL_LENGTH_MAC( alg );
|
||||||
operation->key_set = 0;
|
operation->key_set = 0;
|
||||||
@ -268,8 +268,7 @@ static psa_status_t mac_init(
|
|||||||
else
|
else
|
||||||
#endif /* BUILTIN_ALG_HMAC */
|
#endif /* BUILTIN_ALG_HMAC */
|
||||||
{
|
{
|
||||||
if( ! PSA_ALG_IS_MAC( alg ) )
|
status = PSA_ERROR_NOT_SUPPORTED;
|
||||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( status != PSA_SUCCESS )
|
if( status != PSA_SUCCESS )
|
||||||
|
Loading…
Reference in New Issue
Block a user