Styling and refactoring

Signed-off-by: Archana <archana.madhavan@silabs.com>
diff --git a/library/psa_crypto.c b/library/psa_crypto.c
index 906e9b4..bcbaa3d 100644
--- a/library/psa_crypto.c
+++ b/library/psa_crypto.c
@@ -1991,18 +1991,6 @@
 }
 #endif /* MBEDTLS_PSA_CRYPTO_SE_C */
 
-static psa_status_t psa_copy_key_material( const psa_key_slot_t *source,
-                                           psa_key_slot_t *target )
-{
-    psa_status_t status = psa_copy_key_material_into_slot( target,
-                                                           source->key.data,
-                                                           source->key.bytes );
-    if( status != PSA_SUCCESS )
-        return( status );
-
-    return( PSA_SUCCESS );
-}
-
 psa_status_t psa_copy_key( mbedtls_svc_key_id_t source_key,
                            const psa_key_attributes_t *specified_attributes,
                            mbedtls_svc_key_id_t *target_key )
@@ -2027,13 +2015,13 @@
     if( status != PSA_SUCCESS )
         goto exit;
 
-    /* The actual attributes that we received from the user could have
-     * zero values for key bits and type.These optional attributes
-     * have been validated and so it is safe to inherit these
-     * from the source key.
+    /* The target key type and number of bits have been validated by
+     * psa_validate_optional_attributes() to be either equal to zero or
+     * equal to the ones of the source key. So it is safe to inherit
+     * them from the source key now."
      * */
-     actual_attributes.core.bits = source_slot->attr.bits;
-     actual_attributes.core.type = source_slot->attr.type;
+    actual_attributes.core.bits = source_slot->attr.bits;
+    actual_attributes.core.type = source_slot->attr.type;
 
 
     status = psa_restrict_key_policy( source_slot->attr.type,
@@ -2050,7 +2038,7 @@
         PSA_KEY_LIFETIME_GET_LOCATION( source_slot->attr.lifetime ) )
     {
         /*
-         * If the source and target keys are stored across different locations,
+         * If the source and target keys are stored in different locations,
          * the source key would need to be exported as plaintext and re-imported
          * in the other location. This has security implications which have not
          * been fully mapped. For now, this can be achieved through
@@ -2087,7 +2075,9 @@
     }
     else
     {
-        status = psa_copy_key_material( source_slot, target_slot );
+       status = psa_copy_key_material_into_slot( target_slot,
+                                                 source_slot->key.data,
+                                                 source_slot->key.bytes );
         if( status != PSA_SUCCESS )
             goto exit;
     }
diff --git a/library/psa_crypto_driver_wrappers.c b/library/psa_crypto_driver_wrappers.c
index 00c1706..4123d8a 100644
--- a/library/psa_crypto_driver_wrappers.c
+++ b/library/psa_crypto_driver_wrappers.c
@@ -785,7 +785,7 @@
 
 psa_status_t psa_driver_wrapper_copy_key(
     psa_key_attributes_t *attributes,
-    const uint8_t *source_key, size_t source_key_size,
+    const uint8_t *source_key, size_t source_key_length,
     uint8_t *target_key_buffer, size_t target_key_buffer_size,
     size_t *target_key_buffer_length )
 {
@@ -793,13 +793,24 @@
     psa_key_location_t location =
         PSA_KEY_LIFETIME_GET_LOCATION( attributes->core.lifetime );
 
+#if defined(MBEDTLS_PSA_CRYPTO_SE_C)
+    const psa_drv_se_t *drv;
+    psa_drv_se_context_t *drv_context;
+
+    if( psa_get_se_driver( attributes->core.lifetime, &drv, &drv_context ) )
+    {
+        /* Copying to a secure element is not implemented yet. */
+        return( PSA_ERROR_NOT_SUPPORTED );
+    }
+#endif /* MBEDTLS_PSA_CRYPTO_SE_C */
+
     switch( location )
     {
 #if defined(PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT)
 #if defined(PSA_CRYPTO_DRIVER_TEST)
         case PSA_CRYPTO_TEST_DRIVER_LOCATION:
             return( mbedtls_test_opaque_copy_key( attributes, source_key,
-                                                  source_key_size,
+                                                  source_key_length,
                                                   target_key_buffer,
                                                   target_key_buffer_size,
                                                   target_key_buffer_length) );
@@ -807,7 +818,7 @@
 #endif /* PSA_CRYPTO_ACCELERATOR_DRIVER_PRESENT */
         default:
             (void)source_key;
-            (void)source_key_size;
+            (void)source_key_length;
             (void)target_key_buffer;
             (void)target_key_buffer_size;
             (void)target_key_buffer_length;
diff --git a/library/psa_crypto_driver_wrappers.h b/library/psa_crypto_driver_wrappers.h
index c186228..c6e3d51 100644
--- a/library/psa_crypto_driver_wrappers.h
+++ b/library/psa_crypto_driver_wrappers.h
@@ -102,7 +102,7 @@
 
 psa_status_t psa_driver_wrapper_copy_key(
     psa_key_attributes_t *attributes,
-    const uint8_t *source_key, size_t source_key_size,
+    const uint8_t *source_key, size_t source_key_length,
     uint8_t *target_key_buffer, size_t target_key_buffer_size,
     size_t *target_key_buffer_length );
 /*