In psa_mac_finish, write a safe output even in the BAD_STATE case
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index a2f6897..ca461c2 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -1510,10 +1510,6 @@
{
int ret = 0;
psa_status_t status = PSA_SUCCESS;
- if( ! operation->key_set )
- return( PSA_ERROR_BAD_STATE );
- if( operation->iv_required && ! operation->iv_set )
- return( PSA_ERROR_BAD_STATE );
/* Fill the output buffer with something that isn't a valid mac
* (barring an attack on the mac and deliberately-crafted input),
@@ -1524,6 +1520,11 @@
if( mac_size != 0 )
memset( mac, '!', mac_size );
+ if( ! operation->key_set )
+ return( PSA_ERROR_BAD_STATE );
+ if( operation->iv_required && ! operation->iv_set )
+ return( PSA_ERROR_BAD_STATE );
+
if( mac_size < operation->mac_size )
return( PSA_ERROR_BUFFER_TOO_SMALL );