Fix policy validity check on key creation.
Add a non-regression test.
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index f1ddb14..258caad 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -1469,10 +1469,6 @@
return( status );
}
- status = psa_check_key_slot_policy( slot );
- if( status != PSA_SUCCESS )
- return( status );
-
/* Refuse to create overly large keys.
* Note that this doesn't trigger on import if the attributes don't
* explicitly specify a size (so psa_get_key_bits returns 0), so
@@ -1487,6 +1483,10 @@
slot->attr = attributes->core;
+ status = psa_check_key_slot_policy( slot );
+ if( status != PSA_SUCCESS )
+ return( status );
+
#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
/* For a key in a secure element, we need to do three things:
* create the key file in internal storage, create the