Add stubs for unsupported PSA Crypto API client operations
The psa-api-test/crypto deployment (formally called ts-arch-test)
is modified to use PSA API client methods instead of MbedTLS
directly. This change is the first step to adding missing
operations that the PSA arch tests exercise.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: I6179c389d3176e649290e373ddfa9d9f8974770c
diff --git a/deployments/psa-api-test/crypto/arm-linux/CMakeLists.txt b/deployments/psa-api-test/crypto/arm-linux/CMakeLists.txt
new file mode 100644
index 0000000..ea1b460
--- /dev/null
+++ b/deployments/psa-api-test/crypto/arm-linux/CMakeLists.txt
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../../deployment.cmake REQUIRED)
+
+#-------------------------------------------------------------------------------
+# The CMakeLists.txt for building the psa-api-test deployment for arm-linux
+#
+# Used for building and running psa arch tests on an Arm based Linux device
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/arm-linux/env.cmake)
+project(trusted-services LANGUAGES CXX C)
+add_executable(psa-api-test)
+target_include_directories(psa-api-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# psa-api-test/crypto
+#-------------------------------------------------------------------------------
+include(../crypto-api-test.cmake REQUIRED)
diff --git a/deployments/psa-api-test/crypto/crypto-api-test.cmake b/deployments/psa-api-test/crypto/crypto-api-test.cmake
new file mode 100644
index 0000000..5ad0930
--- /dev/null
+++ b/deployments/psa-api-test/crypto/crypto-api-test.cmake
@@ -0,0 +1,37 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+
+#-------------------------------------------------------------------------------
+# Define test suite to build. Used by the psa_arch_tests external component
+# to configure what test suite gets built.
+#-------------------------------------------------------------------------------
+set(TS_ARCH_TEST_SUITE CRYPTO CACHE STRING "Arch test suite")
+
+#-------------------------------------------------------------------------------
+# Crypto specific components
+#
+#-------------------------------------------------------------------------------
+add_components(
+ TARGET "psa-api-test"
+ BASE_DIR ${TS_ROOT}
+ COMPONENTS
+ "components/service/crypto/include"
+ "components/service/crypto/client/psa"
+)
+
+target_sources(psa-api-test PRIVATE
+ ${TS_ROOT}/deployments/psa-api-test/crypto/crypto_locator.c
+)
+
+# Export psa crypto API
+list(APPEND PSA_ARCH_TESTS_EXTERNAL_INCLUDE_PATHS ${PSA_CRYPTO_API_INCLUDE})
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# psa-api-test
+#-------------------------------------------------------------------------------
+include(../../psa-api-test.cmake REQUIRED)
diff --git a/deployments/psa-api-test/crypto/crypto_locator.c b/deployments/psa-api-test/crypto/crypto_locator.c
new file mode 100644
index 0000000..8571b23
--- /dev/null
+++ b/deployments/psa-api-test/crypto/crypto_locator.c
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stddef.h>
+#include <service_locator.h>
+#include <service/crypto/client/psa/psa_crypto_client.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
+#include "../service_under_test.h"
+
+/* RPC context */
+static rpc_session_handle session_handle = NULL;
+static struct service_context *crypto_service_context = NULL;
+
+
+int locate_service_under_test(void)
+{
+ int status = -1;
+
+ if (!session_handle && !crypto_service_context) {
+
+ struct rpc_caller *caller;
+
+ crypto_service_context =
+ service_locator_query("sn:trustedfirmware.org:crypto:0", &status);
+
+ if (crypto_service_context) {
+
+ session_handle =
+ service_context_open(crypto_service_context, TS_RPC_ENCODING_PACKED_C, &caller);
+
+ if (session_handle) {
+
+ psa_crypto_client_init(caller);
+ status = 0;
+ }
+ else {
+
+ status = -1;
+ relinquish_service_under_test();
+ }
+ }
+ }
+
+ return status;
+}
+
+void relinquish_service_under_test(void)
+{
+ psa_crypto_client_deinit();
+
+ if (crypto_service_context && session_handle) {
+
+ service_context_close(crypto_service_context, session_handle);
+ session_handle = NULL;
+ }
+
+ if (crypto_service_context) {
+
+ service_context_relinquish(crypto_service_context);
+ crypto_service_context = NULL;
+ }
+}
diff --git a/deployments/psa-api-test/crypto/linux-pc/CMakeLists.txt b/deployments/psa-api-test/crypto/linux-pc/CMakeLists.txt
new file mode 100644
index 0000000..1737976
--- /dev/null
+++ b/deployments/psa-api-test/crypto/linux-pc/CMakeLists.txt
@@ -0,0 +1,32 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+cmake_minimum_required(VERSION 3.16)
+include(../../../deployment.cmake REQUIRED)
+
+# Prevents symbols in the psa-api-test executable overriding symbols with
+# with same name in libts during dyanmic linking performed by the program
+# loader. This avoid psa crypto api symbols provided by the mbedcrypto
+# library from being overridden by the same symbols in the psa-api-test
+# executable.
+set(CMAKE_C_VISIBILITY_PRESET hidden)
+
+#-------------------------------------------------------------------------------
+# The CMakeLists.txt for building the psa-api-test deployment for linux-pc
+#
+# Used for building and running psa arch tests in a native PC enviroment.
+# Tests can be run by running the built executable called "psa-api-test"
+#-------------------------------------------------------------------------------
+include(${TS_ROOT}/environments/linux-pc/env.cmake)
+project(trusted-services LANGUAGES CXX C)
+add_executable(psa-api-test)
+target_include_directories(psa-api-test PRIVATE "${TOP_LEVEL_INCLUDE_DIRS}")
+
+#-------------------------------------------------------------------------------
+# Extend with components that are common across all deployments of
+# psa-api-test/crypto
+#-------------------------------------------------------------------------------
+include(../crypto-api-test.cmake REQUIRED)