From b4b9b2879c565a686d797514b0e853d161c6de92 Mon Sep 17 00:00:00 2001 From: Steven Cooreman Date: Thu, 29 Apr 2021 16:24:36 +0200 Subject: [PATCH] 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 --- include/psa/crypto_builtin_composites.h | 3 +-- library/psa_crypto_mac.c | 11 +++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/include/psa/crypto_builtin_composites.h b/include/psa/crypto_builtin_composites.h index 3b0f82ad2..780a6c54e 100644 --- a/include/psa/crypto_builtin_composites.h +++ b/include/psa/crypto_builtin_composites.h @@ -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. diff --git a/library/psa_crypto_mac.c b/library/psa_crypto_mac.c index d8e229325..7122ecdd3 100644 --- a/library/psa_crypto_mac.c +++ b/library/psa_crypto_mac.c @@ -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 );