Improve reuse of crypto client components
Now that the crypto service provider may be extended to support
the entire set of PSA crypto operations, reuse of client side
components between different types of client has become much
more important. This change introduces the crypto caller
component that may be specialized to support different
calling conventions and serializations. A packed-c
specialization is implemented that provides code that
may be reused by any client taht needs to use the
packed-c serialization to talk to a crypto service instance.
To allow multiple crypto callers to co-exist within
the same build, the crypto caller is implemented as
a header file library with static inline functions.
Signed-off-by: Julian Hall <julian.hall@arm.com>
Change-Id: Iac791829470a834f1a29ef59d4442bda93220f91
diff --git a/components/app/ts-demo/test/ts-demo_tests.cpp b/components/app/ts-demo/test/ts-demo_tests.cpp
index 5f23c27..2cc8973 100644
--- a/components/app/ts-demo/test/ts-demo_tests.cpp
+++ b/components/app/ts-demo/test/ts-demo_tests.cpp
@@ -5,7 +5,7 @@
*/
#include <app/ts-demo/ts-demo.h>
-#include <service/crypto/client/cpp/packed-c/packedc_crypto_client.h>
+#include <service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h>
#include <protocols/rpc/common/packed-c/encoding.h>
#include <CppUTest/TestHarness.h>
#include <service_locator.h>
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller.h b/components/service/crypto/client/caller/packed-c/crypto_caller.h
new file mode 100644
index 0000000..e41a8cb
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_H
+#define PACKEDC_CRYPTO_CALLER_H
+
+/**
+ * Includes all header files that form the packed-c crypto caller
+ * interface. May be used by a client that needs to call operations
+ * provided by a crypto service instance using the packed-c serialization.
+ */
+#include "crypto_caller_aead.h"
+#include "crypto_caller_copy_key.h"
+#include "crypto_caller_generate_key.h"
+#include "crypto_caller_hash.h"
+#include "crypto_caller_mac.h"
+#include "crypto_caller_asymmetric_decrypt.h"
+#include "crypto_caller_destroy_key.h"
+#include "crypto_caller_generate_random.h"
+#include "crypto_caller_import_key.h"
+#include "crypto_caller_purge_key.h"
+#include "crypto_caller_asymmetric_encrypt.h"
+#include "crypto_caller_export_key.h"
+#include "crypto_caller_get_key_attributes.h"
+#include "crypto_caller_sign_hash.h"
+#include "crypto_caller_cipher.h"
+#include "crypto_caller_export_public_key.h"
+#include "crypto_caller_key_derivation.h"
+#include "crypto_caller_verify_hash.h"
+
+#endif /* PACKEDC_CRYPTO_CALLER_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_aead.h b/components/service/crypto/client/caller/packed-c/crypto_caller_aead.h
new file mode 100644
index 0000000..b63efa0
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_aead.h
@@ -0,0 +1,618 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_AEAD_H
+#define PACKEDC_CRYPTO_CALLER_AEAD_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/aead.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_aead_encrypt(struct service_client *context,
+ psa_key_id_t key,
+ psa_algorithm_t alg,
+ const uint8_t *nonce,
+ size_t nonce_length,
+ const uint8_t *additional_data,
+ size_t additional_data_length,
+ const uint8_t *plaintext,
+ size_t plaintext_length,
+ uint8_t *aeadtext,
+ size_t aeadtext_size,
+ size_t *aeadtext_length)
+{
+ return PSA_ERROR_NOT_SUPPORTED;
+}
+
+static inline psa_status_t crypto_caller_aead_decrypt(struct service_client *context,
+ psa_key_id_t key,
+ psa_algorithm_t alg,
+ const uint8_t *nonce,
+ size_t nonce_length,
+ const uint8_t *additional_data,
+ size_t additional_data_length,
+ const uint8_t *aeadtext,
+ size_t aeadtext_length,
+ uint8_t *plaintext,
+ size_t plaintext_size,
+ size_t *plaintext_length)
+{
+ return PSA_ERROR_NOT_SUPPORTED;
+}
+
+static inline psa_status_t common_aead_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_key_id_t key,
+ psa_algorithm_t alg,
+ uint32_t opcode)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_aead_setup_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_aead_setup_in);
+
+ req_msg.key_id = key;
+ req_msg.alg = alg;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ opcode, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_aead_setup_out)) {
+
+ struct ts_crypto_aead_setup_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_aead_setup_out));
+ *op_handle = resp_msg.op_handle;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_aead_encrypt_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_key_id_t key,
+ psa_algorithm_t alg)
+{
+ return common_aead_setup(context,
+ op_handle, key, alg, TS_CRYPTO_OPCODE_AEAD_ENCRYPT_SETUP);
+}
+
+static inline psa_status_t crypto_caller_aead_decrypt_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_key_id_t key,
+ psa_algorithm_t alg)
+{
+ return common_aead_setup(context,
+ op_handle, key, alg, TS_CRYPTO_OPCODE_AEAD_DECRYPT_SETUP);
+}
+
+static inline psa_status_t crypto_caller_aead_generate_nonce(struct service_client *context,
+ uint32_t op_handle,
+ uint8_t *nonce,
+ size_t nonce_size,
+ size_t *nonce_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_aead_generate_nonce_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_aead_generate_nonce_in);
+ size_t req_len = req_fixed_len;
+
+ *nonce_length = 0;
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_AEAD_GENERATE_NONCE, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_AEAD_GENERATE_NONCE_OUT_TAG_NONCE, &decoded_record)) {
+
+ if (decoded_record.length <= nonce_size) {
+
+ memcpy(nonce, decoded_record.value, decoded_record.length);
+ *nonce_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_aead_set_nonce(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *nonce,
+ size_t nonce_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_aead_set_nonce_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_aead_set_nonce_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_AEAD_SET_NONCE_IN_TAG_NONCE;
+ data_record.length = nonce_length;
+ data_record.value = nonce;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_AEAD_SET_NONCE, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_aead_set_lengths(struct service_client *context,
+ uint32_t op_handle,
+ size_t ad_length,
+ size_t plaintext_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_aead_set_lengths_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_aead_abort_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+ req_msg.ad_length = ad_length;
+ req_msg.plaintext_length = plaintext_length;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_AEAD_SET_LENGTHS, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_aead_update_ad(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *input,
+ size_t input_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_aead_update_ad_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_aead_update_ad_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_AEAD_UPDATE_AD_IN_TAG_DATA;
+ data_record.length = input_length;
+ data_record.value = input;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_AEAD_UPDATE_AD, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_aead_update(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *input,
+ size_t input_length,
+ uint8_t *output,
+ size_t output_size,
+ size_t *output_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_aead_update_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_aead_update_in);
+ size_t req_len = req_fixed_len;
+
+ *output_length = 0;
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_AEAD_UPDATE_IN_TAG_DATA;
+ data_record.length = input_length;
+ data_record.value = input;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_AEAD_UPDATE, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_AEAD_UPDATE_OUT_TAG_DATA, &decoded_record)) {
+
+ if (decoded_record.length <= output_size) {
+
+ memcpy(output, decoded_record.value, decoded_record.length);
+ *output_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_aead_finish(struct service_client *context,
+ uint32_t op_handle,
+ uint8_t *aeadtext,
+ size_t aeadtext_size,
+ size_t *aeadtext_length,
+ uint8_t *tag,
+ size_t tag_size,
+ size_t *tag_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_aead_finish_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_aead_finish_in);
+ size_t req_len = req_fixed_len;
+
+ *aeadtext_length = 0;
+ *tag_length = 0;
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_AEAD_FINISH, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_AEAD_FINISH_OUT_TAG_CIPHERTEXT, &decoded_record)) {
+
+ if (decoded_record.length <= aeadtext_size) {
+
+ memcpy(aeadtext, decoded_record.value, decoded_record.length);
+ *aeadtext_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+
+ if ((psa_status == PSA_SUCCESS) && tlv_find_decode(&resp_iter,
+ TS_CRYPTO_AEAD_FINISH_OUT_TAG_TAG, &decoded_record)) {
+
+ if (decoded_record.length <= tag_size) {
+
+ memcpy(tag, decoded_record.value, decoded_record.length);
+ *tag_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_aead_verify(struct service_client *context,
+ uint32_t op_handle,
+ uint8_t *plaintext,
+ size_t plaintext_size,
+ size_t *plaintext_length,
+ const uint8_t *tag,
+ size_t tag_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_aead_verify_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_aead_verify_in);
+ size_t req_len = req_fixed_len;
+
+ *plaintext_length = 0;
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_AEAD_VERIFY_IN_TAG_TAG;
+ data_record.length = tag_length;
+ data_record.value = tag;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_AEAD_VERIFY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_AEAD_VERIFY_OUT_TAG_PLAINTEXT, &decoded_record)) {
+
+ if (decoded_record.length <= plaintext_size) {
+
+ memcpy(plaintext, decoded_record.value, decoded_record.length);
+ *plaintext_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_aead_abort(struct service_client *context,
+ uint32_t op_handle)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_aead_abort_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_aead_abort_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_AEAD_ABORT, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_AEAD_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_asymmetric_decrypt.h b/components/service/crypto/client/caller/packed-c/crypto_caller_asymmetric_decrypt.h
new file mode 100644
index 0000000..bdf8069
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_asymmetric_decrypt.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_ASYMMETRIC_DECRYPT_H
+#define PACKEDC_CRYPTO_CALLER_ASYMMETRIC_DECRYPT_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/asymmetric_decrypt.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_asymmetric_decrypt(struct service_client *context,
+ 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_ERROR_GENERIC_ERROR;
+ struct ts_crypto_asymmetric_decrypt_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_asymmetric_decrypt_in);
+ size_t req_len = req_fixed_len;
+
+ *output_length = 0; /* For failure case */
+
+ req_msg.id = id;
+ req_msg.alg = alg;
+
+ /* Mandatory parameter */
+ struct tlv_record ciphertext_record;
+ ciphertext_record.tag = TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_CIPHERTEXT;
+ ciphertext_record.length = input_length;
+ ciphertext_record.value = input;
+ req_len += tlv_required_space(ciphertext_record.length);
+
+ /* Optional parameter */
+ struct tlv_record salt_record;
+ salt_record.tag = TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_SALT;
+ salt_record.length = (salt) ? salt_length : 0;
+ salt_record.value = salt;
+ if (salt) req_len += tlv_required_space(salt_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &ciphertext_record);
+ if (salt) tlv_encode(&req_iter, &salt_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_ASYMMETRIC_DECRYPT, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_ASYMMETRIC_DECRYPT_OUT_TAG_PLAINTEXT, &decoded_record)) {
+
+ if (decoded_record.length <= output_size) {
+
+ memcpy(output, decoded_record.value, decoded_record.length);
+ *output_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_ASYMMETRIC_DECRYPT_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_asymmetric_encrypt.h b/components/service/crypto/client/caller/packed-c/crypto_caller_asymmetric_encrypt.h
new file mode 100644
index 0000000..f92ac6e
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_asymmetric_encrypt.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_ASYMMETRIC_ENCRYPT_H
+#define PACKEDC_CRYPTO_CALLER_ASYMMETRIC_ENCRYPT_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/asymmetric_encrypt.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_asymmetric_encrypt(struct service_client *context,
+ 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_ERROR_GENERIC_ERROR;
+ struct ts_crypto_asymmetric_encrypt_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_asymmetric_encrypt_in);
+ size_t req_len = req_fixed_len;
+
+ *output_length = 0; /* For failure case */
+
+ req_msg.id = id;
+ req_msg.alg = alg;
+
+ /* Mandatory parameter */
+ struct tlv_record plaintext_record;
+ plaintext_record.tag = TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_PLAINTEXT;
+ plaintext_record.length = input_length;
+ plaintext_record.value = input;
+ req_len += tlv_required_space(plaintext_record.length);
+
+ /* Optional parameter */
+ struct tlv_record salt_record;
+ salt_record.tag = TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_SALT;
+ salt_record.length = (salt) ? salt_length : 0;
+ salt_record.value = salt;
+ if (salt) req_len += tlv_required_space(salt_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus = PSA_ERROR_GENERIC_ERROR;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &plaintext_record);
+ if (salt) tlv_encode(&req_iter, &salt_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_ASYMMETRIC_ENCRYPT, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_ASYMMETRIC_ENCRYPT_OUT_TAG_CIPHERTEXT, &decoded_record)) {
+
+ if (decoded_record.length <= output_size) {
+
+ memcpy(output, decoded_record.value, decoded_record.length);
+ *output_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_ASYMMETRIC_ENCRYPT_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_cipher.h b/components/service/crypto/client/caller/packed-c/crypto_caller_cipher.h
new file mode 100644
index 0000000..58679bf
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_cipher.h
@@ -0,0 +1,409 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_CIPHER_H
+#define PACKEDC_CRYPTO_CALLER_CIPHER_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/cipher.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t common_cipher_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_key_id_t key,
+ psa_algorithm_t alg,
+ uint32_t opcode)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_cipher_setup_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_cipher_setup_in);
+
+ req_msg.key_id = key;
+ req_msg.alg = alg;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ opcode, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_cipher_setup_out)) {
+
+ struct ts_crypto_cipher_setup_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_cipher_setup_out));
+ *op_handle = resp_msg.op_handle;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_cipher_encrypt_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_key_id_t key,
+ psa_algorithm_t alg)
+{
+ return common_cipher_setup(context,
+ op_handle, key, alg, TS_CRYPTO_OPCODE_CIPHER_ENCRYPT_SETUP);
+}
+
+static inline psa_status_t crypto_caller_cipher_decrypt_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_key_id_t key,
+ psa_algorithm_t alg)
+{
+ return common_cipher_setup(context,
+ op_handle, key, alg, TS_CRYPTO_OPCODE_CIPHER_DECRYPT_SETUP);
+}
+
+static inline psa_status_t crypto_caller_cipher_generate_iv(struct service_client *context,
+ uint32_t op_handle,
+ uint8_t *iv,
+ size_t iv_size,
+ size_t *iv_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_cipher_generate_iv_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_cipher_generate_iv_in);
+ size_t req_len = req_fixed_len;
+
+ *iv_length = 0;
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_CIPHER_GENERATE_IV, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_CIPHER_GENERATE_IV_OUT_TAG_IV, &decoded_record)) {
+
+ if (decoded_record.length <= iv_size) {
+
+ memcpy(iv, decoded_record.value, decoded_record.length);
+ *iv_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_cipher_set_iv(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *iv,
+ size_t iv_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_cipher_set_iv_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_cipher_set_iv_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_CIPHER_SET_IV_IN_TAG_IV;
+ data_record.length = iv_length;
+ data_record.value = iv;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_CIPHER_SET_IV, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_cipher_update(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *input,
+ size_t input_length,
+ uint8_t *output,
+ size_t output_size,
+ size_t *output_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_cipher_update_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_cipher_update_in);
+ size_t req_len = req_fixed_len;
+
+ *output_length = 0;
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_CIPHER_UPDATE_IN_TAG_DATA;
+ data_record.length = input_length;
+ data_record.value = input;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_CIPHER_UPDATE, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_CIPHER_UPDATE_OUT_TAG_DATA, &decoded_record)) {
+
+ if (decoded_record.length <= output_size) {
+
+ memcpy(output, decoded_record.value, decoded_record.length);
+ *output_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_cipher_finish(struct service_client *context,
+ uint32_t op_handle,
+ uint8_t *output,
+ size_t output_size,
+ size_t *output_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_cipher_finish_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_cipher_finish_in);
+ size_t req_len = req_fixed_len;
+
+ *output_length = 0;
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_CIPHER_FINISH, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_CIPHER_FINISH_OUT_TAG_DATA, &decoded_record)) {
+
+ if (decoded_record.length <= output_size) {
+
+ memcpy(output, decoded_record.value, decoded_record.length);
+ *output_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_cipher_abort(struct service_client *context,
+ uint32_t op_handle)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_cipher_abort_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_cipher_abort_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_CIPHER_ABORT, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline size_t crypto_caller_cipher_max_update_size(struct service_client *context)
+{
+ /* Returns the maximum number of bytes that may be
+ * carried as a parameter of the cipher_update operation
+ * using the packed-c encoding.
+ */
+ size_t payload_space = context->service_info.max_payload;
+ size_t overhead = sizeof(struct ts_crypto_cipher_update_in) + TLV_HDR_LEN;
+
+ return (payload_space > overhead) ? payload_space - overhead : 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_CIPHER_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_copy_key.h b/components/service/crypto/client/caller/packed-c/crypto_caller_copy_key.h
new file mode 100644
index 0000000..43d39d8
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_copy_key.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_COPY_KEY_H
+#define PACKEDC_CRYPTO_CALLER_COPY_KEY_H
+
+#include <string.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/copy_key.h>
+#include "crypto_caller_key_attributes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_copy_key(struct service_client *context,
+ psa_key_id_t source_key,
+ const psa_key_attributes_t *attributes,
+ psa_key_id_t *target_key)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_copy_key_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_copy_key_in);
+
+ /* Set default outputs for failure case */
+ *target_key = 0;
+
+ req_msg.source_key_id = source_key;
+ packedc_crypto_caller_translate_key_attributes_to_proto(&req_msg.attributes, attributes);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status = rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_COPY_KEY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_copy_key_out)) {
+
+ struct ts_crypto_copy_key_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_copy_key_out));
+ *target_key = resp_msg.target_key_id;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_COPY_KEY_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_destroy_key.h b/components/service/crypto/client/caller/packed-c/crypto_caller_destroy_key.h
new file mode 100644
index 0000000..f1ab95b
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_destroy_key.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_DESTROY_KEY_H
+#define PACKEDC_CRYPTO_CALLER_DESTROY_KEY_H
+
+#include <string.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/destroy_key.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_destroy_key(struct service_client *context,
+ psa_key_id_t id)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_destroy_key_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_destroy_key_in);
+
+ req_msg.id = id;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_DESTROY_KEY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_DESTROY_KEY_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_export_key.h b/components/service/crypto/client/caller/packed-c/crypto_caller_export_key.h
new file mode 100644
index 0000000..b3d0132
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_export_key.h
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_EXPORT_KEY_H
+#define PACKEDC_CRYPTO_CALLER_EXPORT_KEY_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/export_key.h>
+#include <protocols/service/crypto/packed-c/export_public_key.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_export_key(struct service_client *context,
+ psa_key_id_t id,
+ uint8_t *data, size_t data_size, size_t *data_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_export_key_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_export_key_in);
+
+ req_msg.id = id;
+
+ *data_length = 0; /* For failure case */
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_EXPORT_KEY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_EXPORT_KEY_OUT_TAG_DATA, &decoded_record)) {
+
+ if (decoded_record.length <= data_size) {
+
+ memcpy(data, decoded_record.value, decoded_record.length);
+ *data_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_EXPORT_KEY_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_export_public_key.h b/components/service/crypto/client/caller/packed-c/crypto_caller_export_public_key.h
new file mode 100644
index 0000000..6c90e07
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_export_public_key.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_EXPORT_PUBLIC_KEY_H
+#define PACKEDC_CRYPTO_CALLER_EXPORT_PUBLIC_KEY_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/export_public_key.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_export_public_key(struct service_client *context,
+ psa_key_id_t id,
+ uint8_t *data, size_t data_size, size_t *data_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_export_public_key_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_export_public_key_in);
+
+ req_msg.id = id;
+
+ *data_length = 0; /* For failure case */
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_EXPORT_PUBLIC_KEY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_EXPORT_PUBLIC_KEY_OUT_TAG_DATA, &decoded_record)) {
+
+ if (decoded_record.length <= data_size) {
+
+ memcpy(data, decoded_record.value, decoded_record.length);
+ *data_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_EXPORT_PUBLIC_KEY_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_generate_key.h b/components/service/crypto/client/caller/packed-c/crypto_caller_generate_key.h
new file mode 100644
index 0000000..853cc4d
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_generate_key.h
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_GENERATE_KEY_H
+#define PACKEDC_CRYPTO_CALLER_GENERATE_KEY_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/key_attributes.h>
+#include <protocols/service/crypto/packed-c/generate_key.h>
+#include "crypto_caller_key_attributes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_generate_key(struct service_client *context,
+ const psa_key_attributes_t *attributes,
+ psa_key_id_t *id)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_generate_key_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_generate_key_in);
+
+ /* Set default outputs for failure case */
+ *id = 0;
+
+ packedc_crypto_caller_translate_key_attributes_to_proto(&req_msg.attributes, attributes);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_GENERATE_KEY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_generate_key_out)) {
+
+ struct ts_crypto_generate_key_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_generate_key_out));
+ *id = resp_msg.id;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_GENERATE_KEY_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_generate_random.h b/components/service/crypto/client/caller/packed-c/crypto_caller_generate_random.h
new file mode 100644
index 0000000..4a239bc
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_generate_random.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_GENERATE_RANDOM_H
+#define PACKEDC_CRYPTO_CALLER_GENERATE_RANDOM_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/generate_random.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_generate_random(struct service_client *context,
+ uint8_t *output, size_t output_size)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_generate_random_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_generate_random_in);
+
+ req_msg.size = output_size;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_GENERATE_RANDOM, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_GENERATE_RANDOM_OUT_TAG_RANDOM_BYTES, &decoded_record)) {
+
+ if (decoded_record.length <= output_size) {
+
+ memcpy(output, decoded_record.value, decoded_record.length);
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_GENERATE_RANDOM_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_get_key_attributes.h b/components/service/crypto/client/caller/packed-c/crypto_caller_get_key_attributes.h
new file mode 100644
index 0000000..86d3026
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_get_key_attributes.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_GET_KEY_ATTRIBUTES_H
+#define PACKEDC_CRYPTO_CALLER_GET_KEY_ATTRIBUTES_H
+
+#include <string.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/get_key_attributes.h>
+#include "crypto_caller_key_attributes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_get_key_attributes(struct service_client *context,
+ psa_key_id_t key,
+ psa_key_attributes_t *attributes)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_get_key_attributes_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_get_key_attributes_in);
+
+ req_msg.id = key;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_GET_KEY_ATTRIBUTES, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_get_key_attributes_out)) {
+
+ struct ts_crypto_get_key_attributes_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_get_key_attributes_out));
+ packedc_crypto_caller_translate_key_attributes_from_proto(
+ attributes, &resp_msg.attributes);
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_GET_KEY_ATTRIBUTES_H */
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
new file mode 100644
index 0000000..b4904ea
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_hash.h
@@ -0,0 +1,359 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_HASH_H
+#define PACKEDC_CRYPTO_CALLER_HASH_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/hash.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_hash_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_algorithm_t alg)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_hash_setup_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_hash_setup_in);
+
+ req_msg.alg = alg;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_HASH_SETUP, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_hash_setup_out)) {
+
+ struct ts_crypto_hash_setup_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_hash_setup_out));
+ *op_handle = resp_msg.op_handle;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_hash_update(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *input,
+ size_t input_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_hash_update_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_hash_update_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_HASH_UPDATE_IN_TAG_DATA;
+ data_record.length = input_length;
+ data_record.value = input;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_HASH_UPDATE, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_hash_finish(struct service_client *context,
+ uint32_t op_handle,
+ uint8_t *hash,
+ size_t hash_size,
+ size_t *hash_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_hash_finish_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_hash_finish_in);
+ size_t req_len = req_fixed_len;
+
+ *hash_length = 0;
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_HASH_FINISH, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_HASH_FINISH_OUT_TAG_HASH, &decoded_record)) {
+
+ if (decoded_record.length <= hash_size) {
+
+ memcpy(hash, decoded_record.value, decoded_record.length);
+ *hash_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_hash_abort(struct service_client *context,
+ uint32_t op_handle)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_hash_abort_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_hash_abort_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_HASH_ABORT, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_hash_verify(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *hash,
+ size_t hash_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_hash_verify_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_hash_verify_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_HASH_VERIFY_IN_TAG_HASH;
+ data_record.length = hash_length;
+ data_record.value = hash;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_HASH_VERIFY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_hash_clone(struct service_client *context,
+ uint32_t source_op_handle,
+ uint32_t *target_op_handle)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_hash_clone_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_hash_clone_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.source_op_handle = source_op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_HASH_CLONE, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_hash_clone_out)) {
+
+ struct ts_crypto_hash_clone_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_hash_clone_out));
+ *target_op_handle = resp_msg.target_op_handle;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_hash_suspend(struct service_client *context,
+ uint32_t op_handle,
+ uint8_t *hash_state,
+ size_t hash_state_size,
+ size_t *hash_state_length)
+{
+ return PSA_ERROR_NOT_SUPPORTED;
+}
+
+static inline psa_status_t crypto_caller_hash_resume(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *hash_state,
+ size_t hash_state_length)
+{
+ return PSA_ERROR_NOT_SUPPORTED;
+}
+
+static inline size_t crypto_caller_hash_max_update_size(struct service_client *context)
+{
+ /* Returns the maximum number of bytes that may be
+ * carried as a parameter of the hash_update operation
+ * using the packed-c encoding.
+ */
+ size_t payload_space = context->service_info.max_payload;
+ size_t overhead = sizeof(struct ts_crypto_hash_update_in) + TLV_HDR_LEN;
+
+ return (payload_space > overhead) ? payload_space - overhead : 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_HASH_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_import_key.h b/components/service/crypto/client/caller/packed-c/crypto_caller_import_key.h
new file mode 100644
index 0000000..25355b1
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_import_key.h
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_IMPORT_KEY_H
+#define PACKEDC_CRYPTO_CALLER_IMPORT_KEY_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/key_attributes.h>
+#include <protocols/service/crypto/packed-c/import_key.h>
+#include <common/tlv/tlv.h>
+#include "crypto_caller_key_attributes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_import_key(struct service_client *context,
+ 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_ERROR_GENERIC_ERROR;
+ struct ts_crypto_import_key_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_import_key_in);
+ size_t req_len = req_fixed_len + tlv_required_space(data_length);
+
+ /* Set default outputs for failure case */
+ *id = 0;
+
+ packedc_crypto_caller_translate_key_attributes_to_proto(&req_msg.attributes, attributes);
+
+ struct tlv_record key_record;
+ key_record.tag = TS_CRYPTO_IMPORT_KEY_IN_TAG_DATA;
+ key_record.length = data_length;
+ key_record.value = data;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &key_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_IMPORT_KEY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_import_key_out)) {
+
+ struct ts_crypto_import_key_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_import_key_out));
+ *id = resp_msg.id;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_IMPORT_KEY_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_key_attributes.h b/components/service/crypto/client/caller/packed-c/crypto_caller_key_attributes.h
new file mode 100644
index 0000000..26c42b8
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_key_attributes.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_KEY_ATTRIBUTES_H
+#define PACKEDC_CRYPTO_CALLER_KEY_ATTRIBUTES_H
+
+#include <psa/crypto.h>
+#include <protocols/service/crypto/packed-c/key_attributes.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline void packedc_crypto_caller_translate_key_attributes_to_proto(
+ struct ts_crypto_key_attributes *proto_attributes,
+ const psa_key_attributes_t *psa_attributes)
+{
+ proto_attributes->type = psa_get_key_type(psa_attributes);
+ proto_attributes->key_bits = psa_get_key_bits(psa_attributes);
+ proto_attributes->lifetime = psa_get_key_lifetime(psa_attributes);
+ proto_attributes->id = psa_get_key_id(psa_attributes);
+
+ proto_attributes->policy.usage = psa_get_key_usage_flags(psa_attributes);
+ proto_attributes->policy.alg = psa_get_key_algorithm(psa_attributes);
+ }
+
+static inline void packedc_crypto_caller_translate_key_attributes_from_proto(
+ psa_key_attributes_t *psa_attributes,
+ const struct ts_crypto_key_attributes *proto_attributes)
+{
+ psa_set_key_type(psa_attributes, proto_attributes->type);
+ psa_set_key_bits(psa_attributes, proto_attributes->key_bits);
+ psa_set_key_lifetime(psa_attributes, proto_attributes->lifetime);
+ psa_set_key_id(psa_attributes, proto_attributes->id);
+
+ psa_set_key_usage_flags(psa_attributes, proto_attributes->policy.usage);
+ psa_set_key_algorithm(psa_attributes, proto_attributes->policy.alg);
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_KEY_ATTRIBUTES_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_key_derivation.h b/components/service/crypto/client/caller/packed-c/crypto_caller_key_derivation.h
new file mode 100644
index 0000000..068a786
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_key_derivation.h
@@ -0,0 +1,547 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_KEY_DERIVATION_H
+#define PACKEDC_CRYPTO_CALLER_KEY_DERIVATION_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/key_derivation.h>
+#include <common/tlv/tlv.h>
+#include "crypto_caller_key_attributes.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_key_derivation_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_algorithm_t alg)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_key_derivation_setup_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_key_derivation_setup_in);
+
+ req_msg.alg = alg;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_SETUP, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_key_derivation_setup_out)) {
+
+ struct ts_crypto_key_derivation_setup_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_key_derivation_setup_out));
+ *op_handle = resp_msg.op_handle;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_key_derivation_get_capacity(struct service_client *context,
+ const uint32_t op_handle,
+ size_t *capacity)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_key_derivation_get_capacity_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_key_derivation_get_capacity_in);
+
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_GET_CAPACITY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_key_derivation_get_capacity_out)) {
+
+ struct ts_crypto_key_derivation_get_capacity_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_key_derivation_get_capacity_out));
+ *capacity = resp_msg.capacity;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_key_derivation_set_capacity(struct service_client *context,
+ uint32_t op_handle,
+ size_t capacity)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_key_derivation_set_capacity_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_key_derivation_set_capacity_in);
+
+ req_msg.op_handle = op_handle;
+ req_msg.capacity = capacity;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_SET_CAPACITY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_key_derivation_input_bytes(struct service_client *context,
+ uint32_t op_handle,
+ psa_key_derivation_step_t step,
+ const uint8_t *data,
+ size_t data_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_key_derivation_input_bytes_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_key_derivation_input_bytes_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+ req_msg.step = step;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_KEY_DERIVATION_INPUT_BYTES_IN_TAG_DATA;
+ data_record.length = data_length;
+ data_record.value = data;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_INPUT_BYTES, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_key_derivation_input_key(struct service_client *context,
+ uint32_t op_handle,
+ psa_key_derivation_step_t step,
+ psa_key_id_t key)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_key_derivation_input_key_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_key_derivation_input_key_in);
+
+ req_msg.op_handle = op_handle;
+ req_msg.step = step;
+ req_msg.key_id = key;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_INPUT_KEY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_key_derivation_output_bytes(struct service_client *context,
+ uint32_t op_handle,
+ uint8_t *output,
+ size_t output_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_key_derivation_output_bytes_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_key_derivation_output_bytes_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+ req_msg.output_len = output_length;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_OUTPUT_BYTES, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES_OUT_TAG_DATA, &decoded_record)) {
+
+ if (decoded_record.length == output_length) {
+
+ memcpy(output, decoded_record.value, decoded_record.length);
+ }
+ else {
+ /* Should have returned the requested number of bytes */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_key_derivation_output_key(struct service_client *context,
+ const psa_key_attributes_t *attributes,
+ uint32_t op_handle,
+ psa_key_id_t *key)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_key_derivation_output_key_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_key_derivation_output_key_in);
+
+ /* Set default outputs for failure case */
+ *key = 0;
+
+ req_msg.op_handle = op_handle;
+ packedc_crypto_caller_translate_key_attributes_to_proto(&req_msg.attributes, attributes);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_OUTPUT_KEY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_key_derivation_output_key_out)) {
+
+ struct ts_crypto_key_derivation_output_key_out resp_msg;
+ memcpy(&resp_msg, resp_buf,
+ sizeof(struct ts_crypto_key_derivation_output_key_out));
+ *key = resp_msg.key_id;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_key_derivation_abort(struct service_client *context,
+ uint32_t op_handle)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_key_derivation_abort_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_key_derivation_abort_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_ABORT, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_key_derivation_key_agreement(struct service_client *context,
+ uint32_t op_handle,
+ psa_key_derivation_step_t step,
+ psa_key_id_t private_key,
+ const uint8_t *peer_key,
+ size_t peer_key_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_key_derivation_key_agreement_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_key_derivation_key_agreement_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+ req_msg.step = step;
+ req_msg.private_key_id = private_key;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT_IN_TAG_PEER_KEY;
+ data_record.length = peer_key_length;
+ data_record.value = peer_key;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_KEY_AGREEMENT, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_raw_key_agreement(struct service_client *context,
+ psa_algorithm_t alg,
+ psa_key_id_t private_key,
+ const uint8_t *peer_key,
+ size_t peer_key_length,
+ uint8_t *output,
+ size_t output_size,
+ size_t *output_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_raw_key_agreement_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_raw_key_agreement_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.alg = alg;
+ req_msg.private_key_id = private_key;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_RAW_KEY_AGREEMENT_IN_TAG_PEER_KEY;
+ data_record.length = peer_key_length;
+ data_record.value = peer_key;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_KEY_DERIVATION_RAW_KEY_AGREEMENT, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_RAW_KEY_AGREEMENT_OUT_TAG_OUTPUT, &decoded_record)) {
+
+ if (decoded_record.length <= output_size) {
+
+ memcpy(output, decoded_record.value, decoded_record.length);
+ *output_length = decoded_record.length;
+ }
+ else {
+ /* Insufficient buffer space */
+ psa_status = PSA_ERROR_INVALID_ARGUMENT;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_KEY_DERIVATION_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_mac.h b/components/service/crypto/client/caller/packed-c/crypto_caller_mac.h
new file mode 100644
index 0000000..41c1d20
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_mac.h
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_MAC_H
+#define PACKEDC_CRYPTO_CALLER_MAC_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/mac.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t common_mac_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_key_id_t key,
+ psa_algorithm_t alg,
+ uint32_t opcode)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_mac_setup_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_mac_setup_in);
+
+ req_msg.key_id = key;
+ req_msg.alg = alg;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ opcode, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ if (resp_len >= sizeof(struct ts_crypto_mac_setup_out)) {
+
+ struct ts_crypto_mac_setup_out resp_msg;
+ memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_mac_setup_out));
+ *op_handle = resp_msg.op_handle;
+ }
+ else {
+ /* Failed to decode response message */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_mac_sign_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_key_id_t key,
+ psa_algorithm_t alg)
+{
+ return common_mac_setup(context, op_handle, key, alg, TS_CRYPTO_OPCODE_MAC_SIGN_SETUP);
+}
+
+static inline psa_status_t crypto_caller_mac_verify_setup(struct service_client *context,
+ uint32_t *op_handle,
+ psa_key_id_t key,
+ psa_algorithm_t alg)
+{
+ return common_mac_setup(context, op_handle, key, alg, TS_CRYPTO_OPCODE_MAC_VERIFY_SETUP);
+}
+
+static inline psa_status_t crypto_caller_mac_update(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *input,
+ size_t input_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_mac_update_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_mac_update_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_MAC_UPDATE_IN_TAG_DATA;
+ data_record.length = input_length;
+ data_record.value = input;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_MAC_UPDATE, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_mac_sign_finish(struct service_client *context,
+ uint32_t op_handle,
+ uint8_t *mac,
+ size_t mac_size,
+ size_t *mac_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_mac_sign_finish_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_mac_sign_finish_in);
+ size_t req_len = req_fixed_len;
+
+ *mac_length = 0;
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_MAC_SIGN_FINISH, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_MAC_SIGN_FINISH_OUT_TAG_MAC, &decoded_record)) {
+
+ if (decoded_record.length <= mac_size) {
+
+ memcpy(mac, decoded_record.value, decoded_record.length);
+ *mac_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_mac_verify_finish(struct service_client *context,
+ uint32_t op_handle,
+ const uint8_t *mac,
+ size_t mac_length)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_mac_verify_finish_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_mac_verify_finish_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ /* Mandatory input data parameter */
+ struct tlv_record data_record;
+ data_record.tag = TS_CRYPTO_MAC_VERIFY_FINISH_IN_TAG_MAC;
+ data_record.length = mac_length;
+ data_record.value = mac;
+ req_len += tlv_required_space(data_record.length);
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &data_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_MAC_VERIFY_FINISH, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline psa_status_t crypto_caller_mac_abort(struct service_client *context,
+ uint32_t op_handle)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_mac_abort_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_mac_abort_in);
+ size_t req_len = req_fixed_len;
+
+ req_msg.op_handle = op_handle;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_MAC_ABORT, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+static inline size_t crypto_caller_mac_max_update_size(struct service_client *context)
+{
+ /* Returns the maximum number of bytes that may be
+ * carried as a parameter of the mac_update operation
+ * using the packed-c encoding.
+ */
+ size_t payload_space = context->service_info.max_payload;
+ size_t overhead = sizeof(struct ts_crypto_mac_update_in) + TLV_HDR_LEN;
+
+ return (payload_space > overhead) ? payload_space - overhead : 0;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_MAC_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_purge_key.h b/components/service/crypto/client/caller/packed-c/crypto_caller_purge_key.h
new file mode 100644
index 0000000..9b50387
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_purge_key.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_PURGE_KEY_H
+#define PACKEDC_CRYPTO_CALLER_PURGE_KEY_H
+
+#include <string.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/purge_key.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_purge_key(struct service_client *context,
+ psa_key_id_t key)
+{
+ psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
+ struct ts_crypto_purge_key_in req_msg;
+ size_t req_len = sizeof(struct ts_crypto_purge_key_in);
+
+ req_msg.id = key;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+
+ memcpy(req_buf, &req_msg, req_len);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_PURGE_KEY, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_PURGE_KEY_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_sign_hash.h b/components/service/crypto/client/caller/packed-c/crypto_caller_sign_hash.h
new file mode 100644
index 0000000..975b7af
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_sign_hash.h
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_SIGN_HASH_H
+#define PACKEDC_CRYPTO_CALLER_SIGN_HASH_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/sign_hash.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_sign_hash(struct service_client *context,
+ 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_ERROR_GENERIC_ERROR;
+ struct ts_crypto_sign_hash_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_sign_hash_in);
+ size_t req_len = req_fixed_len + tlv_required_space(hash_length);
+
+ *signature_length = 0; /* For failure case */
+
+ req_msg.id = id;
+ req_msg.alg = alg;
+
+ struct tlv_record hash_record;
+ hash_record.tag = TS_CRYPTO_SIGN_HASH_IN_TAG_HASH;
+ hash_record.length = hash_length;
+ hash_record.value = hash;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &hash_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_SIGN_HASH, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) {
+
+ psa_status = opstatus;
+
+ if (psa_status == PSA_SUCCESS) {
+
+ struct tlv_const_iterator resp_iter;
+ struct tlv_record decoded_record;
+ tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
+
+ if (tlv_find_decode(&resp_iter,
+ TS_CRYPTO_SIGN_HASH_OUT_TAG_SIGNATURE, &decoded_record)) {
+
+ if (decoded_record.length <= signature_size) {
+
+ memcpy(signature, decoded_record.value, decoded_record.length);
+ *signature_length = decoded_record.length;
+ }
+ else {
+ /* Provided buffer is too small */
+ psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
+ }
+ }
+ else {
+ /* Mandatory response parameter missing */
+ psa_status = PSA_ERROR_GENERIC_ERROR;
+ }
+ }
+ }
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_SIGN_HASH_H */
diff --git a/components/service/crypto/client/caller/packed-c/crypto_caller_verify_hash.h b/components/service/crypto/client/caller/packed-c/crypto_caller_verify_hash.h
new file mode 100644
index 0000000..c5d1d35
--- /dev/null
+++ b/components/service/crypto/client/caller/packed-c/crypto_caller_verify_hash.h
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CALLER_VERIFY_HASH_H
+#define PACKEDC_CRYPTO_CALLER_VERIFY_HASH_H
+
+#include <string.h>
+#include <stdlib.h>
+#include <psa/crypto.h>
+#include <service/common/client/service_client.h>
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <protocols/service/crypto/packed-c/verify_hash.h>
+#include <common/tlv/tlv.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline psa_status_t crypto_caller_verify_hash(struct service_client *context,
+ 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_ERROR_GENERIC_ERROR;
+ struct ts_crypto_verify_hash_in req_msg;
+ size_t req_fixed_len = sizeof(struct ts_crypto_verify_hash_in);
+ size_t req_len = req_fixed_len +
+ tlv_required_space(hash_length) + tlv_required_space(signature_length);
+
+ req_msg.id = id;
+ req_msg.alg = alg;
+
+ struct tlv_record hash_record;
+ hash_record.tag = TS_CRYPTO_VERIFY_HASH_IN_TAG_HASH;
+ hash_record.length = hash_length;
+ hash_record.value = hash;
+
+ struct tlv_record sig_record;
+ sig_record.tag = TS_CRYPTO_VERIFY_HASH_IN_TAG_SIGNATURE;
+ sig_record.length = signature_length;
+ sig_record.value = signature;
+
+ rpc_call_handle call_handle;
+ uint8_t *req_buf;
+
+ call_handle = rpc_caller_begin(context->caller, &req_buf, req_len);
+
+ if (call_handle) {
+
+ uint8_t *resp_buf;
+ size_t resp_len;
+ int opstatus;
+ struct tlv_iterator req_iter;
+
+ memcpy(req_buf, &req_msg, req_fixed_len);
+
+ tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
+ tlv_encode(&req_iter, &hash_record);
+ tlv_encode(&req_iter, &sig_record);
+
+ context->rpc_status =
+ rpc_caller_invoke(context->caller, call_handle,
+ TS_CRYPTO_OPCODE_VERIFY_HASH, &opstatus, &resp_buf, &resp_len);
+
+ if (context->rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
+
+ rpc_caller_end(context->caller, call_handle);
+ }
+
+ return psa_status;
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* PACKEDC_CRYPTO_CALLER_VERIFY_HASH_H */
diff --git a/components/service/crypto/client/cpp/crypto_client.h b/components/service/crypto/client/cpp/crypto_client.h
index d996380..42085be 100644
--- a/components/service/crypto/client/cpp/crypto_client.h
+++ b/components/service/crypto/client/cpp/crypto_client.h
@@ -18,60 +18,95 @@
class crypto_client
{
public:
- virtual ~crypto_client();
+ virtual ~crypto_client();
- int err_rpc_status() const;
+ int err_rpc_status() const;
- /* Key lifecycle methods */
- virtual psa_status_t generate_key(const psa_key_attributes_t *attributes,
- psa_key_id_t *id) = 0;
- virtual psa_status_t destroy_key(psa_key_id_t id) = 0;
- virtual psa_status_t import_key(const psa_key_attributes_t *attributes,
- const uint8_t *data, size_t data_length, psa_key_id_t *id) = 0;
+ /* Key lifecycle methods */
+ virtual psa_status_t generate_key(
+ const psa_key_attributes_t *attributes,
+ psa_key_id_t *id) = 0;
- /* Key export methods */
- virtual psa_status_t export_key(psa_key_id_t id,
- uint8_t *data, size_t data_size,
- size_t *data_length) = 0;
- virtual psa_status_t export_public_key(psa_key_id_t id,
- uint8_t *data, size_t data_size, size_t *data_length) = 0;
+ virtual psa_status_t destroy_key(
+ psa_key_id_t id) = 0;
- /* Sign/verify methods */
- virtual 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) = 0;
- virtual 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) = 0;
+ virtual psa_status_t import_key(
+ const psa_key_attributes_t *attributes,
+ const uint8_t *data, size_t data_length,
+ psa_key_id_t *id) = 0;
- /* Asymmetric encrypt/decrypt */
- virtual 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) = 0;
- virtual 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) = 0;
+ virtual psa_status_t copy_key(
+ psa_key_id_t source_key,
+ const psa_key_attributes_t *attributes,
+ psa_key_id_t *target_key) = 0;
- /* Random number generation */
- virtual psa_status_t generate_random(uint8_t *output, size_t output_size) = 0;
+ virtual psa_status_t purge_key(
+ psa_key_id_t id) = 0;
- /* Hash methods */
- virtual psa_status_t hash_setup(uint32_t *op_handle,
- psa_algorithm_t alg) = 0;
- virtual psa_status_t hash_update(uint32_t op_handle,
- const uint8_t *input, size_t input_length) = 0;
- virtual psa_status_t hash_finish(uint32_t op_handle,
- uint8_t *hash, size_t hash_size, size_t *hash_length) = 0;
+ virtual psa_status_t get_key_attributes(
+ psa_key_id_t id,
+ psa_key_attributes_t *attributes) = 0;
+
+ /* Key export methods */
+ virtual psa_status_t export_key(
+ psa_key_id_t id,
+ uint8_t *data, size_t data_size, size_t *data_length) = 0;
+
+ virtual psa_status_t export_public_key(
+ psa_key_id_t id,
+ uint8_t *data, size_t data_size, size_t *data_length) = 0;
+
+ /* Sign/verify methods */
+ virtual 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) = 0;
+
+ virtual 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) = 0;
+
+ /* Asymmetric encrypt/decrypt */
+ virtual 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) = 0;
+
+ virtual 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) = 0;
+
+ /* Random number generation */
+ virtual psa_status_t generate_random(
+ uint8_t *output, size_t output_size) = 0;
+
+ /* Hash methods */
+ virtual psa_status_t hash_setup(
+ uint32_t *op_handle,
+ psa_algorithm_t alg) = 0;
+
+ virtual psa_status_t hash_update(
+ uint32_t op_handle,
+ const uint8_t *input, size_t input_length) = 0;
+
+ virtual psa_status_t hash_finish(
+ uint32_t op_handle,
+ uint8_t *hash, size_t hash_size, size_t *hash_length) = 0;
protected:
- crypto_client();
- crypto_client(struct rpc_caller *caller);
- void set_caller(struct rpc_caller *caller);
+ crypto_client();
+ crypto_client(struct rpc_caller *caller);
+ void set_caller(struct rpc_caller *caller);
- struct service_client m_client;
+ struct service_client m_client;
};
#endif /* CRYPTO_CLIENT_H */
diff --git a/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.cpp b/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.cpp
deleted file mode 100644
index 43b2a66..0000000
--- a/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.cpp
+++ /dev/null
@@ -1,842 +0,0 @@
-/*
- * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <cstring>
-#include <cstdlib>
-#include "packedc_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/key_attributes.h>
-#include <protocols/service/crypto/packed-c/asymmetric_decrypt.h>
-#include <protocols/service/crypto/packed-c/asymmetric_encrypt.h>
-#include <protocols/service/crypto/packed-c/destroy_key.h>
-#include <protocols/service/crypto/packed-c/export_key.h>
-#include <protocols/service/crypto/packed-c/export_public_key.h>
-#include <protocols/service/crypto/packed-c/generate_key.h>
-#include <protocols/service/crypto/packed-c/generate_random.h>
-#include <protocols/service/crypto/packed-c/import_key.h>
-#include <protocols/service/crypto/packed-c/sign_hash.h>
-#include <protocols/service/crypto/packed-c/verify_hash.h>
-#include <protocols/service/crypto/packed-c/hash.h>
-#include <common/tlv/tlv.h>
-#include <rpc_caller.h>
-
-
-packedc_crypto_client::packedc_crypto_client() :
- crypto_client()
-{
-
-}
-
-packedc_crypto_client::packedc_crypto_client(struct rpc_caller *caller) :
- crypto_client(caller)
-{
-
-}
-
-packedc_crypto_client::~packedc_crypto_client()
-{
-
-}
-
-psa_status_t packedc_crypto_client::generate_key(const psa_key_attributes_t *attributes,
- psa_key_id_t *id)
-{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_generate_key_in req_msg;
- size_t req_len = sizeof(ts_crypto_generate_key_in);
-
- translate_key_attributes(req_msg.attributes, *attributes);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_GENERATE_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(ts_crypto_generate_key_out)) {
-
- struct ts_crypto_generate_key_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(ts_crypto_generate_key_out));
- *id = resp_msg.id;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_client::destroy_key(psa_key_id_t id)
-{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_destroy_key_in req_msg;
- size_t req_len = sizeof(ts_crypto_destroy_key_in);
-
- req_msg.id = id;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_DESTROY_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_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_ERROR_GENERIC_ERROR;
- struct ts_crypto_import_key_in req_msg;
- size_t req_fixed_len = sizeof(ts_crypto_import_key_in);
- size_t req_len = req_fixed_len + tlv_required_space(data_length);
-
- translate_key_attributes(req_msg.attributes, *attributes);
-
- struct tlv_record key_record;
- key_record.tag = TS_CRYPTO_IMPORT_KEY_IN_TAG_DATA;
- key_record.length = data_length;
- key_record.value = data;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &key_record);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_IMPORT_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(ts_crypto_import_key_out)) {
-
- struct ts_crypto_import_key_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(ts_crypto_import_key_out));
- *id = resp_msg.id;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_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_ERROR_GENERIC_ERROR;
- struct ts_crypto_export_key_in req_msg;
- size_t req_len = sizeof(ts_crypto_export_key_in);
-
- req_msg.id = id;
-
- *data_length = 0; /* For failure case */
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_EXPORT_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_EXPORT_KEY_OUT_TAG_DATA, &decoded_record)) {
-
- if (decoded_record.length <= data_size) {
-
- memcpy(data, decoded_record.value, decoded_record.length);
- *data_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_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_ERROR_GENERIC_ERROR;
- struct ts_crypto_export_public_key_in req_msg;
- size_t req_len = sizeof(ts_crypto_export_public_key_in);
-
- req_msg.id = id;
-
- *data_length = 0; /* For failure case */
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_EXPORT_PUBLIC_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_EXPORT_PUBLIC_KEY_OUT_TAG_DATA, &decoded_record)) {
-
- if (decoded_record.length <= data_size) {
-
- memcpy(data, decoded_record.value, decoded_record.length);
- *data_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_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_ERROR_GENERIC_ERROR;
- struct ts_crypto_sign_hash_in req_msg;
- size_t req_fixed_len = sizeof(ts_crypto_sign_hash_in);
- size_t req_len = req_fixed_len + tlv_required_space(hash_length);
-
- *signature_length = 0; /* For failure case */
-
- req_msg.id = id;
- req_msg.alg = alg;
-
- struct tlv_record hash_record;
- hash_record.tag = TS_CRYPTO_SIGN_HASH_IN_TAG_HASH;
- hash_record.length = hash_length;
- hash_record.value = hash;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &hash_record);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_SIGN_HASH, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_SIGN_HASH_OUT_TAG_SIGNATURE, &decoded_record)) {
-
- if (decoded_record.length <= signature_size) {
-
- memcpy(signature, decoded_record.value, decoded_record.length);
- *signature_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-
-psa_status_t packedc_crypto_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_ERROR_GENERIC_ERROR;
- struct ts_crypto_verify_hash_in req_msg;
- size_t req_fixed_len = sizeof(ts_crypto_verify_hash_in);
- size_t req_len = req_fixed_len +
- tlv_required_space(hash_length) + tlv_required_space(signature_length);
-
- req_msg.id = id;
- req_msg.alg = alg;
-
- struct tlv_record hash_record;
- hash_record.tag = TS_CRYPTO_VERIFY_HASH_IN_TAG_HASH;
- hash_record.length = hash_length;
- hash_record.value = hash;
-
- struct tlv_record sig_record;
- sig_record.tag = TS_CRYPTO_VERIFY_HASH_IN_TAG_SIGNATURE;
- sig_record.length = signature_length;
- sig_record.value = signature;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &hash_record);
- tlv_encode(&req_iter, &sig_record);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_VERIFY_HASH, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_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_ERROR_GENERIC_ERROR;
- struct ts_crypto_asymmetric_encrypt_in req_msg;
- size_t req_fixed_len = sizeof(ts_crypto_asymmetric_encrypt_in);
- size_t req_len = req_fixed_len;
-
- *output_length = 0; /* For failure case */
-
- req_msg.id = id;
- req_msg.alg = alg;
-
- /* Mandatory parameter */
- struct tlv_record plaintext_record;
- plaintext_record.tag = TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_PLAINTEXT;
- plaintext_record.length = input_length;
- plaintext_record.value = input;
- req_len += tlv_required_space(plaintext_record.length);
-
- /* Optional parameter */
- struct tlv_record salt_record;
- salt_record.tag = TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_SALT;
- salt_record.length = (salt) ? salt_length : 0;
- salt_record.value = salt;
- if (salt) req_len += tlv_required_space(salt_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus = PSA_ERROR_GENERIC_ERROR;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &plaintext_record);
- if (salt) tlv_encode(&req_iter, &salt_record);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_ASYMMETRIC_ENCRYPT, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_ASYMMETRIC_ENCRYPT_OUT_TAG_CIPHERTEXT, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- *output_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_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_ERROR_GENERIC_ERROR;
- struct ts_crypto_asymmetric_decrypt_in req_msg;
- size_t req_fixed_len = sizeof(ts_crypto_asymmetric_decrypt_in);
- size_t req_len = req_fixed_len;
-
- *output_length = 0; /* For failure case */
-
- req_msg.id = id;
- req_msg.alg = alg;
-
- /* Mandatory parameter */
- struct tlv_record ciphertext_record;
- ciphertext_record.tag = TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_CIPHERTEXT;
- ciphertext_record.length = input_length;
- ciphertext_record.value = input;
- req_len += tlv_required_space(ciphertext_record.length);
-
- /* Optional parameter */
- struct tlv_record salt_record;
- salt_record.tag = TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_SALT;
- salt_record.length = (salt) ? salt_length : 0;
- salt_record.value = salt;
- if (salt) req_len += tlv_required_space(salt_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &ciphertext_record);
- if (salt) tlv_encode(&req_iter, &salt_record);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_ASYMMETRIC_DECRYPT, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_ASYMMETRIC_DECRYPT_OUT_TAG_PLAINTEXT, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- *output_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_client::generate_random(uint8_t *output, size_t output_size)
-{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_generate_random_in req_msg;
- size_t req_len = sizeof(ts_crypto_generate_random_in);
-
- req_msg.size = output_size;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_GENERATE_RANDOM, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_GENERATE_RANDOM_OUT_TAG_RANDOM_BYTES, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_client::hash_setup(uint32_t *op_handle,
- psa_algorithm_t alg)
-{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_hash_setup_in req_msg;
- size_t req_len = sizeof(ts_crypto_hash_setup_in);
-
- req_msg.alg = alg;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_HASH_SETUP, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(ts_crypto_hash_setup_out)) {
-
- struct ts_crypto_hash_setup_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(ts_crypto_hash_setup_out));
- *op_handle = resp_msg.op_handle;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_client::hash_update(uint32_t op_handle,
- const uint8_t *input, size_t input_length)
-{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_hash_update_in req_msg;
- size_t req_fixed_len = sizeof(ts_crypto_hash_update_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = op_handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_HASH_UPDATE_IN_TAG_DATA;
- data_record.length = input_length;
- data_record.value = input;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_HASH_UPDATE, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-psa_status_t packedc_crypto_client::hash_finish(uint32_t op_handle,
- uint8_t *hash, size_t hash_size, size_t *hash_length)
-{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_hash_finish_in req_msg;
- size_t req_fixed_len = sizeof(ts_crypto_hash_finish_in);
- size_t req_len = req_fixed_len;
-
- *hash_length = 0;
- req_msg.op_handle = op_handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(m_client.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- m_client.rpc_status = rpc_caller_invoke(m_client.caller, call_handle,
- TS_CRYPTO_OPCODE_HASH_FINISH, &opstatus, &resp_buf, &resp_len);
-
- if (m_client.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_HASH_FINISH_OUT_TAG_HASH, &decoded_record)) {
-
- if (decoded_record.length <= hash_size) {
-
- memcpy(hash, decoded_record.value, decoded_record.length);
- *hash_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(m_client.caller, call_handle);
- }
-
- return psa_status;
-}
-
-void packedc_crypto_client::translate_key_attributes(
- struct ts_crypto_key_attributes &proto_attributes,
- const psa_key_attributes_t &psa_attributes)
-{
- proto_attributes.type = psa_get_key_type(&psa_attributes);
- proto_attributes.key_bits = psa_get_key_bits(&psa_attributes);
- proto_attributes.lifetime = psa_get_key_lifetime(&psa_attributes);
- proto_attributes.id = psa_get_key_id(&psa_attributes);
-
- proto_attributes.policy.usage = psa_get_key_usage_flags(&psa_attributes);
- proto_attributes.policy.alg = psa_get_key_algorithm(&psa_attributes);
- }
diff --git a/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.h b/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.h
deleted file mode 100644
index be4bb66..0000000
--- a/components/service/crypto/client/cpp/packed-c/packedc_crypto_client.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef PACKEDC_CRYPTO_CLIENT_H
-#define PACKEDC_CRYPTO_CLIENT_H
-
-#include <service/crypto/client/cpp/crypto_client.h>
-#include <protocols/service/crypto/packed-c/key_attributes.h>
-
-/*
- * A concrete crypto_client that uses the packed-c based crypto access protocol
- */
-class packedc_crypto_client : public crypto_client
-{
-public:
- packedc_crypto_client();
- packedc_crypto_client(struct rpc_caller *caller);
- virtual ~packedc_crypto_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);
-
- /* 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);
-
-private:
-
- void translate_key_attributes(struct ts_crypto_key_attributes &proto_attributes,
- const psa_key_attributes_t &psa_attributes);
-};
-
-#endif /* PACKEDC_CRYPTO_CLIENT_H */
diff --git a/components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.h b/components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.h
deleted file mode 100644
index bc407d1..0000000
--- a/components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef PROTOBUF_CRYPTO_CLIENT_H
-#define PROTOBUF_CRYPTO_CLIENT_H
-
-#include <service/crypto/client/cpp/crypto_client.h>
-#include <service/crypto/protobuf/key_attributes.pb.h>
-
-/*
- * A concrete crypto_client that uses the protobuf based crypto access protocol
- */
-class protobuf_crypto_client : public crypto_client
-{
-public:
- protobuf_crypto_client();
- protobuf_crypto_client(struct rpc_caller *caller);
- virtual ~protobuf_crypto_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);
-
- /* 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);
-
-private:
-
- void translate_key_attributes(ts_crypto_KeyAttributes &proto_attributes,
- const psa_key_attributes_t &psa_attributes);
-};
-
-#endif /* PROTOBUF_CRYPTO_CLIENT_H */
diff --git a/components/service/crypto/client/cpp/packed-c/component.cmake b/components/service/crypto/client/cpp/protocol/packed-c/component.cmake
similarity index 100%
rename from components/service/crypto/client/cpp/packed-c/component.cmake
rename to components/service/crypto/client/cpp/protocol/packed-c/component.cmake
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
new file mode 100644
index 0000000..74c07db
--- /dev/null
+++ b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.cpp
@@ -0,0 +1,162 @@
+/*
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include "packedc_crypto_client.h"
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
+#include <rpc_caller.h>
+
+
+packedc_crypto_client::packedc_crypto_client() :
+ crypto_client()
+{
+
+}
+
+packedc_crypto_client::packedc_crypto_client(struct rpc_caller *caller) :
+ crypto_client(caller)
+{
+
+}
+
+packedc_crypto_client::~packedc_crypto_client()
+{
+
+}
+
+psa_status_t packedc_crypto_client::generate_key(
+ const psa_key_attributes_t *attributes,
+ psa_key_id_t *id)
+{
+ return crypto_caller_generate_key(&m_client, attributes, id);
+}
+
+psa_status_t packedc_crypto_client::destroy_key(
+ psa_key_id_t id)
+{
+ return crypto_caller_destroy_key(&m_client, id);
+}
+
+psa_status_t packedc_crypto_client::copy_key(
+ psa_key_id_t source_key,
+ const psa_key_attributes_t *attributes,
+ psa_key_id_t *target_key)
+{
+ return crypto_caller_copy_key(&m_client, source_key, attributes, target_key);
+}
+
+psa_status_t packedc_crypto_client::purge_key(
+ psa_key_id_t id)
+{
+ return crypto_caller_purge_key(&m_client, id);
+}
+
+psa_status_t packedc_crypto_client::get_key_attributes(
+ psa_key_id_t id,
+ psa_key_attributes_t *attributes)
+{
+ return crypto_caller_get_key_attributes(&m_client, id, attributes);
+}
+
+psa_status_t packedc_crypto_client::import_key(
+ const psa_key_attributes_t *attributes,
+ const uint8_t *data, size_t data_length,
+ psa_key_id_t *id)
+{
+ return crypto_caller_import_key(&m_client, attributes,
+ data, data_length, id);
+}
+
+psa_status_t packedc_crypto_client::export_key(
+ psa_key_id_t id,
+ uint8_t *data, size_t data_size,
+ size_t *data_length)
+{
+ return crypto_caller_export_key(&m_client, id,
+ data, data_size, data_length);
+}
+
+psa_status_t packedc_crypto_client::export_public_key(
+ psa_key_id_t id,
+ uint8_t *data, size_t data_size, size_t *data_length)
+{
+ return crypto_caller_export_public_key(&m_client, id,
+ data, data_size, data_length);
+}
+
+psa_status_t packedc_crypto_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)
+{
+ return crypto_caller_sign_hash(&m_client, id, alg,
+ hash, hash_length,
+ signature, signature_size, signature_length);
+}
+
+psa_status_t packedc_crypto_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)
+{
+ return crypto_caller_verify_hash(&m_client, id, alg,
+ hash, hash_length,
+ signature, signature_length);
+}
+
+psa_status_t packedc_crypto_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)
+{
+ return crypto_caller_asymmetric_encrypt(&m_client, id, alg,
+ input, input_length,
+ salt, salt_length,
+ output, output_size, output_length);
+}
+
+psa_status_t packedc_crypto_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)
+{
+ return crypto_caller_asymmetric_decrypt(&m_client, id, alg,
+ input, input_length,
+ salt, salt_length,
+ output, output_size, output_length);
+}
+
+psa_status_t packedc_crypto_client::generate_random(
+ uint8_t *output, size_t output_size)
+{
+ return crypto_caller_generate_random(&m_client,
+ output, output_size);
+}
+
+psa_status_t packedc_crypto_client::hash_setup(
+ uint32_t *op_handle,
+ psa_algorithm_t alg)
+{
+ return crypto_caller_hash_setup(&m_client,
+ op_handle, alg);
+}
+
+psa_status_t packedc_crypto_client::hash_update(
+ uint32_t op_handle,
+ const uint8_t *input, size_t input_length)
+{
+ return crypto_caller_hash_update(&m_client,
+ op_handle, input, input_length);
+}
+
+psa_status_t packedc_crypto_client::hash_finish(
+ uint32_t op_handle,
+ uint8_t *hash, size_t hash_size, size_t *hash_length)
+{
+ return crypto_caller_hash_finish(&m_client,
+ op_handle, hash, hash_size, hash_length);
+}
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
new file mode 100644
index 0000000..0cbc666
--- /dev/null
+++ b/components/service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PACKEDC_CRYPTO_CLIENT_H
+#define PACKEDC_CRYPTO_CLIENT_H
+
+#include <service/crypto/client/cpp/crypto_client.h>
+#include <protocols/service/crypto/packed-c/key_attributes.h>
+
+/*
+ * A concrete crypto_client that uses the packed-c based crypto access protocol
+ */
+class packedc_crypto_client : public crypto_client
+{
+public:
+ packedc_crypto_client();
+ packedc_crypto_client(struct rpc_caller *caller);
+ virtual ~packedc_crypto_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 /* PACKEDC_CRYPTO_CLIENT_H */
diff --git a/components/service/crypto/client/cpp/protobuf/component.cmake b/components/service/crypto/client/cpp/protocol/protobuf/component.cmake
similarity index 100%
rename from components/service/crypto/client/cpp/protobuf/component.cmake
rename to components/service/crypto/client/cpp/protocol/protobuf/component.cmake
diff --git a/components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.cpp b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp
similarity index 97%
rename from components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.cpp
rename to components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp
index 1823a4a..7629f7d 100644
--- a/components/service/crypto/client/cpp/protobuf/protobuf_crypto_client.cpp
+++ b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.cpp
@@ -194,6 +194,28 @@
return psa_status;
}
+psa_status_t protobuf_crypto_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 protobuf_crypto_client::purge_key(
+ psa_key_id_t id)
+{
+ return PSA_ERROR_NOT_SUPPORTED;
+}
+
+psa_status_t protobuf_crypto_client::get_key_attributes(
+ psa_key_id_t id,
+ psa_key_attributes_t *attributes)
+{
+ return PSA_ERROR_NOT_SUPPORTED;
+}
+
+
psa_status_t protobuf_crypto_client::export_key(psa_key_id_t id,
uint8_t *data, size_t data_size,
size_t *data_length)
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
new file mode 100644
index 0000000..c04d82d
--- /dev/null
+++ b/components/service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PROTOBUF_CRYPTO_CLIENT_H
+#define PROTOBUF_CRYPTO_CLIENT_H
+
+#include <service/crypto/client/cpp/crypto_client.h>
+#include <service/crypto/protobuf/key_attributes.pb.h>
+
+/*
+ * A concrete crypto_client that uses the protobuf based crypto access protocol
+ */
+class protobuf_crypto_client : public crypto_client
+{
+public:
+ protobuf_crypto_client();
+ protobuf_crypto_client(struct rpc_caller *caller);
+ virtual ~protobuf_crypto_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);
+
+private:
+
+ void translate_key_attributes(
+ ts_crypto_KeyAttributes &proto_attributes,
+ const psa_key_attributes_t &psa_attributes);
+};
+
+#endif /* PROTOBUF_CRYPTO_CLIENT_H */
diff --git a/components/service/crypto/client/psa/psa_aead.c b/components/service/crypto/client/psa/psa_aead.c
index 6f92f4c..39e0f1e 100644
--- a/components/service/crypto/client/psa/psa_aead.c
+++ b/components/service/crypto/client/psa/psa_aead.c
@@ -4,14 +4,10 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/aead.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
+
psa_status_t psa_aead_encrypt(psa_key_id_t key,
psa_algorithm_t alg,
@@ -43,72 +39,26 @@
return PSA_ERROR_NOT_SUPPORTED;
}
-static psa_status_t common_aead_setup(psa_aead_operation_t *operation,
- psa_key_id_t key,
- psa_algorithm_t alg,
- uint32_t opcode)
-{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_aead_setup_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_aead_setup_in);
-
- req_msg.key_id = key;
- req_msg.alg = alg;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- opcode, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_aead_setup_out)) {
-
- struct ts_crypto_aead_setup_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_aead_setup_out));
- operation->handle = resp_msg.op_handle;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
-}
-
psa_status_t psa_aead_encrypt_setup(psa_aead_operation_t *operation,
psa_key_id_t key,
psa_algorithm_t alg)
{
- return common_aead_setup(operation, key, alg, TS_CRYPTO_OPCODE_AEAD_ENCRYPT_SETUP);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
+
+ return crypto_caller_aead_encrypt_setup(&psa_crypto_client_instance.base,
+ &operation->handle, key, alg);
}
psa_status_t psa_aead_decrypt_setup(psa_aead_operation_t *operation,
psa_key_id_t key,
psa_algorithm_t alg)
{
- return common_aead_setup(operation, key, alg, TS_CRYPTO_OPCODE_AEAD_DECRYPT_SETUP);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
+
+ return crypto_caller_aead_decrypt_setup(&psa_crypto_client_instance.base,
+ &operation->handle, key, alg);
}
psa_status_t psa_aead_generate_nonce(psa_aead_operation_t *operation,
@@ -116,197 +66,36 @@
size_t nonce_size,
size_t *nonce_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_aead_generate_nonce_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_aead_generate_nonce_in);
- size_t req_len = req_fixed_len;
-
- *nonce_length = 0;
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_AEAD_GENERATE_NONCE, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_AEAD_GENERATE_NONCE_OUT_TAG_NONCE, &decoded_record)) {
-
- if (decoded_record.length <= nonce_size) {
-
- memcpy(nonce, decoded_record.value, decoded_record.length);
- *nonce_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_aead_generate_nonce(&psa_crypto_client_instance.base,
+ operation->handle,
+ nonce, nonce_size, nonce_length);
}
psa_status_t psa_aead_set_nonce(psa_aead_operation_t *operation,
const uint8_t *nonce,
size_t nonce_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_aead_set_nonce_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_aead_set_nonce_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_AEAD_SET_NONCE_IN_TAG_NONCE;
- data_record.length = nonce_length;
- data_record.value = nonce;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_AEAD_SET_NONCE, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_aead_set_nonce(&psa_crypto_client_instance.base,
+ operation->handle,
+ nonce, nonce_length);
}
psa_status_t psa_aead_set_lengths(psa_aead_operation_t *operation,
size_t ad_length,
size_t plaintext_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_aead_set_lengths_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_aead_abort_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
- req_msg.ad_length = ad_length;
- req_msg.plaintext_length = plaintext_length;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_AEAD_SET_LENGTHS, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_aead_set_lengths(&psa_crypto_client_instance.base,
+ operation->handle,
+ ad_length, plaintext_length);
}
psa_status_t psa_aead_update_ad(psa_aead_operation_t *operation,
const uint8_t *input,
size_t input_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_aead_update_ad_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_aead_update_ad_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_AEAD_UPDATE_AD_IN_TAG_DATA;
- data_record.length = input_length;
- data_record.value = input;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_AEAD_UPDATE_AD, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_aead_update_ad(&psa_crypto_client_instance.base,
+ operation->handle,
+ input, input_length);
}
psa_status_t psa_aead_update(psa_aead_operation_t *operation,
@@ -316,76 +105,10 @@
size_t output_size,
size_t *output_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_aead_update_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_aead_update_in);
- size_t req_len = req_fixed_len;
-
- *output_length = 0;
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_AEAD_UPDATE_IN_TAG_DATA;
- data_record.length = input_length;
- data_record.value = input;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_AEAD_UPDATE, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_AEAD_UPDATE_OUT_TAG_DATA, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- *output_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_aead_update(&psa_crypto_client_instance.base,
+ operation->handle,
+ input, input_length,
+ output, output_size, output_length);
}
psa_status_t psa_aead_finish(psa_aead_operation_t *operation,
@@ -396,84 +119,10 @@
size_t tag_size,
size_t *tag_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_aead_finish_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_aead_finish_in);
- size_t req_len = req_fixed_len;
-
- *aeadtext_length = 0;
- *tag_length = 0;
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_AEAD_FINISH, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_AEAD_FINISH_OUT_TAG_CIPHERTEXT, &decoded_record)) {
-
- if (decoded_record.length <= aeadtext_size) {
-
- memcpy(aeadtext, decoded_record.value, decoded_record.length);
- *aeadtext_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
-
- if ((psa_status == PSA_SUCCESS) && tlv_find_decode(&resp_iter,
- TS_CRYPTO_AEAD_FINISH_OUT_TAG_TAG, &decoded_record)) {
-
- if (decoded_record.length <= tag_size) {
-
- memcpy(tag, decoded_record.value, decoded_record.length);
- *tag_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_aead_finish(&psa_crypto_client_instance.base,
+ operation->handle,
+ aeadtext, aeadtext_size, aeadtext_length,
+ tag, tag_size, tag_length);
}
psa_status_t psa_aead_verify(psa_aead_operation_t *operation,
@@ -483,108 +132,14 @@
const uint8_t *tag,
size_t tag_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_aead_verify_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_aead_verify_in);
- size_t req_len = req_fixed_len;
-
- *plaintext_length = 0;
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_AEAD_VERIFY_IN_TAG_TAG;
- data_record.length = tag_length;
- data_record.value = tag;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_AEAD_VERIFY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_AEAD_VERIFY_OUT_TAG_PLAINTEXT, &decoded_record)) {
-
- if (decoded_record.length <= plaintext_size) {
-
- memcpy(plaintext, decoded_record.value, decoded_record.length);
- *plaintext_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_aead_verify(&psa_crypto_client_instance.base,
+ operation->handle,
+ plaintext, plaintext_size, plaintext_length,
+ tag, tag_length);
}
psa_status_t psa_aead_abort(psa_aead_operation_t *operation)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_aead_abort_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_aead_abort_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_AEAD_ABORT, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_aead_abort(&psa_crypto_client_instance.base,
+ operation->handle);
}
diff --git a/components/service/crypto/client/psa/psa_asymmetric_decrypt.c b/components/service/crypto/client/psa/psa_asymmetric_decrypt.c
index 1b9300e..d137b6e 100644
--- a/components/service/crypto/client/psa/psa_asymmetric_decrypt.c
+++ b/components/service/crypto/client/psa/psa_asymmetric_decrypt.c
@@ -4,102 +4,22 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/asymmetric_decrypt.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_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)
+ 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_ERROR_GENERIC_ERROR;
- struct ts_crypto_asymmetric_decrypt_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_asymmetric_decrypt_in);
- size_t req_len = req_fixed_len;
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- *output_length = 0; /* For failure case */
-
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- req_msg.id = id;
- req_msg.alg = alg;
-
- /* Mandatory parameter */
- struct tlv_record ciphertext_record;
- ciphertext_record.tag = TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_CIPHERTEXT;
- ciphertext_record.length = input_length;
- ciphertext_record.value = input;
- req_len += tlv_required_space(ciphertext_record.length);
-
- /* Optional parameter */
- struct tlv_record salt_record;
- salt_record.tag = TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_SALT;
- salt_record.length = (salt) ? salt_length : 0;
- salt_record.value = salt;
- if (salt) req_len += tlv_required_space(salt_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &ciphertext_record);
- if (salt) tlv_encode(&req_iter, &salt_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_ASYMMETRIC_DECRYPT, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_ASYMMETRIC_DECRYPT_OUT_TAG_PLAINTEXT, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- *output_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_asymmetric_decrypt(&psa_crypto_client_instance.base,
+ id, alg,
+ input, input_length,
+ salt, salt_length,
+ output, output_size, output_length);
}
diff --git a/components/service/crypto/client/psa/psa_asymmetric_encrypt.c b/components/service/crypto/client/psa/psa_asymmetric_encrypt.c
index efe6c83..bb96657 100644
--- a/components/service/crypto/client/psa/psa_asymmetric_encrypt.c
+++ b/components/service/crypto/client/psa/psa_asymmetric_encrypt.c
@@ -4,102 +4,22 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/asymmetric_encrypt.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_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)
+ 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_ERROR_GENERIC_ERROR;
- struct ts_crypto_asymmetric_encrypt_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_asymmetric_encrypt_in);
- size_t req_len = req_fixed_len;
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- *output_length = 0; /* For failure case */
-
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- req_msg.id = id;
- req_msg.alg = alg;
-
- /* Mandatory parameter */
- struct tlv_record plaintext_record;
- plaintext_record.tag = TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_PLAINTEXT;
- plaintext_record.length = input_length;
- plaintext_record.value = input;
- req_len += tlv_required_space(plaintext_record.length);
-
- /* Optional parameter */
- struct tlv_record salt_record;
- salt_record.tag = TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_SALT;
- salt_record.length = (salt) ? salt_length : 0;
- salt_record.value = salt;
- if (salt) req_len += tlv_required_space(salt_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus = PSA_ERROR_GENERIC_ERROR;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &plaintext_record);
- if (salt) tlv_encode(&req_iter, &salt_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_ASYMMETRIC_ENCRYPT, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_ASYMMETRIC_ENCRYPT_OUT_TAG_CIPHERTEXT, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- *output_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_asymmetric_encrypt(&psa_crypto_client_instance.base,
+ id, alg,
+ input, input_length,
+ salt, salt_length,
+ output, output_size, output_length);
}
diff --git a/components/service/crypto/client/psa/psa_cipher.c b/components/service/crypto/client/psa/psa_cipher.c
index e8ee7af..23d52d1 100644
--- a/components/service/crypto/client/psa/psa_cipher.c
+++ b/components/service/crypto/client/psa/psa_cipher.c
@@ -4,81 +4,27 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/cipher.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
-static psa_status_t common_cipher_setup(psa_cipher_operation_t *operation,
- psa_key_id_t key,
- psa_algorithm_t alg,
- uint32_t opcode)
-{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_cipher_setup_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_cipher_setup_in);
-
- req_msg.key_id = key;
- req_msg.alg = alg;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- opcode, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_cipher_setup_out)) {
-
- struct ts_crypto_cipher_setup_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_cipher_setup_out));
- operation->handle = resp_msg.op_handle;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
-}
psa_status_t psa_cipher_encrypt_setup(psa_cipher_operation_t *operation,
psa_key_id_t key,
psa_algorithm_t alg)
{
- return common_cipher_setup(operation, key, alg, TS_CRYPTO_OPCODE_CIPHER_ENCRYPT_SETUP);
+ return crypto_caller_cipher_encrypt_setup(&psa_crypto_client_instance.base,
+ &operation->handle,
+ key, alg);
}
psa_status_t psa_cipher_decrypt_setup(psa_cipher_operation_t *operation,
psa_key_id_t key,
psa_algorithm_t alg)
{
- return common_cipher_setup(operation, key, alg, TS_CRYPTO_OPCODE_CIPHER_DECRYPT_SETUP);
+ return crypto_caller_cipher_decrypt_setup(&psa_crypto_client_instance.base,
+ &operation->handle,
+ key, alg);
}
psa_status_t psa_cipher_generate_iv(psa_cipher_operation_t *operation,
@@ -86,112 +32,18 @@
size_t iv_size,
size_t *iv_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_cipher_generate_iv_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_cipher_generate_iv_in);
- size_t req_len = req_fixed_len;
-
- *iv_length = 0;
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_CIPHER_GENERATE_IV, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_CIPHER_GENERATE_IV_OUT_TAG_IV, &decoded_record)) {
-
- if (decoded_record.length <= iv_size) {
-
- memcpy(iv, decoded_record.value, decoded_record.length);
- *iv_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_cipher_generate_iv(&psa_crypto_client_instance.base,
+ operation->handle,
+ iv, iv_size, iv_length);
}
psa_status_t psa_cipher_set_iv(psa_cipher_operation_t *operation,
const uint8_t *iv,
size_t iv_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_cipher_set_iv_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_cipher_set_iv_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_CIPHER_SET_IV_IN_TAG_IV;
- data_record.length = iv_length;
- data_record.value = iv;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_CIPHER_SET_IV, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_cipher_set_iv(&psa_crypto_client_instance.base,
+ operation->handle,
+ iv, iv_length);
}
psa_status_t psa_cipher_update(psa_cipher_operation_t *operation,
@@ -201,76 +53,10 @@
size_t output_size,
size_t *output_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_cipher_update_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_cipher_update_in);
- size_t req_len = req_fixed_len;
-
- *output_length = 0;
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_CIPHER_UPDATE_IN_TAG_DATA;
- data_record.length = input_length;
- data_record.value = input;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_CIPHER_UPDATE, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_CIPHER_UPDATE_OUT_TAG_DATA, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- *output_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_cipher_update(&psa_crypto_client_instance.base,
+ operation->handle,
+ input, input_length,
+ output, output_size, output_length);
}
psa_status_t psa_cipher_finish(psa_cipher_operation_t *operation,
@@ -278,111 +64,15 @@
size_t output_size,
size_t *output_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_cipher_finish_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_cipher_finish_in);
- size_t req_len = req_fixed_len;
-
- *output_length = 0;
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_CIPHER_FINISH, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_CIPHER_FINISH_OUT_TAG_DATA, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- *output_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_cipher_finish(&psa_crypto_client_instance.base,
+ operation->handle,
+ output, output_size, output_length);
}
psa_status_t psa_cipher_abort(psa_cipher_operation_t *operation)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_cipher_abort_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_cipher_abort_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_CIPHER_ABORT, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
-}
-
-static size_t max_cipher_update_size(void)
-{
- /* Returns the maximum number of bytes that may be
- * carried as a parameter of the cipher_update operation
- * using the packed-c encoding.
- */
- size_t payload_space = psa_crypto_client_instance.base.service_info.max_payload;
- size_t overhead = sizeof(struct ts_crypto_cipher_update_in) + TLV_HDR_LEN;
-
- return (payload_space > overhead) ? payload_space - overhead : 0;
+ return crypto_caller_cipher_abort(&psa_crypto_client_instance.base,
+ operation->handle);
}
static psa_status_t multi_cipher_update(psa_cipher_operation_t *operation,
@@ -393,7 +83,8 @@
size_t *output_length)
{
psa_status_t psa_status = PSA_SUCCESS;
- size_t max_update_size = max_cipher_update_size();
+ size_t max_update_size =
+ crypto_caller_cipher_max_update_size(&psa_crypto_client_instance.base);
size_t bytes_input = 0;
size_t bytes_output = 0;
diff --git a/components/service/crypto/client/psa/psa_copy_key.c b/components/service/crypto/client/psa/psa_copy_key.c
index 2919a0e..c2f7904 100644
--- a/components/service/crypto/client/psa/psa_copy_key.c
+++ b/components/service/crypto/client/psa/psa_copy_key.c
@@ -4,70 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include "psa_crypto_client_key_attributes.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/copy_key.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_copy_key(psa_key_id_t source_key,
const psa_key_attributes_t *attributes,
psa_key_id_t *target_key)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_copy_key_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_copy_key_in);
-
- /* Set default outputs for failure case */
- *target_key = 0;
-
if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
return psa_crypto_client_instance.init_status;
- req_msg.source_key_id = source_key;
- psa_crypto_client_translate_key_attributes_to_proto(&req_msg.attributes, attributes);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_COPY_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_copy_key_out)) {
-
- struct ts_crypto_copy_key_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_copy_key_out));
- *target_key = resp_msg.target_key_id;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_copy_key(&psa_crypto_client_instance.base,
+ source_key, attributes, target_key);
}
diff --git a/components/service/crypto/client/psa/psa_crypto_client.c b/components/service/crypto/client/psa/psa_crypto_client.c
index 41e21a4..5c2a87c 100644
--- a/components/service/crypto/client/psa/psa_crypto_client.c
+++ b/components/service/crypto/client/psa/psa_crypto_client.c
@@ -8,7 +8,6 @@
#include <service/discovery/client/discovery_client.h>
#include "psa_crypto_client.h"
-/* The singleton psa_crypto_client state */
struct psa_crypto_client psa_crypto_client_instance = {
.base.caller = NULL,
diff --git a/components/service/crypto/client/psa/psa_crypto_client.h b/components/service/crypto/client/psa/psa_crypto_client.h
index d8ae1cb..4fc54a3 100644
--- a/components/service/crypto/client/psa/psa_crypto_client.h
+++ b/components/service/crypto/client/psa/psa_crypto_client.h
@@ -23,8 +23,8 @@
*/
struct psa_crypto_client
{
- struct service_client base;
- psa_status_t init_status;
+ struct service_client base;
+ psa_status_t init_status;
};
extern struct psa_crypto_client psa_crypto_client_instance;
diff --git a/components/service/crypto/client/psa/psa_crypto_client_key_attributes.c b/components/service/crypto/client/psa/psa_crypto_client_key_attributes.c
index b257218..f91f65e 100644
--- a/components/service/crypto/client/psa/psa_crypto_client_key_attributes.c
+++ b/components/service/crypto/client/psa/psa_crypto_client_key_attributes.c
@@ -4,34 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include "psa_crypto_client_key_attributes.h"
-
-
-void psa_crypto_client_translate_key_attributes_to_proto(
- struct ts_crypto_key_attributes *proto_attributes,
- const psa_key_attributes_t *psa_attributes)
-{
- proto_attributes->type = psa_get_key_type(psa_attributes);
- proto_attributes->key_bits = psa_get_key_bits(psa_attributes);
- proto_attributes->lifetime = psa_get_key_lifetime(psa_attributes);
- proto_attributes->id = psa_get_key_id(psa_attributes);
-
- proto_attributes->policy.usage = psa_get_key_usage_flags(psa_attributes);
- proto_attributes->policy.alg = psa_get_key_algorithm(psa_attributes);
- }
-
-void psa_crypto_client_translate_key_attributes_from_proto(
- psa_key_attributes_t *psa_attributes,
- const struct ts_crypto_key_attributes *proto_attributes)
-{
- psa_set_key_type(psa_attributes, proto_attributes->type);
- psa_set_key_bits(psa_attributes, proto_attributes->key_bits);
- psa_set_key_lifetime(psa_attributes, proto_attributes->lifetime);
- psa_set_key_id(psa_attributes, proto_attributes->id);
-
- psa_set_key_usage_flags(psa_attributes, proto_attributes->policy.usage);
- psa_set_key_algorithm(psa_attributes, proto_attributes->policy.alg);
-}
+#include <psa/crypto.h>
/*
* The key attributes structure used on the client API doesn't
diff --git a/components/service/crypto/client/psa/psa_crypto_client_key_attributes.h b/components/service/crypto/client/psa/psa_crypto_client_key_attributes.h
deleted file mode 100644
index a38e1de..0000000
--- a/components/service/crypto/client/psa/psa_crypto_client_key_attributes.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef PSA_CRYPTO_CLIENT_KEY_ATTRIBUTES_H
-#define PSA_CRYPTO_CLIENT_KEY_ATTRIBUTES_H
-
-#include <psa/crypto.h>
-#include <protocols/service/crypto/packed-c/key_attributes.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @brief Translate psa key attributes to packed-c serialization
- *
- * @param[out] proto_attributes The serialized key attributes
- * @param[in] psa_attributes psa key attributes from crypto api
- */
-void psa_crypto_client_translate_key_attributes_to_proto(
- struct ts_crypto_key_attributes *proto_attributes,
- const psa_key_attributes_t *psa_attributes);
-
-/**
- * @brief Translate psa key attributes from packed-c serialization
- *
- * @param[out] psa_attributes psa key attributes from crypto api
- * @param[in] proto_attributes The serialized key attributes
- */
-void psa_crypto_client_translate_key_attributes_from_proto(
- psa_key_attributes_t *psa_attributes,
- const struct ts_crypto_key_attributes *proto_attributes);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* PSA_CRYPTO_CLIENT_KEY_ATTRIBUTES_H */
diff --git a/components/service/crypto/client/psa/psa_destroy_key.c b/components/service/crypto/client/psa/psa_destroy_key.c
index 829a560..c8114cb 100644
--- a/components/service/crypto/client/psa/psa_destroy_key.c
+++ b/components/service/crypto/client/psa/psa_destroy_key.c
@@ -4,46 +4,14 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/destroy_key.h>
-
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_destroy_key(psa_key_id_t id)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_destroy_key_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_destroy_key_in);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- req_msg.id = id;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_DESTROY_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_destroy_key(&psa_crypto_client_instance.base, id);
}
diff --git a/components/service/crypto/client/psa/psa_export_key.c b/components/service/crypto/client/psa/psa_export_key.c
index 420553b..0596b6f 100644
--- a/components/service/crypto/client/psa/psa_export_key.c
+++ b/components/service/crypto/client/psa/psa_export_key.c
@@ -4,81 +4,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/export_key.h>
-#include <protocols/service/crypto/packed-c/export_public_key.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_export_key(psa_key_id_t id,
- uint8_t *data, size_t data_size,
- size_t *data_length)
+ uint8_t *data, size_t data_size, size_t *data_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_export_key_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_export_key_in);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- req_msg.id = id;
-
- *data_length = 0; /* For failure case */
-
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_EXPORT_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_EXPORT_KEY_OUT_TAG_DATA, &decoded_record)) {
-
- if (decoded_record.length <= data_size) {
-
- memcpy(data, decoded_record.value, decoded_record.length);
- *data_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_export_key(&psa_crypto_client_instance.base, id,
+ data, data_size, data_length);
}
diff --git a/components/service/crypto/client/psa/psa_export_public_key.c b/components/service/crypto/client/psa/psa_export_public_key.c
index ad1344c..4343516 100644
--- a/components/service/crypto/client/psa/psa_export_public_key.c
+++ b/components/service/crypto/client/psa/psa_export_public_key.c
@@ -4,79 +4,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/export_public_key.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_export_public_key(psa_key_id_t id,
- uint8_t *data, size_t data_size, size_t *data_length)
+ uint8_t *data, size_t data_size, size_t *data_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_export_public_key_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_export_public_key_in);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- req_msg.id = id;
-
- *data_length = 0; /* For failure case */
-
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_EXPORT_PUBLIC_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_EXPORT_PUBLIC_KEY_OUT_TAG_DATA, &decoded_record)) {
-
- if (decoded_record.length <= data_size) {
-
- memcpy(data, decoded_record.value, decoded_record.length);
- *data_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_export_public_key(&psa_crypto_client_instance.base, id,
+ data, data_size, data_length);
}
diff --git a/components/service/crypto/client/psa/psa_generate_key.c b/components/service/crypto/client/psa/psa_generate_key.c
index 5604020..732068f 100644
--- a/components/service/crypto/client/psa/psa_generate_key.c
+++ b/components/service/crypto/client/psa/psa_generate_key.c
@@ -4,69 +4,16 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include "psa_crypto_client_key_attributes.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/key_attributes.h>
-#include <protocols/service/crypto/packed-c/generate_key.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_generate_key(const psa_key_attributes_t *attributes, psa_key_id_t *id)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_generate_key_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_generate_key_in);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- /* Set default outputs for failure case */
- *id = 0;
-
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- psa_crypto_client_translate_key_attributes_to_proto(&req_msg.attributes, attributes);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_GENERATE_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_generate_key_out)) {
-
- struct ts_crypto_generate_key_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_generate_key_out));
- *id = resp_msg.id;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_generate_key(&psa_crypto_client_instance.base,
+ attributes, id);
}
diff --git a/components/service/crypto/client/psa/psa_generate_random.c b/components/service/crypto/client/psa/psa_generate_random.c
index a942191..1eaa490 100644
--- a/components/service/crypto/client/psa/psa_generate_random.c
+++ b/components/service/crypto/client/psa/psa_generate_random.c
@@ -4,73 +4,14 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/generate_random.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_generate_random(uint8_t *output, size_t output_size)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_generate_random_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_generate_random_in);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- req_msg.size = output_size;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_GENERATE_RANDOM, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_GENERATE_RANDOM_OUT_TAG_RANDOM_BYTES, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_generate_random(&psa_crypto_client_instance.base,
+ output, output_size);
}
diff --git a/components/service/crypto/client/psa/psa_get_key_attributes.c b/components/service/crypto/client/psa/psa_get_key_attributes.c
index 35e3ed4..d625b5d 100644
--- a/components/service/crypto/client/psa/psa_get_key_attributes.c
+++ b/components/service/crypto/client/psa/psa_get_key_attributes.c
@@ -4,66 +4,17 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include "psa_crypto_client_key_attributes.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/get_key_attributes.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_get_key_attributes(psa_key_id_t key,
psa_key_attributes_t *attributes)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_get_key_attributes_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_get_key_attributes_in);
-
if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
return psa_crypto_client_instance.init_status;
- req_msg.id = key;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_GET_KEY_ATTRIBUTES, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_get_key_attributes_out)) {
-
- struct ts_crypto_get_key_attributes_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_get_key_attributes_out));
- psa_crypto_client_translate_key_attributes_from_proto(
- attributes, &resp_msg.attributes);
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_get_key_attributes(&psa_crypto_client_instance.base,
+ key, attributes);
}
diff --git a/components/service/crypto/client/psa/psa_hash.c b/components/service/crypto/client/psa/psa_hash.c
index 469f341..eab35ed 100644
--- a/components/service/crypto/client/psa/psa_hash.c
+++ b/components/service/crypto/client/psa/psa_hash.c
@@ -4,111 +4,27 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/hash.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_hash_setup(psa_hash_operation_t *operation,
psa_algorithm_t alg)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_hash_setup_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_hash_setup_in);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- req_msg.alg = alg;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_HASH_SETUP, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_hash_setup_out)) {
-
- struct ts_crypto_hash_setup_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_hash_setup_out));
- operation->handle = resp_msg.op_handle;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_hash_setup(&psa_crypto_client_instance.base,
+ &operation->handle, alg);
}
psa_status_t psa_hash_update(psa_hash_operation_t *operation,
const uint8_t *input,
size_t input_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_hash_update_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_hash_update_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_HASH_UPDATE_IN_TAG_DATA;
- data_record.length = input_length;
- data_record.value = input;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_HASH_UPDATE, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_hash_update(&psa_crypto_client_instance.base,
+ operation->handle,
+ input, input_length);
}
psa_status_t psa_hash_finish(psa_hash_operation_t *operation,
@@ -116,198 +32,32 @@
size_t hash_size,
size_t *hash_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_hash_finish_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_hash_finish_in);
- size_t req_len = req_fixed_len;
-
- *hash_length = 0;
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_HASH_FINISH, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_HASH_FINISH_OUT_TAG_HASH, &decoded_record)) {
-
- if (decoded_record.length <= hash_size) {
-
- memcpy(hash, decoded_record.value, decoded_record.length);
- *hash_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_hash_finish(&psa_crypto_client_instance.base,
+ operation->handle,
+ hash, hash_size, hash_length);
}
psa_status_t psa_hash_abort(psa_hash_operation_t *operation)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_hash_abort_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_hash_abort_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_HASH_ABORT, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_hash_abort(&psa_crypto_client_instance.base,
+ operation->handle);
}
psa_status_t psa_hash_verify(psa_hash_operation_t *operation,
const uint8_t *hash,
size_t hash_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_hash_verify_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_hash_verify_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_HASH_VERIFY_IN_TAG_HASH;
- data_record.length = hash_length;
- data_record.value = hash;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_HASH_VERIFY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_hash_verify(&psa_crypto_client_instance.base,
+ operation->handle,
+ hash, hash_length);
}
psa_status_t psa_hash_clone(const psa_hash_operation_t *source_operation,
psa_hash_operation_t *target_operation)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_hash_clone_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_hash_clone_in);
- size_t req_len = req_fixed_len;
-
- req_msg.source_op_handle = source_operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_HASH_CLONE, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_hash_clone_out)) {
-
- struct ts_crypto_hash_clone_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_hash_clone_out));
- target_operation->handle = resp_msg.target_op_handle;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_hash_clone(&psa_crypto_client_instance.base,
+ source_operation->handle,
+ &target_operation->handle);
}
psa_status_t psa_hash_suspend(psa_hash_operation_t *operation,
@@ -325,18 +75,6 @@
return PSA_ERROR_NOT_SUPPORTED;
}
-static size_t max_hash_update_size(void)
-{
- /* Returns the maximum number of bytes that may be
- * carried as a parameter of the hash_update operation
- * using the packed-c encoding.
- */
- size_t payload_space = psa_crypto_client_instance.base.service_info.max_payload;
- size_t overhead = sizeof(struct ts_crypto_hash_update_in) + TLV_HDR_LEN;
-
- return (payload_space > overhead) ? payload_space - overhead : 0;
-}
-
static psa_status_t multi_hash_update(psa_hash_operation_t *operation,
psa_algorithm_t alg,
const uint8_t *input,
@@ -344,7 +82,7 @@
{
*operation = psa_hash_operation_init();
psa_status_t psa_status = psa_hash_setup(operation, alg);
- size_t max_update_size = max_hash_update_size();
+ size_t max_update_size = crypto_caller_hash_max_update_size(&psa_crypto_client_instance.base);
if (!max_update_size) {
diff --git a/components/service/crypto/client/psa/psa_import_key.c b/components/service/crypto/client/psa/psa_import_key.c
index fcbb745..a7699cb 100644
--- a/components/service/crypto/client/psa/psa_import_key.c
+++ b/components/service/crypto/client/psa/psa_import_key.c
@@ -4,81 +4,18 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include "psa_crypto_client_key_attributes.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/key_attributes.h>
-#include <protocols/service/crypto/packed-c/import_key.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_import_key(const psa_key_attributes_t *attributes,
- const uint8_t *data, size_t data_length, psa_key_id_t *id)
+ const uint8_t *data, size_t data_length, psa_key_id_t *id)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_import_key_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_import_key_in);
- size_t req_len = req_fixed_len + tlv_required_space(data_length);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- /* Set default outputs for failure case */
- *id = 0;
-
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- psa_crypto_client_translate_key_attributes_to_proto(&req_msg.attributes, attributes);
-
- struct tlv_record key_record;
- key_record.tag = TS_CRYPTO_IMPORT_KEY_IN_TAG_DATA;
- key_record.length = data_length;
- key_record.value = data;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &key_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_IMPORT_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_import_key_out)) {
-
- struct ts_crypto_import_key_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_import_key_out));
- *id = resp_msg.id;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_import_key(&psa_crypto_client_instance.base,
+ attributes,
+ data, data_length, id);
}
diff --git a/components/service/crypto/client/psa/psa_key_derivation.c b/components/service/crypto/client/psa/psa_key_derivation.c
index 9127861..719d90c 100644
--- a/components/service/crypto/client/psa/psa_key_derivation.c
+++ b/components/service/crypto/client/psa/psa_key_derivation.c
@@ -4,154 +4,35 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include "psa_crypto_client_key_attributes.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/key_derivation.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_key_derivation_setup(
psa_key_derivation_operation_t *operation,
psa_algorithm_t alg)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_key_derivation_setup_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_key_derivation_setup_in);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- req_msg.alg = alg;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_SETUP, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_key_derivation_setup_out)) {
-
- struct ts_crypto_key_derivation_setup_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_key_derivation_setup_out));
- operation->handle = resp_msg.op_handle;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_key_derivation_setup(&psa_crypto_client_instance.base,
+ &operation->handle, alg);
}
psa_status_t psa_key_derivation_get_capacity(
const psa_key_derivation_operation_t *operation,
size_t *capacity)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_key_derivation_get_capacity_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_key_derivation_get_capacity_in);
-
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_GET_CAPACITY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_key_derivation_get_capacity_out)) {
-
- struct ts_crypto_key_derivation_get_capacity_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_key_derivation_get_capacity_out));
- *capacity = resp_msg.capacity;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_key_derivation_get_capacity(&psa_crypto_client_instance.base,
+ operation->handle, capacity);
}
psa_status_t psa_key_derivation_set_capacity(
psa_key_derivation_operation_t *operation,
size_t capacity)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_key_derivation_set_capacity_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_key_derivation_set_capacity_in);
-
- req_msg.op_handle = operation->handle;
- req_msg.capacity = capacity;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_SET_CAPACITY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_key_derivation_set_capacity(&psa_crypto_client_instance.base,
+ operation->handle, capacity);
}
psa_status_t psa_key_derivation_input_bytes(
@@ -160,48 +41,9 @@
const uint8_t *data,
size_t data_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_key_derivation_input_bytes_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_key_derivation_input_bytes_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
- req_msg.step = step;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_KEY_DERIVATION_INPUT_BYTES_IN_TAG_DATA;
- data_record.length = data_length;
- data_record.value = data;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_INPUT_BYTES, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_key_derivation_input_bytes(&psa_crypto_client_instance.base,
+ operation->handle, step,
+ data, data_length);
}
psa_status_t psa_key_derivation_input_key(
@@ -209,37 +51,8 @@
psa_key_derivation_step_t step,
psa_key_id_t key)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_key_derivation_input_key_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_key_derivation_input_key_in);
-
- req_msg.op_handle = operation->handle;
- req_msg.step = step;
- req_msg.key_id = key;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_INPUT_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_key_derivation_input_key(&psa_crypto_client_instance.base,
+ operation->handle, step, key);
}
psa_status_t psa_key_derivation_output_bytes(
@@ -247,64 +60,9 @@
uint8_t *output,
size_t output_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_key_derivation_output_bytes_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_key_derivation_output_bytes_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
- req_msg.output_len = output_length;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_OUTPUT_BYTES, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES_OUT_TAG_DATA, &decoded_record)) {
-
- if (decoded_record.length == output_length) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- }
- else {
- /* Should have returned the requested number of bytes */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_key_derivation_output_bytes(&psa_crypto_client_instance.base,
+ operation->handle,
+ output, output_length);
}
psa_status_t psa_key_derivation_output_key(
@@ -312,92 +70,16 @@
psa_key_derivation_operation_t *operation,
psa_key_id_t *key)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_key_derivation_output_key_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_key_derivation_output_key_in);
-
- /* Set default outputs for failure case */
- *key = 0;
-
- req_msg.op_handle = operation->handle;
- psa_crypto_client_translate_key_attributes_to_proto(&req_msg.attributes, attributes);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_OUTPUT_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_key_derivation_output_key_out)) {
-
- struct ts_crypto_key_derivation_output_key_out resp_msg;
- memcpy(&resp_msg, resp_buf,
- sizeof(struct ts_crypto_key_derivation_output_key_out));
- *key = resp_msg.key_id;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_key_derivation_output_key(&psa_crypto_client_instance.base,
+ attributes, operation->handle,
+ key);
}
psa_status_t psa_key_derivation_abort(
psa_key_derivation_operation_t *operation)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_key_derivation_abort_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_key_derivation_abort_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_ABORT, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_key_derivation_abort(&psa_crypto_client_instance.base,
+ operation->handle);
}
psa_status_t psa_key_derivation_key_agreement(
@@ -407,49 +89,9 @@
const uint8_t *peer_key,
size_t peer_key_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_key_derivation_key_agreement_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_key_derivation_key_agreement_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
- req_msg.step = step;
- req_msg.private_key_id = private_key;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT_IN_TAG_PEER_KEY;
- data_record.length = peer_key_length;
- data_record.value = peer_key;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_KEY_AGREEMENT, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_key_derivation_key_agreement(&psa_crypto_client_instance.base,
+ operation->handle, step,
+ private_key, peer_key, peer_key_length);
}
psa_status_t psa_raw_key_agreement(psa_algorithm_t alg,
@@ -460,74 +102,8 @@
size_t output_size,
size_t *output_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_raw_key_agreement_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_raw_key_agreement_in);
- size_t req_len = req_fixed_len;
-
- req_msg.alg = alg;
- req_msg.private_key_id = private_key;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_RAW_KEY_AGREEMENT_IN_TAG_PEER_KEY;
- data_record.length = peer_key_length;
- data_record.value = peer_key;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_KEY_DERIVATION_RAW_KEY_AGREEMENT, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_RAW_KEY_AGREEMENT_OUT_TAG_OUTPUT, &decoded_record)) {
-
- if (decoded_record.length <= output_size) {
-
- memcpy(output, decoded_record.value, decoded_record.length);
- *output_length = decoded_record.length;
- }
- else {
- /* Insufficient buffer space */
- psa_status = PSA_ERROR_INVALID_ARGUMENT;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_raw_key_agreement(&psa_crypto_client_instance.base,
+ alg,
+ private_key, peer_key, peer_key_length,
+ output, output_size, output_length);
}
diff --git a/components/service/crypto/client/psa/psa_mac.c b/components/service/crypto/client/psa/psa_mac.c
index a11a6d0..87a000d 100644
--- a/components/service/crypto/client/psa/psa_mac.c
+++ b/components/service/crypto/client/psa/psa_mac.c
@@ -4,128 +4,42 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/mac.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
-static psa_status_t common_mac_setup(psa_mac_operation_t *operation,
- psa_key_id_t key,
- psa_algorithm_t alg,
- uint32_t opcode)
-{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_mac_setup_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_mac_setup_in);
-
- req_msg.key_id = key;
- req_msg.alg = alg;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- opcode, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- if (resp_len >= sizeof(struct ts_crypto_mac_setup_out)) {
-
- struct ts_crypto_mac_setup_out resp_msg;
- memcpy(&resp_msg, resp_buf, sizeof(struct ts_crypto_mac_setup_out));
- operation->handle = resp_msg.op_handle;
- }
- else {
- /* Failed to decode response message */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
-}
psa_status_t psa_mac_sign_setup(psa_mac_operation_t *operation,
psa_key_id_t key,
psa_algorithm_t alg)
{
- return common_mac_setup(operation, key, alg, TS_CRYPTO_OPCODE_MAC_SIGN_SETUP);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
+
+ return crypto_caller_mac_sign_setup(&psa_crypto_client_instance.base,
+ &operation->handle,
+ key, alg);
}
psa_status_t psa_mac_verify_setup(psa_mac_operation_t *operation,
psa_key_id_t key,
psa_algorithm_t alg)
{
- return common_mac_setup(operation, key, alg, TS_CRYPTO_OPCODE_MAC_VERIFY_SETUP);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
+
+ return crypto_caller_mac_sign_setup(&psa_crypto_client_instance.base,
+ &operation->handle,
+ key, alg);
}
psa_status_t psa_mac_update(psa_mac_operation_t *operation,
const uint8_t *input,
size_t input_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_mac_update_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_mac_update_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_MAC_UPDATE_IN_TAG_DATA;
- data_record.length = input_length;
- data_record.value = input;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_MAC_UPDATE, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_mac_update(&psa_crypto_client_instance.base,
+ operation->handle,
+ input, input_length);
}
psa_status_t psa_mac_sign_finish(psa_mac_operation_t *operation,
@@ -133,158 +47,24 @@
size_t mac_size,
size_t *mac_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_mac_sign_finish_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_mac_sign_finish_in);
- size_t req_len = req_fixed_len;
-
- *mac_length = 0;
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_MAC_SIGN_FINISH, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_MAC_SIGN_FINISH_OUT_TAG_MAC, &decoded_record)) {
-
- if (decoded_record.length <= mac_size) {
-
- memcpy(mac, decoded_record.value, decoded_record.length);
- *mac_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_mac_sign_finish(&psa_crypto_client_instance.base,
+ operation->handle,
+ mac, mac_size, mac_length);
}
psa_status_t psa_mac_verify_finish(psa_mac_operation_t *operation,
const uint8_t *mac,
size_t mac_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_mac_verify_finish_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_mac_verify_finish_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- /* Mandatory input data parameter */
- struct tlv_record data_record;
- data_record.tag = TS_CRYPTO_MAC_VERIFY_FINISH_IN_TAG_MAC;
- data_record.length = mac_length;
- data_record.value = mac;
- req_len += tlv_required_space(data_record.length);
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &data_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_MAC_VERIFY_FINISH, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_mac_verify_finish(&psa_crypto_client_instance.base,
+ operation->handle,
+ mac, mac_length);
}
psa_status_t psa_mac_abort(psa_mac_operation_t *operation)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_mac_abort_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_mac_abort_in);
- size_t req_len = req_fixed_len;
-
- req_msg.op_handle = operation->handle;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_MAC_ABORT, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
-}
-
-static size_t max_mac_update_size(void)
-{
- /* Returns the maximum number of bytes that may be
- * carried as a parameter of the mac_update operation
- * using the packed-c encoding.
- */
- size_t payload_space = psa_crypto_client_instance.base.service_info.max_payload;
- size_t overhead = sizeof(struct ts_crypto_mac_update_in) + TLV_HDR_LEN;
-
- return (payload_space > overhead) ? payload_space - overhead : 0;
+ return crypto_caller_mac_abort(&psa_crypto_client_instance.base,
+ operation->handle);
}
static psa_status_t multi_mac_update(psa_mac_operation_t *operation,
@@ -292,7 +72,7 @@
size_t input_length)
{
psa_status_t psa_status = PSA_SUCCESS;
- size_t max_update_size = max_mac_update_size();
+ size_t max_update_size = crypto_caller_mac_max_update_size(&psa_crypto_client_instance.base);
size_t bytes_processed = 0;
if (!max_update_size) {
diff --git a/components/service/crypto/client/psa/psa_purge_key.c b/components/service/crypto/client/psa/psa_purge_key.c
index f000e51..36f85e1 100644
--- a/components/service/crypto/client/psa/psa_purge_key.c
+++ b/components/service/crypto/client/psa/psa_purge_key.c
@@ -4,46 +4,15 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/purge_key.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_purge_key(psa_key_id_t key)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_purge_key_in req_msg;
- size_t req_len = sizeof(struct ts_crypto_purge_key_in);
-
if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
return psa_crypto_client_instance.init_status;
- req_msg.id = key;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
-
- memcpy(req_buf, &req_msg, req_len);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_PURGE_KEY, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_purge_key(&psa_crypto_client_instance.base, key);
}
diff --git a/components/service/crypto/client/psa/psa_sign_hash.c b/components/service/crypto/client/psa/psa_sign_hash.c
index d310a02..d93cb6b 100644
--- a/components/service/crypto/client/psa/psa_sign_hash.c
+++ b/components/service/crypto/client/psa/psa_sign_hash.c
@@ -4,90 +4,19 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/sign_hash.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_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)
+ 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_ERROR_GENERIC_ERROR;
- struct ts_crypto_sign_hash_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_sign_hash_in);
- size_t req_len = req_fixed_len + tlv_required_space(hash_length);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- *signature_length = 0; /* For failure case */
-
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- req_msg.id = id;
- req_msg.alg = alg;
-
- struct tlv_record hash_record;
- hash_record.tag = TS_CRYPTO_SIGN_HASH_IN_TAG_HASH;
- hash_record.length = hash_length;
- hash_record.value = hash;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &hash_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_SIGN_HASH, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) {
-
- psa_status = opstatus;
-
- if (psa_status == PSA_SUCCESS) {
-
- struct tlv_const_iterator resp_iter;
- struct tlv_record decoded_record;
- tlv_const_iterator_begin(&resp_iter, resp_buf, resp_len);
-
- if (tlv_find_decode(&resp_iter,
- TS_CRYPTO_SIGN_HASH_OUT_TAG_SIGNATURE, &decoded_record)) {
-
- if (decoded_record.length <= signature_size) {
-
- memcpy(signature, decoded_record.value, decoded_record.length);
- *signature_length = decoded_record.length;
- }
- else {
- /* Provided buffer is too small */
- psa_status = PSA_ERROR_BUFFER_TOO_SMALL;
- }
- }
- else {
- /* Mandatory response parameter missing */
- psa_status = PSA_ERROR_GENERIC_ERROR;
- }
- }
- }
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_sign_hash(&psa_crypto_client_instance.base,
+ id, alg,
+ hash, hash_length,
+ signature, signature_size, signature_length);
}
diff --git a/components/service/crypto/client/psa/psa_verify_hash.c b/components/service/crypto/client/psa/psa_verify_hash.c
index accd9cd..d0ab32b 100644
--- a/components/service/crypto/client/psa/psa_verify_hash.c
+++ b/components/service/crypto/client/psa/psa_verify_hash.c
@@ -4,68 +4,20 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
#include <psa/crypto.h>
#include "psa_crypto_client.h"
-#include <protocols/rpc/common/packed-c/status.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <protocols/service/crypto/packed-c/verify_hash.h>
-#include <common/tlv/tlv.h>
+#include <service/crypto/client/caller/packed-c/crypto_caller.h>
psa_status_t psa_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)
+ const uint8_t *hash, size_t hash_length,
+ const uint8_t *signature, size_t signature_length)
{
- psa_status_t psa_status = PSA_ERROR_GENERIC_ERROR;
- struct ts_crypto_verify_hash_in req_msg;
- size_t req_fixed_len = sizeof(struct ts_crypto_verify_hash_in);
- size_t req_len = req_fixed_len +
- tlv_required_space(hash_length) + tlv_required_space(signature_length);
+ if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
+ return psa_crypto_client_instance.init_status;
- if (psa_crypto_client_instance.init_status != PSA_SUCCESS)
- return psa_crypto_client_instance.init_status;
-
- req_msg.id = id;
- req_msg.alg = alg;
-
- struct tlv_record hash_record;
- hash_record.tag = TS_CRYPTO_VERIFY_HASH_IN_TAG_HASH;
- hash_record.length = hash_length;
- hash_record.value = hash;
-
- struct tlv_record sig_record;
- sig_record.tag = TS_CRYPTO_VERIFY_HASH_IN_TAG_SIGNATURE;
- sig_record.length = signature_length;
- sig_record.value = signature;
-
- rpc_call_handle call_handle;
- uint8_t *req_buf;
-
- call_handle = rpc_caller_begin(psa_crypto_client_instance.base.caller, &req_buf, req_len);
-
- if (call_handle) {
-
- uint8_t *resp_buf;
- size_t resp_len;
- int opstatus;
- struct tlv_iterator req_iter;
-
- memcpy(req_buf, &req_msg, req_fixed_len);
-
- tlv_iterator_begin(&req_iter, &req_buf[req_fixed_len], req_len - req_fixed_len);
- tlv_encode(&req_iter, &hash_record);
- tlv_encode(&req_iter, &sig_record);
-
- psa_crypto_client_instance.base.rpc_status =
- rpc_caller_invoke(psa_crypto_client_instance.base.caller, call_handle,
- TS_CRYPTO_OPCODE_VERIFY_HASH, &opstatus, &resp_buf, &resp_len);
-
- if (psa_crypto_client_instance.base.rpc_status == TS_RPC_CALL_ACCEPTED) psa_status = opstatus;
-
- rpc_caller_end(psa_crypto_client_instance.base.caller, call_handle);
- }
-
- return psa_status;
+ return crypto_caller_verify_hash(&psa_crypto_client_instance.base,
+ id, alg,
+ hash, hash_length,
+ signature, signature_length);
}
diff --git a/components/service/crypto/client/test/test_crypto_client.h b/components/service/crypto/client/test/test_crypto_client.h
index f1d70a1..7e10eaa 100644
--- a/components/service/crypto/client/test/test_crypto_client.h
+++ b/components/service/crypto/client/test/test_crypto_client.h
@@ -7,7 +7,7 @@
#ifndef TEST_CRYPTO_CLIENT_H
#define TEST_CRYPTO_CLIENT_H
-#include <service/crypto/client/cpp/protobuf/protobuf_crypto_client.h>
+#include <service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h>
#include <vector>
/*
diff --git a/components/service/crypto/test/service/crypto_service_limit_tests.cpp b/components/service/crypto/test/service/crypto_service_limit_tests.cpp
index 21f136b..d056af8 100644
--- a/components/service/crypto/test/service/crypto_service_limit_tests.cpp
+++ b/components/service/crypto/test/service/crypto_service_limit_tests.cpp
@@ -8,7 +8,7 @@
#include <vector>
#include <cstring>
#include <cstdint>
-#include <service/crypto/client/cpp/protobuf/protobuf_crypto_client.h>
+#include <service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h>
#include <protocols/rpc/common/packed-c/encoding.h>
#include <service_locator.h>
#include <CppUTest/TestHarness.h>
@@ -167,4 +167,4 @@
CHECK_EQUAL(PSA_SUCCESS, generate_status);
CHECK_EQUAL(PSA_SUCCESS, destroy_status);
CHECK_EQUAL(expected_limit, actual_limit);
-}
\ No newline at end of file
+}
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 094969c..61bb8c4 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
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <service/crypto/client/cpp/packed-c/packedc_crypto_client.h>
+#include <service/crypto/client/cpp/protocol/packed-c/packedc_crypto_client.h>
#include <service/crypto/test/service/crypto_service_scenarios.h>
#include <protocols/rpc/common/packed-c/encoding.h>
#include <service_locator.h>
diff --git a/components/service/crypto/test/service/protobuf/crypto_service_protobuf_tests.cpp b/components/service/crypto/test/service/protobuf/crypto_service_protobuf_tests.cpp
index 9483f25..1230752 100644
--- a/components/service/crypto/test/service/protobuf/crypto_service_protobuf_tests.cpp
+++ b/components/service/crypto/test/service/protobuf/crypto_service_protobuf_tests.cpp
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <service/crypto/client/cpp/protobuf/protobuf_crypto_client.h>
+#include <service/crypto/client/cpp/protocol/protobuf/protobuf_crypto_client.h>
#include <service/crypto/test/service/crypto_service_scenarios.h>
#include <protocols/rpc/common/packed-c/encoding.h>
#include <service_locator.h>
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
index 4263532..bfe5e5e 100644
--- 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
@@ -44,6 +44,27 @@
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)
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
index fe72bf2..32a3f1d 100644
--- 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
@@ -23,6 +23,10 @@
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,