Remove redundant key_set from MAC operation structure

The purpose of key_set was to guard the operation structure from being
used for update/finish before a key was set. Now that the implementation
fully adheres to the PSA API, that function is covered by the `alg`
variable instead. It's set to the algorithm in use when a key is set, and
is zero when the operation is reset/invalid.

Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
Steven Cooreman 2021-04-29 16:24:36 +02:00
parent 6e6451ec01
commit b4b9b2879c
2 changed files with 4 additions and 10 deletions

View File

@ -62,7 +62,6 @@ typedef struct
typedef struct
{
psa_algorithm_t alg;
unsigned int key_set : 1;
unsigned int has_input : 1;
unsigned int is_sign : 1;
uint8_t mac_size;
@ -78,7 +77,7 @@ typedef struct
} ctx;
} mbedtls_psa_mac_operation_t;
#define MBEDTLS_PSA_MAC_OPERATION_INIT {0, 0, 0, 0, 0, {0}}
#define MBEDTLS_PSA_MAC_OPERATION_INIT {0, 0, 0, 0, {0}}
/*
* BEYOND THIS POINT, TEST DRIVER DECLARATIONS ONLY.

View File

@ -246,7 +246,6 @@ static psa_status_t mac_init(
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
operation->alg = PSA_ALG_FULL_LENGTH_MAC( alg );
operation->key_set = 0;
operation->has_input = 0;
operation->is_sign = 0;
@ -307,7 +306,6 @@ static psa_status_t mac_abort( mbedtls_psa_mac_operation_t *operation )
}
operation->alg = 0;
operation->key_set = 0;
operation->has_input = 0;
operation->is_sign = 0;
@ -385,9 +383,7 @@ static psa_status_t mac_setup( mbedtls_psa_mac_operation_t *operation,
}
exit:
if( status == PSA_SUCCESS )
operation->key_set = 1;
else
if( status != PSA_SUCCESS )
mac_abort( operation );
return( status );
@ -444,7 +440,7 @@ static psa_status_t mac_update(
const uint8_t *input,
size_t input_length )
{
if( ! operation->key_set )
if( operation->alg == 0 )
return( PSA_ERROR_BAD_STATE );
operation->has_input = 1;
@ -476,9 +472,8 @@ static psa_status_t mac_finish_internal( mbedtls_psa_mac_operation_t *operation,
uint8_t *mac,
size_t mac_size )
{
if( ! operation->key_set )
if( operation->alg == 0 )
return( PSA_ERROR_BAD_STATE );
if( mac_size < operation->mac_size )
return( PSA_ERROR_BUFFER_TOO_SMALL );