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
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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(