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>
diff --git a/include/psa/crypto_builtin_composites.h b/include/psa/crypto_builtin_composites.h
index 3b0f82a..780a6c5 100644
--- a/include/psa/crypto_builtin_composites.h
+++ b/include/psa/crypto_builtin_composites.h
@@ -62,7 +62,6 @@
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 @@
} 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 d8e2293..7122ecd 100644
--- a/library/psa_crypto_mac.c
+++ b/library/psa_crypto_mac.c
@@ -246,7 +246,6 @@
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 @@
}
operation->alg = 0;
- operation->key_set = 0;
operation->has_input = 0;
operation->is_sign = 0;
@@ -385,9 +383,7 @@
}
exit:
- if( status == PSA_SUCCESS )
- operation->key_set = 1;
- else
+ if( status != PSA_SUCCESS )
mac_abort( operation );
return( status );
@@ -444,7 +440,7 @@
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 @@
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 );