refactor(lib/attestation): build option for plat token buffer size

Until now, the size of the buffer for the platform token received
from EL3 was fixed at 4kB. Now it can be configured through build
option ATTEST_PLAT_TOKEN_SIZE (defaults to 4kB).

Also suppresses a coverity misra error about uninitialized
`platform_token_len` variable.

Change-Id: Ib11b325dbc1db930e517ce55c2f61dc36f594b8b
Signed-off-by: Juan Pablo Conde <juanpablo.conde@arm.com>
diff --git a/docs/getting_started/build-options.rst b/docs/getting_started/build-options.rst
index b02f788..4718195 100644
--- a/docs/getting_started/build-options.rst
+++ b/docs/getting_started/build-options.rst
@@ -291,6 +291,7 @@
    RMM_CBMC_VIEWER_OUTPUT	,ON | OFF		,OFF			,"Generate report of CBMC results using the tool cbmc-viewer"
    RMM_CBMC_SINGLE_TESTBENCH	,			,OFF			,"Run CBMC on a single testbench instead on all of them"
    RMM_CCA_DA			,ON | OFF		,OFF			,"Enable Device Assignment support in RMM (experimental)"
+   ATTEST_PLAT_TOKEN_SIZE	,       		,0x1000			,"Maximum size in bytes expected for the Attestation platform token"
 
 .. _llvm_build:
 
diff --git a/lib/attestation/CMakeLists.txt b/lib/attestation/CMakeLists.txt
index 7f96dd0..887c128 100644
--- a/lib/attestation/CMakeLists.txt
+++ b/lib/attestation/CMakeLists.txt
@@ -12,9 +12,24 @@
     DEFAULT 1000
     ADVANCED)
 
+arm_config_option(
+    NAME ATTEST_PLAT_TOKEN_SIZE
+    HELP "Maximum size in bytes expected for the Attestation platform token"
+    TYPE STRING
+    DEFAULT 0x1000
+    ADVANCED)
+
 target_compile_definitions(rmm-lib-attestation
     PRIVATE "MBEDTLS_ECP_MAX_OPS=${MBEDTLS_ECP_MAX_OPS}U")
 
+target_compile_definitions(rmm-lib-attestation
+    PRIVATE "ATTEST_PLAT_TOKEN_SIZE=U(${ATTEST_PLAT_TOKEN_SIZE})")
+
+MATH(EXPR CCA_TOKEN_BUFFER_BYTES "${RMM_CCA_TOKEN_BUFFER} * 0x1000")
+if (${CCA_TOKEN_BUFFER_BYTES} LESS ${ATTEST_PLAT_TOKEN_SIZE})
+    message(FATAL_ERROR "RMM_CCA_TOKEN_BUFFER size is less than ATTEST_PLAT_TOKEN_SIZE")
+endif()
+
 target_link_libraries(rmm-lib-attestation
   PRIVATE
     rmm-lib-arch
diff --git a/lib/attestation/src/attestation_key.c b/lib/attestation/src/attestation_key.c
index ca0ffbb..93d4c71 100644
--- a/lib/attestation/src/attestation_key.c
+++ b/lib/attestation/src/attestation_key.c
@@ -22,7 +22,7 @@
 /*
  * The platform token which will be needed during attestation.
  */
-static unsigned char rmm_platform_token_buf[SZ_4K];
+static unsigned char rmm_platform_token_buf[ATTEST_PLAT_TOKEN_SIZE];
 static struct q_useful_buf rmm_platform_token;
 
 /*
@@ -226,6 +226,7 @@
 	 * Make sure the token length does not exceed the size of the
 	 * token buffer
 	 */
+	/* coverity[misra_c_2012_rule_9_1_violation:SUPPRESS] */
 	assert(platform_token_len <= sizeof(rmm_platform_token_buf));
 
 	/* coverity[misra_c_2012_rule_9_1_violation:SUPPRESS] */