Attest: Add ARM_CCA attestation token profile

Specification:
https://developer.arm.com/documentation/den0137/latest

Signed-off-by: Tamas Ban <tamas.ban@arm.com>
Change-Id: I5baa8004e72a5c6e8202fbe67c2dc86a7a2a358a
diff --git a/config/config_default.cmake b/config/config_default.cmake
index f9d8506..b3391e9 100755
--- a/config/config_default.cmake
+++ b/config/config_default.cmake
@@ -147,7 +147,7 @@
 set(SYMMETRIC_INITIAL_ATTESTATION       OFF         CACHE BOOL      "Use symmetric crypto for inital attestation")
 set(ATTEST_INCLUDE_OPTIONAL_CLAIMS      ON          CACHE BOOL      "Include optional claims in initial attestation token")
 set(ATTEST_INCLUDE_COSE_KEY_ID          OFF         CACHE BOOL      "Include COSE key-id in initial attestation token")
-set(ATTEST_TOKEN_PROFILE                "PSA_IOT_1" CACHE STRING    "Set the initial attestation token profile. Options: PSA_IOT_1, PSA_2_0_0")
+set(ATTEST_TOKEN_PROFILE                "PSA_IOT_1" CACHE STRING    "Set the initial attestation token profile. Options: PSA_IOT_1, PSA_2_0_0, ARM_CCA")
 set(ATTEST_STACK_SIZE                   "0x700"     CACHE STRING    "The stack size of the Initial Attestation Secure Partition")
 
 set(TFM_PARTITION_PLATFORM              ON          CACHE BOOL      "Enable Platform partition")
diff --git a/interface/include/tfm_attest_iat_defs.h b/interface/include/tfm_attest_iat_defs.h
index 940de40..e5eebc5 100644
--- a/interface/include/tfm_attest_iat_defs.h
+++ b/interface/include/tfm_attest_iat_defs.h
@@ -49,6 +49,23 @@
 #define IAT_SW_COMPONENTS                  (IAT_ARM_RANGE_BASE + 6)
 #define IAT_VERIFICATION_SERVICE           (IAT_ARM_RANGE_BASE + 7)
 
+#elif defined(ATTEST_TOKEN_PROFILE_ARM_CCA)
+
+/* In case of  ARM_CCA profile */
+#define IAT_NONCE                          10  /* EAT nonce*/
+#define IAT_INSTANCE_ID                    256 /* EAT ueid */
+#define IAT_PROFILE_DEFINITION             265 /* EAT eat_profile */
+#define IAT_ARM_RANGE_BASE                 (2393)
+#define IAT_CLIENT_ID                      (IAT_ARM_RANGE_BASE + 1)
+#define IAT_SECURITY_LIFECYCLE             (IAT_ARM_RANGE_BASE + 2)
+#define IAT_IMPLEMENTATION_ID              (IAT_ARM_RANGE_BASE + 3)
+#define IAT_BOOT_SEED                      (IAT_ARM_RANGE_BASE + 4)
+#define IAT_CERTIFICATION_REFERENCE        (IAT_ARM_RANGE_BASE + 5)
+#define IAT_SW_COMPONENTS                  (IAT_ARM_RANGE_BASE + 6)
+#define IAT_VERIFICATION_SERVICE           (IAT_ARM_RANGE_BASE + 7)
+#define IAT_PLATFORM_CONFIG                (IAT_ARM_RANGE_BASE + 8)
+#define IAT_PLATFORM_HASH_ALGO_ID          (IAT_ARM_RANGE_BASE + 9)
+
 #else
 #error "Attestation token profile is incorrect"
 #endif
diff --git a/platform/ext/common/provisioning.c b/platform/ext/common/provisioning.c
index d90a863..8b6c3e7 100644
--- a/platform/ext/common/provisioning.c
+++ b/platform/ext/common/provisioning.c
@@ -94,6 +94,8 @@
     "PSA_IOT_PROFILE_1",
 #elif defined(ATTEST_TOKEN_PROFILE_PSA_2_0_0)
     "http://arm.com/psa/2.0.0",
+#elif defined(ATTEST_TOKEN_PROFILE_ARM_CCA)
+    "http://arm.com/CCA-SSD/1.0.0",
 #else
 #ifdef TFM_PARTITION_INITIAL_ATTESTATION
 #error "Attestation token profile is incorrect"
diff --git a/platform/ext/target/arm/rss/config.cmake b/platform/ext/target/arm/rss/config.cmake
index 5a3744a..77ef180 100644
--- a/platform/ext/target/arm/rss/config.cmake
+++ b/platform/ext/target/arm/rss/config.cmake
@@ -34,6 +34,8 @@
 set(MEASURED_BOOT_HASH_ALG              PSA_ALG_SHA_256 CACHE STRING "Hash algorithm used by Measured boot services")
 set(TFM_MBEDCRYPTO_PLATFORM_EXTRA_CONFIG_PATH ${CMAKE_CURRENT_LIST_DIR}/mbedtls_extra_config.h CACHE PATH "Config to append to standard Mbed Crypto config, used by platforms to cnfigure feature support")
 
+set(ATTEST_TOKEN_PROFILE                "ARM_CCA"  CACHE STRING   "Set the initial attestation token profile")
+
 set(CONFIG_TFM_USE_TRUSTZONE            OFF        CACHE BOOL     "Enable use of TrustZone to transition between NSPE and SPE")
 set(TFM_MULTI_CORE_TOPOLOGY             ON         CACHE BOOL     "Whether to build for a dual-cpu architecture")
 set(TFM_PLAT_SPECIFIC_MULTI_CORE_COMM   ON         CACHE BOOL     "Whether to use a platform specific inter-core communication instead of mailbox in dual-cpu topology")
diff --git a/secure_fw/partitions/initial_attestation/attest_core.c b/secure_fw/partitions/initial_attestation/attest_core.c
index c5b9719..ba12ebd 100644
--- a/secure_fw/partitions/initial_attestation/attest_core.c
+++ b/secure_fw/partitions/initial_attestation/attest_core.c
@@ -298,6 +298,74 @@
     return PSA_ATTEST_ERR_SUCCESS;
 }
 
+#ifdef ATTEST_TOKEN_PROFILE_ARM_CCA
+/*!
+ * \brief Static function to add the platform hash algorithm identifier
+ *        claim to the attestation token. This hash algo is used for extending
+ *        the boot measurements.
+ *
+ * \param[in]  token_ctx  Token encoding context
+ * \param[in]  challenge  Pointer to buffer which stores the hash algo.
+ *
+ * \return Returns error code as specified in \ref psa_attest_err_t
+ */
+static enum psa_attest_err_t
+attest_add_hash_algo_claim(struct attest_token_encode_ctx *token_ctx)
+{
+    struct q_useful_buf_c hash_algo;
+    uint8_t buf[PLATFORM_HASH_ALGO_ID_MAX_SIZE];
+    uint32_t size = sizeof(buf);
+    enum tfm_plat_err_t err;
+
+    err = tfm_attest_hal_get_platform_hash_algo(&size, buf);
+    if (err != TFM_PLAT_ERR_SUCCESS) {
+        return PSA_ATTEST_ERR_GENERAL;
+    }
+
+    hash_algo.ptr = &buf;
+    hash_algo.len = size;
+    attest_token_encode_add_tstr(token_ctx,
+                                 IAT_PLATFORM_HASH_ALGO_ID,
+                                 &hash_algo);
+
+    return PSA_ATTEST_ERR_SUCCESS;
+}
+
+/*!
+ * \brief Static function to add the platform hash algorithm identifier
+ *        claim to the attestation token. This hash algo is used for extending
+ *        the boot measurements.
+ *
+ * \param[in]  token_ctx  Token encoding context
+ * \param[in]  challenge  Pointer to buffer which stores the hash algo.
+ *
+ * \return Returns error code as specified in \ref psa_attest_err_t
+ */
+static enum psa_attest_err_t
+attest_add_platform_config_claim(struct attest_token_encode_ctx *token_ctx)
+{
+
+    uint8_t plat_config[PLATFORM_CONFIG_MAX_SIZE];
+    enum tfm_plat_err_t res;
+    uint32_t size = sizeof(plat_config);
+    struct q_useful_buf_c claim_value;
+
+    res = tfm_attest_hal_get_platform_config(&size, plat_config);
+    if (res != TFM_PLAT_ERR_SUCCESS) {
+        return PSA_ATTEST_ERR_GENERAL;
+    }
+
+    claim_value.ptr = plat_config;
+    claim_value.len = size;
+
+    attest_token_encode_add_bstr(token_ctx,
+                                 IAT_PLATFORM_CONFIG,
+                                 &claim_value);
+
+    return PSA_ATTEST_ERR_SUCCESS;
+}
+#endif
+
 /*!
  * \brief Static function to add security lifecycle claim to attestation token.
  *
@@ -366,7 +434,6 @@
     return PSA_ATTEST_ERR_SUCCESS;
 }
 
-#ifdef INCLUDE_OPTIONAL_CLAIMS /* Remove them from release build */
 /*!
  * \brief Static function to add the verification service indicator claim
  *        to the attestation token.
@@ -470,7 +537,6 @@
 
     return PSA_ATTEST_ERR_SUCCESS;
 }
-#endif /* INCLUDE_OPTIONAL_CLAIMS */
 
 /*!
  * \brief Static function to verify the input challenge size
@@ -549,24 +615,6 @@
 }
 #endif /* INCLUDE_TEST_CODE */
 
-#if defined(ATTEST_TOKEN_PROFILE_PSA_IOT_1) || \
-    defined(ATTEST_TOKEN_PROFILE_PSA_2_0_0)
-    static enum psa_attest_err_t
-    (*claim_query_funcs[])(struct attest_token_encode_ctx *) = {
-        &attest_add_boot_seed_claim,
-        &attest_add_instance_id_claim,
-        &attest_add_implementation_id_claim,
-        &attest_add_caller_id_claim,
-        &attest_add_security_lifecycle_claim,
-        &attest_add_all_sw_components,
-#ifdef INCLUDE_OPTIONAL_CLAIMS
-        &attest_add_verification_service,
-        &attest_add_profile_definition,
-        &attest_add_cert_ref_claim
-#endif
-    };
-#endif
-
 static enum psa_attest_err_t attest_get_t_cose_algorithm(
         int32_t *cose_algorithm_id)
 {
@@ -621,6 +669,39 @@
     return PSA_ATTEST_ERR_SUCCESS;
 }
 
+#if defined(ATTEST_TOKEN_PROFILE_PSA_IOT_1) || \
+    defined(ATTEST_TOKEN_PROFILE_PSA_2_0_0)
+    static enum psa_attest_err_t
+    (*claim_query_funcs[])(struct attest_token_encode_ctx *) = {
+        &attest_add_boot_seed_claim,
+        &attest_add_instance_id_claim,
+        &attest_add_implementation_id_claim,
+        &attest_add_caller_id_claim,
+        &attest_add_security_lifecycle_claim,
+        &attest_add_all_sw_components,
+#ifdef INCLUDE_OPTIONAL_CLAIMS
+        &attest_add_verification_service,
+        &attest_add_profile_definition,
+        &attest_add_cert_ref_claim
+#endif
+    };
+#elif defined(ATTEST_TOKEN_PROFILE_ARM_CCA)
+
+    static enum psa_attest_err_t
+    (*claim_query_funcs[])(struct attest_token_encode_ctx *) = {
+        &attest_add_instance_id_claim,
+        &attest_add_implementation_id_claim,
+        &attest_add_security_lifecycle_claim,
+        &attest_add_all_sw_components,
+        &attest_add_profile_definition,
+        &attest_add_hash_algo_claim,
+        &attest_add_platform_config_claim,
+#ifdef INCLUDE_OPTIONAL_CLAIMS
+        &attest_add_verification_service,
+#endif
+    };
+#endif
+
 /*!
  * \brief Static function to create the initial attestation token
  *