aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Hall <julian.hall@arm.com>2021-08-09 14:28:13 +0100
committerGyorgy Szing <Gyorgy.Szing@arm.com>2021-10-06 00:49:02 +0200
commitc6e7a8ad01e0e6f7164b52d904ed3816426f7bd8 (patch)
tree4248cf9ebdf76addf94ace9cfa95a6cc2ca35af0
parentc1f8b6e628d863d8160c18bfe7760704fb5fa612 (diff)
downloadtrusted-services-c6e7a8ad01e0e6f7164b52d904ed3816426f7bd8.tar.gz
Establish pattern for extending crypto service tests
To match the modular extensions to the crypto service provider, this change establishes a pattern for extending service level tests in a similarly modular way. By componentizing groups of test cases, a subset of tests may be used to match the service provider under test. The hash crypto extension is used to establish the pattern. Note that because the Cpp crypto clients now use the same crypto caller as the PSA Crypto client, the explicit PSA Crypto API client is no longer needed and has been removed. Signed-off-by: Julian Hall <julian.hall@arm.com> Change-Id: Ic8f975c9061f8aa0377dd59614862a4745a8c38c
-rw-r--r--components/service/crypto/client/caller/packed-c/crypto_caller_hash.h2
-rw-r--r--components/service/crypto/client/cpp/crypto_client.cpp30
-rw-r--r--components/service/crypto/client/cpp/crypto_client.h14
-rw-r--r--components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp28
-rw-r--r--components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h43
-rw-r--r--components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp25
-rw-r--r--components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h13
-rw-r--r--components/service/crypto/test/service/component.cmake1
-rw-r--r--components/service/crypto/test/service/crypto_service_scenarios.cpp27
-rw-r--r--components/service/crypto/test/service/crypto_service_scenarios.h1
-rw-r--r--components/service/crypto/test/service/extension/hash/component.cmake (renamed from components/service/crypto/test/service/psa_crypto_api/component.cmake)4
-rw-r--r--components/service/crypto/test/service/extension/hash/hash_service_scenarios.cpp136
-rw-r--r--components/service/crypto/test/service/extension/hash/hash_service_scenarios.h32
-rw-r--r--components/service/crypto/test/service/extension/hash/hash_test_vectors.cpp (renamed from components/service/crypto/test/service/crypto_test_vectors.cpp)6
-rw-r--r--components/service/crypto/test/service/extension/hash/hash_test_vectors.h (renamed from components/service/crypto/test/service/crypto_test_vectors.h)4
-rw-r--r--components/service/crypto/test/service/extension/hash/packed-c/component.cmake13
-rw-r--r--components/service/crypto/test/service/extension/hash/packed-c/hash_service_packedc_tests.cpp68
-rw-r--r--components/service/crypto/test/service/packed-c/crypto_service_packedc_tests.cpp5
-rw-r--r--components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_client.cpp178
-rw-r--r--components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_client.h68
-rw-r--r--components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_tests.cpp108
-rw-r--r--deployments/component-test/component-test.cmake2
-rw-r--r--deployments/libts/linux-pc/CMakeLists.txt1
-rw-r--r--deployments/ts-demo/ts-demo.cmake1
-rw-r--r--deployments/ts-service-test/ts-service-test.cmake3
25 files changed, 398 insertions, 415 deletions
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_hash.h b/components/service/crypto/client/caller/packed-c/crypto_caller_hash.h
index b4904ea..9a332ff 100644
--- a/components/service/crypto/client/caller/packed-c/crypto_caller_hash.h
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_hash.h
@@ -340,7 +340,7 @@ static inline psa_status_t crypto_caller_hash_resume(struct service_client *cont
return PSA_ERROR_NOT_SUPPORTED;
}
-static inline size_t crypto_caller_hash_max_update_size(struct service_client *context)
+static inline size_t crypto_caller_hash_max_update_size(const struct service_client *context)
{
/* Returns the maximum number of bytes that may be
* carried as a parameter of the hash_update operation
diff --git a/components/service/crypto/client/cpp/crypto_client.cpp b/components/service/crypto/client/cpp/crypto_client.cpp
index 33eb7d1..3537c8a 100644
--- a/components/service/crypto/client/cpp/crypto_client.cpp
+++ b/components/service/crypto/client/cpp/crypto_client.cpp
@@ -5,31 +5,47 @@
*/
#include "crypto_client.h"
+#include <service/discovery/client/discovery_client.h>
#include <protocols/rpc/common/packed-c/status.h>
crypto_client::crypto_client() :
- m_client()
+ m_client()
{
- service_client_init(&m_client, NULL);
+ service_client_init(&m_client, NULL);
}
crypto_client::crypto_client(struct rpc_caller *caller) :
- m_client()
+ m_client()
{
- service_client_init(&m_client, caller);
+ service_client_init(&m_client, caller);
+
+ if (caller) {
+
+ discovery_client_get_service_info(&m_client);
+ }
}
crypto_client::~crypto_client()
{
- service_client_deinit(&m_client);
+ service_client_deinit(&m_client);
}
void crypto_client::set_caller(struct rpc_caller *caller)
{
- m_client.caller = caller;
+ m_client.caller = caller;
+
+ if (caller) {
+
+ discovery_client_get_service_info(&m_client);
+ }
}
int crypto_client::err_rpc_status() const
{
- return m_client.rpc_status;
+ return m_client.rpc_status;
+}
+
+struct service_info crypto_client::get_service_info() const
+{
+ return m_client.service_info;
}
diff --git a/components/service/crypto/client/cpp/crypto_client.h b/components/service/crypto/client/cpp/crypto_client.h
index 42085be..68d80ee 100644
--- a/components/service/crypto/client/cpp/crypto_client.h
+++ b/components/service/crypto/client/cpp/crypto_client.h
@@ -21,6 +21,7 @@ public:
virtual ~crypto_client();
int err_rpc_status() const;
+ struct service_info get_service_info() const;
/* Key lifecycle methods */
virtual psa_status_t generate_key(
@@ -89,6 +90,8 @@ public:
uint8_t *output, size_t output_size) = 0;
/* Hash methods */
+ virtual size_t hash_max_update_size() const = 0;
+
virtual psa_status_t hash_setup(
uint32_t *op_handle,
psa_algorithm_t alg) = 0;
@@ -101,6 +104,17 @@ public:
uint32_t op_handle,
uint8_t *hash, size_t hash_size, size_t *hash_length) = 0;
+ virtual psa_status_t hash_abort(
+ uint32_t op_handle) = 0;
+
+ virtual psa_status_t hash_verify(
+ uint32_t op_handle,
+ const uint8_t *hash, size_t hash_length) = 0;
+
+ virtual psa_status_t hash_clone(
+ uint32_t source_op_handle,
+ uint32_t *target_op_handle) = 0;
+
protected:
crypto_client();
crypto_client(struct rpc_caller *caller);
diff --git a/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp
index 74c07db..09ff7af 100644
--- a/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp
+++ b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp
@@ -137,6 +137,11 @@ psa_status_t packedc_crypto_client::generate_random(
output, output_size);
}
+size_t packedc_crypto_client::hash_max_update_size() const
+{
+ return crypto_caller_hash_max_update_size(&m_client);
+}
+
psa_status_t packedc_crypto_client::hash_setup(
uint32_t *op_handle,
psa_algorithm_t alg)
@@ -160,3 +165,26 @@ psa_status_t packedc_crypto_client::hash_finish(
return crypto_caller_hash_finish(&m_client,
op_handle, hash, hash_size, hash_length);
}
+
+psa_status_t packedc_crypto_client::hash_abort(
+ uint32_t op_handle)
+{
+ return crypto_caller_hash_abort(&m_client,
+ op_handle);
+}
+
+psa_status_t packedc_crypto_client::hash_verify(
+ uint32_t op_handle,
+ const uint8_t *hash, size_t hash_length)
+{
+ return crypto_caller_hash_verify(&m_client,
+ op_handle, hash, hash_length);
+}
+
+psa_status_t packedc_crypto_client::hash_clone(
+ uint32_t source_op_handle,
+ uint32_t *target_op_handle)
+{
+ return crypto_caller_hash_clone(&m_client,
+ source_op_handle, target_op_handle);
+}
diff --git a/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h
index 0cbc666..bd6a484 100644
--- a/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h
+++ b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h
@@ -75,21 +75,42 @@ public:
const uint8_t *salt, size_t salt_length,
uint8_t *output, size_t output_size, size_t *output_length);
- psa_status_t asymmetric_decrypt(psa_key_id_t id, psa_algorithm_t alg,
- const uint8_t *input, size_t input_length,
- const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length);
+ psa_status_t asymmetric_decrypt(
+ psa_key_id_t id,
+ psa_algorithm_t alg,
+ const uint8_t *input, size_t input_length,
+ const uint8_t *salt, size_t salt_length,
+ uint8_t *output, size_t output_size, size_t *output_length);
/* Random number generation */
- psa_status_t generate_random(uint8_t *output, size_t output_size);
+ psa_status_t generate_random(
+ uint8_t *output, size_t output_size);
/* Hash methods */
- psa_status_t hash_setup(uint32_t *op_handle,
- psa_algorithm_t alg);
- psa_status_t hash_update(uint32_t op_handle,
- const uint8_t *input, size_t input_length);
- psa_status_t hash_finish(uint32_t op_handle,
- uint8_t *hash, size_t hash_size, size_t *hash_length);
+ size_t hash_max_update_size() const;
+
+ psa_status_t hash_setup(
+ uint32_t *op_handle,
+ psa_algorithm_t alg);
+
+ psa_status_t hash_update(
+ uint32_t op_handle,
+ const uint8_t *input, size_t input_length);
+
+ psa_status_t hash_finish(
+ uint32_t op_handle,
+ uint8_t *hash, size_t hash_size, size_t *hash_length);
+
+ psa_status_t hash_abort(
+ uint32_t op_handle);
+
+ psa_status_t hash_verify(
+ uint32_t op_handle,
+ const uint8_t *hash, size_t hash_length);
+
+ psa_status_t hash_clone(
+ uint32_t source_op_handle,
+ uint32_t *target_op_handle);
};
diff --git a/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp
index 7629f7d..db9c0e9 100644
--- a/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp
+++ b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp
@@ -732,6 +732,11 @@ psa_status_t protobuf_crypto_client::generate_random(uint8_t *output, size_t out
return psa_status;
}
+size_t protobuf_crypto_client::hash_max_update_size() const
+{
+ return 0;
+}
+
psa_status_t protobuf_crypto_client::hash_setup(uint32_t *op_handle,
psa_algorithm_t alg)
{
@@ -750,6 +755,26 @@ psa_status_t protobuf_crypto_client::hash_finish(uint32_t op_handle,
return PSA_ERROR_NOT_SUPPORTED;
}
+psa_status_t protobuf_crypto_client::hash_abort(
+ uint32_t op_handle)
+{
+ return PSA_ERROR_NOT_SUPPORTED;
+}
+
+psa_status_t protobuf_crypto_client::hash_verify(
+ uint32_t op_handle,
+ const uint8_t *hash, size_t hash_length)
+{
+ return PSA_ERROR_NOT_SUPPORTED;
+}
+
+psa_status_t protobuf_crypto_client::hash_clone(
+ uint32_t source_op_handle,
+ uint32_t *target_op_handle)
+{
+ return PSA_ERROR_NOT_SUPPORTED;
+}
+
void protobuf_crypto_client::translate_key_attributes(ts_crypto_KeyAttributes &proto_attributes,
const psa_key_attributes_t &psa_attributes)
{
diff --git a/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h
index c04d82d..0221597 100644
--- a/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h
+++ b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h
@@ -87,6 +87,8 @@ public:
uint8_t *output, size_t output_size);
/* Hash methods */
+ size_t hash_max_update_size() const;
+
psa_status_t hash_setup(
uint32_t *op_handle,
psa_algorithm_t alg);
@@ -99,6 +101,17 @@ public:
uint32_t op_handle,
uint8_t *hash, size_t hash_size, size_t *hash_length);
+ psa_status_t hash_abort(
+ uint32_t op_handle);
+
+ psa_status_t hash_verify(
+ uint32_t op_handle,
+ const uint8_t *hash, size_t hash_length);
+
+ psa_status_t hash_clone(
+ uint32_t source_op_handle,
+ uint32_t *target_op_handle);
+
private:
void translate_key_attributes(
diff --git a/components/service/crypto/test/service/component.cmake b/components/service/crypto/test/service/component.cmake
index be08793..e64379a 100644
--- a/components/service/crypto/test/service/component.cmake
+++ b/components/service/crypto/test/service/component.cmake
@@ -11,5 +11,4 @@ endif()
target_sources(${TGT} PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/crypto_service_scenarios.cpp"
"${CMAKE_CURRENT_LIST_DIR}/crypto_service_limit_tests.cpp"
- "${CMAKE_CURRENT_LIST_DIR}/crypto_test_vectors.cpp"
)
diff --git a/components/service/crypto/test/service/crypto_service_scenarios.cpp b/components/service/crypto/test/service/crypto_service_scenarios.cpp
index ed33aad..63a231f 100644
--- a/components/service/crypto/test/service/crypto_service_scenarios.cpp
+++ b/components/service/crypto/test/service/crypto_service_scenarios.cpp
@@ -10,7 +10,6 @@
#include <vector>
#include <CppUTest/TestHarness.h>
#include "crypto_service_scenarios.h"
-#include "crypto_test_vectors.h"
crypto_service_scenarios::crypto_service_scenarios(crypto_client *crypto_client) :
m_crypto_client(crypto_client)
@@ -365,32 +364,6 @@ void crypto_service_scenarios::asymEncryptDecryptWithSalt()
CHECK_EQUAL(PSA_SUCCESS, status);
}
-void crypto_service_scenarios::calculateHash()
-{
- psa_status_t status;
- std::vector<uint8_t> input;
- std::vector<uint8_t> expected_output;
- uint8_t output[PSA_HASH_MAX_SIZE];
- size_t output_len;
-
- crypto_test_vectors::plaintext_1_len_610(input);
- crypto_test_vectors::sha256_1(expected_output);
-
- uint32_t op_handle = 0;
-
- status = m_crypto_client->hash_setup(&op_handle, PSA_ALG_SHA_256);
- CHECK_EQUAL(PSA_SUCCESS, status);
-
- status = m_crypto_client->hash_update(op_handle, &input[0], input.size());
- CHECK_EQUAL(PSA_SUCCESS, status);
-
- status = m_crypto_client->hash_finish(op_handle, output, sizeof(output), &output_len);
- CHECK_EQUAL(PSA_SUCCESS, status);
-
- UNSIGNED_LONGS_EQUAL(expected_output.size(), output_len);
- MEMCMP_EQUAL(&expected_output[0], &output[0], output_len);
-}
-
void crypto_service_scenarios::generateRandomNumbers()
{
psa_status_t status;
diff --git a/components/service/crypto/test/service/crypto_service_scenarios.h b/components/service/crypto/test/service/crypto_service_scenarios.h
index ddfaa62..648baae 100644
--- a/components/service/crypto/test/service/crypto_service_scenarios.h
+++ b/components/service/crypto/test/service/crypto_service_scenarios.h
@@ -26,7 +26,6 @@ public:
void exportPublicKey();
void generatePersistentKeys();
void generateVolatileKeys();
- void calculateHash();
private:
crypto_client *m_crypto_client;
diff --git a/components/service/crypto/test/service/psa_crypto_api/component.cmake b/components/service/crypto/test/service/extension/hash/component.cmake
index 5fb9a17..5709b87 100644
--- a/components/service/crypto/test/service/psa_crypto_api/component.cmake
+++ b/components/service/crypto/test/service/extension/hash/component.cmake
@@ -9,6 +9,6 @@ if (NOT DEFINED TGT)
endif()
target_sources(${TGT} PRIVATE
- "${CMAKE_CURRENT_LIST_DIR}/psa_crypto_api_tests.cpp"
- "${CMAKE_CURRENT_LIST_DIR}/psa_crypto_api_client.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/hash_service_scenarios.cpp"
+ "${CMAKE_CURRENT_LIST_DIR}/hash_test_vectors.cpp"
)
diff --git a/components/service/crypto/test/service/extension/hash/hash_service_scenarios.cpp b/components/service/crypto/test/service/extension/hash/hash_service_scenarios.cpp
new file mode 100644
index 0000000..f76d59e
--- /dev/null
+++ b/components/service/crypto/test/service/extension/hash/hash_service_scenarios.cpp
@@ -0,0 +1,136 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <string>
+#include <cstring>
+#include <cstdint>
+#include <vector>
+#include <CppUTest/TestHarness.h>
+#include "hash_service_scenarios.h"
+#include "hash_test_vectors.h"
+
+hash_service_scenarios::hash_service_scenarios(crypto_client *crypto_client) :
+ m_crypto_client(crypto_client),
+ m_ref_input(NULL)
+{
+
+}
+
+hash_service_scenarios::~hash_service_scenarios()
+{
+ delete m_crypto_client;
+ m_crypto_client = NULL;
+
+ delete [] m_ref_input;
+ m_ref_input = NULL;
+}
+
+void hash_service_scenarios::create_ref_input(size_t size)
+{
+ m_ref_input = new uint8_t[size];
+ memset(m_ref_input, 0x51, size);
+}
+
+void hash_service_scenarios::calculateHash()
+{
+ /* Calculates a hash and compares result against test vector */
+ psa_status_t status;
+ std::vector<uint8_t> input;
+ std::vector<uint8_t> expected_output;
+ uint8_t output[PSA_HASH_MAX_SIZE];
+ size_t output_len;
+
+ hash_test_vectors::plaintext_1_len_610(input);
+ hash_test_vectors::sha256_1(expected_output);
+
+ uint32_t op_handle = 0;
+
+ status = m_crypto_client->hash_setup(&op_handle, PSA_ALG_SHA_256);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ status = m_crypto_client->hash_update(op_handle, &input[0], input.size());
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ status = m_crypto_client->hash_finish(op_handle, output, sizeof(output), &output_len);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ UNSIGNED_LONGS_EQUAL(expected_output.size(), output_len);
+ MEMCMP_EQUAL(&expected_output[0], &output[0], output_len);
+}
+
+void hash_service_scenarios::hashAndVerify()
+{
+ /* Calculates and verifies hash over a large reference input */
+ size_t max_payload = m_crypto_client->hash_max_update_size();
+ size_t input_size = 9999;
+ size_t byte_count = 0;
+
+ create_ref_input(input_size);
+
+ uint8_t hash[PSA_HASH_MAX_SIZE];
+ size_t hash_len;
+
+ uint32_t op_handle = 0;
+ psa_status_t status;
+
+ status = m_crypto_client->hash_setup(&op_handle, PSA_ALG_SHA_256);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ while (byte_count < input_size) {
+
+ size_t bytes_left = input_size - byte_count;
+ size_t update_size = (bytes_left < max_payload) ?
+ bytes_left :
+ max_payload;
+
+ status = m_crypto_client->hash_update(op_handle, &m_ref_input[byte_count], update_size);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ byte_count += update_size;
+ }
+
+ uint32_t clone_op_handle = 0;
+
+ status = m_crypto_client->hash_clone(op_handle, &clone_op_handle);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ status = m_crypto_client->hash_finish(op_handle, hash, sizeof(hash), &hash_len);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ status = m_crypto_client->hash_verify(clone_op_handle, hash, hash_len);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+}
+
+void hash_service_scenarios::hashAbort()
+{
+ /* Aborts a hash operation after the first update */
+ size_t max_payload = m_crypto_client->hash_max_update_size();
+ size_t input_size = 15999;
+
+ create_ref_input(input_size);
+
+ uint8_t hash[PSA_HASH_MAX_SIZE];
+ size_t hash_len;
+
+ uint32_t op_handle = 0;
+ psa_status_t status;
+
+ status = m_crypto_client->hash_setup(&op_handle, PSA_ALG_SHA_256);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ size_t update_size = (input_size < max_payload) ?
+ input_size :
+ max_payload;
+
+ status = m_crypto_client->hash_update(op_handle, &m_ref_input[0], update_size);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ status = m_crypto_client->hash_abort(op_handle);
+ CHECK_EQUAL(PSA_SUCCESS, status);
+
+ status = m_crypto_client->hash_update(op_handle, &m_ref_input[0], update_size);
+ CHECK_EQUAL(PSA_ERROR_BAD_STATE, status);
+}
diff --git a/components/service/crypto/test/service/extension/hash/hash_service_scenarios.h b/components/service/crypto/test/service/extension/hash/hash_service_scenarios.h
new file mode 100644
index 0000000..84bd7d7
--- /dev/null
+++ b/components/service/crypto/test/service/extension/hash/hash_service_scenarios.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+#include <service/crypto/client/cpp/crypto_client.h>
+
+/*
+ * Service-level test scenarios for the hash extension to the crypto service
+ * that may be reused using different concrete crypto_clients to check
+ * end-to-end operation using different protocol serialization schemes.
+ */
+class hash_service_scenarios
+{
+public:
+ hash_service_scenarios(crypto_client *crypto_client);
+ ~hash_service_scenarios();
+
+ void calculateHash();
+ void hashAndVerify();
+ void hashAbort();
+
+private:
+
+ void create_ref_input(size_t size);
+
+ crypto_client *m_crypto_client;
+ uint8_t *m_ref_input;
+};
diff --git a/components/service/crypto/test/service/crypto_test_vectors.cpp b/components/service/crypto/test/service/extension/hash/hash_test_vectors.cpp
index 7f781b4..bc8b4fd 100644
--- a/components/service/crypto/test/service/crypto_test_vectors.cpp
+++ b/components/service/crypto/test/service/extension/hash/hash_test_vectors.cpp
@@ -5,9 +5,9 @@
*/
#include <cstring>
-#include "crypto_test_vectors.h"
+#include "hash_test_vectors.h"
-void crypto_test_vectors::plaintext_1_len_610(std::vector<uint8_t> &plaintext)
+void hash_test_vectors::plaintext_1_len_610(std::vector<uint8_t> &plaintext)
{
/* Plaintext 1 - data length 610 bytes */
const uint8_t data[] =
@@ -57,7 +57,7 @@ void crypto_test_vectors::plaintext_1_len_610(std::vector<uint8_t> &plaintext)
memcpy(&plaintext[0], data, sizeof(data));
}
-void crypto_test_vectors::sha256_1(std::vector<uint8_t> &hash)
+void hash_test_vectors::sha256_1(std::vector<uint8_t> &hash)
{
/* SHA256 for plaintext_1 */
const uint8_t data[] =
diff --git a/components/service/crypto/test/service/crypto_test_vectors.h b/components/service/crypto/test/service/extension/hash/hash_test_vectors.h
index 828fafb..71c396a 100644
--- a/components/service/crypto/test/service/crypto_test_vectors.h
+++ b/components/service/crypto/test/service/extension/hash/hash_test_vectors.h
@@ -9,9 +9,9 @@
/*
* A selection of test vectors in the form of blocks of plaintext,
- * ciphertext, expected hashes etc.
+ * expected hashes etc. for testing hash operations.
*/
-class crypto_test_vectors
+class hash_test_vectors
{
public:
diff --git a/components/service/crypto/test/service/extension/hash/packed-c/component.cmake b/components/service/crypto/test/service/extension/hash/packed-c/component.cmake
new file mode 100644
index 0000000..0110b1a
--- /dev/null
+++ b/components/service/crypto/test/service/extension/hash/packed-c/component.cmake
@@ -0,0 +1,13 @@
+#-------------------------------------------------------------------------------
+# Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+#
+# SPDX-License-Identifier: BSD-3-Clause
+#
+#-------------------------------------------------------------------------------
+if (NOT DEFINED TGT)
+ message(FATAL_ERROR "mandatory parameter TGT is not defined.")
+endif()
+
+target_sources(${TGT} PRIVATE
+ "${CMAKE_CURRENT_LIST_DIR}/hash_service_packedc_tests.cpp"
+ )
diff --git a/components/service/crypto/test/service/extension/hash/packed-c/hash_service_packedc_tests.cpp b/components/service/crypto/test/service/extension/hash/packed-c/hash_service_packedc_tests.cpp
new file mode 100644
index 0000000..6bc55cf
--- /dev/null
+++ b/components/service/crypto/test/service/extension/hash/packed-c/hash_service_packedc_tests.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h>
+#include <service/crypto/test/service/extension/hash/hash_service_scenarios.h>
+#include <protocols/rpc/common/packed-c/encoding.h>
+#include <service_locator.h>
+#include <CppUTest/TestHarness.h>
+
+/*
+ * Service-level hash tests that use the packed-c access protocol serialization
+ */
+TEST_GROUP(CryptoHashServicePackedcTests)
+{
+ void setup()
+ {
+ struct rpc_caller *caller;
+ int status;
+
+ m_rpc_session_handle = NULL;
+ m_crypto_service_context = NULL;
+ m_scenarios = NULL;
+
+ service_locator_init();
+
+ m_crypto_service_context = service_locator_query("sn:trustedfirmware.org:crypto:0", &status);
+ CHECK_TRUE(m_crypto_service_context);
+
+ m_rpc_session_handle = service_context_open(m_crypto_service_context, TS_RPC_ENCODING_PACKED_C, &caller);
+ CHECK_TRUE(m_rpc_session_handle);
+
+ m_scenarios = new hash_service_scenarios(new packedc_crypto_client(caller));
+ }
+
+ void teardown()
+ {
+ delete m_scenarios;
+ m_scenarios = NULL;
+
+ service_context_close(m_crypto_service_context, m_rpc_session_handle);
+ m_rpc_session_handle = NULL;
+
+ service_context_relinquish(m_crypto_service_context);
+ m_crypto_service_context = NULL;
+ }
+
+ rpc_session_handle m_rpc_session_handle;
+ struct service_context *m_crypto_service_context;
+ hash_service_scenarios *m_scenarios;
+};
+
+TEST(CryptoHashServicePackedcTests, calculateHash)
+{
+ m_scenarios->calculateHash();
+}
+
+TEST(CryptoHashServicePackedcTests, hashAndVerify)
+{
+ m_scenarios->hashAndVerify();
+}
+
+TEST(CryptoHashServicePackedcTests, hashAbort)
+{
+ m_scenarios->hashAbort();
+}
diff --git a/components/service/crypto/test/service/packed-c/crypto_service_packedc_tests.cpp b/components/service/crypto/test/service/packed-c/crypto_service_packedc_tests.cpp
index 61bb8c4..695929b 100644
--- a/components/service/crypto/test/service/packed-c/crypto_service_packedc_tests.cpp
+++ b/components/service/crypto/test/service/packed-c/crypto_service_packedc_tests.cpp
@@ -92,11 +92,6 @@ TEST(CryptoServicePackedcTests, asymEncryptDecryptWithSalt)
m_scenarios->asymEncryptDecryptWithSalt();
}
-TEST(CryptoServicePackedcTests, calculateHash)
-{
- m_scenarios->calculateHash();
-}
-
TEST(CryptoServicePackedcTests, generateRandomNumbers)
{
m_scenarios->generateRandomNumbers();
diff --git a/components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_client.cpp b/components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_client.cpp
deleted file mode 100644
index bfe5e5e..0000000
--- a/components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_client.cpp
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "psa_crypto_api_client.h"
-#include <service/crypto/client/psa/psa_crypto_client.h>
-
-
-psa_crypto_api_client::psa_crypto_api_client() :
- crypto_client()
-{
-
-}
-
-psa_crypto_api_client::~psa_crypto_api_client()
-{
-
-}
-
-psa_status_t psa_crypto_api_client::generate_key(const psa_key_attributes_t *attributes, psa_key_id_t *id)
-{
- psa_status_t psa_status = psa_generate_key(attributes, id);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::destroy_key(psa_key_id_t id)
-{
- psa_status_t psa_status = psa_destroy_key(id);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::import_key(const psa_key_attributes_t *attributes,
- const uint8_t *data, size_t data_length, psa_key_id_t *id)
-{
- psa_status_t psa_status = psa_import_key(attributes, data, data_length, id);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::copy_key(
- psa_key_id_t source_key,
- const psa_key_attributes_t *attributes,
- psa_key_id_t *target_key)
-{
- return PSA_ERROR_NOT_SUPPORTED;
-}
-
-psa_status_t psa_crypto_api_client::purge_key(
- psa_key_id_t id)
-{
- return PSA_ERROR_NOT_SUPPORTED;
-}
-
-psa_status_t psa_crypto_api_client::get_key_attributes(
- psa_key_id_t id,
- psa_key_attributes_t *attributes)
-{
- return PSA_ERROR_NOT_SUPPORTED;
-}
-
-psa_status_t psa_crypto_api_client::export_key(psa_key_id_t id,
- uint8_t *data, size_t data_size,
- size_t *data_length)
-{
- psa_status_t psa_status = psa_export_key(id, data, data_size, data_length);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::export_public_key(psa_key_id_t id,
- uint8_t *data, size_t data_size, size_t *data_length)
-{
- psa_status_t psa_status = psa_export_public_key(id, data, data_size, data_length);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::sign_hash(psa_key_id_t id, psa_algorithm_t alg,
- const uint8_t *hash, size_t hash_length,
- uint8_t *signature, size_t signature_size, size_t *signature_length)
-{
- psa_status_t psa_status = psa_sign_hash(id, alg, hash, hash_length,
- signature, signature_size, signature_length);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-
-psa_status_t psa_crypto_api_client::verify_hash(psa_key_id_t id, psa_algorithm_t alg,
- const uint8_t *hash, size_t hash_length,
- const uint8_t *signature, size_t signature_length)
-{
- psa_status_t psa_status = psa_verify_hash(id, alg, hash, hash_length,
- signature, signature_length);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::asymmetric_encrypt(psa_key_id_t id, psa_algorithm_t alg,
- const uint8_t *input, size_t input_length,
- const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length)
-{
- psa_status_t psa_status = psa_asymmetric_encrypt(id, alg, input, input_length,
- salt, salt_length,
- output, output_size, output_length);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::asymmetric_decrypt(psa_key_id_t id, psa_algorithm_t alg,
- const uint8_t *input, size_t input_length,
- const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length)
-{
- psa_status_t psa_status = psa_asymmetric_decrypt(id, alg, input, input_length,
- salt, salt_length,
- output, output_size, output_length);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::generate_random(uint8_t *output, size_t output_size)
-{
- psa_status_t psa_status = psa_generate_random(output, output_size);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::hash_setup(uint32_t *op_handle,
- psa_algorithm_t alg)
-{
- psa_hash_operation_t op = psa_hash_operation_init();
- psa_status_t psa_status = psa_hash_setup(&op, alg);
-
- *op_handle = op.handle;
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::hash_update(uint32_t op_handle,
- const uint8_t *input, size_t input_length)
-{
- psa_hash_operation_t op = psa_hash_operation_init();
- op.handle = op_handle;
-
- psa_status_t psa_status = psa_hash_update(&op, input, input_length);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
-
-psa_status_t psa_crypto_api_client::hash_finish(uint32_t op_handle,
- uint8_t *hash, size_t hash_size, size_t *hash_length)
-{
- psa_hash_operation_t op = psa_hash_operation_init();
- op.handle = op_handle;
-
- psa_status_t psa_status = psa_hash_finish(&op, hash, hash_size, hash_length);
- m_client.rpc_status = psa_crypto_client_rpc_status();
-
- return psa_status;
-}
diff --git a/components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_client.h b/components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_client.h
deleted file mode 100644
index 32a3f1d..0000000
--- a/components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_client.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef PSA_CRYPTO_API_CLIENT_H
-#define PSA_CRYPTO_API_CLIENT_H
-
-#include <service/crypto/client/cpp/crypto_client.h>
-
-/*
- * A concrete crypto_client that uses the psa crypto api
- */
-class psa_crypto_api_client : public crypto_client
-{
-public:
- psa_crypto_api_client();
- virtual ~psa_crypto_api_client();
-
- /* Key lifecycle methods */
- psa_status_t generate_key(const psa_key_attributes_t *attributes, psa_key_id_t *id);
- psa_status_t destroy_key(psa_key_id_t id);
- psa_status_t import_key(const psa_key_attributes_t *attributes,
- const uint8_t *data, size_t data_length, psa_key_id_t *id);
- psa_status_t copy_key(psa_key_id_t source_key,
- const psa_key_attributes_t *attributes, psa_key_id_t *target_key);
- psa_status_t purge_key(psa_key_id_t id);
- psa_status_t get_key_attributes(psa_key_id_t id, psa_key_attributes_t *attributes);
-
- /* Key export methods */
- psa_status_t export_key(psa_key_id_t id,
- uint8_t *data, size_t data_size,
- size_t *data_length);
- psa_status_t export_public_key(psa_key_id_t id,
- uint8_t *data, size_t data_size, size_t *data_length);
-
- /* Sign/verify methods */
- psa_status_t sign_hash(psa_key_id_t id, psa_algorithm_t alg,
- const uint8_t *hash, size_t hash_length,
- uint8_t *signature, size_t signature_size, size_t *signature_length);
- psa_status_t verify_hash(psa_key_id_t id, psa_algorithm_t alg,
- const uint8_t *hash, size_t hash_length,
- const uint8_t *signature, size_t signature_length);
-
- /* Asymmetric encrypt/decrypt */
- psa_status_t asymmetric_encrypt(psa_key_id_t id, psa_algorithm_t alg,
- const uint8_t *input, size_t input_length,
- const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length);
- psa_status_t asymmetric_decrypt(psa_key_id_t id, psa_algorithm_t alg,
- const uint8_t *input, size_t input_length,
- const uint8_t *salt, size_t salt_length,
- uint8_t *output, size_t output_size, size_t *output_length);
-
- /* Random number generation */
- psa_status_t generate_random(uint8_t *output, size_t output_size);
-
- /* Hash methods */
- psa_status_t hash_setup(uint32_t *op_handle,
- psa_algorithm_t alg);
- psa_status_t hash_update(uint32_t op_handle,
- const uint8_t *input, size_t input_length);
- psa_status_t hash_finish(uint32_t op_handle,
- uint8_t *hash, size_t hash_size, size_t *hash_length);
-};
-
-#endif /* PSA_CRYPTO_API_CLIENT_H */
diff --git a/components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_tests.cpp b/components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_tests.cpp
deleted file mode 100644
index b222995..0000000
--- a/components/service/crypto/test/service/psa_crypto_api/psa_crypto_api_tests.cpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include "psa_crypto_api_client.h"
-#include <psa/crypto.h>
-#include <service/crypto/client/psa/psa_crypto_client.h>
-#include <service/crypto/test/service/crypto_service_scenarios.h>
-#include <service/discovery/client/discovery_client.h>
-#include <protocols/rpc/common/packed-c/encoding.h>
-#include <service_locator.h>
-#include <CppUTest/TestHarness.h>
-
-/*
- * Service-level tests that use the psa crypto api
- */
-TEST_GROUP(PsaCryptoApiTests)
-{
- void setup()
- {
- struct rpc_caller *caller;
- int status;
-
- m_rpc_session_handle = NULL;
- m_crypto_service_context = NULL;
- m_scenarios = NULL;
-
- service_locator_init();
-
- m_crypto_service_context = service_locator_query("sn:trustedfirmware.org:crypto:0", &status);
- CHECK_TRUE(m_crypto_service_context);
-
- m_rpc_session_handle = service_context_open(m_crypto_service_context, TS_RPC_ENCODING_PACKED_C, &caller);
- CHECK_TRUE(m_rpc_session_handle);
-
- psa_crypto_client_init(caller);
- psa_crypto_init();
-
- discovery_client_get_service_info(psa_crypto_client_base());
-
- m_scenarios = new crypto_service_scenarios(new psa_crypto_api_client());
- }
-
- void teardown()
- {
- delete m_scenarios;
- m_scenarios = NULL;
-
- psa_crypto_client_deinit();
-
- service_context_close(m_crypto_service_context, m_rpc_session_handle);
- m_rpc_session_handle = NULL;
-
- service_context_relinquish(m_crypto_service_context);
- m_crypto_service_context = NULL;
- }
-
- rpc_session_handle m_rpc_session_handle;
- struct service_context *m_crypto_service_context;
- crypto_service_scenarios *m_scenarios;
-};
-
-TEST(PsaCryptoApiTests, generateVolatileKeys)
-{
- m_scenarios->generateVolatileKeys();
-}
-
-TEST(PsaCryptoApiTests, generatePersistentKeys)
-{
- m_scenarios->generatePersistentKeys();
-}
-
-TEST(PsaCryptoApiTests, exportPublicKey)
-{
- m_scenarios->exportPublicKey();
-}
-
-TEST(PsaCryptoApiTests, exportAndImportKeyPair)
-{
- m_scenarios->exportAndImportKeyPair();
-}
-
-TEST(PsaCryptoApiTests, signAndVerifyHash)
-{
- m_scenarios->signAndVerifyHash();
-}
-
-TEST(PsaCryptoApiTests, asymEncryptDecrypt)
-{
- m_scenarios->asymEncryptDecrypt();
-}
-
-TEST(PsaCryptoApiTests, asymEncryptDecryptWithSalt)
-{
- m_scenarios->asymEncryptDecryptWithSalt();
-}
-
-TEST(PsaCryptoApiTests, calculateHash)
-{
- m_scenarios->calculateHash();
-}
-
-TEST(PsaCryptoApiTests, generateRandomNumbers)
-{
- m_scenarios->generateRandomNumbers();
-}
diff --git a/deployments/component-test/component-test.cmake b/deployments/component-test/component-test.cmake
index cb2be38..681957f 100644
--- a/deployments/component-test/component-test.cmake
+++ b/deployments/component-test/component-test.cmake
@@ -90,6 +90,8 @@ add_components(
"components/service/crypto/test/service"
"components/service/crypto/test/service/protobuf"
"components/service/crypto/test/service/packed-c"
+ "components/service/crypto/test/service/extension/hash"
+ "components/service/crypto/test/service/extension/hash/packed-c"
"components/service/crypto/test/protocol"
"components/service/secure_storage/include"
"components/service/secure_storage/frontend/psa/its"
diff --git a/deployments/libts/linux-pc/CMakeLists.txt b/deployments/libts/linux-pc/CMakeLists.txt
index bd96394..5f58aa9 100644
--- a/deployments/libts/linux-pc/CMakeLists.txt
+++ b/deployments/libts/linux-pc/CMakeLists.txt
@@ -132,6 +132,7 @@ add_components(
"components/app/test-runner"
"components/common/tlv"
"components/service/common/include"
+ "components/service/discovery/client"
"components/service/secure_storage/include"
"components/service/secure_storage/test/service"
"components/service/secure_storage/frontend/psa/its"
diff --git a/deployments/ts-demo/ts-demo.cmake b/deployments/ts-demo/ts-demo.cmake
index 8f934a7..3e7cca0 100644
--- a/deployments/ts-demo/ts-demo.cmake
+++ b/deployments/ts-demo/ts-demo.cmake
@@ -39,6 +39,7 @@ add_components(
"components/common/tlv"
"components/service/common/include"
"components/service/common/client"
+ "components/service/discovery/client"
"components/service/crypto/client/cpp"
"components/service/crypto/client/cpp/protocol/packed-c"
"protocols/service/crypto/packed-c"
diff --git a/deployments/ts-service-test/ts-service-test.cmake b/deployments/ts-service-test/ts-service-test.cmake
index c756687..92348ec 100644
--- a/deployments/ts-service-test/ts-service-test.cmake
+++ b/deployments/ts-service-test/ts-service-test.cmake
@@ -36,7 +36,8 @@ add_components(
"components/service/crypto/test/service"
"components/service/crypto/test/service/protobuf"
"components/service/crypto/test/service/packed-c"
- "components/service/crypto/test/service/psa_crypto_api"
+ "components/service/crypto/test/service/extension/hash"
+ "components/service/crypto/test/service/extension/hash/packed-c"
"components/service/crypto/client/psa"
"components/service/crypto/client/cpp"
"components/service/crypto/client/cpp/protocol/protobuf"