Crypto: Decouple TF-M Crypto service from mbed TLS types and macros

Provide an abstraction layer towards the underlying crypto library
that implements the PSA Crypto core functionalities. Remove the
assumption that this library is mbed TLS, i.e. provide this
abstraction layer specifically for mbed TLS but could be implemented
for other crypto libraries as well, if needed, as generic as possible.

Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: I9f2690a749a01209c39acfce161d4953765e22ed
diff --git a/secure_fw/partitions/crypto/crypto_library.c b/secure_fw/partitions/crypto/crypto_library.c
new file mode 100644
index 0000000..ae1823b
--- /dev/null
+++ b/secure_fw/partitions/crypto/crypto_library.c
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2022, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "config_crypto.h"
+
+#include "crypto_library.h"
+
+#include "mbedtls/build_info.h"
+
+#ifndef MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER
+#error "MBEDTLS_PSA_CRYPTO_KEY_ID_ENCODES_OWNER must be selected in Mbed TLS config file"
+#endif
+
+/* Mbed TLS is guaranteed not to have a version string longer than 18 bytes */
+static char mbedtls_version_full[18];
+
+/*!
+ * \defgroup tfm_crypto_library Set of functions implementing the abstractions of the underlying cryptographic
+ *                              library that implements the PSA Crypto APIs to provide the PSA Crypto core
+ *                              functionality to the TF-M Crypto service. Currently it supports only an
+ *                              mbed TLS based abstraction.
+ */
+/*!@{*/
+tfm_crypto_library_key_id_t tfm_crypto_library_key_id_init(int32_t owner, psa_key_id_t key_id)
+{
+    return mbedtls_svc_key_id_make(owner, key_id);
+}
+
+char *tfm_crypto_library_get_info(void)
+{
+    memcpy(mbedtls_version_full, MBEDTLS_VERSION_STRING_FULL, sizeof(MBEDTLS_VERSION_STRING_FULL));
+    return mbedtls_version_full;
+}
+/*!@}*/