Add packed-c protocol support for crypto service
To provide a lightweight parameter encoding that is aligned to
conventions used by SCMI, the packed-c parameter serialization has
been added to the crypto service. This builds on generic
components that allow other packed-c service access protocols
to be added easily. Service level tests have been extended to
use both protobuf and packed-c clients.
Signed-off-by: julhal01 <julian.hall@arm.com>
Change-Id: I9279b0814bcc9cf6c4aa4e30629e2f46f2df4c23
diff --git a/components/service/crypto/client/cpp/crypto_client.h b/components/service/crypto/client/cpp/crypto_client.h
index 3d0366f..5f6f0e1 100644
--- a/components/service/crypto/client/cpp/crypto_client.h
+++ b/components/service/crypto/client/cpp/crypto_client.h
@@ -9,66 +9,61 @@
#include <cstdint>
#include <psa/crypto.h>
-#include <service/crypto/protobuf/key_attributes.pb.h>
-
struct rpc_caller;
-/** Provides a client interface for accessing an instance of the PSA Crypto service.
- **/
+/*
+ * Provides a client interface for accessing an instance of the Crypto service
+ * using a C++ version of the PSA Crypto API.
+ */
class crypto_client
{
public:
- crypto_client(struct rpc_caller *caller);
virtual ~crypto_client();
int err_rpc_status() const;
/* Key lifecycle methods */
- psa_status_t generate_key(const psa_key_attributes_t *attributes, psa_key_handle_t *handle);
- psa_status_t destroy_key(psa_key_handle_t handle);
- psa_status_t open_key(psa_key_id_t id, psa_key_handle_t *handle);
- psa_status_t close_key(psa_key_handle_t handle);
- psa_status_t import_key(const psa_key_attributes_t *attributes,
- const uint8_t *data, size_t data_length, psa_key_handle_t *handle);
+ virtual psa_status_t generate_key(const psa_key_attributes_t *attributes, psa_key_handle_t *handle) = 0;
+ virtual psa_status_t destroy_key(psa_key_handle_t handle) = 0;
+ virtual psa_status_t open_key(psa_key_id_t id, psa_key_handle_t *handle) = 0;
+ virtual psa_status_t close_key(psa_key_handle_t handle) = 0;
+ virtual psa_status_t import_key(const psa_key_attributes_t *attributes,
+ const uint8_t *data, size_t data_length, psa_key_handle_t *handle) = 0;
/* Key export methods */
- psa_status_t export_key(psa_key_handle_t handle,
+ virtual psa_status_t export_key(psa_key_handle_t handle,
uint8_t *data, size_t data_size,
- size_t *data_length);
- psa_status_t export_public_key(psa_key_handle_t handle,
- uint8_t *data, size_t data_size, size_t *data_length);
+ size_t *data_length) = 0;
+ virtual psa_status_t export_public_key(psa_key_handle_t handle,
+ uint8_t *data, size_t data_size, size_t *data_length) = 0;
/* Sign/verify methods */
- psa_status_t sign_hash(psa_key_handle_t handle, psa_algorithm_t alg,
+ virtual psa_status_t sign_hash(psa_key_handle_t handle, 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_handle_t handle, psa_algorithm_t alg,
+ uint8_t *signature, size_t signature_size, size_t *signature_length) = 0;
+ virtual psa_status_t verify_hash(psa_key_handle_t handle, psa_algorithm_t alg,
const uint8_t *hash, size_t hash_length,
- const uint8_t *signature, size_t signature_length);
+ const uint8_t *signature, size_t signature_length) = 0;
/* Asymmetric encrypt/decrypt */
- psa_status_t asymmetric_encrypt(psa_key_handle_t handle, psa_algorithm_t alg,
+ virtual psa_status_t asymmetric_encrypt(psa_key_handle_t handle, 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_handle_t handle, psa_algorithm_t alg,
+ uint8_t *output, size_t output_size, size_t *output_length) = 0;
+ virtual psa_status_t asymmetric_decrypt(psa_key_handle_t handle, 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);
+ uint8_t *output, size_t output_size, size_t *output_length) = 0;
/* Random number generation */
- psa_status_t generate_random(uint8_t *output, size_t output_size);
+ virtual psa_status_t generate_random(uint8_t *output, size_t output_size) = 0;
protected:
crypto_client();
+ crypto_client(struct rpc_caller *caller);
void set_caller(struct rpc_caller *caller);
-private:
-
- void translate_key_attributes(ts_crypto_KeyAttributes &proto_attributes,
- const psa_key_attributes_t &psa_attributes);
-
struct rpc_caller *m_caller;
int m_err_rpc_status;
};