Merge remote-tracking branch 'origin/release/2.2.x'

Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: I91cfb0c6862b986bd301eaef93672d97eef9d3a3
diff --git a/docs/tfm_erpc_test_build_and_run.rst b/docs/tfm_erpc_test_build_and_run.rst
index 920e3f2..4613d34 100644
--- a/docs/tfm_erpc_test_build_and_run.rst
+++ b/docs/tfm_erpc_test_build_and_run.rst
@@ -50,9 +50,9 @@
 +-------------------------+-------------------------------------+
 | MCUBOOT_LOG_LEVEL       | ``OFF``                             |
 +-------------------------+-------------------------------------+
-| TFM_SPM_LOG_LEVEL       | ``TFM_SPM_LOG_LEVEL_SILENCE``       |
+| TFM_SPM_LOG_LEVEL       | ``LOG_LEVEL_NONE``                  |
 +-------------------------+-------------------------------------+
-| TFM_PARTITION_LOG_LEVEL | ``TFM_PARTITION_LOG_LEVEL_SILENCE`` |
+| TFM_PARTITION_LOG_LEVEL | ``LOG_LEVEL_NONE``                  |
 +-------------------------+-------------------------------------+
 
 Execute tests on TC3 FVP with TCP Transport
diff --git a/erpc/host_example/README.rst b/erpc/host_example/README.rst
index 5c5f044..240d012 100644
--- a/erpc/host_example/README.rst
+++ b/erpc/host_example/README.rst
@@ -16,7 +16,7 @@
 
     cmake -G"Unix Makefiles" -S <path_to_tf-m> -B build_spe -DTFM_PLATFORM=musca_s1 \
     -DTFM_PARTITION_CRYPTO=ON -DTFM_PARTITION_INTERNAL_TRUSTED_STORAGE=ON \
-    -DTFM_SPM_LOG_LEVEL=TFM_SPM_LOG_LEVEL_SILENCE -DTFM_PARTITION_LOG_LEVEL=TFM_PARTITION_LOG_LEVEL_SILENCE \
+    -DTFM_SPM_LOG_LEVEL=LOG_LEVEL_NONE -DTFM_PARTITION_LOG_LEVEL=LOG_LEVEL_NONE \
     -DMCUBOOT_LOG_LEVEL=OFF
 
     cmake --build build_spe -- install -j
@@ -156,4 +156,4 @@
 
 --------------
 
-*Copyright (c) 2023, Arm Limited. All rights reserved.*
+*SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors*
diff --git a/tests_reg/test/framework/test_framework.c b/tests_reg/test/framework/test_framework.c
index d9a5232..496d422 100644
--- a/tests_reg/test/framework/test_framework.c
+++ b/tests_reg/test/framework/test_framework.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2022, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -50,6 +50,8 @@
      *           covered in the switch.
      */
     }
+
+    return NULL;
 }
 
 enum test_suite_err_t run_test(const char *suite_type, struct test_suite_t test_suites[])
diff --git a/tests_reg/test/framework/test_log.h b/tests_reg/test/framework/test_log.h
index 995f726..4c14c60 100644
--- a/tests_reg/test/framework/test_log.h
+++ b/tests_reg/test/framework/test_log.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -9,7 +9,7 @@
 #define __TEST_LOG_H__
 
 #ifdef USE_SP_LOG
-#include "tfm_sp_log.h"
+#include "tfm_log_unpriv.h"
 #elif defined USE_STDIO
 #include <stdio.h>
 #else
@@ -20,7 +20,9 @@
 extern "C" {
 #endif
 
-#if defined USE_SP_LOG || USE_STDIO
+#if defined USE_SP_LOG
+#define TEST_LOG(...) tfm_log_unpriv(LOG_MARKER_RAW __VA_ARGS__)
+#elif defined USE_STDIO
 #define TEST_LOG(...) printf(__VA_ARGS__)
 #else
 #define TEST_LOG(...) tfm_log_printf(__VA_ARGS__)
diff --git a/tests_reg/test/secure_fw/suites/crypto/crypto_tests_common.c b/tests_reg/test/secure_fw/suites/crypto/crypto_tests_common.c
index 35703b2..1ec66e2 100644
--- a/tests_reg/test/secure_fw/suites/crypto/crypto_tests_common.c
+++ b/tests_reg/test/secure_fw/suites/crypto/crypto_tests_common.c
@@ -15,6 +15,45 @@
 #define PSA_HASH_LENGTH_MAX     64
 #define ECDSA_KEYS_PRIV_SZ_MAX  48
 
+/* Helper function to convert from string representation to binary */
+static uint8_t char_to_uint8_t(char c)
+{
+    if (c >= '0' && c <= '9') {
+        return c - '0';
+    } else if (c >= 'a' && c <= 'f') {
+        return c - 'a' + 10;
+    } else if (c >= 'A' && c <= 'F') {
+        return c - 'A' + 10;
+    } else {
+        assert(0);
+    }
+}
+
+static void StringToBuffer(const char *str, size_t len, uint8_t *buf) {
+  for (int i = 0; i < len; i++) {
+    buf[i] = char_to_uint8_t(*str) * 16 + char_to_uint8_t(*(str + 1));
+    str += 2;
+  }
+}
+
+/* Helper function to convert from binary to string representation */
+static char uint8_to_char(uint8_t u)
+{
+    assert( u < (1UL << 4));
+    const uint8_t arr[] = {'0', '1', '2', '3', '4', '5', '6', '7',
+                           '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
+    return arr[u];
+}
+
+static void BufferToString(const uint8_t *buf, size_t len, char *str) {
+  for (int i = 0; i < len; i++) {
+    *str = uint8_to_char((buf[i] >> 4) & 0xf);
+    *(str + 1) = uint8_to_char(buf[i] & 0xf);
+    str += 2;
+  }
+  str[0] = '\0';
+}
+
 void psa_key_interface_test(const psa_key_type_t key_type,
                             struct test_result_t *ret)
 {
@@ -1581,14 +1620,18 @@
     const uint32_t msg_num = sizeof(msg_size)/sizeof(msg_size[0]);
     uint32_t idx, start_idx = 0;
     uint8_t *hmac_res;
-
+#ifdef TFM_CRYPTO_TEST_SINGLE_PART_FUNCS
+    uint8_t hmac[PSA_HASH_LENGTH(PSA_ALG_HMAC_GET_HASH(alg))];
+    size_t hmac_length = 0;
+    uint32_t comp_result;
+#endif /* TFM_CRYPTO_TEST_SINGLE_PART_FUNCS */
     psa_key_id_t key_id_local = PSA_KEY_ID_NULL;
     psa_key_type_t key_type = PSA_KEY_TYPE_HMAC;
     psa_status_t status;
     psa_mac_operation_t handle = psa_mac_operation_init();
     psa_key_attributes_t key_attributes = psa_key_attributes_init();
     psa_key_attributes_t retrieved_attributes = psa_key_attributes_init();
-    psa_key_usage_t usage = PSA_KEY_USAGE_VERIFY_HASH;
+    psa_key_usage_t usage = PSA_KEY_USAGE_VERIFY_HASH | PSA_KEY_USAGE_SIGN_HASH;
 
     ret->val = TEST_PASSED;
 
@@ -1624,6 +1667,43 @@
 
     psa_reset_key_attributes(&retrieved_attributes);
 
+    /* Cycle until idx points to the correct index in the algorithm table */
+    for (idx=0; hash_alg[idx] != PSA_ALG_HMAC_GET_HASH(alg); idx++);
+
+    if (key_bits == BIT_SIZE_TEST_LONG_KEY) {
+        hmac_res = (uint8_t *)long_key_hmac_val;
+    } else {
+        hmac_res = (uint8_t *)hmac_val[idx];
+    }
+
+#ifdef TFM_CRYPTO_TEST_SINGLE_PART_FUNCS
+    /* Compute the HMAC */
+    status = psa_mac_compute(key_id_local, alg,
+                             (const uint8_t *)msg, strlen(msg),
+                             hmac, sizeof(hmac), &hmac_length);
+    if (status != PSA_SUCCESS) {
+        TEST_FAIL("Error using the single shot API for computing mac");
+        goto destroy_key_mac;
+    }
+
+    /* Check that the computed MAC matches with the reference */
+    comp_result = memcmp(hmac, hmac_res, hmac_length);
+    if (comp_result != 0) {
+        TEST_FAIL("Single shot API mac does not match reference");
+        goto destroy_key_mac;
+    }
+
+    /* Test the verification function against the reference values */
+    status = psa_mac_verify(key_id_local, alg,
+                            (const uint8_t *)msg, strlen(msg),
+                            hmac_res,
+                            PSA_HASH_LENGTH(PSA_ALG_HMAC_GET_HASH(alg)));
+    if (status != PSA_SUCCESS) {
+        TEST_FAIL("Error using the single shot API for verifying mac");
+        goto destroy_key_mac;
+    }
+#endif /* TFM_CRYPTO_TEST_SINGLE_PART_FUNCS */
+
     /* Setup the mac object for hmac */
     status = psa_mac_verify_setup(&handle, key_id_local, alg);
     if (status != PSA_SUCCESS) {
@@ -1637,7 +1717,7 @@
     }
 
     /* Update object with all the chunks of message */
-    for (idx=0; idx<msg_num; idx++) {
+    for (idx = 0; idx < msg_num; idx++) {
         status = psa_mac_update(&handle,
                                 (const uint8_t *)&msg[start_idx],
                                 msg_size[idx]);
@@ -1648,34 +1728,13 @@
         start_idx += msg_size[idx];
     }
 
-    /* Cycle until idx points to the correct index in the algorithm table */
-    for (idx=0; hash_alg[idx] != PSA_ALG_HMAC_GET_HASH(alg); idx++);
-
-    if (key_bits == BIT_SIZE_TEST_LONG_KEY) {
-        hmac_res = (uint8_t *)long_key_hmac_val;
-    } else {
-        hmac_res = (uint8_t *)hmac_val[idx];
-    }
-
     /* Finalise and verify the mac value */
     status = psa_mac_verify_finish(&handle, hmac_res,
                                    PSA_HASH_LENGTH(PSA_ALG_HMAC_GET_HASH(alg)));
     if (status != PSA_SUCCESS) {
         TEST_FAIL("Error during finalising the mac operation");
-        goto destroy_key_mac;
     }
 
-#ifdef TFM_CRYPTO_TEST_SINGLE_PART_FUNCS
-    /* Do the same as above with the single shot APIs */
-    status = psa_mac_verify(key_id_local, alg,
-                            (const uint8_t *)msg, strlen(msg),
-                            hmac_res,
-                            PSA_HASH_LENGTH(PSA_ALG_HMAC_GET_HASH(alg)));
-    if (status != PSA_SUCCESS) {
-        TEST_FAIL("Error using the single shot API");
-    }
-#endif
-
 destroy_key_mac:
     /* Destroy the key */
     status = psa_destroy_key(key_id_local);
@@ -3168,45 +3227,6 @@
     }
 };
 
-/* Helper function to convert from string representation to binary */
-static uint8_t char_to_uint8_t(char c)
-{
-    if (c >= '0' && c <= '9') {
-        return c - '0';
-    } else if (c >= 'a' && c <= 'f') {
-        return c - 'a' + 10;
-    } else if (c >= 'A' && c <= 'F') {
-        return c - 'A' + 10;
-    } else {
-        assert(0);
-    }
-}
-
-static void StringToBuffer(const char *str, size_t len, uint8_t *buf) {
-  for (int i = 0; i < len; i++) {
-    buf[i] = char_to_uint8_t(*str) * 16 + char_to_uint8_t(*(str + 1));
-    str += 2;
-  }
-}
-
-/* Helper function to convert from binary to string representation */
-static char uint8_to_char(uint8_t u)
-{
-    assert( u < (1UL << 4));
-    const uint8_t arr[] = {'0', '1', '2', '3', '4', '5', '6', '7',
-                           '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
-    return arr[u];
-}
-
-static void BufferToString(const uint8_t *buf, size_t len, char *str) {
-  for (int i = 0; i < len; i++) {
-    *str = uint8_to_char((buf[i] >> 4) & 0xf);
-    *(str + 1) = uint8_to_char(buf[i] & 0xf);
-    str += 2;
-  }
-  str[0] = '\0';
-}
-
 void psa_sign_verify_hash_test(psa_algorithm_t alg, uint8_t curve_selector,
                                struct test_result_t *ret)
 {
diff --git a/tests_reg/test/secure_fw/suites/fpu/service/tfm_fpu_service_test.c b/tests_reg/test/secure_fw/suites/fpu/service/tfm_fpu_service_test.c
index 092f68a..0e02a52 100644
--- a/tests_reg/test/secure_fw/suites/fpu/service/tfm_fpu_service_test.c
+++ b/tests_reg/test/secure_fw/suites/fpu/service/tfm_fpu_service_test.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021-2024, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -11,7 +11,7 @@
 #include "psa/client.h"
 #include "psa/service.h"
 #include "psa_manifest/tfm_fpu_service_test.h"
-#include "tfm_sp_log.h"
+#include "tfm_log_unpriv.h"
 #include "tfm_peripherals_def.h"
 
 /*
@@ -92,12 +92,12 @@
 
         if (memcmp(fp_caller_buffer, expecting_caller_content,
                    FP_CALLER_BUF_SIZE)) {
-            LOG_ERRFMT("FP caller registers are not correctly restored!");
+            ERROR_UNPRIV_RAW("FP caller registers are not correctly restored!");
             status = PSA_ERROR_GENERIC_ERROR;
         } else {
             if (memcmp(fp_callee_buffer, expecting_callee_content,
                        FP_CALLEE_BUF_SIZE)) {
-                LOG_ERRFMT("FP callee registers are not correctly restored!");
+                ERROR_UNPRIV_RAW("FP callee registers are not correctly restored!");
                 status = PSA_ERROR_GENERIC_ERROR;
             }
         }
diff --git a/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.c b/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.c
index 732f915..aaef76d 100644
--- a/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.c
+++ b/tests_reg/test/secure_fw/suites/spm/ipc/service/tfm_ipc_service/tfm_ipc_service_test.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018-2024, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -12,7 +12,7 @@
 #include "psa_manifest/tfm_ipc_service_test.h"
 #include "spm_test_defs.h"
 #include "tfm_hal_isolation.h"
-#include "tfm_sp_log.h"
+#include "tfm_log_unpriv.h"
 #include "client_api_test_defs.h"
 #include "client_api_test_service.h"
 
diff --git a/tests_reg/test/secure_fw/suites/spm/irq/service/tfm_flih_test_service/tfm_flih_test_service.c b/tests_reg/test/secure_fw/suites/spm/irq/service/tfm_flih_test_service/tfm_flih_test_service.c
index fdd43b6..bacb820 100644
--- a/tests_reg/test/secure_fw/suites/spm/irq/service/tfm_flih_test_service/tfm_flih_test_service.c
+++ b/tests_reg/test/secure_fw/suites/spm/irq/service/tfm_flih_test_service/tfm_flih_test_service.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -8,7 +8,7 @@
 #include "cmsis_compiler.h"
 #include "tfm_plat_test.h"
 #include "spm_test_defs.h"
-#include "tfm_sp_log.h"
+#include "tfm_log_unpriv.h"
 #include "psa/service.h"
 #include "psa_manifest/tfm_flih_test_service.h"
 
@@ -106,7 +106,7 @@
         status = PSA_SUCCESS;
         break;
     default:
-        LOG_ERRFMT("FLIH test service: Invalid message type: 0x%x\r\n",
+        ERROR_UNPRIV_RAW("FLIH test service: Invalid message type: 0x%x\n",
             msg->type);
         status = PSA_ERROR_PROGRAMMER_ERROR;
         break;
diff --git a/tests_reg/test/secure_fw/suites/spm/irq/service/tfm_slih_test_service/tfm_slih_test_service.c b/tests_reg/test/secure_fw/suites/spm/irq/service/tfm_slih_test_service/tfm_slih_test_service.c
index b970372..7c1734f 100644
--- a/tests_reg/test/secure_fw/suites/spm/irq/service/tfm_slih_test_service/tfm_slih_test_service.c
+++ b/tests_reg/test/secure_fw/suites/spm/irq/service/tfm_slih_test_service/tfm_slih_test_service.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -7,7 +7,7 @@
 
 #include "tfm_plat_test.h"
 #include "spm_test_defs.h"
-#include "tfm_sp_log.h"
+#include "tfm_log_unpriv.h"
 #include "psa/service.h"
 #include "psa_manifest/tfm_slih_test_service.h"
 
@@ -40,7 +40,7 @@
         status = PSA_SUCCESS;
         break;
     default:
-        LOG_ERRFMT("SLIH test service: Invalid message type: 0x%x\r\n",
+        ERROR_UNPRIV_RAW("SLIH test service: Invalid message type: 0x%x\n",
             msg->type);
         status = PSA_ERROR_PROGRAMMER_ERROR;
         break;
diff --git a/tests_reg/test/secure_fw/suites/spm/sfn/service/sfn_backend_test_partition/sfn_backend_test_partition.c b/tests_reg/test/secure_fw/suites/spm/sfn/service/sfn_backend_test_partition/sfn_backend_test_partition.c
index 3960108..8af959b 100644
--- a/tests_reg/test/secure_fw/suites/spm/sfn/service/sfn_backend_test_partition/sfn_backend_test_partition.c
+++ b/tests_reg/test/secure_fw/suites/spm/sfn/service/sfn_backend_test_partition/sfn_backend_test_partition.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021-2022, Arm Limited. All rights reserved.
+ * SPDX-FileCopyrightText: Copyright The TrustedFirmware-M Contributors
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -9,7 +9,7 @@
 #include "psa/service.h"
 #include "psa_manifest/sfn_backend_test_partition.h"
 #include "spm_test_defs.h"
-#include "tfm_sp_log.h"
+#include "tfm_log_unpriv.h"
 #include "client_api_test_defs.h"
 #include "client_api_test_service.h"
 #if PSA_FRAMEWORK_HAS_MM_IOVEC
@@ -85,6 +85,6 @@
 
 psa_status_t sfn_test_partition_init(void)
 {
-    LOG_DBGFMT("[DBG][SFN Test] SFN Test Partition initialized\r\n");
+    VERBOSE_UNPRIV("[SFN Test] SFN Test Partition initialized\r\n");
     return PSA_SUCCESS;
 }