SST: Replace SST APIs with PSA PS APIs

Refactors the SST non-secure interfaces, secure API, veneers and
manifest to implement the PSA Protected Storage specification. Adds a
stub implementation for the new SST APIs; another patch will add the
final implementation.

Change-Id: Id62eb82c9d33afd2114962ab1994d567cd81e4f7
Signed-off-by: Jamie Fox <jamie.fox@arm.com>
diff --git a/test/framework/non_secure_suites.c b/test/framework/non_secure_suites.c
index 496dc4f..35890d9 100644
--- a/test/framework/non_secure_suites.c
+++ b/test/framework/non_secure_suites.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -35,6 +35,8 @@
 
 #ifdef SERVICES_TEST_NS
     /* List test cases which compliant with level 1 isolation */
+
+#ifndef PSA_PROTECTED_STORAGE
     /* Non-secure SST test cases */
     {&register_testsuite_ns_sst_interface, 0, 0, 0},
 
@@ -47,6 +49,7 @@
 #endif /* TFM_PARTITION_TEST_SST */
 
 #endif /* TFM_NS_CLIENT_IDENTIFICATION */
+#endif /* !PSA_PROTECTED_STORAGE */
 
     /* Non-secure Audit Logging test cases */
     {&register_testsuite_ns_audit_interface, 0, 0, 0},
diff --git a/test/framework/secure_suites.c b/test/framework/secure_suites.c
index 1dde38d..181f1b1 100644
--- a/test/framework/secure_suites.c
+++ b/test/framework/secure_suites.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -16,8 +16,6 @@
 #include "test/suites/invert/secure/invert_s_tests.h"
 #include "test/suites/crypto/secure/crypto_s_tests.h"
 
-#include "secure_fw/services/secure_storage/sst_object_system.h"
-
 static struct test_suite_t test_suites[] = {
 #if TFM_LVL == 3
 #ifdef SERVICES_TEST_S
@@ -30,6 +28,8 @@
 
 #ifdef SERVICES_TEST_S
     /* List test cases which compliant with level 1 isolation */
+
+#ifndef PSA_PROTECTED_STORAGE
     /* Secure SST test cases */
     {&register_testsuite_s_sst_sec_interface, 0, 0, 0},
     {&register_testsuite_s_sst_reliability, 0, 0, 0},
@@ -37,6 +37,7 @@
 #if defined(SST_ROLLBACK_PROTECTION) && defined(SST_ENCRYPTION)
     {&register_testsuite_s_rollback_protection, 0, 0, 0},
 #endif
+#endif /* !PSA_PROTECTED_STORAGE */
 
     /* Secure Audit Logging test cases */
     {&register_testsuite_s_audit_interface, 0, 0, 0},
@@ -63,14 +64,12 @@
      */
 }
 
-#if TFM_LVL == 1
 static void tear_down_integ_test(void)
 {
-    /* Leave the SST area clean after execute the tests */
-    sst_system_wipe_all();
-    sst_system_prepare();
+    /* Left empty intentionally, currently implemented
+     * test suites require no tear down
+     */
 }
-#endif /* TFM_LVL == 1 */
 
 void start_integ_test(void)
 {
@@ -78,7 +77,5 @@
     integ_test("Secure",
                test_suites,
                sizeof(test_suites)/sizeof(test_suites[0]));
-#if TFM_LVL == 1
     tear_down_integ_test();
-#endif /* TFM_LVL == 1 */
 }
diff --git a/test/framework/test_framework_helpers.c b/test/framework/test_framework_helpers.c
index d9870f4..7423325 100755
--- a/test/framework/test_framework_helpers.c
+++ b/test/framework/test_framework_helpers.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -9,27 +9,37 @@
 
 #include <stdio.h>
 
-const char *sst_err_to_str(enum psa_sst_err_t err)
+const char *psa_ps_status_to_str(psa_ps_status_t status)
 {
-    switch (err) {
-    case PSA_SST_ERR_SUCCESS:
-        return "PSA_SST_ERR_SUCCESS";
-    case PSA_SST_ERR_ASSET_NOT_PREPARED:
-        return "PSA_SST_ERR_ASSET_NOT_PREPARED";
-    case PSA_SST_ERR_ASSET_NOT_FOUND:
-        return "PSA_SST_ERR_ASSET_NOT_FOUND";
-    case PSA_SST_ERR_PARAM_ERROR:
-        return "PSA_SST_ERR_PARAM_ERROR";
-    case PSA_SST_ERR_STORAGE_SYSTEM_FULL:
-        return "PSA_SST_ERR_STORAGE_SYSTEM_FULL";
-    case PSA_SST_ERR_SYSTEM_ERROR:
-        return "PSA_SST_ERR_SYSTEM_ERROR";
-    case PSA_SST_ERR_FORCE_INT_SIZE:
-        return "PSA_SST_ERR_FORCE_INT_SIZE";
-    /* default:  The default is not defined intentionally to force the
-     *           compiler to check that all the enumeration values are
-     *           covered in the switch.
-     */
+    switch (status) {
+    case PSA_PS_SUCCESS:
+        return "PSA_PS_SUCCESS";
+    case PSA_PS_ERROR_WRITE_ONCE:
+        return "PSA_PS_ERROR_WRITE_ONCE";
+    case PSA_PS_ERROR_FLAGS_NOT_SUPPORTED:
+        return "PSA_PS_ERROR_FLAGS_NOT_SUPPORTED";
+    case PSA_PS_ERROR_INSUFFICIENT_SPACE:
+        return "PSA_PS_ERROR_INSUFFICIENT_SPACE";
+    case PSA_PS_ERROR_STORAGE_FAILURE:
+        return "PSA_PS_ERROR_STORAGE_FAILURE";
+    case PSA_PS_ERROR_UID_NOT_FOUND:
+        return "PSA_PS_ERROR_UID_NOT_FOUND";
+    case PSA_PS_ERROR_INCORRECT_SIZE:
+        return "PSA_PS_ERROR_INCORRECT_SIZE";
+    case PSA_PS_ERROR_OFFSET_INVALID:
+        return "PSA_PS_ERROR_OFFSET_INVALID";
+    case PSA_PS_ERROR_INVALID_ARGUMENT:
+        return "PSA_PS_ERROR_INVALID_ARGUMENT";
+    case PSA_PS_ERROR_DATA_CORRUPT:
+        return "PSA_PS_ERROR_DATA_CORRUPT";
+    case PSA_PS_ERROR_AUTH_FAILED:
+        return "PSA_PS_ERROR_AUTH_FAILED";
+    case PSA_PS_ERROR_OPERATION_FAILED:
+        return "PSA_PS_ERROR_OPERATION_FAILED";
+    case PSA_PS_ERROR_NOT_SUPPORTED:
+        return "PSA_PS_ERROR_NOT_SUPPORTED";
+    default:
+        return "Unknown error";
     }
 }
 
diff --git a/test/framework/test_framework_helpers.h b/test/framework/test_framework_helpers.h
index c0e7a7a..03eb3dc 100755
--- a/test/framework/test_framework_helpers.h
+++ b/test/framework/test_framework_helpers.h
@@ -1,22 +1,21 @@
 /*
- * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
  */
 
-#ifndef __HELPERS_H__
-#define __HELPERS_H__
+#ifndef __TEST_FRAMEWORK_HELPERS_H__
+#define __TEST_FRAMEWORK_HELPERS_H__
+
+#include <stdint.h>
+#include "psa_protected_storage.h"
+#include "test_framework.h"
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include <stdint.h>
-#include "tfm_sst_defs.h"
-#include "secure_fw/services/secure_storage/sst_asset_management.h"
-#include "test_framework.h"
-
 enum serial_color_t {
     BLACK = 0,
     RED = 1,
@@ -29,13 +28,13 @@
 };
 
 /**
- * \brief Translates psa_sst_err_t into a string.
+ * \brief Translates psa_ps_status_t into a string.
  *
- * \param[in] err  psa_sst_err_t error value.
+ * \param[in] err  psa_ps_status_t status value.
  *
- * \return psa_sst_err_t as string.
+ * \return psa_ps_status_t as string.
  */
-const char *sst_err_to_str(enum psa_sst_err_t err);
+const char *psa_ps_status_to_str(psa_ps_status_t status);
 
 /**
  * \brief Translates asset permissions into a string.
@@ -59,4 +58,4 @@
 }
 #endif
 
-#endif /* __HELPERS_H__ */
+#endif /* __TEST_FRAMEWORK_HELPERS_H__ */
diff --git a/test/suites/sst/CMakeLists.inc b/test/suites/sst/CMakeLists.inc
index c293132..dcd5e32 100644
--- a/test/suites/sst/CMakeLists.inc
+++ b/test/suites/sst/CMakeLists.inc
@@ -1,5 +1,5 @@
 #-------------------------------------------------------------------------------
-# Copyright (c) 2017-2018, Arm Limited. All rights reserved.
+# Copyright (c) 2017-2019, Arm Limited. All rights reserved.
 #
 # SPDX-License-Identifier: BSD-3-Clause
 #
@@ -27,36 +27,44 @@
 if (NOT DEFINED ENABLE_SECURE_STORAGE_SERVICE_TESTS)
 	message(FATAL_ERROR "Incomplete build configuration: ENABLE_SECURE_STORAGE_SERVICE_TESTS is undefined. ")
 elseif (ENABLE_SECURE_STORAGE_SERVICE_TESTS)
-	list(APPEND ALL_SRC_C_S "${SECURE_STORAGE_TEST_DIR}/secure/s_test_helpers.c"
-			"${SECURE_STORAGE_TEST_DIR}/secure/sst_sec_interface_testsuite.c"
-			"${SECURE_STORAGE_TEST_DIR}/secure/sst_reliability_testsuite.c"
+	if (NOT DEFINED PSA_PROTECTED_STORAGE)
+		message(FATAL_ERROR "Incomplete build configuration: PSA_PROTECTED_STORAGE is undefined.")
+
+	elseif (PSA_PROTECTED_STORAGE)
+		set_property(SOURCE ${ALL_SRC_C_S} APPEND PROPERTY COMPILE_DEFINITIONS PSA_PROTECTED_STORAGE)
+		set_property(SOURCE ${ALL_SRC_C_NS} APPEND PROPERTY COMPILE_DEFINITIONS PSA_PROTECTED_STORAGE)
+
+	else()
+		list(APPEND ALL_SRC_C_S "${SECURE_STORAGE_TEST_DIR}/secure/sst_sec_interface_testsuite.c"
+				"${SECURE_STORAGE_TEST_DIR}/secure/sst_reliability_testsuite.c"
+			)
+		if (SST_ROLLBACK_PROTECTION AND SST_ENCRYPTION AND TFM_LVL EQUAL 1)
+			list(APPEND ALL_SRC_C_S "${SECURE_STORAGE_TEST_DIR}/secure/sst_rollback_protection_testsuite.c"
+						"${SECURE_STORAGE_TEST_DIR}/secure/nv_counters/test_sst_nv_counters.c")
+		endif()
+
+		list(APPEND ALL_SRC_C_NS
+				"${SECURE_STORAGE_TEST_DIR}/non_secure/ns_test_helpers.c"
+				"${SECURE_STORAGE_TEST_DIR}/non_secure/sst_ns_interface_testsuite.c"
 		)
-	if (SST_ROLLBACK_PROTECTION AND SST_ENCRYPTION AND TFM_LVL EQUAL 1)
-		list(APPEND ALL_SRC_C_S "${SECURE_STORAGE_TEST_DIR}/secure/sst_rollback_protection_testsuite.c"
-					"${SECURE_STORAGE_TEST_DIR}/secure/nv_counters/test_sst_nv_counters.c")
-	endif()
 
-	list(APPEND ALL_SRC_C_NS
-			"${SECURE_STORAGE_TEST_DIR}/non_secure/ns_test_helpers.c"
-			"${SECURE_STORAGE_TEST_DIR}/non_secure/sst_ns_interface_testsuite.c"
-	)
+		if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
+			message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.")
+		elseif (TFM_NS_CLIENT_IDENTIFICATION)
+			list(APPEND ALL_SRC_C_NS "${SECURE_STORAGE_TEST_DIR}/non_secure/sst_policy_testsuite.c")
+			set_property(SOURCE ${ALL_SRC_C_NS} APPEND PROPERTY COMPILE_DEFINITIONS TFM_NS_CLIENT_IDENTIFICATION)
+		endif()
 
-	if (NOT DEFINED TFM_NS_CLIENT_IDENTIFICATION)
-		message(FATAL_ERROR "Incomplete build configuration: TFM_NS_CLIENT_IDENTIFICATION is undefined.")
-	elseif (TFM_NS_CLIENT_IDENTIFICATION)
-		list(APPEND ALL_SRC_C_NS "${SECURE_STORAGE_TEST_DIR}/non_secure/sst_policy_testsuite.c")
-		set_property(SOURCE ${ALL_SRC_C_NS} APPEND PROPERTY COMPILE_DEFINITIONS TFM_NS_CLIENT_IDENTIFICATION)
-	endif()
+		if (NOT DEFINED TFM_PARTITION_TEST_SST)
+			message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined.")
+		elseif (TFM_PARTITION_TEST_SST AND TFM_NS_CLIENT_IDENTIFICATION)
+			list(APPEND ALL_SRC_C_NS "${SECURE_STORAGE_TEST_DIR}/non_secure/sst_ns_ref_access_testsuite.c")
+		endif()
 
-	if (NOT DEFINED TFM_PARTITION_TEST_SST)
-		message(FATAL_ERROR "Incomplete build configuration: TFM_PARTITION_TEST_SST is undefined.")
-	elseif (TFM_PARTITION_TEST_SST AND TFM_NS_CLIENT_IDENTIFICATION)
-		list(APPEND ALL_SRC_C_NS "${SECURE_STORAGE_TEST_DIR}/non_secure/sst_ns_ref_access_testsuite.c")
-	endif()
-
-	if (SST_ENABLE_PARTIAL_ASSET_RW)
-		set_property(SOURCE ${ALL_SRC_C_S} APPEND PROPERTY COMPILE_DEFINITIONS SST_ENABLE_PARTIAL_ASSET_RW)
-		set_property(SOURCE ${ALL_SRC_C_NS} APPEND PROPERTY COMPILE_DEFINITIONS SST_ENABLE_PARTIAL_ASSET_RW)
+		if (SST_ENABLE_PARTIAL_ASSET_RW)
+			set_property(SOURCE ${ALL_SRC_C_S} APPEND PROPERTY COMPILE_DEFINITIONS SST_ENABLE_PARTIAL_ASSET_RW)
+			set_property(SOURCE ${ALL_SRC_C_NS} APPEND PROPERTY COMPILE_DEFINITIONS SST_ENABLE_PARTIAL_ASSET_RW)
+		endif()
 	endif()
 
 	if (NOT SST_RAM_FS AND NOT REFERENCE_PLATFORM)
diff --git a/test/suites/sst/non_secure/ns_test_helpers.h b/test/suites/sst/non_secure/ns_test_helpers.h
index fe0798b..e18d812 100644
--- a/test/suites/sst/non_secure/ns_test_helpers.h
+++ b/test/suites/sst/non_secure/ns_test_helpers.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -17,18 +17,6 @@
 #define CONCAT_(x, y) x ## y
 #define CONCAT(x, y) CONCAT_(x, y)
 
-/*!
- * \struct sst_test_buf_t
- *
- * \brief Structure to store test data information to read/write from/to asset.
- *
- */
-struct sst_test_buf_t {
-    uint8_t *data;   /*!< Address of input/output data */
-    uint32_t size;   /*!< Size of input/output data */
-    uint32_t offset; /*!< Offset within asset */
-};
-
 /**
  * Several tests use a buffer to read back data from an asset. This buffer is
  * larger than the size of the asset data by PADDING_SIZE bytes. This allows
@@ -41,7 +29,7 @@
  * Then a correct and successful read would give this result: "XXXXAAAAXXXX"
  * (Assuming a PADDING_SIZE of 8)
  */
-#define BUFFER_SIZE SST_ASSET_MAX_SIZE_AES_KEY_192
+#define BUFFER_SIZE 24
 #define PADDING_SIZE 8
 #define HALF_PADDING_SIZE 4
 
diff --git a/test/suites/sst/secure/s_test_helpers.c b/test/suites/sst/secure/s_test_helpers.c
deleted file mode 100755
index 4a02d03..0000000
--- a/test/suites/sst/secure/s_test_helpers.c
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- *
- */
-
-#include "s_test_helpers.h"
-
-#include <stdio.h>
-#include <string.h>
-
-#include "test/framework/test_framework.h"
-#include "secure_fw/services/secure_storage/sst_object_system.h"
-
-uint32_t prepare_test_ctx(struct test_result_t *ret)
-{
-    /* Wipes secure storage area */
-    sst_system_wipe_all();
-
-    /* Prepares secure storage area before write */
-    if (sst_system_prepare() != PSA_SST_ERR_SUCCESS) {
-        TEST_FAIL("Wiped system should be preparable");
-        return 1;
-    }
-
-    return 0;
-}
diff --git a/test/suites/sst/secure/s_test_helpers.h b/test/suites/sst/secure/s_test_helpers.h
index 5fb913f..1d8d664 100755
--- a/test/suites/sst/secure/s_test_helpers.h
+++ b/test/suites/sst/secure/s_test_helpers.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017-2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2017-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -12,20 +12,6 @@
 extern "C" {
 #endif
 
-#include "test/framework/test_framework.h"
-
-/*!
- * \struct sst_test_buf_t
- *
- * \brief Structure to store test data information to read/write from/to asset.
- *
- */
-struct sst_test_buf_t {
-    uint8_t *data;   /*!< Address of input/output data */
-    uint32_t size;   /*!< Size of input/output data */
-    uint32_t offset; /*!< Offset within asset */
-};
-
 /**
  * Several tests use a buffer to read back data from an asset. This buffer is
  * larger than the size of the asset data by PADDING_SIZE bytes. This allows
@@ -38,23 +24,13 @@
  * Then a correct and successful read would give this result: "XXXXAAAAXXXX"
  * (Assuming a PADDING_SIZE of 8)
  */
-#define BUFFER_SIZE SST_ASSET_MAX_SIZE_AES_KEY_192
+#define BUFFER_SIZE 24
 #define PADDING_SIZE 8
 #define HALF_PADDING_SIZE 4
 
 #define BUFFER_PLUS_PADDING_SIZE (BUFFER_SIZE + PADDING_SIZE)
 #define BUFFER_PLUS_HALF_PADDING_SIZE (BUFFER_SIZE + HALF_PADDING_SIZE)
 
-/**
- * \brief Prepares secure storage area for the new tests. It executes wipes and
- *        prepare.
- *
- * \param[out] ret  Pointer to the test result structure.
- *
- * \return 0 if the context is correcly prepared. Otherwise 1.
- */
-uint32_t prepare_test_ctx(struct test_result_t *ret);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/test/test_services/tfm_secure_client_service/tfm_secure_client_service.c b/test/test_services/tfm_secure_client_service/tfm_secure_client_service.c
index b17f6f3..280e1af 100644
--- a/test/test_services/tfm_secure_client_service/tfm_secure_client_service.c
+++ b/test/test_services/tfm_secure_client_service/tfm_secure_client_service.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -12,11 +12,11 @@
  * \brief Service initialisation function. No special initialisation is
  *        required.
  *
- * \return Returns error code as specified in \ref psa_sst_err_t
+ * \return Returns 0 on success
  */
-enum psa_sst_err_t tfm_secure_client_service_init(void)
+int32_t tfm_secure_client_service_init(void)
 {
-    return PSA_SST_ERR_SUCCESS;
+    return 0;
 }
 
 int32_t tfm_secure_client_service_sfn_run_tests(void)
diff --git a/test/test_services/tfm_secure_client_service/tfm_secure_client_service.h b/test/test_services/tfm_secure_client_service/tfm_secure_client_service.h
index d45b92a..baa650a 100644
--- a/test/test_services/tfm_secure_client_service/tfm_secure_client_service.h
+++ b/test/test_services/tfm_secure_client_service/tfm_secure_client_service.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Arm Limited. All rights reserved.
+ * Copyright (c) 2018-2019, Arm Limited. All rights reserved.
  *
  * SPDX-License-Identifier: BSD-3-Clause
  *
@@ -9,7 +9,6 @@
 #define __TFM_SECURE_CLIENT_SERVICE_H__
 
 #include <stdint.h>
-#include "tfm_sst_defs.h"
 
 #ifdef __cplusplus
 extern "C" {