mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-27 04:34:14 +01:00
psa: mac: Re-organize psa_mac_setup() internal function
Re-organize psa_mac_setup() to prepare the move to a dedicated function of the additional checks on the algorithm and the key attributes done by this function. We want to move those checks in a dedicated function to be able to do them without duplicating them in psa_mac_compute(). Signed-off-by: Ronald Cron <ronald.cron@arm.com>
This commit is contained in:
parent
a93e423739
commit
48f875e809
@ -2308,14 +2308,12 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_status_t unlock_status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_slot_t *slot;
|
||||
uint8_t mac_size;
|
||||
|
||||
/* A context must be freshly initialized before it can be set up. */
|
||||
if( operation->id != 0 )
|
||||
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(
|
||||
key,
|
||||
&slot,
|
||||
@ -2324,24 +2322,28 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
|
||||
psa_key_attributes_t attributes = {
|
||||
psa_key_attributes_t key_attributes = {
|
||||
.core = slot->attr
|
||||
};
|
||||
psa_key_attributes_t *attributes = &key_attributes;
|
||||
|
||||
if( ! PSA_ALG_IS_MAC( alg ) )
|
||||
{
|
||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Validate the combination of key type and algorithm */
|
||||
status = psa_mac_key_can_do( alg, psa_get_key_type( &attributes ) );
|
||||
status = psa_mac_key_can_do( alg, psa_get_key_type( attributes ) );
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
|
||||
operation->is_sign = is_sign;
|
||||
|
||||
/* Get the output length for the algorithm and key combination */
|
||||
operation->mac_size = PSA_MAC_LENGTH(
|
||||
psa_get_key_type( &attributes ),
|
||||
psa_get_key_bits( &attributes ),
|
||||
mac_size = PSA_MAC_LENGTH( psa_get_key_type( attributes ),
|
||||
psa_get_key_bits( attributes ),
|
||||
alg );
|
||||
|
||||
if( operation->mac_size < 4 )
|
||||
if( mac_size < 4 )
|
||||
{
|
||||
/* A very short MAC is too short for security since it can be
|
||||
* brute-forced. Ancient protocols with 32-bit MACs do exist,
|
||||
@ -2351,8 +2353,8 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( operation->mac_size > PSA_MAC_LENGTH( psa_get_key_type( &attributes ),
|
||||
psa_get_key_bits( &attributes ),
|
||||
if( mac_size > PSA_MAC_LENGTH( psa_get_key_type( attributes ),
|
||||
psa_get_key_bits( attributes ),
|
||||
PSA_ALG_FULL_LENGTH_MAC( alg ) ) )
|
||||
{
|
||||
/* It's impossible to "truncate" to a larger length than the full length
|
||||
@ -2361,11 +2363,14 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
operation->is_sign = is_sign;
|
||||
operation->mac_size = mac_size;
|
||||
|
||||
/* Dispatch the MAC setup call with validated input */
|
||||
if( is_sign )
|
||||
{
|
||||
status = psa_driver_wrapper_mac_sign_setup( operation,
|
||||
&attributes,
|
||||
&key_attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg );
|
||||
@ -2373,7 +2378,7 @@ static psa_status_t psa_mac_setup( psa_mac_operation_t *operation,
|
||||
else
|
||||
{
|
||||
status = psa_driver_wrapper_mac_verify_setup( operation,
|
||||
&attributes,
|
||||
&key_attributes,
|
||||
slot->key.data,
|
||||
slot->key.bytes,
|
||||
alg );
|
||||
|
Loading…
Reference in New Issue
Block a user