Platform: Rework dummy crypto_key and tfm_rotpk to fix unresolved at
tfm_s link with ARMCLANG
In case of build with PLATFORM_DUMMY_CRYPTO_KEYS, crypto_key is
include in bl2 to provide tfm_plat_get_rotpk_hash used by bl2 only.
When compiling secure without tfm_rotpk, device_rotpk is unresolved
With ARMCLANG even if tfm_plat_get_rotpk_hash is not used by secure.
Change-Id: Ifb5e51a2dff327bba2233d34302efdaf006cec6d
Signed-off-by: Michel Jaouen <michel.jaouen@st.com>
diff --git a/platform/CMakeLists.txt b/platform/CMakeLists.txt
index aaad44e..bf3ea53 100644
--- a/platform/CMakeLists.txt
+++ b/platform/CMakeLists.txt
@@ -113,7 +113,6 @@
ext/common/uart_stdout.c
ext/common/boot_hal.c
$<$<BOOL:${PLATFORM_DUMMY_NV_COUNTERS}>:ext/common/template/nv_counters.c>
- $<$<BOOL:${PLATFORM_DUMMY_CRYPTO_KEYS}>:ext/common/template/crypto_keys.c>
$<$<BOOL:${PLATFORM_DUMMY_ROTPK}>:ext/common/template/tfm_rotpk.c>
$<$<BOOL:${PLATFORM_DUMMY_IAK}>:ext/common/template/tfm_initial_attestation_key_material.c>
)
diff --git a/platform/ext/common/template/crypto_keys.c b/platform/ext/common/template/crypto_keys.c
index d4d755c..9876a56 100644
--- a/platform/ext/common/template/crypto_keys.c
+++ b/platform/ext/common/template/crypto_keys.c
@@ -43,9 +43,6 @@
extern const uint32_t initial_attestation_private_key_size;
#endif /* SYMMETRIC_INITIAL_ATTESTATION */
-extern const struct tfm_plat_rotpk_t device_rotpk[];
-extern const uint32_t rotpk_key_cnt;
-
/**
* \brief Copy the key to the destination buffer
*
@@ -164,24 +161,3 @@
return TFM_PLAT_ERR_SUCCESS;
}
#endif /* SYMMETRIC_INITIAL_ATTESTATION */
-
-#ifdef BL2
-enum tfm_plat_err_t
-tfm_plat_get_rotpk_hash(uint8_t image_id,
- uint8_t *rotpk_hash,
- uint32_t *rotpk_hash_size)
-{
- if(*rotpk_hash_size < ROTPK_HASH_LEN) {
- return TFM_PLAT_ERR_SYSTEM_ERR;
- }
-
- if (image_id >= rotpk_key_cnt) {
- return TFM_PLAT_ERR_SYSTEM_ERR;
- }
-
- *rotpk_hash_size = ROTPK_HASH_LEN;
- copy_key(rotpk_hash, device_rotpk[image_id].key_hash, *rotpk_hash_size);
-
- return TFM_PLAT_ERR_SUCCESS;
-}
-#endif
diff --git a/platform/ext/common/template/tfm_rotpk.c b/platform/ext/common/template/tfm_rotpk.c
index 72811a5..b222d69 100644
--- a/platform/ext/common/template/tfm_rotpk.c
+++ b/platform/ext/common/template/tfm_rotpk.c
@@ -75,4 +75,42 @@
#endif
};
const uint32_t rotpk_key_cnt = MCUBOOT_IMAGE_NUMBER;
+
+/**
+ * \brief Copy the key to the destination buffer
+ *
+ * \param[out] p_dst Pointer to buffer where to store the key
+ * \param[in] p_src Pointer to the key
+ * \param[in] size Length of the key
+ */
+static inline void copy_key(uint8_t *p_dst, const uint8_t *p_src, size_t size)
+{
+ uint32_t i;
+
+ for (i = size; i > 0; i--) {
+ *p_dst = *p_src;
+ p_src++;
+ p_dst++;
+ }
+}
+
+enum tfm_plat_err_t
+tfm_plat_get_rotpk_hash(uint8_t image_id,
+ uint8_t *rotpk_hash,
+ uint32_t *rotpk_hash_size)
+{
+ if(*rotpk_hash_size < ROTPK_HASH_LEN) {
+ return TFM_PLAT_ERR_SYSTEM_ERR;
+ }
+
+ if (image_id >= rotpk_key_cnt) {
+ return TFM_PLAT_ERR_SYSTEM_ERR;
+ }
+
+ *rotpk_hash_size = ROTPK_HASH_LEN;
+ copy_key(rotpk_hash, device_rotpk[image_id].key_hash, *rotpk_hash_size);
+
+ return TFM_PLAT_ERR_SUCCESS;
+}
+
#endif /* BL2 */