Rename functions that inject key material to an allocated handle

This commit starts a migration to a new interface for key creation.
Today, the application allocates a handle, then fills its metadata,
and finally injects key material. The new interface fills metadata
into a temporary structure, and a handle is allocated at the same time
it gets filled with both metadata and key material.

This commit was obtained by moving the declaration of the old-style
functions to crypto_extra.h and renaming them with the to_handle
suffix, adding declarations for the new-style functions in crypto.h
under their new name, and running

    perl -i -pe 's/\bpsa_(import|copy|generator_import|generate)_key\b/$&_to_handle/g' library/*.c tests/suites/*.function programs/psa/*.c
    perl -i -pe 's/\bpsa_get_key_lifetime\b/$&_from_handle/g' library/*.c tests/suites/*.function programs/psa/*.c

Many functions that are specific to the old interface, and which will
not remain under the same name with the new interface, are still in
crypto.h for now.

All functional tests should still pass. The documentation may have
some broken links.
diff --git a/include/psa/crypto.h b/include/psa/crypto.h
index 6a7bce8..564dd87 100644
--- a/include/psa/crypto.h
+++ b/include/psa/crypto.h
@@ -93,6 +93,24 @@
 
 /**@}*/
 
+/** \defgroup attributes Key attributes
+ * @{
+ */
+
+/** The type of a structure containing key attributes.
+ *
+ * This is an opaque structure that can represent the metadata of a key
+ * object, including the key type and size, domain parameters, usage policies,
+ * location in storage, and any other similar information.
+ *
+ * The actual key material is not considered an attribute of a key.
+ * Key attributes do not contain information that is generally considered
+ * highly confidential.
+ */
+typedef struct psa_key_attributes_s psa_key_attributes_t;
+
+/**@}*/
+
 /** \defgroup policy Key policies
  * @{
  */
@@ -231,26 +249,6 @@
  * @{
  */
 
-/** \brief Retrieve the lifetime of an open key.
- *
- * \param handle        Handle to query.
- * \param[out] lifetime On success, the lifetime value.
- *
- * \retval #PSA_SUCCESS
- *         Success.
- * \retval #PSA_ERROR_INVALID_HANDLE
- * \retval #PSA_ERROR_COMMUNICATION_FAILURE
- * \retval #PSA_ERROR_HARDWARE_FAILURE
- * \retval #PSA_ERROR_TAMPERING_DETECTED
- * \retval #PSA_ERROR_BAD_STATE
- *         The library has not been previously initialized by psa_crypto_init().
- *         It is implementation-dependent whether a failure to initialize
- *         results in this error code.
- */
-psa_status_t psa_get_key_lifetime(psa_key_handle_t handle,
-                                  psa_key_lifetime_t *lifetime);
-
-
 /** Allocate a key slot for a transient key, i.e. a key which is only stored
  * in volatile memory.
  *
@@ -302,43 +300,6 @@
                           psa_key_id_t id,
                           psa_key_handle_t *handle);
 
-/** Create a new persistent key slot.
- *
- * Create a new persistent key slot and return a handle to it. The handle
- * remains valid until the application calls psa_close_key() or terminates.
- * The application can open the key again with psa_open_key() until it
- * removes the key by calling psa_destroy_key().
- *
- * \param lifetime      The lifetime of the key. This designates a storage
- *                      area where the key material is stored. This must not
- *                      be #PSA_KEY_LIFETIME_VOLATILE.
- * \param id            The persistent identifier of the key.
- * \param[out] handle   On success, a handle to the newly created key slot.
- *                      When key material is later created in this key slot,
- *                      it will be saved to the specified persistent location.
- *
- * \retval #PSA_SUCCESS
- *         Success. The application can now use the value of `*handle`
- *         to access the newly allocated key slot.
- * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
- * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
- * \retval #PSA_ERROR_ALREADY_EXISTS
- *         There is already a key with the identifier \p id in the storage
- *         area designated by \p lifetime.
- * \retval #PSA_ERROR_INVALID_ARGUMENT
- *         \p lifetime is invalid, for example #PSA_KEY_LIFETIME_VOLATILE.
- * \retval #PSA_ERROR_INVALID_ARGUMENT
- *         \p id is invalid for the specified lifetime.
- * \retval #PSA_ERROR_NOT_SUPPORTED
- *         \p lifetime is not supported.
- * \retval #PSA_ERROR_NOT_PERMITTED
- *         \p lifetime is valid, but the application does not have the
- *         permission to create a key there.
- */
-psa_status_t psa_create_key(psa_key_lifetime_t lifetime,
-                            psa_key_id_t id,
-                            psa_key_handle_t *handle);
-
 /** Close a key handle.
  *
  * If the handle designates a volatile key, destroy the key material and
@@ -417,7 +378,8 @@
  *         It is implementation-dependent whether a failure to initialize
  *         results in this error code.
  */
-psa_status_t psa_import_key(psa_key_handle_t handle,
+psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
+                            psa_key_handle_t *handle,
                             psa_key_type_t type,
                             const uint8_t *data,
                             size_t data_length);
@@ -809,8 +771,8 @@
  * \retval #PSA_ERROR_TAMPERING_DETECTED
  */
 psa_status_t psa_copy_key(psa_key_handle_t source_handle,
-                          psa_key_handle_t target_handle,
-                          const psa_key_policy_t *constraint);
+                          const psa_key_attributes_t *attributes,
+                          psa_key_handle_t *target_handle);
 
 /**@}*/
 
@@ -3006,7 +2968,8 @@
  *         It is implementation-dependent whether a failure to initialize
  *         results in this error code.
  */
-psa_status_t psa_generator_import_key(psa_key_handle_t handle,
+psa_status_t psa_generator_import_key(const psa_key_attributes_t *attributes,
+                                      psa_key_handle_t *handle,
                                       psa_key_type_t type,
                                       size_t bits,
                                       psa_crypto_generator_t *generator);
@@ -3398,7 +3361,8 @@
  *         It is implementation-dependent whether a failure to initialize
  *         results in this error code.
  */
-psa_status_t psa_generate_key(psa_key_handle_t handle,
+psa_status_t psa_generate_key(const psa_key_attributes_t *attributes,
+                              psa_key_handle_t *handle,
                               psa_key_type_t type,
                               size_t bits,
                               const void *extra,
diff --git a/include/psa/crypto_extra.h b/include/psa/crypto_extra.h
index 093355d..efd1b76 100644
--- a/include/psa/crypto_extra.h
+++ b/include/psa/crypto_extra.h
@@ -202,6 +202,93 @@
 /* FIXME Deprecated. Remove this as soon as all the tests are updated. */
 #define PSA_ALG_SELECT_RAW                      ((psa_algorithm_t)0x31000001)
 
+/** \defgroup to_handle Key creation to allocated handle
+ * @{
+ *
+ * The functions in this section are legacy interfaces where the properties
+ * of a key object are set after allocating a handle, in constrast with the
+ * preferred interface where key objects are created atomically from
+ * a structure that represents the properties.
+ */
+
+/** Create a new persistent key slot.
+ *
+ * Create a new persistent key slot and return a handle to it. The handle
+ * remains valid until the application calls psa_close_key() or terminates.
+ * The application can open the key again with psa_open_key() until it
+ * removes the key by calling psa_destroy_key().
+ *
+ * \param lifetime      The lifetime of the key. This designates a storage
+ *                      area where the key material is stored. This must not
+ *                      be #PSA_KEY_LIFETIME_VOLATILE.
+ * \param id            The persistent identifier of the key.
+ * \param[out] handle   On success, a handle to the newly created key slot.
+ *                      When key material is later created in this key slot,
+ *                      it will be saved to the specified persistent location.
+ *
+ * \retval #PSA_SUCCESS
+ *         Success. The application can now use the value of `*handle`
+ *         to access the newly allocated key slot.
+ * \retval #PSA_ERROR_INSUFFICIENT_MEMORY
+ * \retval #PSA_ERROR_INSUFFICIENT_STORAGE
+ * \retval #PSA_ERROR_ALREADY_EXISTS
+ *         There is already a key with the identifier \p id in the storage
+ *         area designated by \p lifetime.
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
+ *         \p lifetime is invalid, for example #PSA_KEY_LIFETIME_VOLATILE.
+ * \retval #PSA_ERROR_INVALID_ARGUMENT
+ *         \p id is invalid for the specified lifetime.
+ * \retval #PSA_ERROR_NOT_SUPPORTED
+ *         \p lifetime is not supported.
+ * \retval #PSA_ERROR_NOT_PERMITTED
+ *         \p lifetime is valid, but the application does not have the
+ *         permission to create a key there.
+ */
+psa_status_t psa_create_key(psa_key_lifetime_t lifetime,
+                            psa_key_id_t id,
+                            psa_key_handle_t *handle);
+
+/** \brief Retrieve the lifetime of an open key.
+ *
+ * \param handle        Handle to query.
+ * \param[out] lifetime On success, the lifetime value.
+ *
+ * \retval #PSA_SUCCESS
+ *         Success.
+ * \retval #PSA_ERROR_INVALID_HANDLE
+ * \retval #PSA_ERROR_COMMUNICATION_FAILURE
+ * \retval #PSA_ERROR_HARDWARE_FAILURE
+ * \retval #PSA_ERROR_TAMPERING_DETECTED
+ * \retval #PSA_ERROR_BAD_STATE
+ *         The library has not been previously initialized by psa_crypto_init().
+ *         It is implementation-dependent whether a failure to initialize
+ *         results in this error code.
+ */
+psa_status_t psa_get_key_lifetime_from_handle(psa_key_handle_t handle,
+                                  psa_key_lifetime_t *lifetime);
+
+psa_status_t psa_import_key_to_handle(psa_key_handle_t handle,
+                            psa_key_type_t type,
+                            const uint8_t *data,
+                            size_t data_length);
+
+psa_status_t psa_copy_key_to_handle(psa_key_handle_t source_handle,
+                          psa_key_handle_t target_handle,
+                          const psa_key_policy_t *constraint);
+
+psa_status_t psa_generator_import_key_to_handle(psa_key_handle_t handle,
+                                      psa_key_type_t type,
+                                      size_t bits,
+                                      psa_crypto_generator_t *generator);
+
+psa_status_t psa_generate_key_to_handle(psa_key_handle_t handle,
+                              psa_key_type_t type,
+                              size_t bits,
+                              const void *extra,
+                              size_t extra_size);
+
+/**@}*/
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/library/cipher.c b/library/cipher.c
index e854cf6..11f6f8e 100644
--- a/library/cipher.c
+++ b/library/cipher.c
@@ -338,7 +338,7 @@
             return( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
 
         /* Populate new key slot. */
-        status = psa_import_key( cipher_psa->slot,
+        status = psa_import_key_to_handle( cipher_psa->slot,
                                  key_type, key, key_bytelen );
         if( status != PSA_SUCCESS )
             return( MBEDTLS_ERR_CIPHER_HW_ACCEL_FAILED );
diff --git a/library/pk.c b/library/pk.c
index a1e278e..6bbfdd1 100644
--- a/library/pk.c
+++ b/library/pk.c
@@ -629,7 +629,7 @@
         return( MBEDTLS_ERR_PK_HW_ACCEL_FAILED );
 
     /* import private key in slot */
-    if( PSA_SUCCESS != psa_import_key( key, key_type, d, d_len ) )
+    if( PSA_SUCCESS != psa_import_key_to_handle( key, key_type, d, d_len ) )
         return( MBEDTLS_ERR_PK_HW_ACCEL_FAILED );
 
     /* remember slot number to be destroyed later by caller */
diff --git a/library/pk_wrap.c b/library/pk_wrap.c
index c7f879a..0c74825 100644
--- a/library/pk_wrap.c
+++ b/library/pk_wrap.c
@@ -589,7 +589,7 @@
         goto cleanup;
     }
 
-    if( psa_import_key( key_slot, psa_type, buf + sizeof( buf ) - key_len, key_len )
+    if( psa_import_key_to_handle( key_slot, psa_type, buf + sizeof( buf ) - key_len, key_len )
          != PSA_SUCCESS )
     {
         ret = MBEDTLS_ERR_PK_BAD_INPUT_DATA;
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 3ecab01..2fab91c 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -903,7 +903,7 @@
     return( status );
 }
 
-psa_status_t psa_import_key( psa_key_handle_t handle,
+psa_status_t psa_import_key_to_handle( psa_key_handle_t handle,
                              psa_key_type_t type,
                              const uint8_t *data,
                              size_t data_length )
@@ -1228,7 +1228,7 @@
     status = psa_internal_export_key( source, buffer, buffer_size, &length, 0 );
     if( status != PSA_SUCCESS )
         goto exit;
-    status = psa_import_key( target, source->type, buffer, length );
+    status = psa_import_key_to_handle( target, source->type, buffer, length );
 
 exit:
     if( buffer_size != 0 )
@@ -1237,7 +1237,7 @@
     return( status );
 }
 
-psa_status_t psa_copy_key(psa_key_handle_t source_handle,
+psa_status_t psa_copy_key_to_handle(psa_key_handle_t source_handle,
                           psa_key_handle_t target_handle,
                           const psa_key_policy_t *constraint)
 {
@@ -3277,7 +3277,7 @@
 /* Key Lifetime */
 /****************************************************************/
 
-psa_status_t psa_get_key_lifetime( psa_key_handle_t handle,
+psa_status_t psa_get_key_lifetime_from_handle( psa_key_handle_t handle,
                                    psa_key_lifetime_t *lifetime )
 {
     psa_key_slot_t *slot;
@@ -3996,7 +3996,7 @@
 }
 #endif /* MBEDTLS_DES_C */
 
-psa_status_t psa_generator_import_key( psa_key_handle_t handle,
+psa_status_t psa_generator_import_key_to_handle( psa_key_handle_t handle,
                                        psa_key_type_t type,
                                        size_t bits,
                                        psa_crypto_generator_t *generator )
@@ -4020,7 +4020,7 @@
     if( type == PSA_KEY_TYPE_DES )
         psa_des_set_key_parity( data, bytes );
 #endif /* MBEDTLS_DES_C */
-    status = psa_import_key( handle, type, data, bytes );
+    status = psa_import_key_to_handle( handle, type, data, bytes );
 
 exit:
     mbedtls_free( data );
@@ -4749,7 +4749,7 @@
 }
 #endif /* MBEDTLS_PSA_INJECT_ENTROPY */
 
-psa_status_t psa_generate_key( psa_key_handle_t handle,
+psa_status_t psa_generate_key_to_handle( psa_key_handle_t handle,
                                psa_key_type_t type,
                                size_t bits,
                                const void *extra,
diff --git a/library/ssl_cli.c b/library/ssl_cli.c
index 4e5b3a6..65bc64c 100644
--- a/library/ssl_cli.c
+++ b/library/ssl_cli.c
@@ -3148,7 +3148,7 @@
             return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
 
         /* Generate ECDH private key. */
-        status = psa_generate_key( handshake->ecdh_psa_privkey,
+        status = psa_generate_key_to_handle( handshake->ecdh_psa_privkey,
                           PSA_KEY_TYPE_ECC_KEYPAIR( handshake->ecdh_psa_curve ),
                           MBEDTLS_PSA_ECC_KEY_BITS_OF_CURVE( handshake->ecdh_psa_curve ),
                           NULL, 0 );
diff --git a/library/ssl_tls.c b/library/ssl_tls.c
index 660d548..2681442 100644
--- a/library/ssl_tls.c
+++ b/library/ssl_tls.c
@@ -544,7 +544,7 @@
     if( status != PSA_SUCCESS )
         return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
 
-    status = psa_import_key( master_slot, PSA_KEY_TYPE_DERIVE, secret, slen );
+    status = psa_import_key_to_handle( master_slot, PSA_KEY_TYPE_DERIVE, secret, slen );
     if( status != PSA_SUCCESS )
         return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
 
diff --git a/programs/psa/crypto_examples.c b/programs/psa/crypto_examples.c
index 2f7c445..90cc000 100644
--- a/programs/psa/crypto_examples.c
+++ b/programs/psa/crypto_examples.c
@@ -179,7 +179,7 @@
                              alg );
     ASSERT_STATUS( status, PSA_SUCCESS );
 
-    status = psa_generate_key( key_handle, PSA_KEY_TYPE_AES, key_bits,
+    status = psa_generate_key_to_handle( key_handle, PSA_KEY_TYPE_AES, key_bits,
                                NULL, 0 );
     ASSERT_STATUS( status, PSA_SUCCESS );
 
@@ -229,7 +229,7 @@
                              alg );
     ASSERT_STATUS( status, PSA_SUCCESS );
 
-    status = psa_generate_key( key_handle, PSA_KEY_TYPE_AES, key_bits,
+    status = psa_generate_key_to_handle( key_handle, PSA_KEY_TYPE_AES, key_bits,
                                NULL, 0 );
     ASSERT_STATUS( status, PSA_SUCCESS );
 
@@ -277,7 +277,7 @@
                              alg );
     ASSERT_STATUS( status, PSA_SUCCESS );
 
-    status = psa_generate_key( key_handle, PSA_KEY_TYPE_AES, key_bits,
+    status = psa_generate_key_to_handle( key_handle, PSA_KEY_TYPE_AES, key_bits,
                                NULL, 0 );
     ASSERT_STATUS( status, PSA_SUCCESS );
 
diff --git a/programs/psa/key_ladder_demo.c b/programs/psa/key_ladder_demo.c
index 23c2347..1c3d921 100644
--- a/programs/psa/key_ladder_demo.c
+++ b/programs/psa/key_ladder_demo.c
@@ -208,7 +208,7 @@
                               KDF_ALG );
     PSA_CHECK( psa_set_key_policy( key_handle, &policy ) );
 
-    PSA_CHECK( psa_generate_key( key_handle,
+    PSA_CHECK( psa_generate_key_to_handle( key_handle,
                                  PSA_KEY_TYPE_DERIVE,
                                  PSA_BYTES_TO_BITS( KEY_SIZE_BYTES ),
                                  NULL, 0 ) );
@@ -255,7 +255,7 @@
     PSA_CHECK( psa_allocate_key( master_key_handle ) );
     psa_key_policy_set_usage( &policy, usage, alg );
     PSA_CHECK( psa_set_key_policy( *master_key_handle, &policy ) );
-    PSA_CHECK( psa_import_key( *master_key_handle,
+    PSA_CHECK( psa_import_key_to_handle( *master_key_handle,
                                PSA_KEY_TYPE_DERIVE,
                                key_data, key_size ) );
 exit:
@@ -309,7 +309,7 @@
         PSA_CHECK( psa_set_key_policy( *key_handle, &policy ) );
         /* Use the generator obtained from the parent key to create
          * the next intermediate key. */
-        PSA_CHECK( psa_generator_import_key(
+        PSA_CHECK( psa_generator_import_key_to_handle(
                        *key_handle,
                        PSA_KEY_TYPE_DERIVE,
                        PSA_BYTES_TO_BITS( KEY_SIZE_BYTES ),
@@ -348,7 +348,7 @@
                    WRAPPING_KEY_SALT, WRAPPING_KEY_SALT_LENGTH,
                    NULL, 0,
                    PSA_BITS_TO_BYTES( WRAPPING_KEY_BITS ) ) );
-    PSA_CHECK( psa_generator_import_key(
+    PSA_CHECK( psa_generator_import_key_to_handle(
                    *wrapping_key_handle,
                    PSA_KEY_TYPE_AES,
                    WRAPPING_KEY_BITS,
diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function
index d85d9ed..7415b63 100644
--- a/tests/suites/test_suite_pk.function
+++ b/tests/suites/test_suite_pk.function
@@ -97,7 +97,7 @@
         return( PK_PSA_INVALID_SLOT );
 
     /* generate key */
-    if( PSA_SUCCESS != psa_generate_key( key, type, bits, NULL, 0 ) )
+    if( PSA_SUCCESS != psa_generate_key_to_handle( key, type, bits, NULL, 0 ) )
         return( PK_PSA_INVALID_SLOT );
 
     return( key );
diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function
index e017364..7972597 100644
--- a/tests/suites/test_suite_psa_crypto.function
+++ b/tests/suites/test_suite_psa_crypto.function
@@ -216,7 +216,7 @@
     PSA_ASSERT( psa_allocate_key( &handle ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
-    PSA_ASSERT( psa_import_key( handle, key_type, key_bytes, key_length ) );
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type, key_bytes, key_length ) );
 
     *status = psa_mac_sign_setup( operation, handle, alg );
     /* Whether setup succeeded or failed, abort must succeed. */
@@ -250,7 +250,7 @@
     PSA_ASSERT( psa_allocate_key( &handle ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
-    PSA_ASSERT( psa_import_key( handle, key_type, key_bytes, key_length ) );
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type, key_bytes, key_length ) );
 
     *status = psa_cipher_encrypt_setup( operation, handle, alg );
     /* Whether setup succeeded or failed, abort must succeed. */
@@ -1118,7 +1118,7 @@
     PSA_ASSERT( psa_crypto_init( ) );
 
     PSA_ASSERT( psa_allocate_key( &handle ) );
-    status = psa_import_key( handle, type, data->x, data->len );
+    status = psa_import_key_to_handle( handle, type, data->x, data->len );
     TEST_EQUAL( status, expected_status );
     if( status == PSA_SUCCESS )
         PSA_ASSERT( psa_destroy_key( handle ) );
@@ -1151,9 +1151,9 @@
     psa_key_policy_set_usage( &policy, usage, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    status = psa_import_key( handle, type1, data1->x, data1->len );
+    status = psa_import_key_to_handle( handle, type1, data1->x, data1->len );
     TEST_EQUAL( status, expected_import1_status );
-    status = psa_import_key( handle, type2, data2->x, data2->len );
+    status = psa_import_key_to_handle( handle, type2, data2->x, data2->len );
     TEST_EQUAL( status, expected_import2_status );
 
     if( expected_import1_status == PSA_SUCCESS ||
@@ -1193,7 +1193,7 @@
 
     /* Try importing the key */
     PSA_ASSERT( psa_allocate_key( &handle ) );
-    status = psa_import_key( handle, type, p, length );
+    status = psa_import_key_to_handle( handle, type, p, length );
     TEST_EQUAL( status, expected_status );
     if( status == PSA_SUCCESS )
         PSA_ASSERT( psa_destroy_key( handle ) );
@@ -1242,7 +1242,7 @@
                 PSA_ERROR_DOES_NOT_EXIST );
 
     /* Import the key */
-    PSA_ASSERT( psa_import_key( handle, type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, type,
                                 data->x, data->len ) );
 
     /* Test the key information */
@@ -1283,7 +1283,7 @@
         PSA_ASSERT( psa_allocate_key( &handle2 ) );
         PSA_ASSERT( psa_set_key_policy( handle2, &policy ) );
 
-        PSA_ASSERT( psa_import_key( handle2, type,
+        PSA_ASSERT( psa_import_key_to_handle( handle2, type,
                                     exported,
                                     exported_length ) );
         PSA_ASSERT( psa_export_key( handle2,
@@ -1321,11 +1321,11 @@
     PSA_ASSERT( psa_allocate_key( &handle ) );
 
     /* Import the key */
-    PSA_ASSERT( psa_import_key( handle, type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, type,
                                 data, sizeof( data ) ) );
 
     /* Import the key again */
-    status = psa_import_key( handle, type, data, sizeof( data ) );
+    status = psa_import_key_to_handle( handle, type, data, sizeof( data ) );
     TEST_EQUAL( status, PSA_ERROR_ALREADY_EXISTS );
 
 exit:
@@ -1424,7 +1424,7 @@
     PSA_ASSERT( psa_allocate_key( &handle ) );
 
     /* Import the key - expect failure */
-    status = psa_import_key( handle, type,
+    status = psa_import_key_to_handle( handle, type,
                              data->x, data->len );
     TEST_EQUAL( status, expected_import_status );
 
@@ -1455,7 +1455,7 @@
     PSA_ASSERT( psa_allocate_key( &handle ) );
 
     /* Import the key - expect failure */
-    status = psa_import_key( handle, type,
+    status = psa_import_key_to_handle( handle, type,
                              data->x, data->len );
     TEST_EQUAL( status, expected_import_status );
 
@@ -1489,7 +1489,7 @@
     ASSERT_ALLOC( exported, export_size );
 
     /* Import the key */
-    PSA_ASSERT( psa_import_key( handle, type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, type,
                                 data->x, data->len ) );
 
     PSA_ASSERT( psa_export_key( handle, exported, export_size,
@@ -1534,7 +1534,7 @@
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
     /* Import the key */
-    PSA_ASSERT( psa_import_key( handle, type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, type,
                                 data->x, data->len ) );
 
     /* Export the public key */
@@ -1584,7 +1584,7 @@
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
     /* Import the key */
-    status = psa_import_key( handle, type, data->x, data->len );
+    status = psa_import_key_to_handle( handle, type, data->x, data->len );
     PSA_ASSERT( status );
 
     /* Test the key information */
@@ -1626,7 +1626,7 @@
     TEST_EQUAL( psa_key_policy_get_algorithm( &policy_set ), alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy_set ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key, sizeof( key ) ) );
 
     PSA_ASSERT( psa_get_key_policy( handle, &policy_get ) );
@@ -1684,7 +1684,7 @@
     psa_key_policy_set_usage( &policy, policy_usage, policy_alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x, key_data->len ) );
 
     status = psa_mac_sign_setup( &operation, handle, exercise_alg );
@@ -1728,7 +1728,7 @@
     psa_key_policy_set_usage( &policy, policy_usage, policy_alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x, key_data->len ) );
 
     status = psa_cipher_encrypt_setup( &operation, handle, exercise_alg );
@@ -1780,7 +1780,7 @@
     psa_key_policy_set_usage( &policy, policy_usage, policy_alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x, key_data->len ) );
 
     status = psa_aead_encrypt( handle, exercise_alg,
@@ -1835,7 +1835,7 @@
     psa_key_policy_set_usage( &policy, policy_usage, policy_alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x, key_data->len ) );
 
     PSA_ASSERT( psa_get_key_information( handle,
@@ -1903,7 +1903,7 @@
     psa_key_policy_set_usage( &policy, policy_usage, policy_alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x, key_data->len ) );
 
     status = psa_asymmetric_sign( handle, exercise_alg,
@@ -1948,7 +1948,7 @@
     psa_key_policy_set_usage( &policy, policy_usage, policy_alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x, key_data->len ) );
 
     status = psa_key_derivation( &generator, handle,
@@ -1988,7 +1988,7 @@
     psa_key_policy_set_usage( &policy, policy_usage, policy_alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x, key_data->len ) );
 
     PSA_ASSERT( psa_key_derivation_setup( &generator, exercise_alg ) );
@@ -2026,7 +2026,7 @@
     psa_key_policy_set_usage( &policy, policy_usage, policy_alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x, key_data->len ) );
 
     status = raw_key_agreement_with_self( exercise_alg, handle );
@@ -2084,7 +2084,7 @@
     PSA_ASSERT( psa_allocate_key( &source_handle ) );
     psa_key_policy_set_usage( &source_policy, source_usage, source_alg );
     PSA_ASSERT( psa_set_key_policy( source_handle, &source_policy ) );
-    PSA_ASSERT( psa_import_key( source_handle, source_type,
+    PSA_ASSERT( psa_import_key_to_handle( source_handle, source_type,
                                 material->x, material->len ) );
     PSA_ASSERT( psa_get_key_information( source_handle, NULL, &source_bits ) );
 
@@ -2095,7 +2095,7 @@
     target_policy = psa_key_policy_init();
 
     /* Copy the key. */
-    PSA_ASSERT( psa_copy_key( source_handle, target_handle, p_constraint ) );
+    PSA_ASSERT( psa_copy_key_to_handle( source_handle, target_handle, p_constraint ) );
 
     /* Destroy the source to ensure that this doesn't affect the target. */
     PSA_ASSERT( psa_destroy_key( source_handle ) );
@@ -2170,7 +2170,7 @@
     PSA_ASSERT( psa_allocate_key( &source_handle ) );
     psa_key_policy_set_usage( &source_policy, source_usage, source_alg );
     PSA_ASSERT( psa_set_key_policy( source_handle, &source_policy ) );
-    PSA_ASSERT( psa_import_key( source_handle, source_type,
+    PSA_ASSERT( psa_import_key_to_handle( source_handle, source_type,
                                 material->x, material->len ) );
     PSA_ASSERT( psa_get_key_information( source_handle, NULL, &source_bits ) );
 
@@ -2181,7 +2181,7 @@
     target_policy = psa_key_policy_init();
 
     /* Copy the key. */
-    TEST_EQUAL( psa_copy_key( source_handle, target_handle, p_constraint ),
+    TEST_EQUAL( psa_copy_key_to_handle( source_handle, target_handle, p_constraint ),
                 expected_status );
 
     /* Test that the target slot is unaffected. */
@@ -2588,7 +2588,7 @@
                               alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key, sizeof(key) ) );
 
     /* Call update without calling setup beforehand. */
@@ -2715,7 +2715,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key->x, key->len ) );
 
     /* Calculate the MAC. */
@@ -2762,7 +2762,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key->x, key->len ) );
 
     PSA_ASSERT( psa_mac_verify_setup( &operation,
@@ -2882,7 +2882,7 @@
                               PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT,
                               alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key, sizeof(key) ) );
 
 
@@ -3040,7 +3040,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key->x, key->len ) );
 
     PSA_ASSERT( psa_cipher_encrypt_setup( &operation,
@@ -3110,7 +3110,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key->x, key->len ) );
 
     PSA_ASSERT( psa_cipher_encrypt_setup( &operation,
@@ -3186,7 +3186,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key->x, key->len ) );
 
     PSA_ASSERT( psa_cipher_decrypt_setup( &operation,
@@ -3260,7 +3260,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key->x, key->len ) );
 
     PSA_ASSERT( psa_cipher_decrypt_setup( &operation,
@@ -3327,7 +3327,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key->x, key->len ) );
 
     PSA_ASSERT( psa_cipher_encrypt_setup( &operation1,
@@ -3413,7 +3413,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key->x, key->len ) );
 
     PSA_ASSERT( psa_cipher_encrypt_setup( &operation1,
@@ -3517,7 +3517,7 @@
                               alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x, key_data->len ) );
 
     TEST_EQUAL( psa_aead_encrypt( handle, alg,
@@ -3580,7 +3580,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT , alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -3629,7 +3629,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT , alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -3688,7 +3688,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
     PSA_ASSERT( psa_get_key_information( handle,
@@ -3742,7 +3742,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_SIGN, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -3785,7 +3785,7 @@
                               alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
     PSA_ASSERT( psa_get_key_information( handle,
@@ -3852,7 +3852,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -3885,7 +3885,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_VERIFY, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -3929,7 +3929,7 @@
     PSA_ASSERT( psa_allocate_key( &handle ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_ENCRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -3999,7 +3999,7 @@
                               alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -4065,7 +4065,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -4129,7 +4129,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DECRYPT, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -4216,7 +4216,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -4253,7 +4253,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, key_type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, key_type,
                                 key_data,
                                 sizeof( key_data ) ) );
 
@@ -4348,7 +4348,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, PSA_KEY_TYPE_DERIVE,
+    PSA_ASSERT( psa_import_key_to_handle( handle, PSA_KEY_TYPE_DERIVE,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -4445,7 +4445,7 @@
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
-    PSA_ASSERT( psa_import_key( handle, PSA_KEY_TYPE_DERIVE,
+    PSA_ASSERT( psa_import_key_to_handle( handle, PSA_KEY_TYPE_DERIVE,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -4533,7 +4533,7 @@
     PSA_ASSERT( psa_allocate_key( &base_handle ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( base_handle, &policy ) );
-    PSA_ASSERT( psa_import_key( base_handle, PSA_KEY_TYPE_DERIVE,
+    PSA_ASSERT( psa_import_key_to_handle( base_handle, PSA_KEY_TYPE_DERIVE,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -4545,7 +4545,7 @@
     PSA_ASSERT( psa_allocate_key( &derived_handle ) );
     psa_key_policy_set_usage( &policy, derived_usage, derived_alg );
     PSA_ASSERT( psa_set_key_policy( derived_handle, &policy ) );
-    PSA_ASSERT( psa_generator_import_key( derived_handle,
+    PSA_ASSERT( psa_generator_import_key_to_handle( derived_handle,
                                           derived_type,
                                           derived_bits,
                                           &generator ) );
@@ -4597,7 +4597,7 @@
     PSA_ASSERT( psa_allocate_key( &base_handle ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( base_handle, &policy ) );
-    PSA_ASSERT( psa_import_key( base_handle, PSA_KEY_TYPE_DERIVE,
+    PSA_ASSERT( psa_import_key_to_handle( base_handle, PSA_KEY_TYPE_DERIVE,
                                 key_data->x,
                                 key_data->len ) );
 
@@ -4619,7 +4619,7 @@
     PSA_ASSERT( psa_allocate_key( &derived_handle ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_EXPORT, 0 );
     PSA_ASSERT( psa_set_key_policy( derived_handle, &policy ) );
-    PSA_ASSERT( psa_generator_import_key( derived_handle,
+    PSA_ASSERT( psa_generator_import_key_to_handle( derived_handle,
                                           PSA_KEY_TYPE_RAW_DATA,
                                           derived_bits,
                                           &generator ) );
@@ -4630,7 +4630,7 @@
     PSA_ASSERT( psa_destroy_key( derived_handle ) );
     PSA_ASSERT( psa_allocate_key( &derived_handle ) );
     PSA_ASSERT( psa_set_key_policy( derived_handle, &policy ) );
-    PSA_ASSERT( psa_generator_import_key( derived_handle,
+    PSA_ASSERT( psa_generator_import_key_to_handle( derived_handle,
                                           PSA_KEY_TYPE_RAW_DATA,
                                           PSA_BYTES_TO_BITS( bytes2 ),
                                           &generator ) );
@@ -4672,7 +4672,7 @@
     PSA_ASSERT( psa_allocate_key( &our_key ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( our_key, &policy ) );
-    PSA_ASSERT( psa_import_key( our_key, our_key_type,
+    PSA_ASSERT( psa_import_key_to_handle( our_key, our_key_type,
                                 our_key_data->x,
                                 our_key_data->len ) );
 
@@ -4719,7 +4719,7 @@
     PSA_ASSERT( psa_allocate_key( &our_key ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( our_key, &policy ) );
-    PSA_ASSERT( psa_import_key( our_key, our_key_type,
+    PSA_ASSERT( psa_import_key_to_handle( our_key, our_key_type,
                                 our_key_data->x,
                                 our_key_data->len ) );
 
@@ -4756,7 +4756,7 @@
     PSA_ASSERT( psa_allocate_key( &our_key ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( our_key, &policy ) );
-    PSA_ASSERT( psa_import_key( our_key, our_key_type,
+    PSA_ASSERT( psa_import_key_to_handle( our_key, our_key_type,
                                 our_key_data->x,
                                 our_key_data->len ) );
 
@@ -4817,7 +4817,7 @@
     PSA_ASSERT( psa_allocate_key( &our_key ) );
     psa_key_policy_set_usage( &policy, PSA_KEY_USAGE_DERIVE, alg );
     PSA_ASSERT( psa_set_key_policy( our_key, &policy ) );
-    PSA_ASSERT( psa_import_key( our_key, our_key_type,
+    PSA_ASSERT( psa_import_key_to_handle( our_key, our_key_type,
                                 our_key_data->x,
                                 our_key_data->len ) );
 
@@ -4932,7 +4932,7 @@
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
     /* Generate a key */
-    TEST_EQUAL( psa_generate_key( handle, type, bits, NULL, 0 ),
+    TEST_EQUAL( psa_generate_key_to_handle( handle, type, bits, NULL, 0 ),
                 expected_status );
 
     /* Test the key information */
@@ -4992,13 +4992,13 @@
     {
         case IMPORT_KEY:
             /* Import the key */
-            PSA_ASSERT( psa_import_key( handle, type,
+            PSA_ASSERT( psa_import_key_to_handle( handle, type,
                                         data->x, data->len ) );
             break;
 
         case GENERATE_KEY:
             /* Generate a key */
-            PSA_ASSERT( psa_generate_key( handle, type, bits,
+            PSA_ASSERT( psa_generate_key_to_handle( handle, type, bits,
                                           NULL, 0 ) );
             break;
 
@@ -5009,14 +5009,14 @@
                                       base_policy_alg );
             PSA_ASSERT( psa_set_key_policy(
                             base_key, &base_policy_set ) );
-            PSA_ASSERT( psa_import_key( base_key, PSA_KEY_TYPE_DERIVE,
+            PSA_ASSERT( psa_import_key_to_handle( base_key, PSA_KEY_TYPE_DERIVE,
                                         data->x, data->len ) );
             /* Derive a key. */
             PSA_ASSERT( psa_key_derivation( &generator, base_key,
                                             base_policy_alg,
                                             NULL, 0, NULL, 0,
                                             export_size ) );
-            PSA_ASSERT( psa_generator_import_key(
+            PSA_ASSERT( psa_generator_import_key_to_handle(
                             handle, PSA_KEY_TYPE_RAW_DATA,
                             bits, &generator ) );
             break;
diff --git a/tests/suites/test_suite_psa_crypto_init.function b/tests/suites/test_suite_psa_crypto_init.function
index c8f6e1b..9f464ac 100644
--- a/tests/suites/test_suite_psa_crypto_init.function
+++ b/tests/suites/test_suite_psa_crypto_init.function
@@ -189,7 +189,7 @@
         PSA_ASSERT( status );
         mbedtls_psa_crypto_free( );
     }
-    status = psa_import_key( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) );
+    status = psa_import_key_to_handle( 1, PSA_KEY_TYPE_RAW_DATA, data, sizeof( data ) );
     TEST_EQUAL( status, PSA_ERROR_BAD_STATE );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_psa_crypto_persistent_key.function b/tests/suites/test_suite_psa_crypto_persistent_key.function
index 90e10f6..245eeef 100644
--- a/tests/suites/test_suite_psa_crypto_persistent_key.function
+++ b/tests/suites/test_suite_psa_crypto_persistent_key.function
@@ -98,7 +98,7 @@
     PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
                                 &handle ) );
 
-    TEST_EQUAL( psa_import_key( handle, PSA_KEY_TYPE_RAW_DATA,
+    TEST_EQUAL( psa_import_key_to_handle( handle, PSA_KEY_TYPE_RAW_DATA,
                                 data, data_length ),
                 expected_status );
 
@@ -126,7 +126,7 @@
 
     if( should_store == 1 )
     {
-        PSA_ASSERT( psa_import_key(
+        PSA_ASSERT( psa_import_key_to_handle(
                         handle, first_type,
                         first_data->x, first_data->len ) );
     }
@@ -147,7 +147,7 @@
     /* Create another key in the same slot */
     PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
                                 &handle ) );
-    PSA_ASSERT( psa_import_key(
+    PSA_ASSERT( psa_import_key_to_handle(
                     handle, second_type,
                     second_data->x, second_data->len ) );
 
@@ -170,7 +170,7 @@
 
     PSA_ASSERT( psa_create_key( PSA_KEY_LIFETIME_PERSISTENT, key_id,
                                 &handle ) );
-    TEST_EQUAL( psa_import_key( handle, type, data->x, data->len ),
+    TEST_EQUAL( psa_import_key_to_handle( handle, type, data->x, data->len ),
                 expected_status );
 
     if( expected_status != PSA_SUCCESS )
@@ -179,7 +179,7 @@
         goto exit;
     }
 
-    PSA_ASSERT( psa_get_key_lifetime( handle, &lifetime ) );
+    PSA_ASSERT( psa_get_key_lifetime_from_handle( handle, &lifetime ) );
     TEST_EQUAL( lifetime, PSA_KEY_LIFETIME_PERSISTENT );
 
 exit:
@@ -215,10 +215,10 @@
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
 
     /* Import the key */
-    PSA_ASSERT( psa_import_key( handle, type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, type,
                                 data->x, data->len ) );
 
-    PSA_ASSERT( psa_get_key_lifetime( handle, &lifetime_get ) );
+    PSA_ASSERT( psa_get_key_lifetime_from_handle( handle, &lifetime_get ) );
     TEST_EQUAL( lifetime_get, PSA_KEY_LIFETIME_PERSISTENT );
 
     /* Test the key information */
diff --git a/tests/suites/test_suite_psa_crypto_slot_management.function b/tests/suites/test_suite_psa_crypto_slot_management.function
index 0278b88..e393743 100644
--- a/tests/suites/test_suite_psa_crypto_slot_management.function
+++ b/tests/suites/test_suite_psa_crypto_slot_management.function
@@ -84,7 +84,7 @@
     TEST_ASSERT( handle != 0 );
     psa_key_policy_set_usage( &policy, usage_flags, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
-    PSA_ASSERT( psa_import_key( handle, type, key_data->x, key_data->len ) );
+    PSA_ASSERT( psa_import_key_to_handle( handle, type, key_data->x, key_data->len ) );
     PSA_ASSERT( psa_get_key_information( handle, &read_type, NULL ) );
     TEST_EQUAL( read_type, type );
 
@@ -137,7 +137,7 @@
     TEST_ASSERT( handle != 0 );
     psa_key_policy_set_usage( &policy, usage_flags, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
-    PSA_ASSERT( psa_import_key( handle, type, key_data->x, key_data->len ) );
+    PSA_ASSERT( psa_import_key_to_handle( handle, type, key_data->x, key_data->len ) );
     PSA_ASSERT( psa_get_key_information( handle, &read_type, NULL ) );
     TEST_EQUAL( read_type, type );
 
@@ -215,7 +215,7 @@
     TEST_ASSERT( handle1 != 0 );
     psa_key_policy_set_usage( &policy1, PSA_KEY_USAGE_EXPORT, 0 );
     PSA_ASSERT( psa_set_key_policy( handle1, &policy1 ) );
-    PSA_ASSERT( psa_import_key( handle1, type1,
+    PSA_ASSERT( psa_import_key_to_handle( handle1, type1,
                                 material1, sizeof( material1 ) ) );
 
     if( reopen_policy == CLOSE_BEFORE )
@@ -334,7 +334,7 @@
                                     &source_handle ) );
     psa_key_policy_set_usage( &source_policy, source_usage, source_alg );
     PSA_ASSERT( psa_set_key_policy( source_handle, &source_policy ) );
-    PSA_ASSERT( psa_import_key( source_handle, source_type,
+    PSA_ASSERT( psa_import_key_to_handle( source_handle, source_type,
                                 material->x, material->len ) );
     PSA_ASSERT( psa_get_key_information( source_handle, NULL, &source_bits ) );
 
@@ -349,7 +349,7 @@
     target_policy = psa_key_policy_init();
 
     /* Copy the key. */
-    PSA_ASSERT( psa_copy_key( source_handle, target_handle, NULL ) );
+    PSA_ASSERT( psa_copy_key_to_handle( source_handle, target_handle, NULL ) );
 
     /* Destroy the source to ensure that this doesn't affect the target. */
     PSA_ASSERT( psa_destroy_key( source_handle ) );
@@ -435,7 +435,7 @@
     PSA_ASSERT( psa_set_key_policy( target_handle, &target_policy ) );
 
     /* Copy the key. */
-    TEST_EQUAL( psa_copy_key( source_handle, target_handle, NULL ),
+    TEST_EQUAL( psa_copy_key_to_handle( source_handle, target_handle, NULL ),
                 PSA_ERROR_DOES_NOT_EXIST );
 
     /* Test that the slots are unaffected. */
@@ -496,7 +496,7 @@
                                     &source_handle ) );
     psa_key_policy_set_usage( &source_policy, source_usage, source_alg );
     PSA_ASSERT( psa_set_key_policy( source_handle, &source_policy ) );
-    PSA_ASSERT( psa_import_key( source_handle, source_type,
+    PSA_ASSERT( psa_import_key_to_handle( source_handle, source_type,
                                 source_material->x, source_material->len ) );
     PSA_ASSERT( psa_get_key_information( source_handle, NULL, &source_bits ) );
 
@@ -508,12 +508,12 @@
                                     &target_handle ) );
     psa_key_policy_set_usage( &target_policy, target_usage, target_alg );
     PSA_ASSERT( psa_set_key_policy( target_handle, &target_policy ) );
-    PSA_ASSERT( psa_import_key( target_handle, target_type,
+    PSA_ASSERT( psa_import_key_to_handle( target_handle, target_type,
                                 target_material->x, target_material->len ) );
     PSA_ASSERT( psa_get_key_information( target_handle, NULL, &target_bits ) );
 
     /* Copy the key. */
-    TEST_EQUAL( psa_copy_key( source_handle, target_handle, NULL ),
+    TEST_EQUAL( psa_copy_key_to_handle( source_handle, target_handle, NULL ),
                 PSA_ERROR_ALREADY_EXISTS );
 
     /* Test that the target slot is unaffected. */
@@ -573,12 +573,12 @@
                                     &handle ) );
     psa_key_policy_set_usage( &policy, usage, alg );
     PSA_ASSERT( psa_set_key_policy( handle, &policy ) );
-    PSA_ASSERT( psa_import_key( handle, type,
+    PSA_ASSERT( psa_import_key_to_handle( handle, type,
                                 material->x, material->len ) );
     PSA_ASSERT( psa_get_key_information( handle, NULL, &bits ) );
 
     /* Copy the key. */
-    TEST_EQUAL( psa_copy_key( handle, handle, NULL ),
+    TEST_EQUAL( psa_copy_key_to_handle( handle, handle, NULL ),
                 PSA_ERROR_ALREADY_EXISTS );
 
     /* Test that the slot is unaffected. */
@@ -624,7 +624,7 @@
     TEST_ASSERT( handle1 != 0 );
     psa_key_policy_set_usage( &policy, 0, 0 );
     PSA_ASSERT( psa_set_key_policy( handle1, &policy ) );
-    PSA_ASSERT( psa_import_key( handle1, PSA_KEY_TYPE_RAW_DATA,
+    PSA_ASSERT( psa_import_key_to_handle( handle1, PSA_KEY_TYPE_RAW_DATA,
                                 material, sizeof( material ) ) );
 
     /* Attempt to close and destroy some invalid handles. */
@@ -671,7 +671,7 @@
         for( j = 0; j < i; j++ )
             TEST_ASSERT( handles[i] != handles[j] );
         PSA_ASSERT( psa_set_key_policy( handles[i], &policy ) );
-        PSA_ASSERT( psa_import_key( handles[i], PSA_KEY_TYPE_RAW_DATA,
+        PSA_ASSERT( psa_import_key_to_handle( handles[i], PSA_KEY_TYPE_RAW_DATA,
                                     (uint8_t *) &i, sizeof( i ) ) );
     }
     max_handles = i;