@@ -312,6 +312,15 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx,
312
312
if ( status != PSA_SUCCESS )
313
313
return ( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
314
314
315
+ /* Indicate that we own the key slot and need to
316
+ * destroy it in mbedtls_cipher_free(). */
317
+ cipher_psa -> slot_state = MBEDTLS_CIPHER_PSA_KEY_OWNED ;
318
+
319
+ /* From that point on, the responsibility for destroying the
320
+ * key slot is on mbedtls_cipher_free(). This includes the case
321
+ * where the policy setup or key import below fail, as
322
+ * mbedtls_cipher_free() needs to be called in any case. */
323
+
315
324
/* Setup policy for the new key slot. */
316
325
psa_key_policy_init ( & key_policy );
317
326
@@ -325,14 +334,6 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx,
325
334
status = psa_set_key_policy ( cipher_psa -> slot , & key_policy );
326
335
if ( status != PSA_SUCCESS )
327
336
return ( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
328
- /* Indicate that we own the key slot and need to
329
- * destroy it in mbedtls_cipher_free(). */
330
- cipher_psa -> slot_state = MBEDTLS_CIPHER_PSA_KEY_OWNED ;
331
-
332
- /* From that point on, the responsibility for destroying the
333
- * key slot is on mbedtls_cipher_free(). This includes the case
334
- * where the policy setup or key import below fail, as
335
- * mbedtls_cipher_free() needs to be called in any case. */
336
337
337
338
/* Populate new key slot. */
338
339
status = psa_import_key ( cipher_psa -> slot ,
0 commit comments