cmake: Rename mbedcrypto library to tfpsacrypto

Do not do the same in the make build system yet,
cmake build system only scope for this PR.

Signed-off-by: Ronald Cron <ronald.cron@arm.com>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c7831d7..1b05902 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -384,7 +384,7 @@
 # and programs. This shared test code is compiled and linked to test suites and
 # programs objects as a set of compiled objects. The compiled objects are NOT
 # built into a library that the test suite and program objects would link
-# against as they link against the mbedcrypto, mbedx509 and mbedtls libraries.
+# against as they link against the tfpsacrypto, mbedx509 and mbedtls libraries.
 # The reason is that such library is expected to have mutual dependencies with
 # the aforementioned libraries and that there is as of today no portable way of
 # handling such dependencies (only toolchain specific solutions).
diff --git a/README.md b/README.md
index 7ca0e8e..dbee4a8 100644
--- a/README.md
+++ b/README.md
@@ -40,7 +40,7 @@
 
 The main systems used for development are CMake and GNU Make. Those systems are always complete and up-to-date. The others should reflect all changes present in the CMake and Make build system, although features may not be ported there automatically.
 
-The Make and CMake build systems create three libraries: libmbedcrypto, libmbedx509, and libmbedtls. Note that libmbedtls depends on libmbedx509 and libmbedcrypto, and libmbedx509 depends on libmbedcrypto. As a result, some linkers will expect flags to be in a specific order, for example the GNU linker wants `-lmbedtls -lmbedx509 -lmbedcrypto`.
+The Make and CMake build systems create three libraries: libmbedcrypto/libtfpsacrypto, libmbedx509, and libmbedtls. Note that libmbedtls depends on libmbedx509 and libmbedcrypto/libtfpsacrypto, and libmbedx509 depends on libmbedcrypto/libtfpsacrypto. As a result, some linkers will expect flags to be in a specific order, for example the GNU linker wants `-lmbedtls -lmbedx509 -lmbedcrypto`.
 
 ### Tool versions
 
@@ -200,7 +200,7 @@
 If prompted, set `MbedTLS_DIR` to `${YOUR_MBEDTLS_INSTALL_DIR}/cmake`. This
 creates the following targets:
 
-- `MbedTLS::mbedcrypto` (Crypto library)
+- `MbedTLS::tfpsacrypto` (Crypto library)
 - `MbedTLS::mbedtls` (TLS library)
 - `MbedTLS::mbedx509` (X509 library)
 
@@ -210,7 +210,7 @@
 
     target_link_libraries(xyz
         PUBLIC MbedTLS::mbedtls
-               MbedTLS::mbedcrypto
+               MbedTLS::tfpsacrypto
                MbedTLS::mbedx509)
 
 This will link the Mbed TLS libraries to your library or application, and add
diff --git a/pkgconfig/mbedcrypto.pc.in b/pkgconfig/mbedcrypto.pc.in
index 2d130ea..28b9716 100644
--- a/pkgconfig/mbedcrypto.pc.in
+++ b/pkgconfig/mbedcrypto.pc.in
@@ -7,4 +7,4 @@
 URL: @PKGCONFIG_PROJECT_HOMEPAGE_URL@
 Version: @PROJECT_VERSION@
 Cflags: -I"${includedir}"
-Libs: -L"${libdir}" -lmbedcrypto -lbuiltin -leverest -lp256m
+Libs: -L"${libdir}" -ltfpsacrypto -lbuiltin -leverest -lp256m
diff --git a/programs/test/dlopen.c b/programs/test/dlopen.c
index f241254..3a0f37d 100644
--- a/programs/test/dlopen.c
+++ b/programs/test/dlopen.c
@@ -19,7 +19,8 @@
 #define SO_SUFFIX ".so"
 #endif
 
-#define CRYPTO_SO_FILENAME "libmbedcrypto" SO_SUFFIX
+#define MBEDCRYPTO_SO_FILENAME "libmbedcrypto" SO_SUFFIX
+#define TFPSACRYPTO_SO_FILENAME "libtfpsacrypto" SO_SUFFIX
 #define X509_SO_FILENAME "libmbedx509" SO_SUFFIX
 #define TLS_SO_FILENAME "libmbedtls" SO_SUFFIX
 
@@ -73,8 +74,16 @@
 #endif  /* MBEDTLS_X509_CRT_PARSE_C */
 
 #if defined(MBEDTLS_MD_C)
-    void *crypto_so = dlopen(CRYPTO_SO_FILENAME, RTLD_NOW);
-    CHECK_DLERROR("dlopen", CRYPTO_SO_FILENAME);
+    const char *crypto_so_filename = NULL;
+    void *crypto_so = dlopen(MBEDCRYPTO_SO_FILENAME, RTLD_NOW);
+    if (dlerror() == NULL) {
+        crypto_so_filename = MBEDCRYPTO_SO_FILENAME;
+    } else {
+        crypto_so = dlopen(TFPSACRYPTO_SO_FILENAME, RTLD_NOW);
+        CHECK_DLERROR("dlopen", TFPSACRYPTO_SO_FILENAME);
+        crypto_so_filename = TFPSACRYPTO_SO_FILENAME;
+    }
+
     const int *(*md_list)(void) =
         dlsym(crypto_so, "mbedtls_md_list");
     CHECK_DLERROR("dlsym", "mbedtls_md_list");
@@ -83,9 +92,9 @@
         ;
     }
     mbedtls_printf("dlopen(%s): %u hashes\n",
-                   CRYPTO_SO_FILENAME, n);
+                   crypto_so_filename, n);
     dlclose(crypto_so);
-    CHECK_DLERROR("dlclose", CRYPTO_SO_FILENAME);
+    CHECK_DLERROR("dlclose", crypto_so_filename);
 #endif  /* MBEDTLS_MD_C */
 
     return 0;
diff --git a/tests/scripts/components-build-system.sh b/tests/scripts/components-build-system.sh
index f2b74a9..7ebe627 100644
--- a/tests/scripts/components-build-system.sh
+++ b/tests/scripts/components-build-system.sh
@@ -20,7 +20,7 @@
     msg "build/test: cmake shared" # ~ 2min
     cmake -DUSE_SHARED_MBEDTLS_LIBRARY=On .
     make
-    ldd programs/util/strerror | grep libmbedcrypto
+    ldd programs/util/strerror | grep libtfpsacrypto
     make test
     programs/test/dlopen_demo.sh
 }
diff --git a/tf-psa-crypto/core/CMakeLists.txt b/tf-psa-crypto/core/CMakeLists.txt
index 8337bec..cc5e45c 100644
--- a/tf-psa-crypto/core/CMakeLists.txt
+++ b/tf-psa-crypto/core/CMakeLists.txt
@@ -93,7 +93,7 @@
     add_library(${tfpsacrypto_static_target} STATIC ${src_crypto})
     set_base_compile_options(${tfpsacrypto_static_target})
     target_compile_options(${tfpsacrypto_static_target} PRIVATE ${LIBS_C_FLAGS})
-    set_target_properties(${tfpsacrypto_static_target} PROPERTIES OUTPUT_NAME mbedcrypto)
+    set_target_properties(${tfpsacrypto_static_target} PROPERTIES OUTPUT_NAME tfpsacrypto)
     target_link_libraries(${tfpsacrypto_static_target} PUBLIC ${libs})
 
     target_link_libraries(${tfpsacrypto_static_target} PUBLIC ${builtin_static_target})
diff --git a/tf-psa-crypto/pkgconfig/tfpsacrypto.pc.in b/tf-psa-crypto/pkgconfig/tfpsacrypto.pc.in
index 2d130ea..28b9716 100644
--- a/tf-psa-crypto/pkgconfig/tfpsacrypto.pc.in
+++ b/tf-psa-crypto/pkgconfig/tfpsacrypto.pc.in
@@ -7,4 +7,4 @@
 URL: @PKGCONFIG_PROJECT_HOMEPAGE_URL@
 Version: @PROJECT_VERSION@
 Cflags: -I"${includedir}"
-Libs: -L"${libdir}" -lmbedcrypto -lbuiltin -leverest -lp256m
+Libs: -L"${libdir}" -ltfpsacrypto -lbuiltin -leverest -lp256m