Change crypto providers to use rpc_service_interface
Signed-off-by: Imre Kis <imre.kis@arm.com>
Change-Id: Id99d8b095ee1221fdf4486dd109c222dfce51c94
diff --git a/components/service/crypto/backend/psa_ipc/crypto_ipc_backend.c b/components/service/crypto/backend/psa_ipc/crypto_ipc_backend.c
index 6262c0c..9bf1c78 100644
--- a/components/service/crypto/backend/psa_ipc/crypto_ipc_backend.c
+++ b/components/service/crypto/backend/psa_ipc/crypto_ipc_backend.c
@@ -10,9 +10,9 @@
#include <protocols/rpc/common/packed-c/status.h>
#include "crypto_ipc_backend.h"
-psa_status_t crypto_ipc_backend_init(struct rpc_caller *caller)
+psa_status_t crypto_ipc_backend_init(struct rpc_caller_session *session)
{
- psa_status_t status = psa_crypto_client_init(caller);
+ psa_status_t status = psa_crypto_client_init(session);
if (status == PSA_SUCCESS)
status = psa_crypto_init();
diff --git a/components/service/crypto/backend/psa_ipc/crypto_ipc_backend.h b/components/service/crypto/backend/psa_ipc/crypto_ipc_backend.h
index 4724364..27ac598 100644
--- a/components/service/crypto/backend/psa_ipc/crypto_ipc_backend.h
+++ b/components/service/crypto/backend/psa_ipc/crypto_ipc_backend.h
@@ -57,7 +57,7 @@
*
* \return PSA_SUCCESS if backend initialized successfully
*/
-psa_status_t crypto_ipc_backend_init(struct rpc_caller *caller);
+psa_status_t crypto_ipc_backend_init(struct rpc_caller_session *session);
/**
* \brief Clean-up to free any resource used by the crypto backend
diff --git a/components/service/crypto/backend/stub/stub_crypto_backend.c b/components/service/crypto/backend/stub/stub_crypto_backend.c
index f969b43..edb45f8 100644
--- a/components/service/crypto/backend/stub/stub_crypto_backend.c
+++ b/components/service/crypto/backend/stub/stub_crypto_backend.c
@@ -13,11 +13,20 @@
psa_status_t stub_crypto_backend_init(void)
{
- static struct dummy_caller dummy_caller;
- struct rpc_caller *caller = dummy_caller_init(&dummy_caller,
- TS_RPC_CALL_ACCEPTED, PSA_ERROR_SERVICE_FAILURE);
+ static struct rpc_caller_interface dummy_caller;
+ struct rpc_caller_session session = { 0 };
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ psa_status_t status = PSA_ERROR_GENERIC_ERROR;
- psa_status_t status = psa_crypto_client_init(caller);
+ rpc_status = dummy_caller_init(&dummy_caller, RPC_SUCCESS, PSA_ERROR_SERVICE_FAILURE);
+ if (rpc_status != RPC_SUCCESS)
+ return PSA_ERROR_GENERIC_ERROR;
+
+ rpc_status = rpc_caller_session_find_and_open(&session, &dummy_caller, NULL, 0);
+ if (rpc_status != RPC_SUCCESS)
+ return PSA_ERROR_GENERIC_ERROR;
+
+ status = psa_crypto_client_init(&session);
if (status == PSA_SUCCESS)
status = psa_crypto_init();
diff --git a/components/service/crypto/factory/crypto_provider_factory.h b/components/service/crypto/factory/crypto_provider_factory.h
index f4b1491..f5b8787 100644
--- a/components/service/crypto/factory/crypto_provider_factory.h
+++ b/components/service/crypto/factory/crypto_provider_factory.h
@@ -28,6 +28,8 @@
*/
struct crypto_provider *crypto_provider_factory_create(void);
+struct crypto_provider *crypto_protobuf_provider_factory_create(void);
+
/**
* \brief Destroys a created crypto provider
*
diff --git a/components/service/crypto/factory/full/crypto_provider_factory.c b/components/service/crypto/factory/full/crypto_provider_factory.c
index ee2b447..45af9aa 100644
--- a/components/service/crypto/factory/full/crypto_provider_factory.c
+++ b/components/service/crypto/factory/full/crypto_provider_factory.c
@@ -19,8 +19,6 @@
#include <service/crypto/provider/extension/mac/serializer/packed-c/packedc_mac_provider_serializer.h>
#include <service/crypto/provider/extension/aead/aead_provider.h>
#include <service/crypto/provider/extension/aead/serializer/packed-c/packedc_aead_provider_serializer.h>
-#include <service/discovery/provider/discovery_provider.h>
-#include <service/discovery/provider/serializer/packed-c/packedc_discovery_provider_serializer.h>
/**
* A crypto provider factory that constucts a crypto provider
@@ -32,12 +30,12 @@
static struct full_crypto_provider
{
struct crypto_provider crypto_provider;
+ struct crypto_provider crypto_provider_protobuf;
struct hash_provider hash_provider;
struct cipher_provider cipher_provider;
struct key_derivation_provider key_derivation_provider;
struct mac_provider mac_provider;
struct aead_provider aead_provider;
-
} instance;
struct crypto_provider *crypto_provider_factory_create(void)
@@ -45,17 +43,8 @@
/**
* Initialize the core crypto provider
*/
- crypto_provider_init(&instance.crypto_provider);
-
- /* Register serializers for the core crypto provider */
- crypto_provider_register_serializer(&instance.crypto_provider,
- TS_RPC_ENCODING_PROTOBUF, pb_crypto_provider_serializer_instance());
- crypto_provider_register_serializer(&instance.crypto_provider,
- TS_RPC_ENCODING_PACKED_C, packedc_crypto_provider_serializer_instance());
-
- /* Register serializer for the associated discovery provider */
- discovery_provider_register_serializer(&instance.crypto_provider.discovery_provider,
- TS_RPC_ENCODING_PACKED_C, packedc_discovery_provider_serializer_instance());
+ crypto_provider_init(&instance.crypto_provider, TS_RPC_ENCODING_PACKED_C,
+ packedc_crypto_provider_serializer_instance());
/**
* Extend with hash operations
@@ -85,7 +74,8 @@
key_derivation_provider_init(&instance.key_derivation_provider);
key_derivation_provider_register_serializer(&instance.key_derivation_provider,
- TS_RPC_ENCODING_PACKED_C, packedc_key_derivation_provider_serializer_instance());
+ TS_RPC_ENCODING_PACKED_C,
+ packedc_key_derivation_provider_serializer_instance());
crypto_provider_extend(&instance.crypto_provider,
&instance.key_derivation_provider.base_provider);
@@ -115,6 +105,14 @@
return &instance.crypto_provider;
}
+struct crypto_provider *crypto_protobuf_provider_factory_create(void)
+{
+ crypto_provider_init(&instance.crypto_provider_protobuf, TS_RPC_ENCODING_PROTOBUF,
+ pb_crypto_provider_serializer_instance());
+
+ return &instance.crypto_provider_protobuf;
+}
+
/**
* \brief Destroys a created crypto provider
*
diff --git a/components/service/crypto/provider/crypto_provider.c b/components/service/crypto/provider/crypto_provider.c
index 67a5b34..d1798d7 100644
--- a/components/service/crypto/provider/crypto_provider.c
+++ b/components/service/crypto/provider/crypto_provider.c
@@ -3,100 +3,98 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
+#include <protocols/rpc/common/packed-c/status.h>
+#include <protocols/service/crypto/packed-c/opcodes.h>
+#include <psa/crypto.h>
+#include <service/crypto/provider/crypto_provider.h>
#include <stdint.h>
#include <stdlib.h>
-#include <protocols/service/crypto/packed-c/opcodes.h>
-#include <service/crypto/provider/crypto_provider.h>
-#include <protocols/rpc/common/packed-c/status.h>
-#include <psa/crypto.h>
+
+#include "crypto_uuid.h"
/* Service request handlers */
-static rpc_status_t generate_key_handler(void *context, struct call_req* req);
-static rpc_status_t destroy_key_handler(void *context, struct call_req* req);
-static rpc_status_t export_key_handler(void *context, struct call_req* req);
-static rpc_status_t export_public_key_handler(void *context, struct call_req* req);
-static rpc_status_t import_key_handler(void *context, struct call_req* req);
-static rpc_status_t asymmetric_sign_handler(void *context, struct call_req* req);
-static rpc_status_t asymmetric_verify_handler(void *context, struct call_req* req);
-static rpc_status_t asymmetric_decrypt_handler(void *context, struct call_req* req);
-static rpc_status_t asymmetric_encrypt_handler(void *context, struct call_req* req);
-static rpc_status_t generate_random_handler(void *context, struct call_req* req);
-static rpc_status_t copy_key_handler(void *context, struct call_req* req);
-static rpc_status_t purge_key_handler(void *context, struct call_req* req);
-static rpc_status_t get_key_attributes_handler(void *context, struct call_req* req);
+static rpc_status_t generate_key_handler(void *context, struct rpc_request *req);
+static rpc_status_t destroy_key_handler(void *context, struct rpc_request *req);
+static rpc_status_t export_key_handler(void *context, struct rpc_request *req);
+static rpc_status_t export_public_key_handler(void *context, struct rpc_request *req);
+static rpc_status_t import_key_handler(void *context, struct rpc_request *req);
+static rpc_status_t asymmetric_sign_handler(void *context, struct rpc_request *req);
+static rpc_status_t asymmetric_verify_handler(void *context, struct rpc_request *req);
+static rpc_status_t asymmetric_decrypt_handler(void *context, struct rpc_request *req);
+static rpc_status_t asymmetric_encrypt_handler(void *context, struct rpc_request *req);
+static rpc_status_t generate_random_handler(void *context, struct rpc_request *req);
+static rpc_status_t copy_key_handler(void *context, struct rpc_request *req);
+static rpc_status_t purge_key_handler(void *context, struct rpc_request *req);
+static rpc_status_t get_key_attributes_handler(void *context, struct rpc_request *req);
/* Handler mapping table for service */
static const struct service_handler handler_table[] = {
- {TS_CRYPTO_OPCODE_GENERATE_KEY, generate_key_handler},
- {TS_CRYPTO_OPCODE_DESTROY_KEY, destroy_key_handler},
- {TS_CRYPTO_OPCODE_EXPORT_KEY, export_key_handler},
- {TS_CRYPTO_OPCODE_EXPORT_PUBLIC_KEY, export_public_key_handler},
- {TS_CRYPTO_OPCODE_IMPORT_KEY, import_key_handler},
- {TS_CRYPTO_OPCODE_SIGN_HASH, asymmetric_sign_handler},
- {TS_CRYPTO_OPCODE_VERIFY_HASH, asymmetric_verify_handler},
- {TS_CRYPTO_OPCODE_ASYMMETRIC_DECRYPT, asymmetric_decrypt_handler},
- {TS_CRYPTO_OPCODE_ASYMMETRIC_ENCRYPT, asymmetric_encrypt_handler},
- {TS_CRYPTO_OPCODE_GENERATE_RANDOM, generate_random_handler},
- {TS_CRYPTO_OPCODE_COPY_KEY, copy_key_handler},
- {TS_CRYPTO_OPCODE_PURGE_KEY, purge_key_handler},
- {TS_CRYPTO_OPCODE_GET_KEY_ATTRIBUTES, get_key_attributes_handler},
- {TS_CRYPTO_OPCODE_SIGN_MESSAGE, asymmetric_sign_handler},
- {TS_CRYPTO_OPCODE_VERIFY_MESSAGE, asymmetric_verify_handler},
+ { TS_CRYPTO_OPCODE_GENERATE_KEY, generate_key_handler },
+ { TS_CRYPTO_OPCODE_DESTROY_KEY, destroy_key_handler },
+ { TS_CRYPTO_OPCODE_EXPORT_KEY, export_key_handler },
+ { TS_CRYPTO_OPCODE_EXPORT_PUBLIC_KEY, export_public_key_handler },
+ { TS_CRYPTO_OPCODE_IMPORT_KEY, import_key_handler },
+ { TS_CRYPTO_OPCODE_SIGN_HASH, asymmetric_sign_handler },
+ { TS_CRYPTO_OPCODE_VERIFY_HASH, asymmetric_verify_handler },
+ { TS_CRYPTO_OPCODE_ASYMMETRIC_DECRYPT, asymmetric_decrypt_handler },
+ { TS_CRYPTO_OPCODE_ASYMMETRIC_ENCRYPT, asymmetric_encrypt_handler },
+ { TS_CRYPTO_OPCODE_GENERATE_RANDOM, generate_random_handler },
+ { TS_CRYPTO_OPCODE_COPY_KEY, copy_key_handler },
+ { TS_CRYPTO_OPCODE_PURGE_KEY, purge_key_handler },
+ { TS_CRYPTO_OPCODE_GET_KEY_ATTRIBUTES, get_key_attributes_handler },
+ { TS_CRYPTO_OPCODE_SIGN_MESSAGE, asymmetric_sign_handler },
+ { TS_CRYPTO_OPCODE_VERIFY_MESSAGE, asymmetric_verify_handler },
};
-struct rpc_interface *crypto_provider_init(struct crypto_provider *context)
+struct rpc_service_interface *
+crypto_provider_init(struct crypto_provider *context, unsigned int encoding,
+ const struct crypto_provider_serializer *serializer)
{
- /* Initialise the crypto provider */
- for (size_t encoding = 0; encoding < TS_RPC_ENCODING_LIMIT; ++encoding)
- context->serializers[encoding] = NULL;
+ const struct rpc_uuid crypto_service_uuid[2] = {
+ { .uuid = TS_PSA_CRYPTO_SERVICE_UUID },
+ { .uuid = TS_PSA_CRYPTO_PROTOBUF_SERVICE_UUID },
+ };
- service_provider_init(&context->base_provider, context,
- handler_table, sizeof(handler_table)/sizeof(struct service_handler));
+ if (encoding >= TS_RPC_ENCODING_LIMIT)
+ return NULL;
- /* Initialise the associated discovery provider */
- discovery_provider_init(&context->discovery_provider);
- service_provider_extend(&context->base_provider, &context->discovery_provider.base_provider);
+ context->serializer = serializer;
+
+ service_provider_init(&context->base_provider, context, &crypto_service_uuid[encoding],
+ handler_table,
+ sizeof(handler_table) / sizeof(struct service_handler));
return service_provider_get_rpc_interface(&context->base_provider);
}
void crypto_provider_deinit(struct crypto_provider *context)
{
- discovery_provider_deinit(&context->discovery_provider);
+ (void)context;
}
void crypto_provider_register_serializer(struct crypto_provider *context,
- unsigned int encoding, const struct crypto_provider_serializer *serializer)
+ const struct crypto_provider_serializer *serializer)
{
- if (encoding < TS_RPC_ENCODING_LIMIT) {
-
- context->serializers[encoding] = serializer;
- discovery_provider_register_supported_encoding(&context->discovery_provider, encoding);
- }
+ context->serializer = serializer;
}
-void crypto_provider_extend(struct crypto_provider *context,
- struct service_provider *sub_provider)
+void crypto_provider_extend(struct crypto_provider *context, struct service_provider *sub_provider)
{
service_provider_extend(&context->base_provider, sub_provider);
}
-static const struct crypto_provider_serializer* get_crypto_serializer(void *context,
- const struct call_req *req)
+static const struct crypto_provider_serializer *get_crypto_serializer(void *context,
+ const struct rpc_request *req)
{
- struct crypto_provider *this_instance = (struct crypto_provider*)context;
- const struct crypto_provider_serializer* serializer = NULL;
- unsigned int encoding = call_req_get_encoding(req);
+ struct crypto_provider *this_instance = (struct crypto_provider *)context;
- if (encoding < TS_RPC_ENCODING_LIMIT) serializer = this_instance->serializers[encoding];
-
- return serializer;
+ return this_instance->serializer;
}
-static rpc_status_t generate_key_handler(void *context, struct call_req* req)
+static rpc_status_t generate_key_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
@@ -104,20 +102,18 @@
if (serializer)
rpc_status = serializer->deserialize_generate_key_req(req_buf, &attributes);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status;
psa_key_id_t id;
psa_status = psa_generate_key(&attributes, &id);
if (psa_status == PSA_SUCCESS) {
-
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_generate_key_resp(resp_buf, id);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
psa_reset_key_attributes(&attributes);
@@ -125,10 +121,10 @@
return rpc_status;
}
-static rpc_status_t destroy_key_handler(void *context, struct call_req* req)
+static rpc_status_t destroy_key_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_id_t id;
@@ -136,21 +132,20 @@
if (serializer)
rpc_status = serializer->deserialize_destroy_key_req(req_buf, &id);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status;
psa_status = psa_destroy_key(id);
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t export_key_handler(void *context, struct call_req* req)
+static rpc_status_t export_key_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_id_t id;
@@ -158,40 +153,37 @@
if (serializer)
rpc_status = serializer->deserialize_export_key_req(req_buf, &id);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
size_t max_export_size = PSA_EXPORT_KEY_PAIR_MAX_SIZE;
uint8_t *key_buffer = malloc(max_export_size);
if (key_buffer) {
-
size_t export_size;
- psa_status_t psa_status = psa_export_key(id, key_buffer,
- max_export_size, &export_size);
+ psa_status_t psa_status =
+ psa_export_key(id, key_buffer, max_export_size, &export_size);
if (psa_status == PSA_SUCCESS) {
+ struct rpc_buffer *resp_buf = &req->response;
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_export_key_resp(resp_buf,
- key_buffer, export_size);
+ rpc_status = serializer->serialize_export_key_resp(
+ resp_buf, key_buffer, export_size);
}
free(key_buffer);
- call_req_set_opstatus(req, psa_status);
- }
- else {
+ req->service_status = psa_status;
+ } else {
/* Failed to allocate key buffer */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
return rpc_status;
}
-static rpc_status_t export_public_key_handler(void *context, struct call_req* req)
+static rpc_status_t export_public_key_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_id_t id;
@@ -199,85 +191,79 @@
if (serializer)
rpc_status = serializer->deserialize_export_public_key_req(req_buf, &id);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
size_t max_export_size = PSA_EXPORT_PUBLIC_KEY_MAX_SIZE;
uint8_t *key_buffer = malloc(max_export_size);
if (key_buffer) {
-
size_t export_size;
- psa_status_t psa_status = psa_export_public_key(id, key_buffer,
- max_export_size, &export_size);
+ psa_status_t psa_status = psa_export_public_key(
+ id, key_buffer, max_export_size, &export_size);
if (psa_status == PSA_SUCCESS) {
+ struct rpc_buffer *resp_buf = &req->response;
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_export_public_key_resp(resp_buf,
- key_buffer, export_size);
+ rpc_status = serializer->serialize_export_public_key_resp(
+ resp_buf, key_buffer, export_size);
}
free(key_buffer);
- call_req_set_opstatus(req, psa_status);
- }
- else {
+ req->service_status = psa_status;
+ } else {
/* Failed to allocate key buffer */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
return rpc_status;
}
-static rpc_status_t import_key_handler(void *context, struct call_req* req)
+static rpc_status_t import_key_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
if (serializer) {
-
size_t key_data_len = serializer->max_deserialised_parameter_size(req_buf);
uint8_t *key_buffer = malloc(key_data_len);
if (key_buffer) {
-
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
- rpc_status = serializer->deserialize_import_key_req(req_buf, &attributes,
- key_buffer, &key_data_len);
+ rpc_status = serializer->deserialize_import_key_req(
+ req_buf, &attributes, key_buffer, &key_data_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status;
psa_key_id_t id;
- psa_status = psa_import_key(&attributes, key_buffer, key_data_len, &id);
+ psa_status =
+ psa_import_key(&attributes, key_buffer, key_data_len, &id);
if (psa_status == PSA_SUCCESS) {
+ struct rpc_buffer *resp_buf = &req->response;
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_import_key_resp(resp_buf, id);
+ rpc_status =
+ serializer->serialize_import_key_resp(resp_buf, id);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
psa_reset_key_attributes(&attributes);
free(key_buffer);
- }
- else {
-
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ } else {
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
return rpc_status;
}
-static rpc_status_t asymmetric_sign_handler(void *context, struct call_req* req)
+static rpc_status_t asymmetric_sign_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_id_t id;
@@ -286,36 +272,37 @@
uint8_t hash_buffer[PSA_HASH_MAX_SIZE];
if (serializer)
- rpc_status = serializer->deserialize_asymmetric_sign_req(req_buf, &id, &alg, hash_buffer, &hash_len);
+ rpc_status = serializer->deserialize_asymmetric_sign_req(req_buf, &id, &alg,
+ hash_buffer, &hash_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status;
size_t sig_len;
uint8_t sig_buffer[PSA_SIGNATURE_MAX_SIZE];
- psa_status = (call_req_get_opcode(req) == TS_CRYPTO_OPCODE_SIGN_HASH) ?
- psa_sign_hash(id, alg, hash_buffer, hash_len,
- sig_buffer, sizeof(sig_buffer), &sig_len) :
- psa_sign_message(id, alg, hash_buffer, hash_len,
- sig_buffer, sizeof(sig_buffer), &sig_len);
+ psa_status = (req->opcode == TS_CRYPTO_OPCODE_SIGN_HASH) ?
+ psa_sign_hash(id, alg, hash_buffer, hash_len, sig_buffer,
+ sizeof(sig_buffer), &sig_len) :
+ psa_sign_message(id, alg, hash_buffer, hash_len, sig_buffer,
+ sizeof(sig_buffer), &sig_len);
if (psa_status == PSA_SUCCESS) {
+ struct rpc_buffer *resp_buf = &req->response;
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_asymmetric_sign_resp(resp_buf, sig_buffer, sig_len);
+ rpc_status = serializer->serialize_asymmetric_sign_resp(
+ resp_buf, sig_buffer, sig_len);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t asymmetric_verify_handler(void *context, struct call_req* req)
+static rpc_status_t asymmetric_verify_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_id_t id;
@@ -326,36 +313,31 @@
uint8_t sig_buffer[PSA_SIGNATURE_MAX_SIZE];
if (serializer)
- rpc_status = serializer->deserialize_asymmetric_verify_req(req_buf, &id, &alg,
- hash_buffer, &hash_len,
- sig_buffer, &sig_len);
+ rpc_status = serializer->deserialize_asymmetric_verify_req(
+ req_buf, &id, &alg, hash_buffer, &hash_len, sig_buffer, &sig_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status;
- psa_status = (call_req_get_opcode(req) == TS_CRYPTO_OPCODE_VERIFY_HASH) ?
- psa_verify_hash(id, alg,
- hash_buffer, hash_len,
- sig_buffer, sig_len) :
- psa_verify_message(id, alg,
- hash_buffer, hash_len,
- sig_buffer, sig_len);
+ psa_status = (req->opcode == TS_CRYPTO_OPCODE_VERIFY_HASH) ?
+ psa_verify_hash(id, alg, hash_buffer, hash_len, sig_buffer,
+ sig_len) :
+ psa_verify_message(id, alg, hash_buffer, hash_len, sig_buffer,
+ sig_len);
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t asymmetric_decrypt_handler(void *context, struct call_req* req)
+static rpc_status_t asymmetric_decrypt_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
if (serializer) {
-
size_t max_param_size = serializer->max_deserialised_parameter_size(req_buf);
psa_key_id_t id;
@@ -366,61 +348,54 @@
uint8_t *salt_buffer = malloc(salt_len);
if (ciphertext_buffer && salt_buffer) {
+ rpc_status = serializer->deserialize_asymmetric_decrypt_req(
+ req_buf, &id, &alg, ciphertext_buffer, &ciphertext_len, salt_buffer,
+ &salt_len);
- rpc_status = serializer->deserialize_asymmetric_decrypt_req(req_buf,
- &id, &alg,
- ciphertext_buffer, &ciphertext_len,
- salt_buffer, &salt_len);
-
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status = psa_get_key_attributes(id, &attributes);
if (psa_status == PSA_SUCCESS) {
-
- size_t max_decrypt_size = PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(
- psa_get_key_type(&attributes),
- psa_get_key_bits(&attributes),
- alg);
+ size_t max_decrypt_size =
+ PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(
+ psa_get_key_type(&attributes),
+ psa_get_key_bits(&attributes), alg);
size_t plaintext_len;
uint8_t *plaintext_buffer = malloc(max_decrypt_size);
if (plaintext_buffer) {
-
/* Salt is an optional parameter */
uint8_t *salt = (salt_len) ? salt_buffer : NULL;
- psa_status = psa_asymmetric_decrypt(id, alg,
- ciphertext_buffer, ciphertext_len,
- salt, salt_len,
- plaintext_buffer, max_decrypt_size, &plaintext_len);
+ psa_status = psa_asymmetric_decrypt(
+ id, alg, ciphertext_buffer, ciphertext_len,
+ salt, salt_len, plaintext_buffer,
+ max_decrypt_size, &plaintext_len);
if (psa_status == PSA_SUCCESS) {
-
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_asymmetric_decrypt_resp(resp_buf,
- plaintext_buffer, plaintext_len);
+ struct rpc_buffer *resp_buf =
+ &req->response;
+ rpc_status = serializer->serialize_asymmetric_decrypt_resp(
+ resp_buf, plaintext_buffer, plaintext_len);
}
free(plaintext_buffer);
- }
- else {
+ } else {
/* Failed to allocate ouptput buffer */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
psa_reset_key_attributes(&attributes);
}
- }
- else {
+ } else {
/* Failed to allocate buffers */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
free(ciphertext_buffer);
@@ -430,14 +405,13 @@
return rpc_status;
}
-static rpc_status_t asymmetric_encrypt_handler(void *context, struct call_req* req)
+static rpc_status_t asymmetric_encrypt_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
if (serializer) {
-
size_t max_param_size = serializer->max_deserialised_parameter_size(req_buf);
psa_key_id_t id;
@@ -448,61 +422,55 @@
uint8_t *salt_buffer = malloc(salt_len);
if (plaintext_buffer && salt_buffer) {
+ rpc_status = serializer->deserialize_asymmetric_encrypt_req(
+ req_buf, &id, &alg, plaintext_buffer, &plaintext_len, salt_buffer,
+ &salt_len);
- rpc_status = serializer->deserialize_asymmetric_encrypt_req(req_buf,
- &id, &alg,
- plaintext_buffer, &plaintext_len,
- salt_buffer, &salt_len);
-
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status = psa_get_key_attributes(id, &attributes);
if (psa_status == PSA_SUCCESS) {
-
- size_t max_encrypt_size = PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(
- psa_get_key_type(&attributes),
- psa_get_key_bits(&attributes),
- alg);
+ size_t max_encrypt_size =
+ PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(
+ psa_get_key_type(&attributes),
+ psa_get_key_bits(&attributes), alg);
size_t ciphertext_len;
uint8_t *ciphertext_buffer = malloc(max_encrypt_size);
if (ciphertext_buffer) {
-
/* Salt is an optional parameter */
uint8_t *salt = (salt_len) ? salt_buffer : NULL;
- psa_status = psa_asymmetric_encrypt(id, alg,
- plaintext_buffer, plaintext_len,
- salt, salt_len,
- ciphertext_buffer, max_encrypt_size, &ciphertext_len);
+ psa_status = psa_asymmetric_encrypt(
+ id, alg, plaintext_buffer, plaintext_len,
+ salt, salt_len, ciphertext_buffer,
+ max_encrypt_size, &ciphertext_len);
if (psa_status == PSA_SUCCESS) {
+ struct rpc_buffer *resp_buf =
+ &req->response;
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_asymmetric_encrypt_resp(resp_buf,
- ciphertext_buffer, ciphertext_len);
+ rpc_status = serializer->serialize_asymmetric_encrypt_resp(
+ resp_buf, ciphertext_buffer, ciphertext_len);
}
free(ciphertext_buffer);
- }
- else {
+ } else {
/* Failed to allocate ouptput buffer */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
psa_reset_key_attributes(&attributes);
}
- }
- else {
+ } else {
/* Failed to allocate buffers */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
free(plaintext_buffer);
@@ -512,10 +480,10 @@
return rpc_status;
}
-static rpc_status_t generate_random_handler(void *context, struct call_req* req)
+static rpc_status_t generate_random_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
size_t output_size;
@@ -523,59 +491,55 @@
if (serializer)
rpc_status = serializer->deserialize_generate_random_req(req_buf, &output_size);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status;
uint8_t *output_buffer = malloc(output_size);
if (output_buffer) {
-
psa_status = psa_generate_random(output_buffer, output_size);
if (psa_status == PSA_SUCCESS) {
+ struct rpc_buffer *resp_buf = &req->response;
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_generate_random_resp(resp_buf,
- output_buffer, output_size);
+ rpc_status = serializer->serialize_generate_random_resp(
+ resp_buf, output_buffer, output_size);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
free(output_buffer);
- }
- else {
+ } else {
/* Failed to allocate output buffer */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
return rpc_status;
}
-static rpc_status_t copy_key_handler(void *context, struct call_req* req)
+static rpc_status_t copy_key_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_key_id_t source_key_id;
if (serializer)
- rpc_status = serializer->deserialize_copy_key_req(req_buf, &attributes, &source_key_id);
+ rpc_status =
+ serializer->deserialize_copy_key_req(req_buf, &attributes, &source_key_id);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_key_id_t target_key_id;
psa_status_t psa_status = psa_copy_key(source_key_id, &attributes, &target_key_id);
if (psa_status == PSA_SUCCESS) {
-
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_copy_key_resp(resp_buf, target_key_id);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
psa_reset_key_attributes(&attributes);
@@ -583,10 +547,10 @@
return rpc_status;
}
-static rpc_status_t purge_key_handler(void *context, struct call_req* req)
+static rpc_status_t purge_key_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_id_t id;
@@ -594,19 +558,18 @@
if (serializer)
rpc_status = serializer->deserialize_purge_key_req(req_buf, &id);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = psa_purge_key(id);
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t get_key_attributes_handler(void *context, struct call_req* req)
+static rpc_status_t get_key_attributes_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct crypto_provider_serializer *serializer = get_crypto_serializer(context, req);
psa_key_id_t id;
@@ -614,20 +577,20 @@
if (serializer)
rpc_status = serializer->deserialize_get_key_attributes_req(req_buf, &id);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
-
+ if (rpc_status == RPC_SUCCESS) {
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
psa_status_t psa_status = psa_get_key_attributes(id, &attributes);
if (psa_status == PSA_SUCCESS) {
+ struct rpc_buffer *resp_buf = &req->response;
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
- rpc_status = serializer->serialize_get_key_attributes_resp(resp_buf, &attributes);
+ rpc_status = serializer->serialize_get_key_attributes_resp(resp_buf,
+ &attributes);
}
psa_reset_key_attributes(&attributes);
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
diff --git a/components/service/crypto/provider/crypto_provider.h b/components/service/crypto/provider/crypto_provider.h
index ce33c23..1720264 100644
--- a/components/service/crypto/provider/crypto_provider.h
+++ b/components/service/crypto/provider/crypto_provider.h
@@ -7,10 +7,9 @@
#ifndef CRYPTO_PROVIDER_H
#define CRYPTO_PROVIDER_H
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
#include <service/common/provider/service_provider.h>
#include <service/crypto/provider/serializer/crypto_provider_serializer.h>
-#include <service/discovery/provider/discovery_provider.h>
#include <protocols/rpc/common/packed-c/encoding.h>
#ifdef __cplusplus
@@ -20,8 +19,7 @@
struct crypto_provider
{
struct service_provider base_provider;
- const struct crypto_provider_serializer *serializers[TS_RPC_ENCODING_LIMIT];
- struct discovery_provider discovery_provider;
+ const struct crypto_provider_serializer *serializer;
};
/*
@@ -29,7 +27,8 @@
* backend that realizes the PSA Crypto API should have been initialized
* prior to initializing the crypto provider.
*/
-struct rpc_interface *crypto_provider_init(struct crypto_provider *context);
+struct rpc_service_interface *crypto_provider_init(struct crypto_provider *context,
+ unsigned int encoding, const struct crypto_provider_serializer *serializer);
/*
* When operation of the provider is no longer required, this function
@@ -44,7 +43,6 @@
* for compatibility with different types of client.
*/
void crypto_provider_register_serializer(struct crypto_provider *context,
- unsigned int encoding,
const struct crypto_provider_serializer *serializer);
/*
diff --git a/components/service/crypto/provider/crypto_uuid.h b/components/service/crypto/provider/crypto_uuid.h
new file mode 100644
index 0000000..ec35f24
--- /dev/null
+++ b/components/service/crypto/provider/crypto_uuid.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef CRYPTO_UUID_H
+#define CRYPTO_UUID_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TS_PSA_CRYPTO_SERVICE_UUID \
+{ 0xd9, 0xdf, 0x52, 0xd5, 0x16, 0xa2, 0x4b, 0xb2, 0x9a, 0xa4, 0xd2, 0x6d, 0x3b, 0x84, 0xe8, 0xc0 }
+
+#define TS_PSA_CRYPTO_PROTOBUF_SERVICE_UUID \
+{ 0x6b, 0xa9, 0xde, 0x75, 0x39, 0x3e, 0x4c, 0x7f, 0xaa, 0xbb, 0x7f, 0x71, 0xcc, 0x6b, 0x14, 0x2e }
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CRYPTO_UUID_H */
diff --git a/components/service/crypto/provider/extension/aead/aead_provider.c b/components/service/crypto/provider/extension/aead/aead_provider.c
index 14a2543..696474e 100644
--- a/components/service/crypto/provider/extension/aead/aead_provider.c
+++ b/components/service/crypto/provider/extension/aead/aead_provider.c
@@ -11,15 +11,15 @@
#include <psa/crypto.h>
/* Service request handlers */
-static rpc_status_t aead_setup_handler(void *context, struct call_req *req);
-static rpc_status_t aead_generate_nonce_handler(void *context, struct call_req *req);
-static rpc_status_t aead_set_nonce_handler(void *context, struct call_req *req);
-static rpc_status_t aead_set_lengths_handler(void *context, struct call_req *req);
-static rpc_status_t aead_update_ad_handler(void *context, struct call_req *req);
-static rpc_status_t aead_update_handler(void *context, struct call_req *req);
-static rpc_status_t aead_finish_handler(void *context, struct call_req *req);
-static rpc_status_t aead_verify_handler(void *context, struct call_req *req);
-static rpc_status_t aead_abort_handler(void *context, struct call_req *req);
+static rpc_status_t aead_setup_handler(void *context, struct rpc_request *req);
+static rpc_status_t aead_generate_nonce_handler(void *context, struct rpc_request *req);
+static rpc_status_t aead_set_nonce_handler(void *context, struct rpc_request *req);
+static rpc_status_t aead_set_lengths_handler(void *context, struct rpc_request *req);
+static rpc_status_t aead_update_ad_handler(void *context, struct rpc_request *req);
+static rpc_status_t aead_update_handler(void *context, struct rpc_request *req);
+static rpc_status_t aead_finish_handler(void *context, struct rpc_request *req);
+static rpc_status_t aead_verify_handler(void *context, struct rpc_request *req);
+static rpc_status_t aead_abort_handler(void *context, struct rpc_request *req);
/* Handler mapping table for service */
static const struct service_handler handler_table[] = {
@@ -37,12 +37,14 @@
void aead_provider_init(struct aead_provider *context)
{
+ const struct rpc_uuid nil_uuid = { 0 };
+
crypto_context_pool_init(&context->context_pool);
for (size_t encoding = 0; encoding < TS_RPC_ENCODING_LIMIT; ++encoding)
context->serializers[encoding] = NULL;
- service_provider_init(&context->base_provider, context,
+ service_provider_init(&context->base_provider, context, &nil_uuid,
handler_table, sizeof(handler_table)/sizeof(struct service_handler));
}
@@ -59,21 +61,18 @@
}
static const struct aead_provider_serializer* get_serializer(void *context,
- const struct call_req *req)
+ const struct rpc_request *req)
{
struct aead_provider *this_instance = (struct aead_provider*)context;
- const struct aead_provider_serializer* serializer = NULL;
- unsigned int encoding = call_req_get_encoding(req);
+ unsigned int encoding = 0; /* No other encodings supported */
- if (encoding < TS_RPC_ENCODING_LIMIT) serializer = this_instance->serializers[encoding];
-
- return serializer;
+ return this_instance->serializers[encoding];
}
-static rpc_status_t aead_setup_handler(void *context, struct call_req *req)
+static rpc_status_t aead_setup_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct aead_provider_serializer *serializer = get_serializer(context, req);
struct aead_provider *this_instance = (struct aead_provider*)context;
@@ -83,13 +82,13 @@
if (serializer)
rpc_status = serializer->deserialize_aead_setup_req(req_buf, &key_id, &alg);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
uint32_t op_handle;
struct crypto_context *crypto_context =
crypto_context_pool_alloc(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_AEAD, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_AEAD, req->source_id,
&op_handle);
if (crypto_context) {
@@ -98,36 +97,34 @@
crypto_context->op.aead = psa_aead_operation_init();
- psa_status = (call_req_get_opcode(req) == TS_CRYPTO_OPCODE_AEAD_ENCRYPT_SETUP) ?
+ psa_status = (req->opcode == TS_CRYPTO_OPCODE_AEAD_ENCRYPT_SETUP) ?
psa_aead_encrypt_setup(&crypto_context->op.aead, key_id, alg) :
psa_aead_decrypt_setup(&crypto_context->op.aead, key_id, alg);
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_aead_setup_resp(resp_buf, op_handle);
}
- if ((psa_status != PSA_SUCCESS) || (rpc_status != TS_RPC_CALL_ACCEPTED)) {
-
+ if ((psa_status != PSA_SUCCESS) || (rpc_status != RPC_SUCCESS))
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
- }
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
else {
/* Failed to allocate crypto context for transaction */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
return rpc_status;
}
-static rpc_status_t aead_generate_nonce_handler(void *context, struct call_req *req)
+static rpc_status_t aead_generate_nonce_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct aead_provider_serializer *serializer = get_serializer(context, req);
struct aead_provider *this_instance = (struct aead_provider*)context;
@@ -136,13 +133,13 @@
if (serializer)
rpc_status = serializer->deserialize_aead_generate_nonce_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_AEAD, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_AEAD, req->source_id,
op_handle);
if (crypto_context) {
@@ -155,22 +152,22 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_aead_generate_nonce_resp(resp_buf,
nonce, nonce_len);
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t aead_set_nonce_handler(void *context, struct call_req *req)
+static rpc_status_t aead_set_nonce_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct aead_provider_serializer *serializer = get_serializer(context, req);
struct aead_provider *this_instance = (struct aead_provider*)context;
@@ -182,13 +179,13 @@
rpc_status = serializer->deserialize_aead_set_nonce_req(req_buf, &op_handle,
&nonce, &nonce_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_AEAD, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_AEAD, req->source_id,
op_handle);
if (crypto_context) {
@@ -196,16 +193,16 @@
psa_status = psa_aead_set_nonce(&crypto_context->op.aead, nonce, nonce_len);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t aead_set_lengths_handler(void *context, struct call_req *req)
+static rpc_status_t aead_set_lengths_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct aead_provider_serializer *serializer = get_serializer(context, req);
struct aead_provider *this_instance = (struct aead_provider*)context;
@@ -217,13 +214,13 @@
rpc_status = serializer->deserialize_aead_set_lengths_req(req_buf, &op_handle,
&ad_length, &plaintext_length);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_AEAD, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_AEAD, req->source_id,
op_handle);
if (crypto_context) {
@@ -232,16 +229,16 @@
ad_length, plaintext_length);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t aead_update_ad_handler(void *context, struct call_req *req)
+static rpc_status_t aead_update_ad_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct aead_provider_serializer *serializer = get_serializer(context, req);
struct aead_provider *this_instance = (struct aead_provider*)context;
@@ -253,13 +250,13 @@
rpc_status = serializer->deserialize_aead_update_ad_req(req_buf, &op_handle,
&input, &input_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_AEAD, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_AEAD, req->source_id,
op_handle);
if (crypto_context) {
@@ -267,16 +264,16 @@
psa_status = psa_aead_update_ad(&crypto_context->op.aead, input, input_len);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t aead_update_handler(void *context, struct call_req *req)
+static rpc_status_t aead_update_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct aead_provider_serializer *serializer = get_serializer(context, req);
struct aead_provider *this_instance = (struct aead_provider*)context;
@@ -288,13 +285,13 @@
rpc_status = serializer->deserialize_aead_update_req(req_buf, &op_handle,
&input, &input_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_AEAD, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_AEAD, req->source_id,
op_handle);
if (crypto_context) {
@@ -311,7 +308,7 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_aead_update_resp(resp_buf,
output, output_len);
}
@@ -324,16 +321,16 @@
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t aead_finish_handler(void *context, struct call_req *req)
+static rpc_status_t aead_finish_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct aead_provider_serializer *serializer = get_serializer(context, req);
struct aead_provider *this_instance = (struct aead_provider*)context;
@@ -342,13 +339,13 @@
if (serializer)
rpc_status = serializer->deserialize_aead_finish_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_AEAD, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_AEAD, req->source_id,
op_handle);
if (crypto_context) {
@@ -365,7 +362,7 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_aead_finish_resp(resp_buf,
ciphertext, ciphertext_len,
tag, tag_len);
@@ -374,16 +371,16 @@
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t aead_verify_handler(void *context, struct call_req *req)
+static rpc_status_t aead_verify_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct aead_provider_serializer *serializer = get_serializer(context, req);
struct aead_provider *this_instance = (struct aead_provider*)context;
@@ -395,13 +392,13 @@
rpc_status = serializer->deserialize_aead_verify_req(req_buf, &op_handle,
&tag, &tag_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_AEAD, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_AEAD, req->source_id,
op_handle);
if (crypto_context) {
@@ -415,7 +412,7 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_aead_verify_resp(resp_buf,
plaintext, plaintext_len);
@@ -423,16 +420,16 @@
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t aead_abort_handler(void *context, struct call_req *req)
+static rpc_status_t aead_abort_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct aead_provider_serializer *serializer = get_serializer(context, req);
struct aead_provider *this_instance = (struct aead_provider*)context;
@@ -441,7 +438,7 @@
if (serializer)
rpc_status = serializer->deserialize_aead_abort_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
/* Return success if operation is no longer active and
* doesn't need aborting.
@@ -450,7 +447,7 @@
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_AEAD, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_AEAD, req->source_id,
op_handle);
if (crypto_context) {
@@ -459,7 +456,7 @@
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
diff --git a/components/service/crypto/provider/extension/aead/aead_provider.h b/components/service/crypto/provider/extension/aead/aead_provider.h
index 33fa7d0..b25cde8 100644
--- a/components/service/crypto/provider/extension/aead/aead_provider.h
+++ b/components/service/crypto/provider/extension/aead/aead_provider.h
@@ -7,7 +7,7 @@
#ifndef AEAD_PROVIDER_H
#define AEAD_PROVIDER_H
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
#include <service/common/provider/service_provider.h>
#include <service/crypto/provider/extension/aead/serializer/aead_provider_serializer.h>
#include <service/crypto/provider/crypto_context_pool.h>
diff --git a/components/service/crypto/provider/extension/aead/serializer/aead_provider_serializer.h b/components/service/crypto/provider/extension/aead/serializer/aead_provider_serializer.h
index bb1a2a9..2bf7a01 100644
--- a/components/service/crypto/provider/extension/aead/serializer/aead_provider_serializer.h
+++ b/components/service/crypto/provider/extension/aead/serializer/aead_provider_serializer.h
@@ -10,7 +10,7 @@
#include <stddef.h>
#include <stdint.h>
#include <psa/crypto.h>
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
/* Provides a common interface for parameter serialization operations
* for the aead service provider.
@@ -18,62 +18,62 @@
struct aead_provider_serializer {
/* Operation: aead_setup */
- rpc_status_t (*deserialize_aead_setup_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_aead_setup_req)(const struct rpc_buffer *req_buf,
psa_key_id_t *id,
psa_algorithm_t *alg);
- rpc_status_t (*serialize_aead_setup_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_aead_setup_resp)(struct rpc_buffer *resp_buf,
uint32_t op_handle);
/* Operation: aead_generate_nonce */
- rpc_status_t (*deserialize_aead_generate_nonce_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_aead_generate_nonce_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
- rpc_status_t (*serialize_aead_generate_nonce_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_aead_generate_nonce_resp)(struct rpc_buffer *resp_buf,
const uint8_t *nonce, size_t nonce_len);
/* Operation: aead_set_nonce */
- rpc_status_t (*deserialize_aead_set_nonce_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_aead_set_nonce_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **nonce, size_t *nonce_len);
/* Operation: aead_set_lengths */
- rpc_status_t (*deserialize_aead_set_lengths_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_aead_set_lengths_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
size_t *ad_length,
size_t *plaintext_length);
/* Operation: aead_update_ad */
- rpc_status_t (*deserialize_aead_update_ad_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_aead_update_ad_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **input, size_t *input_len);
/* Operation: aead_update */
- rpc_status_t (*deserialize_aead_update_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_aead_update_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **input, size_t *input_len);
- rpc_status_t (*serialize_aead_update_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_aead_update_resp)(struct rpc_buffer *resp_buf,
const uint8_t *output, size_t output_len);
/* Operation: aead_finish */
- rpc_status_t (*deserialize_aead_finish_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_aead_finish_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
- rpc_status_t (*serialize_aead_finish_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_aead_finish_resp)(struct rpc_buffer *resp_buf,
const uint8_t *aeadtext, size_t aeadtext_len,
const uint8_t *tag, size_t tag_len);
/* Operation: aead_verify */
- rpc_status_t (*deserialize_aead_verify_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_aead_verify_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **tag, size_t *tag_len);
- rpc_status_t (*serialize_aead_verify_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_aead_verify_resp)(struct rpc_buffer *resp_buf,
const uint8_t *plaintext, size_t plaintext_len);
/* Operation: aead_abort */
- rpc_status_t (*deserialize_aead_abort_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_aead_abort_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
};
diff --git a/components/service/crypto/provider/extension/aead/serializer/packed-c/packedc_aead_provider_serializer.c b/components/service/crypto/provider/extension/aead/serializer/packed-c/packedc_aead_provider_serializer.c
index 6f00b3e..738d5f2 100644
--- a/components/service/crypto/provider/extension/aead/serializer/packed-c/packedc_aead_provider_serializer.c
+++ b/components/service/crypto/provider/extension/aead/serializer/packed-c/packedc_aead_provider_serializer.c
@@ -11,29 +11,29 @@
#include "packedc_aead_provider_serializer.h"
/* Operation: aead_setup */
-static rpc_status_t deserialize_aead_setup_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_aead_setup_req(const struct rpc_buffer *req_buf,
psa_key_id_t *id,
psa_algorithm_t *alg)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_aead_setup_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_aead_setup_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*id = recv_msg.key_id;
*alg = recv_msg.alg;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_aead_setup_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_aead_setup_resp(struct rpc_buffer *resp_buf,
uint32_t op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct ts_crypto_aead_setup_out resp_msg;
size_t fixed_len = sizeof(struct ts_crypto_aead_setup_out);
@@ -42,35 +42,35 @@
if (fixed_len <= resp_buf->size) {
memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: aead_generate_nonce */
-static rpc_status_t deserialize_aead_generate_nonce_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_aead_generate_nonce_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_aead_generate_nonce_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_aead_generate_nonce_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_aead_generate_nonce_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_aead_generate_nonce_resp(struct rpc_buffer *resp_buf,
const uint8_t *nonce, size_t nonce_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
@@ -82,28 +82,28 @@
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(out_record.length);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(out_record.length);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: aead_set_nonce */
-static rpc_status_t deserialize_aead_set_nonce_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_aead_set_nonce_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **nonce, size_t *nonce_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_aead_set_nonce_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_aead_set_nonce_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -111,7 +111,7 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_AEAD_SET_NONCE_IN_TAG_NONCE, &decoded_record)) {
@@ -128,18 +128,18 @@
}
/* Operation: aead_set_lengths */
-static rpc_status_t deserialize_aead_set_lengths_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_aead_set_lengths_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
size_t *ad_length,
size_t *plaintext_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_aead_set_lengths_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_aead_set_lengths_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -152,20 +152,20 @@
}
/* Operation: aead_update_ad */
-static rpc_status_t deserialize_aead_update_ad_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_aead_update_ad_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **input, size_t *input_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_aead_update_ad_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_aead_update_ad_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -173,7 +173,7 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_AEAD_UPDATE_AD_IN_TAG_DATA, &decoded_record)) {
@@ -190,20 +190,20 @@
}
/* Operation: aead_update */
-static rpc_status_t deserialize_aead_update_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_aead_update_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **input, size_t *input_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_aead_update_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_aead_update_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -211,7 +211,7 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_AEAD_UPDATE_IN_TAG_DATA, &decoded_record)) {
@@ -227,10 +227,10 @@
return rpc_status;
}
-static rpc_status_t serialize_aead_update_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_aead_update_resp(struct rpc_buffer *resp_buf,
const uint8_t *output, size_t output_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
@@ -242,40 +242,40 @@
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(out_record.length);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(out_record.length);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: aead_finish */
-static rpc_status_t deserialize_aead_finish_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_aead_finish_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_aead_finish_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_aead_finish_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_aead_finish_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_aead_finish_resp(struct rpc_buffer *resp_buf,
const uint8_t *aeadtext, size_t aeadtext_len,
const uint8_t *tag, size_t tag_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
int encoded_tlv_count = 0;
- resp_buf->data_len = 0;
+ resp_buf->data_length = 0;
tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
@@ -286,7 +286,7 @@
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len += tlv_required_space(out_record.length);
+ resp_buf->data_length += tlv_required_space(out_record.length);
++encoded_tlv_count;
}
@@ -296,31 +296,32 @@
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len += tlv_required_space(out_record.length);
+ resp_buf->data_length += tlv_required_space(out_record.length);
++encoded_tlv_count;
}
/* Check that expected TLV records have been encoded */
- if (encoded_tlv_count == 2) rpc_status = TS_RPC_CALL_ACCEPTED;
+ if (encoded_tlv_count == 2)
+ rpc_status = RPC_SUCCESS;
return rpc_status;
}
/* Operation: aead_verify */
-static rpc_status_t deserialize_aead_verify_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_aead_verify_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **tag, size_t *tag_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_aead_verify_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_aead_verify_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -328,7 +329,7 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_AEAD_VERIFY_IN_TAG_TAG, &decoded_record)) {
@@ -344,10 +345,10 @@
return rpc_status;
}
-static rpc_status_t serialize_aead_verify_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_aead_verify_resp(struct rpc_buffer *resp_buf,
const uint8_t *plaintext, size_t plaintext_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
@@ -359,26 +360,26 @@
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(out_record.length);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(out_record.length);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: aead_abort */
-static rpc_status_t deserialize_aead_abort_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_aead_abort_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_aead_abort_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_aead_abort_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
diff --git a/components/service/crypto/provider/extension/cipher/cipher_provider.c b/components/service/crypto/provider/extension/cipher/cipher_provider.c
index a5dd037..ceecdee 100644
--- a/components/service/crypto/provider/extension/cipher/cipher_provider.c
+++ b/components/service/crypto/provider/extension/cipher/cipher_provider.c
@@ -11,12 +11,12 @@
#include <psa/crypto.h>
/* Service request handlers */
-static rpc_status_t cipher_setup_handler(void *context, struct call_req* req);
-static rpc_status_t cipher_generate_iv_handler(void *context, struct call_req* req);
-static rpc_status_t cipher_set_iv_handler(void *context, struct call_req* req);
-static rpc_status_t cipher_update_handler(void *context, struct call_req* req);
-static rpc_status_t cipher_finish_handler(void *context, struct call_req* req);
-static rpc_status_t cipher_abort_handler(void *context, struct call_req* req);
+static rpc_status_t cipher_setup_handler(void *context, struct rpc_request *req);
+static rpc_status_t cipher_generate_iv_handler(void *context, struct rpc_request *req);
+static rpc_status_t cipher_set_iv_handler(void *context, struct rpc_request *req);
+static rpc_status_t cipher_update_handler(void *context, struct rpc_request *req);
+static rpc_status_t cipher_finish_handler(void *context, struct rpc_request *req);
+static rpc_status_t cipher_abort_handler(void *context, struct rpc_request *req);
/* Handler mapping table for service */
static const struct service_handler handler_table[] = {
@@ -31,12 +31,14 @@
void cipher_provider_init(struct cipher_provider *context)
{
+ const struct rpc_uuid nil_uuid = { 0 };
+
crypto_context_pool_init(&context->context_pool);
for (size_t encoding = 0; encoding < TS_RPC_ENCODING_LIMIT; ++encoding)
context->serializers[encoding] = NULL;
- service_provider_init(&context->base_provider, context,
+ service_provider_init(&context->base_provider, context, &nil_uuid,
handler_table, sizeof(handler_table)/sizeof(struct service_handler));
}
@@ -53,21 +55,18 @@
}
static const struct cipher_provider_serializer* get_serializer(void *context,
- const struct call_req *req)
+ const struct rpc_request *req)
{
struct cipher_provider *this_instance = (struct cipher_provider*)context;
- const struct cipher_provider_serializer* serializer = NULL;
- unsigned int encoding = call_req_get_encoding(req);
+ unsigned int encoding = 0; /* No other encodings supported */
- if (encoding < TS_RPC_ENCODING_LIMIT) serializer = this_instance->serializers[encoding];
-
- return serializer;
+ return this_instance->serializers[encoding];
}
-static rpc_status_t cipher_setup_handler(void *context, struct call_req* req)
+static rpc_status_t cipher_setup_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct cipher_provider_serializer *serializer = get_serializer(context, req);
struct cipher_provider *this_instance = (struct cipher_provider*)context;
@@ -77,13 +76,13 @@
if (serializer)
rpc_status = serializer->deserialize_cipher_setup_req(req_buf, &key_id, &alg);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
uint32_t op_handle;
struct crypto_context *crypto_context =
crypto_context_pool_alloc(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_CIPHER, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_CIPHER, req->source_id,
&op_handle);
if (crypto_context) {
@@ -92,36 +91,34 @@
crypto_context->op.cipher = psa_cipher_operation_init();
- psa_status = (call_req_get_opcode(req) == TS_CRYPTO_OPCODE_CIPHER_ENCRYPT_SETUP) ?
+ psa_status = (req->opcode == TS_CRYPTO_OPCODE_CIPHER_ENCRYPT_SETUP) ?
psa_cipher_encrypt_setup(&crypto_context->op.cipher, key_id, alg) :
psa_cipher_decrypt_setup(&crypto_context->op.cipher, key_id, alg);
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_cipher_setup_resp(resp_buf, op_handle);
}
- if ((psa_status != PSA_SUCCESS) || (rpc_status != TS_RPC_CALL_ACCEPTED)) {
-
+ if ((psa_status != PSA_SUCCESS) || (rpc_status != RPC_SUCCESS))
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
- }
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
else {
/* Failed to allocate crypto context for transaction */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
return rpc_status;
}
-static rpc_status_t cipher_generate_iv_handler(void *context, struct call_req* req)
+static rpc_status_t cipher_generate_iv_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct cipher_provider_serializer *serializer = get_serializer(context, req);
struct cipher_provider *this_instance = (struct cipher_provider*)context;
@@ -130,13 +127,13 @@
if (serializer)
rpc_status = serializer->deserialize_cipher_generate_iv_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_CIPHER, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_CIPHER, req->source_id,
op_handle);
if (crypto_context) {
@@ -148,21 +145,21 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_cipher_generate_iv_resp(resp_buf, iv, iv_len);
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t cipher_set_iv_handler(void *context, struct call_req* req)
+static rpc_status_t cipher_set_iv_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct cipher_provider_serializer *serializer = get_serializer(context, req);
struct cipher_provider *this_instance = (struct cipher_provider*)context;
@@ -174,13 +171,13 @@
rpc_status = serializer->deserialize_cipher_set_iv_req(req_buf, &op_handle,
&iv, &iv_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_CIPHER, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_CIPHER, req->source_id,
op_handle);
if (crypto_context) {
@@ -188,16 +185,16 @@
psa_status = psa_cipher_set_iv(&crypto_context->op.cipher, iv, iv_len);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t cipher_update_handler(void *context, struct call_req* req)
+static rpc_status_t cipher_update_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct cipher_provider_serializer *serializer = get_serializer(context, req);
struct cipher_provider *this_instance = (struct cipher_provider*)context;
@@ -209,13 +206,13 @@
rpc_status = serializer->deserialize_cipher_update_req(req_buf, &op_handle,
&input, &input_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_CIPHER, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_CIPHER, req->source_id,
op_handle);
if (crypto_context) {
@@ -232,7 +229,7 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_cipher_update_resp(resp_buf,
output, output_len);
}
@@ -245,16 +242,16 @@
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t cipher_finish_handler(void *context, struct call_req* req)
+static rpc_status_t cipher_finish_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct cipher_provider_serializer *serializer = get_serializer(context, req);
struct cipher_provider *this_instance = (struct cipher_provider*)context;
@@ -263,13 +260,13 @@
if (serializer)
rpc_status = serializer->deserialize_cipher_finish_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_CIPHER, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_CIPHER, req->source_id,
op_handle);
if (crypto_context) {
@@ -281,23 +278,23 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_cipher_finish_resp(resp_buf, output, output_len);
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t cipher_abort_handler(void *context, struct call_req* req)
+static rpc_status_t cipher_abort_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct cipher_provider_serializer *serializer = get_serializer(context, req);
struct cipher_provider *this_instance = (struct cipher_provider*)context;
@@ -306,7 +303,7 @@
if (serializer)
rpc_status = serializer->deserialize_cipher_abort_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
/* Return success if operation is no longer active and
* doesn't need aborting.
@@ -315,7 +312,7 @@
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_CIPHER, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_CIPHER, req->source_id,
op_handle);
if (crypto_context) {
@@ -324,7 +321,7 @@
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
diff --git a/components/service/crypto/provider/extension/cipher/cipher_provider.h b/components/service/crypto/provider/extension/cipher/cipher_provider.h
index df2a27d..be03a80 100644
--- a/components/service/crypto/provider/extension/cipher/cipher_provider.h
+++ b/components/service/crypto/provider/extension/cipher/cipher_provider.h
@@ -7,7 +7,7 @@
#ifndef CIPHER_PROVIDER_H
#define CIPHER_PROVIDER_H
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
#include <service/common/provider/service_provider.h>
#include <service/crypto/provider/extension/cipher/serializer/cipher_provider_serializer.h>
#include <service/crypto/provider/crypto_context_pool.h>
diff --git a/components/service/crypto/provider/extension/cipher/serializer/cipher_provider_serializer.h b/components/service/crypto/provider/extension/cipher/serializer/cipher_provider_serializer.h
index ccc9b96..21169d9 100644
--- a/components/service/crypto/provider/extension/cipher/serializer/cipher_provider_serializer.h
+++ b/components/service/crypto/provider/extension/cipher/serializer/cipher_provider_serializer.h
@@ -10,7 +10,7 @@
#include <stddef.h>
#include <stdint.h>
#include <psa/crypto.h>
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
/* Provides a common interface for parameter serialization operations
* for the cipher service provider.
@@ -18,42 +18,42 @@
struct cipher_provider_serializer {
/* Operation: cipher_setup */
- rpc_status_t (*deserialize_cipher_setup_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_cipher_setup_req)(const struct rpc_buffer *req_buf,
psa_key_id_t *id,
psa_algorithm_t *alg);
- rpc_status_t (*serialize_cipher_setup_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_cipher_setup_resp)(struct rpc_buffer *resp_buf,
uint32_t op_handle);
/* Operation: cipher_generate_iv */
- rpc_status_t (*deserialize_cipher_generate_iv_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_cipher_generate_iv_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
- rpc_status_t (*serialize_cipher_generate_iv_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_cipher_generate_iv_resp)(struct rpc_buffer *resp_buf,
const uint8_t *iv, size_t iv_len);
/* Operation: cipher_set_iv */
- rpc_status_t (*deserialize_cipher_set_iv_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_cipher_set_iv_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **iv, size_t *iv_len);
/* Operation: cipher_update */
- rpc_status_t (*deserialize_cipher_update_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_cipher_update_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **data, size_t *data_len);
- rpc_status_t (*serialize_cipher_update_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_cipher_update_resp)(struct rpc_buffer *resp_buf,
const uint8_t *data, size_t data_len);
/* Operation: cipher_finish */
- rpc_status_t (*deserialize_cipher_finish_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_cipher_finish_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
- rpc_status_t (*serialize_cipher_finish_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_cipher_finish_resp)(struct rpc_buffer *resp_buf,
const uint8_t *data, size_t data_len);
/* Operation: cipher_abort */
- rpc_status_t (*deserialize_cipher_abort_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_cipher_abort_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
};
diff --git a/components/service/crypto/provider/extension/cipher/serializer/packed-c/packedc_cipher_provider_serializer.c b/components/service/crypto/provider/extension/cipher/serializer/packed-c/packedc_cipher_provider_serializer.c
index 1acb165..eb9cce3 100644
--- a/components/service/crypto/provider/extension/cipher/serializer/packed-c/packedc_cipher_provider_serializer.c
+++ b/components/service/crypto/provider/extension/cipher/serializer/packed-c/packedc_cipher_provider_serializer.c
@@ -11,29 +11,29 @@
#include "packedc_cipher_provider_serializer.h"
/* Operation: cipher_setup */
-static rpc_status_t deserialize_cipher_setup_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_cipher_setup_req(const struct rpc_buffer *req_buf,
psa_key_id_t *id,
psa_algorithm_t *alg)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_cipher_setup_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_cipher_setup_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*id = recv_msg.key_id;
*alg = recv_msg.alg;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_cipher_setup_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_cipher_setup_resp(struct rpc_buffer *resp_buf,
uint32_t op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct ts_crypto_cipher_setup_out resp_msg;
size_t fixed_len = sizeof(struct ts_crypto_cipher_setup_out);
@@ -42,35 +42,35 @@
if (fixed_len <= resp_buf->size) {
memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: cipher_generate_iv */
-static rpc_status_t deserialize_cipher_generate_iv_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_cipher_generate_iv_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_cipher_generate_iv_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_cipher_generate_iv_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_cipher_generate_iv_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_cipher_generate_iv_resp(struct rpc_buffer *resp_buf,
const uint8_t *iv, size_t iv_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
@@ -82,28 +82,28 @@
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(iv_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(iv_len);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: cipher_set_iv */
-static rpc_status_t deserialize_cipher_set_iv_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_cipher_set_iv_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **iv, size_t *iv_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_cipher_set_iv_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_cipher_set_iv_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -111,7 +111,7 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_CIPHER_SET_IV_IN_TAG_IV, &decoded_record)) {
@@ -128,20 +128,20 @@
}
/* Operation: cipher_update */
-static rpc_status_t deserialize_cipher_update_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_cipher_update_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
- const uint8_t **data, size_t *data_len)
+ const uint8_t **data, size_t *data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_cipher_update_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_cipher_update_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -149,97 +149,97 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_CIPHER_UPDATE_IN_TAG_DATA, &decoded_record)) {
*data = decoded_record.value;
- *data_len = decoded_record.length;
+ *data_length = decoded_record.length;
}
else {
/* Default to a zero length data */
- *data_len = 0;
+ *data_length = 0;
}
}
return rpc_status;
}
-static rpc_status_t serialize_cipher_update_resp(struct call_param_buf *resp_buf,
- const uint8_t *data, size_t data_len)
+static rpc_status_t serialize_cipher_update_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *data, size_t data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
out_record.tag = TS_CRYPTO_CIPHER_UPDATE_OUT_TAG_DATA;
- out_record.length = data_len;
+ out_record.length = data_length;
out_record.value = data;
tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(data_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(data_length);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: cipher_finish */
-static rpc_status_t deserialize_cipher_finish_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_cipher_finish_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_cipher_finish_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_cipher_finish_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_cipher_finish_resp(struct call_param_buf *resp_buf,
- const uint8_t *data, size_t data_len)
+static rpc_status_t serialize_cipher_finish_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *data, size_t data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
out_record.tag = TS_CRYPTO_CIPHER_FINISH_OUT_TAG_DATA;
- out_record.length = data_len;
+ out_record.length = data_length;
out_record.value = data;
tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(data_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(data_length);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: cipher_abort */
-static rpc_status_t deserialize_cipher_abort_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_cipher_abort_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_cipher_abort_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_cipher_abort_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
diff --git a/components/service/crypto/provider/extension/hash/hash_provider.c b/components/service/crypto/provider/extension/hash/hash_provider.c
index b50fac1..1c4da5d 100644
--- a/components/service/crypto/provider/extension/hash/hash_provider.c
+++ b/components/service/crypto/provider/extension/hash/hash_provider.c
@@ -11,12 +11,12 @@
#include <psa/crypto.h>
/* Service request handlers */
-static rpc_status_t hash_setup_handler(void *context, struct call_req* req);
-static rpc_status_t hash_update_handler(void *context, struct call_req* req);
-static rpc_status_t hash_finish_handler(void *context, struct call_req* req);
-static rpc_status_t hash_abort_handler(void *context, struct call_req* req);
-static rpc_status_t hash_verify_handler(void *context, struct call_req* req);
-static rpc_status_t hash_clone_handler(void *context, struct call_req* req);
+static rpc_status_t hash_setup_handler(void *context, struct rpc_request *req);
+static rpc_status_t hash_update_handler(void *context, struct rpc_request *req);
+static rpc_status_t hash_finish_handler(void *context, struct rpc_request *req);
+static rpc_status_t hash_abort_handler(void *context, struct rpc_request *req);
+static rpc_status_t hash_verify_handler(void *context, struct rpc_request *req);
+static rpc_status_t hash_clone_handler(void *context, struct rpc_request *req);
/* Handler mapping table for service */
static const struct service_handler handler_table[] = {
@@ -30,12 +30,14 @@
void hash_provider_init(struct hash_provider *context)
{
+ const struct rpc_uuid nil_uuid = { 0 };
+
crypto_context_pool_init(&context->context_pool);
for (size_t encoding = 0; encoding < TS_RPC_ENCODING_LIMIT; ++encoding)
context->serializers[encoding] = NULL;
- service_provider_init(&context->base_provider, context,
+ service_provider_init(&context->base_provider, context, &nil_uuid,
handler_table, sizeof(handler_table)/sizeof(struct service_handler));
}
@@ -52,21 +54,18 @@
}
static const struct hash_provider_serializer* get_serializer(void *context,
- const struct call_req *req)
+ const struct rpc_request *req)
{
struct hash_provider *this_instance = (struct hash_provider*)context;
- const struct hash_provider_serializer* serializer = NULL;
- unsigned int encoding = call_req_get_encoding(req);
+ unsigned int encoding = 0; /* No other encodings supported */
- if (encoding < TS_RPC_ENCODING_LIMIT) serializer = this_instance->serializers[encoding];
-
- return serializer;
+ return this_instance->serializers[encoding];
}
-static rpc_status_t hash_setup_handler(void *context, struct call_req* req)
+static rpc_status_t hash_setup_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct hash_provider_serializer *serializer = get_serializer(context, req);
struct hash_provider *this_instance = (struct hash_provider*)context;
@@ -75,13 +74,13 @@
if (serializer)
rpc_status = serializer->deserialize_hash_setup_req(req_buf, &alg);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
uint32_t op_handle;
struct crypto_context *crypto_context =
crypto_context_pool_alloc(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_HASH, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_HASH, req->source_id,
&op_handle);
if (crypto_context) {
@@ -93,30 +92,28 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_hash_setup_resp(resp_buf, op_handle);
}
- if ((psa_status != PSA_SUCCESS) || (rpc_status != TS_RPC_CALL_ACCEPTED)) {
-
+ if ((psa_status != PSA_SUCCESS) || (rpc_status != RPC_SUCCESS))
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
- }
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
else {
/* Failed to allocate crypto context for transaction */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
return rpc_status;
}
-static rpc_status_t hash_update_handler(void *context, struct call_req* req)
+static rpc_status_t hash_update_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct hash_provider_serializer *serializer = get_serializer(context, req);
struct hash_provider *this_instance = (struct hash_provider*)context;
@@ -127,13 +124,13 @@
if (serializer)
rpc_status = serializer->deserialize_hash_update_req(req_buf, &op_handle, &data, &data_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_HASH, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_HASH, req->source_id,
op_handle);
if (crypto_context) {
@@ -141,16 +138,16 @@
psa_status = psa_hash_update(&crypto_context->op.hash, data, data_len);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t hash_finish_handler(void *context, struct call_req* req)
+static rpc_status_t hash_finish_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct hash_provider_serializer *serializer = get_serializer(context, req);
struct hash_provider *this_instance = (struct hash_provider*)context;
@@ -159,13 +156,13 @@
if (serializer)
rpc_status = serializer->deserialize_hash_finish_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_HASH, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_HASH, req->source_id,
op_handle);
if (crypto_context) {
@@ -177,23 +174,23 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_hash_finish_resp(resp_buf, hash, hash_len);
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t hash_abort_handler(void *context, struct call_req* req)
+static rpc_status_t hash_abort_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct hash_provider_serializer *serializer = get_serializer(context, req);
struct hash_provider *this_instance = (struct hash_provider*)context;
@@ -202,7 +199,7 @@
if (serializer)
rpc_status = serializer->deserialize_hash_abort_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
/* Return success if operation is no longer active and
* doesn't need aborting.
@@ -211,7 +208,7 @@
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_HASH, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_HASH, req->source_id,
op_handle);
if (crypto_context) {
@@ -220,16 +217,16 @@
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t hash_verify_handler(void *context, struct call_req* req)
+static rpc_status_t hash_verify_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct hash_provider_serializer *serializer = get_serializer(context, req);
struct hash_provider *this_instance = (struct hash_provider*)context;
@@ -240,13 +237,13 @@
if (serializer)
rpc_status = serializer->deserialize_hash_verify_req(req_buf, &op_handle, &hash, &hash_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_HASH, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_HASH, req->source_id,
op_handle);
if (crypto_context) {
@@ -257,16 +254,16 @@
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t hash_clone_handler(void *context, struct call_req* req)
+static rpc_status_t hash_clone_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct hash_provider_serializer *serializer = get_serializer(context, req);
struct hash_provider *this_instance = (struct hash_provider*)context;
@@ -275,13 +272,13 @@
if (serializer)
rpc_status = serializer->deserialize_hash_clone_req(req_buf, &source_op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *source_crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_HASH, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_HASH, req->source_id,
source_op_handle);
if (source_crypto_context) {
@@ -290,7 +287,7 @@
struct crypto_context *target_crypto_context = crypto_context_pool_alloc(
&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_HASH, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_HASH, req->source_id,
&target_op_handle);
if (target_crypto_context) {
@@ -302,13 +299,13 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_hash_clone_resp(resp_buf, target_op_handle);
}
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
diff --git a/components/service/crypto/provider/extension/hash/hash_provider.h b/components/service/crypto/provider/extension/hash/hash_provider.h
index 917d1f1..2dad161 100644
--- a/components/service/crypto/provider/extension/hash/hash_provider.h
+++ b/components/service/crypto/provider/extension/hash/hash_provider.h
@@ -7,7 +7,7 @@
#ifndef HASH_PROVIDER_H
#define HASH_PROVIDER_H
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
#include <service/common/provider/service_provider.h>
#include <service/crypto/provider/extension/hash/serializer/hash_provider_serializer.h>
#include <service/crypto/provider/crypto_context_pool.h>
diff --git a/components/service/crypto/provider/extension/hash/serializer/hash_provider_serializer.h b/components/service/crypto/provider/extension/hash/serializer/hash_provider_serializer.h
index 1611e6e..bfb4d8b 100644
--- a/components/service/crypto/provider/extension/hash/serializer/hash_provider_serializer.h
+++ b/components/service/crypto/provider/extension/hash/serializer/hash_provider_serializer.h
@@ -10,7 +10,7 @@
#include <stddef.h>
#include <stdint.h>
#include <psa/crypto.h>
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
/* Provides a common interface for parameter serialization operations
* for the hash service provider.
@@ -18,38 +18,38 @@
struct hash_provider_serializer {
/* Operation: hash_setup */
- rpc_status_t (*deserialize_hash_setup_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_hash_setup_req)(const struct rpc_buffer *req_buf,
psa_algorithm_t *alg);
- rpc_status_t (*serialize_hash_setup_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_hash_setup_resp)(struct rpc_buffer *resp_buf,
uint32_t op_handle);
/* Operation: hash_update */
- rpc_status_t (*deserialize_hash_update_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_hash_update_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **data, size_t *data_len);
/* Operation: hash_finish */
- rpc_status_t (*deserialize_hash_finish_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_hash_finish_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
- rpc_status_t (*serialize_hash_finish_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_hash_finish_resp)(struct rpc_buffer *resp_buf,
const uint8_t *hash, size_t hash_len);
/* Operation: hash_abort */
- rpc_status_t (*deserialize_hash_abort_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_hash_abort_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
/* Operation: hash_verify */
- rpc_status_t (*deserialize_hash_verify_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_hash_verify_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **hash, size_t *hash_len);
/* Operation: hash_clone */
- rpc_status_t (*deserialize_hash_clone_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_hash_clone_req)(const struct rpc_buffer *req_buf,
uint32_t *source_op_handle);
- rpc_status_t (*serialize_hash_clone_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_hash_clone_resp)(struct rpc_buffer *resp_buf,
uint32_t target_op_handle);
};
diff --git a/components/service/crypto/provider/extension/hash/serializer/packed-c/packedc_hash_provider_serializer.c b/components/service/crypto/provider/extension/hash/serializer/packed-c/packedc_hash_provider_serializer.c
index ac0c35e..6f131c5 100644
--- a/components/service/crypto/provider/extension/hash/serializer/packed-c/packedc_hash_provider_serializer.c
+++ b/components/service/crypto/provider/extension/hash/serializer/packed-c/packedc_hash_provider_serializer.c
@@ -11,27 +11,27 @@
#include "packedc_hash_provider_serializer.h"
/* Operation: hash_setup */
-static rpc_status_t deserialize_hash_setup_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_hash_setup_req(const struct rpc_buffer *req_buf,
psa_algorithm_t *alg)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_hash_setup_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_hash_setup_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*alg = recv_msg.alg;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_hash_setup_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_hash_setup_resp(struct rpc_buffer *resp_buf,
uint32_t op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct ts_crypto_hash_setup_out resp_msg;
size_t fixed_len = sizeof(struct ts_crypto_hash_setup_out);
@@ -40,28 +40,28 @@
if (fixed_len <= resp_buf->size) {
memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: hash_update */
-static rpc_status_t deserialize_hash_update_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_hash_update_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
- const uint8_t **data, size_t *data_len)
+ const uint8_t **data, size_t *data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_hash_update_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_hash_update_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -69,16 +69,16 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_HASH_UPDATE_IN_TAG_DATA, &decoded_record)) {
*data = decoded_record.value;
- *data_len = decoded_record.length;
+ *data_length = decoded_record.length;
}
else {
/* Default to a zero length data */
- *data_len = 0;
+ *data_length = 0;
}
}
@@ -86,27 +86,27 @@
}
/* Operation: hash_finish */
-static rpc_status_t deserialize_hash_finish_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_hash_finish_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_hash_finish_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_hash_finish_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_hash_finish_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_hash_finish_resp(struct rpc_buffer *resp_buf,
const uint8_t *hash, size_t hash_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
@@ -118,46 +118,46 @@
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(hash_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(hash_len);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: hash_abort */
-static rpc_status_t deserialize_hash_abort_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_hash_abort_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_hash_abort_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_hash_abort_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: hash_verify */
-static rpc_status_t deserialize_hash_verify_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_hash_verify_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **hash, size_t *hash_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_hash_verify_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_hash_verify_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -165,7 +165,7 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_HASH_VERIFY_IN_TAG_HASH, &decoded_record)) {
@@ -182,27 +182,27 @@
}
/* Operation: hash_clone */
-static rpc_status_t deserialize_hash_clone_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_hash_clone_req(const struct rpc_buffer *req_buf,
uint32_t *source_op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_hash_clone_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_hash_clone_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*source_op_handle = recv_msg.source_op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_hash_clone_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_hash_clone_resp(struct rpc_buffer *resp_buf,
uint32_t target_op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct ts_crypto_hash_clone_out resp_msg;
size_t fixed_len = sizeof(struct ts_crypto_hash_clone_out);
@@ -211,8 +211,8 @@
if (fixed_len <= resp_buf->size) {
memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
diff --git a/components/service/crypto/provider/extension/key_derivation/key_derivation_provider.c b/components/service/crypto/provider/extension/key_derivation/key_derivation_provider.c
index aebcf92..9503f7c 100644
--- a/components/service/crypto/provider/extension/key_derivation/key_derivation_provider.c
+++ b/components/service/crypto/provider/extension/key_derivation/key_derivation_provider.c
@@ -11,16 +11,17 @@
#include <psa/crypto.h>
/* Service request handlers */
-static rpc_status_t key_derivation_setup_handler(void *context, struct call_req* req);
-static rpc_status_t key_derivation_get_capacity_handler(void *context, struct call_req* req);
-static rpc_status_t key_derivation_set_capacity_handler(void *context, struct call_req* req);
-static rpc_status_t key_derivation_input_bytes_handler(void *context, struct call_req* req);
-static rpc_status_t key_derivation_input_key_handler(void *context, struct call_req* req);
-static rpc_status_t key_derivation_output_bytes_handler(void *context, struct call_req* req);
-static rpc_status_t key_derivation_output_key_handler(void *context, struct call_req* req);
-static rpc_status_t key_derivation_abort_handler(void *context, struct call_req* req);
-static rpc_status_t key_derivation_key_agreement_handler(void *context, struct call_req* req);
-static rpc_status_t key_derivation_raw_key_agreement_handler(void *context, struct call_req* req);
+static rpc_status_t key_derivation_setup_handler(void *context, struct rpc_request *req);
+static rpc_status_t key_derivation_get_capacity_handler(void *context, struct rpc_request *req);
+static rpc_status_t key_derivation_set_capacity_handler(void *context, struct rpc_request *req);
+static rpc_status_t key_derivation_input_bytes_handler(void *context, struct rpc_request *req);
+static rpc_status_t key_derivation_input_key_handler(void *context, struct rpc_request *req);
+static rpc_status_t key_derivation_output_bytes_handler(void *context, struct rpc_request *req);
+static rpc_status_t key_derivation_output_key_handler(void *context, struct rpc_request *req);
+static rpc_status_t key_derivation_abort_handler(void *context, struct rpc_request *req);
+static rpc_status_t key_derivation_key_agreement_handler(void *context, struct rpc_request *req);
+static rpc_status_t key_derivation_raw_key_agreement_handler(void *context,
+ struct rpc_request *req);
/* Handler mapping table for service */
static const struct service_handler handler_table[] = {
@@ -38,12 +39,14 @@
void key_derivation_provider_init(struct key_derivation_provider *context)
{
+ const struct rpc_uuid nil_uuid = { 0 };
+
crypto_context_pool_init(&context->context_pool);
for (size_t encoding = 0; encoding < TS_RPC_ENCODING_LIMIT; ++encoding)
context->serializers[encoding] = NULL;
- service_provider_init(&context->base_provider, context,
+ service_provider_init(&context->base_provider, context, &nil_uuid,
handler_table, sizeof(handler_table)/sizeof(struct service_handler));
}
@@ -60,21 +63,18 @@
}
static const struct key_derivation_provider_serializer* get_serializer(void *context,
- const struct call_req *req)
+ const struct rpc_request *req)
{
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
- const struct key_derivation_provider_serializer* serializer = NULL;
- unsigned int encoding = call_req_get_encoding(req);
+ unsigned int encoding = 0; /* No other encodings supported */
- if (encoding < TS_RPC_ENCODING_LIMIT) serializer = this_instance->serializers[encoding];
-
- return serializer;
+ return this_instance->serializers[encoding];
}
-static rpc_status_t key_derivation_setup_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_setup_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
@@ -83,13 +83,13 @@
if (serializer)
rpc_status = serializer->deserialize_key_derivation_setup_req(req_buf, &alg);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
uint32_t op_handle;
struct crypto_context *crypto_context =
crypto_context_pool_alloc(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, req->source_id,
&op_handle);
if (crypto_context) {
@@ -101,30 +101,28 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_key_derivation_setup_resp(resp_buf, op_handle);
}
- if ((psa_status != PSA_SUCCESS) || (rpc_status != TS_RPC_CALL_ACCEPTED)) {
-
+ if ((psa_status != PSA_SUCCESS) || (rpc_status != RPC_SUCCESS))
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
- }
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
else {
/* Failed to allocate crypto context for transaction */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
return rpc_status;
}
-static rpc_status_t key_derivation_get_capacity_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_get_capacity_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
@@ -133,13 +131,13 @@
if (serializer)
rpc_status = serializer->deserialize_key_derivation_get_capacity_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, req->source_id,
op_handle);
if (crypto_context) {
@@ -151,22 +149,22 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_key_derivation_get_capacity_resp(resp_buf,
capacity);
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t key_derivation_set_capacity_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_set_capacity_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
@@ -177,13 +175,13 @@
rpc_status = serializer->deserialize_key_derivation_set_capacity_req(req_buf,
&op_handle, &capacity);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, req->source_id,
op_handle);
if (crypto_context) {
@@ -192,16 +190,16 @@
capacity);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t key_derivation_input_bytes_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_input_bytes_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
@@ -214,13 +212,13 @@
rpc_status = serializer->deserialize_key_derivation_input_bytes_req(req_buf,
&op_handle, &step, &data, &data_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, req->source_id,
op_handle);
if (crypto_context) {
@@ -229,16 +227,16 @@
step, data, data_len);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t key_derivation_input_key_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_input_key_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
@@ -250,7 +248,7 @@
rpc_status = serializer->deserialize_key_derivation_input_key_req(req_buf,
&op_handle, &step, &key_id);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_INVALID_HANDLE;
@@ -260,7 +258,7 @@
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, req->source_id,
op_handle);
if (crypto_context) {
@@ -270,16 +268,16 @@
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t key_derivation_output_bytes_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_output_bytes_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
@@ -290,13 +288,13 @@
rpc_status = serializer->deserialize_key_derivation_output_bytes_req(req_buf,
&op_handle, &output_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, req->source_id,
op_handle);
if (crypto_context) {
@@ -310,7 +308,7 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_key_derivation_output_bytes_resp(resp_buf,
output, output_len);
}
@@ -323,16 +321,16 @@
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t key_derivation_output_key_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_output_key_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
@@ -343,13 +341,13 @@
rpc_status = serializer->deserialize_key_derivation_output_key_req(req_buf,
&op_handle, &attributes);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, req->source_id,
op_handle);
if (crypto_context) {
@@ -362,13 +360,13 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_key_derivation_output_key_resp(resp_buf,
key_id);
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
psa_reset_key_attributes(&attributes);
@@ -376,10 +374,10 @@
return rpc_status;
}
-static rpc_status_t key_derivation_abort_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_abort_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
@@ -388,7 +386,7 @@
if (serializer)
rpc_status = serializer->deserialize_key_derivation_abort_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
/* Return success if operation is no longer active and
* doesn't need aborting.
@@ -397,7 +395,7 @@
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, req->source_id,
op_handle);
if (crypto_context) {
@@ -406,16 +404,16 @@
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t key_derivation_key_agreement_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_key_agreement_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
struct key_derivation_provider *this_instance = (struct key_derivation_provider*)context;
@@ -429,13 +427,13 @@
rpc_status = serializer->deserialize_key_derivation_key_agreement_req(req_buf,
&op_handle, &step, &private_key_id, &peer_key, &peer_key_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_KEY_DERIVATION, req->source_id,
op_handle);
if (crypto_context) {
@@ -444,16 +442,16 @@
step, private_key_id, peer_key, peer_key_len);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t key_derivation_raw_key_agreement_handler(void *context, struct call_req* req)
+static rpc_status_t key_derivation_raw_key_agreement_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct key_derivation_provider_serializer *serializer = get_serializer(context, req);
psa_algorithm_t alg;
@@ -465,7 +463,7 @@
rpc_status = serializer->deserialize_key_derivation_raw_key_agreement_req(req_buf,
&alg, &private_key_id, &peer_key, &peer_key_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
size_t output_len;
uint8_t output[PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE];
@@ -476,12 +474,12 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_key_derivation_raw_key_agreement_resp(resp_buf,
output, output_len);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
diff --git a/components/service/crypto/provider/extension/key_derivation/key_derivation_provider.h b/components/service/crypto/provider/extension/key_derivation/key_derivation_provider.h
index 1ac07f2..0abaed6 100644
--- a/components/service/crypto/provider/extension/key_derivation/key_derivation_provider.h
+++ b/components/service/crypto/provider/extension/key_derivation/key_derivation_provider.h
@@ -7,7 +7,7 @@
#ifndef KEY_DERIVATION_PROVIDER_H
#define KEY_DERIVATION_PROVIDER_H
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
#include <service/common/provider/service_provider.h>
#include <service/crypto/provider/extension/key_derivation/serializer/key_derivation_provider_serializer.h>
#include <service/crypto/provider/crypto_context_pool.h>
diff --git a/components/service/crypto/provider/extension/key_derivation/serializer/key_derivation_provider_serializer.h b/components/service/crypto/provider/extension/key_derivation/serializer/key_derivation_provider_serializer.h
index 4bbeb41..bff1a64 100644
--- a/components/service/crypto/provider/extension/key_derivation/serializer/key_derivation_provider_serializer.h
+++ b/components/service/crypto/provider/extension/key_derivation/serializer/key_derivation_provider_serializer.h
@@ -10,7 +10,7 @@
#include <stddef.h>
#include <stdint.h>
#include <psa/crypto.h>
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
/* Provides a common interface for parameter serialization operations
* for the key_derivation service provider.
@@ -18,70 +18,70 @@
struct key_derivation_provider_serializer {
/* Operation: key_derivation_setup */
- rpc_status_t (*deserialize_key_derivation_setup_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_key_derivation_setup_req)(const struct rpc_buffer *req_buf,
psa_algorithm_t *alg);
- rpc_status_t (*serialize_key_derivation_setup_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_key_derivation_setup_resp)(struct rpc_buffer *resp_buf,
uint32_t op_handle);
/* Operation: key_derivation_get_capacity */
- rpc_status_t (*deserialize_key_derivation_get_capacity_req)(const struct call_param_buf *req_buf,
- uint32_t *op_handle);
+ rpc_status_t (*deserialize_key_derivation_get_capacity_req)(
+ const struct rpc_buffer *req_buf, uint32_t *op_handle);
- rpc_status_t (*serialize_key_derivation_get_capacity_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_key_derivation_get_capacity_resp)(struct rpc_buffer *resp_buf,
size_t capacity);
/* Operation: key_derivation_set_capacity */
- rpc_status_t (*deserialize_key_derivation_set_capacity_req)(const struct call_param_buf *req_buf,
- uint32_t *op_handle,
- size_t *capacity);
+ rpc_status_t (*deserialize_key_derivation_set_capacity_req)(
+ const struct rpc_buffer *req_buf, uint32_t *op_handle, size_t *capacity);
/* Operation: key_derivation_input_bytes */
- rpc_status_t (*deserialize_key_derivation_input_bytes_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_key_derivation_input_bytes_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
psa_key_derivation_step_t *step,
const uint8_t **data, size_t *data_len);
/* Operation: key_derivation_input_key */
- rpc_status_t (*deserialize_key_derivation_input_key_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_key_derivation_input_key_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
psa_key_derivation_step_t *step,
psa_key_id_t *key_id);
/* Operation: key_derivation_output_bytes */
- rpc_status_t (*deserialize_key_derivation_output_bytes_req)(const struct call_param_buf *req_buf,
- uint32_t *op_handle,
- size_t *output_len);
+ rpc_status_t (*deserialize_key_derivation_output_bytes_req)(
+ const struct rpc_buffer *req_buf, uint32_t *op_handle, size_t *output_len);
- rpc_status_t (*serialize_key_derivation_output_bytes_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_key_derivation_output_bytes_resp)(struct rpc_buffer *resp_buf,
const uint8_t *data, size_t data_len);
/* Operation: key_derivation_output_key */
- rpc_status_t (*deserialize_key_derivation_output_key_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_key_derivation_output_key_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
psa_key_attributes_t *attributes);
- rpc_status_t (*serialize_key_derivation_output_key_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_key_derivation_output_key_resp)(struct rpc_buffer *resp_buf,
psa_key_id_t key_id);
/* Operation: key_derivation_abort */
- rpc_status_t (*deserialize_key_derivation_abort_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_key_derivation_abort_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
/* Operation: key_derivation_key_agreement */
- rpc_status_t (*deserialize_key_derivation_key_agreement_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_key_derivation_key_agreement_req)(
+ const struct rpc_buffer *req_buf,
uint32_t *op_handle,
psa_key_derivation_step_t *step,
psa_key_id_t *private_key_id,
const uint8_t **peer_key, size_t *peer_key_len);
/* Operation: key_derivation_raw_key_agreement */
- rpc_status_t (*deserialize_key_derivation_raw_key_agreement_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_key_derivation_raw_key_agreement_req)(
+ const struct rpc_buffer *req_buf,
psa_algorithm_t *alg,
psa_key_id_t *private_key_id,
const uint8_t **peer_key, size_t *peer_key_len);
- rpc_status_t (*serialize_key_derivation_raw_key_agreement_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_key_derivation_raw_key_agreement_resp)(struct rpc_buffer *resp_buf,
const uint8_t *output, size_t output_len);
};
diff --git a/components/service/crypto/provider/extension/key_derivation/serializer/packed-c/packedc_key_derivation_provider_serializer.c b/components/service/crypto/provider/extension/key_derivation/serializer/packed-c/packedc_key_derivation_provider_serializer.c
index 0d92f50..03bb3dc 100644
--- a/components/service/crypto/provider/extension/key_derivation/serializer/packed-c/packedc_key_derivation_provider_serializer.c
+++ b/components/service/crypto/provider/extension/key_derivation/serializer/packed-c/packedc_key_derivation_provider_serializer.c
@@ -13,28 +13,28 @@
/* Operation: key_derivation_setup */
static rpc_status_t deserialize_key_derivation_setup_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
psa_algorithm_t *alg)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_key_derivation_setup_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_key_derivation_setup_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*alg = recv_msg.alg;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
static rpc_status_t serialize_key_derivation_setup_resp(
- struct call_param_buf *resp_buf,
+ struct rpc_buffer *resp_buf,
uint32_t op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct ts_crypto_key_derivation_setup_out resp_msg;
size_t fixed_len = sizeof(struct ts_crypto_key_derivation_setup_out);
@@ -43,8 +43,8 @@
if (fixed_len <= resp_buf->size) {
memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
@@ -52,28 +52,28 @@
/* Operation: key_derivation_get_capacity */
static rpc_status_t deserialize_key_derivation_get_capacity_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_key_derivation_get_capacity_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_key_derivation_get_capacity_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
static rpc_status_t serialize_key_derivation_get_capacity_resp(
- struct call_param_buf *resp_buf,
+ struct rpc_buffer *resp_buf,
size_t capacity)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct ts_crypto_key_derivation_get_capacity_out resp_msg;
size_t fixed_len = sizeof(struct ts_crypto_key_derivation_get_capacity_out);
@@ -82,8 +82,8 @@
if (fixed_len <= resp_buf->size) {
memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
@@ -91,20 +91,20 @@
/* Operation: key_derivation_set_capacity */
static rpc_status_t deserialize_key_derivation_set_capacity_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
uint32_t *op_handle,
size_t *capacity)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_key_derivation_set_capacity_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_key_derivation_set_capacity_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
*capacity = recv_msg.capacity;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
@@ -112,21 +112,21 @@
/* Operation: key_derivation_input_bytes */
static rpc_status_t deserialize_key_derivation_input_bytes_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
uint32_t *op_handle,
psa_key_derivation_step_t *step,
- const uint8_t **data, size_t *data_len)
+ const uint8_t **data, size_t *data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_key_derivation_input_bytes_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_key_derivation_input_bytes_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -135,17 +135,17 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter,
TS_CRYPTO_KEY_DERIVATION_INPUT_BYTES_IN_TAG_DATA, &decoded_record)) {
*data = decoded_record.value;
- *data_len = decoded_record.length;
+ *data_length = decoded_record.length;
}
else {
/* Default to a zero length data */
- *data_len = 0;
+ *data_length = 0;
}
}
@@ -154,22 +154,22 @@
/* Operation: key_derivation_input_key */
static rpc_status_t deserialize_key_derivation_input_key_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
uint32_t *op_handle,
psa_key_derivation_step_t *step,
psa_key_id_t *key_id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_key_derivation_input_key_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_key_derivation_input_key_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
*step = recv_msg.step;
*key_id = recv_msg.key_id;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
@@ -177,43 +177,43 @@
/* Operation: key_derivation_output_bytes */
static rpc_status_t deserialize_key_derivation_output_bytes_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
uint32_t *op_handle,
size_t *output_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_key_derivation_output_bytes_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_key_derivation_output_bytes_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
*output_len = recv_msg.output_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
static rpc_status_t serialize_key_derivation_output_bytes_resp(
- struct call_param_buf *resp_buf,
- const uint8_t *data, size_t data_len)
+ struct rpc_buffer *resp_buf,
+ const uint8_t *data, size_t data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
out_record.tag = TS_CRYPTO_KEY_DERIVATION_OUTPUT_BYTES_OUT_TAG_DATA;
- out_record.length = data_len;
+ out_record.length = data_length;
out_record.value = data;
tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(data_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(data_length);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
@@ -221,15 +221,15 @@
/* Operation: key_derivation_output_key */
static rpc_status_t deserialize_key_derivation_output_key_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
uint32_t *op_handle,
psa_key_attributes_t *attributes)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_key_derivation_output_key_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_key_derivation_output_key_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -237,17 +237,17 @@
packedc_crypto_provider_translate_key_attributes_from_proto(attributes,
&recv_msg.attributes);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
static rpc_status_t serialize_key_derivation_output_key_resp(
- struct call_param_buf *resp_buf,
+ struct rpc_buffer *resp_buf,
psa_key_id_t key_id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct ts_crypto_key_derivation_output_key_out resp_msg;
size_t fixed_len = sizeof(struct ts_crypto_key_derivation_output_key_out);
@@ -256,8 +256,8 @@
if (fixed_len <= resp_buf->size) {
memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
@@ -265,18 +265,18 @@
/* Operation: key_derivation_abort */
static rpc_status_t deserialize_key_derivation_abort_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_key_derivation_abort_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_key_derivation_abort_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
@@ -284,22 +284,22 @@
/* Operation: key_derivation_key_agreement */
static rpc_status_t deserialize_key_derivation_key_agreement_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
uint32_t *op_handle,
psa_key_derivation_step_t *step,
psa_key_id_t *private_key_id,
const uint8_t **peer_key, size_t *peer_key_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_key_derivation_key_agreement_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_key_derivation_key_agreement_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -309,7 +309,7 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter,
TS_CRYPTO_KEY_DERIVATION_KEY_AGREEMENT_IN_TAG_PEER_KEY, &decoded_record)) {
@@ -328,21 +328,21 @@
/* Operation: key_derivation_raw_key_agreement */
static rpc_status_t deserialize_key_derivation_raw_key_agreement_req(
- const struct call_param_buf *req_buf,
+ const struct rpc_buffer *req_buf,
psa_algorithm_t *alg,
psa_key_id_t *private_key_id,
const uint8_t **peer_key, size_t *peer_key_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_raw_key_agreement_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_raw_key_agreement_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -351,7 +351,7 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter,
TS_CRYPTO_RAW_KEY_AGREEMENT_IN_TAG_PEER_KEY, &decoded_record)) {
@@ -369,10 +369,10 @@
}
static rpc_status_t serialize_key_derivation_raw_key_agreement_resp(
- struct call_param_buf *resp_buf,
+ struct rpc_buffer *resp_buf,
const uint8_t *output, size_t output_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
@@ -384,8 +384,8 @@
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(output_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(output_len);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
diff --git a/components/service/crypto/provider/extension/mac/mac_provider.c b/components/service/crypto/provider/extension/mac/mac_provider.c
index eef5558..1e2081e 100644
--- a/components/service/crypto/provider/extension/mac/mac_provider.c
+++ b/components/service/crypto/provider/extension/mac/mac_provider.c
@@ -11,11 +11,11 @@
#include <psa/crypto.h>
/* Service request handlers */
-static rpc_status_t mac_setup_handler(void *context, struct call_req* req);
-static rpc_status_t mac_update_handler(void *context, struct call_req* req);
-static rpc_status_t mac_sign_finish_handler(void *context, struct call_req* req);
-static rpc_status_t mac_verify_finish_handler(void *context, struct call_req* req);
-static rpc_status_t mac_abort_handler(void *context, struct call_req* req);
+static rpc_status_t mac_setup_handler(void *context, struct rpc_request *req);
+static rpc_status_t mac_update_handler(void *context, struct rpc_request *req);
+static rpc_status_t mac_sign_finish_handler(void *context, struct rpc_request *req);
+static rpc_status_t mac_verify_finish_handler(void *context, struct rpc_request *req);
+static rpc_status_t mac_abort_handler(void *context, struct rpc_request *req);
/* Handler mapping table for service */
static const struct service_handler handler_table[] = {
@@ -29,12 +29,14 @@
void mac_provider_init(struct mac_provider *context)
{
+ const struct rpc_uuid nil_uuid = { 0 };
+
crypto_context_pool_init(&context->context_pool);
for (size_t encoding = 0; encoding < TS_RPC_ENCODING_LIMIT; ++encoding)
context->serializers[encoding] = NULL;
- service_provider_init(&context->base_provider, context,
+ service_provider_init(&context->base_provider, context, &nil_uuid,
handler_table, sizeof(handler_table)/sizeof(struct service_handler));
}
@@ -51,21 +53,18 @@
}
static const struct mac_provider_serializer* get_serializer(void *context,
- const struct call_req *req)
+ const struct rpc_request *req)
{
struct mac_provider *this_instance = (struct mac_provider*)context;
- const struct mac_provider_serializer* serializer = NULL;
- unsigned int encoding = call_req_get_encoding(req);
+ unsigned int encoding = 0; /* No other encodings supported */
- if (encoding < TS_RPC_ENCODING_LIMIT) serializer = this_instance->serializers[encoding];
-
- return serializer;
+ return this_instance->serializers[encoding];
}
-static rpc_status_t mac_setup_handler(void *context, struct call_req* req)
+static rpc_status_t mac_setup_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct mac_provider_serializer *serializer = get_serializer(context, req);
struct mac_provider *this_instance = (struct mac_provider*)context;
@@ -75,13 +74,13 @@
if (serializer)
rpc_status = serializer->deserialize_mac_setup_req(req_buf, &key_id, &alg);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
uint32_t op_handle;
struct crypto_context *crypto_context =
crypto_context_pool_alloc(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_MAC, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_MAC, req->source_id,
&op_handle);
if (crypto_context) {
@@ -89,36 +88,34 @@
crypto_context->op.mac = psa_mac_operation_init();
psa_status_t psa_status =
- (call_req_get_opcode(req) == TS_CRYPTO_OPCODE_MAC_SIGN_SETUP) ?
+ (req->opcode == TS_CRYPTO_OPCODE_MAC_SIGN_SETUP) ?
psa_mac_sign_setup(&crypto_context->op.mac, key_id, alg) :
psa_mac_verify_setup(&crypto_context->op.mac, key_id, alg);
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_mac_setup_resp(resp_buf, op_handle);
}
- if ((psa_status != PSA_SUCCESS) || (rpc_status != TS_RPC_CALL_ACCEPTED)) {
-
+ if ((psa_status != PSA_SUCCESS) || (rpc_status != RPC_SUCCESS))
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
- }
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
else {
/* Failed to allocate crypto context for transaction */
- rpc_status = TS_RPC_ERROR_RESOURCE_FAILURE;
+ rpc_status = RPC_ERROR_RESOURCE_FAILURE;
}
}
return rpc_status;
}
-static rpc_status_t mac_update_handler(void *context, struct call_req* req)
+static rpc_status_t mac_update_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct mac_provider_serializer *serializer = get_serializer(context, req);
struct mac_provider *this_instance = (struct mac_provider*)context;
@@ -129,13 +126,13 @@
if (serializer)
rpc_status = serializer->deserialize_mac_update_req(req_buf, &op_handle, &data, &data_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_MAC, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_MAC, req->source_id,
op_handle);
if (crypto_context) {
@@ -143,16 +140,16 @@
psa_status = psa_mac_update(&crypto_context->op.mac, data, data_len);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t mac_sign_finish_handler(void *context, struct call_req* req)
+static rpc_status_t mac_sign_finish_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct mac_provider_serializer *serializer = get_serializer(context, req);
struct mac_provider *this_instance = (struct mac_provider*)context;
@@ -161,13 +158,13 @@
if (serializer)
rpc_status = serializer->deserialize_mac_sign_finish_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_MAC, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_MAC, req->source_id,
op_handle);
if (crypto_context) {
@@ -179,23 +176,23 @@
if (psa_status == PSA_SUCCESS) {
- struct call_param_buf *resp_buf = call_req_get_resp_buf(req);
+ struct rpc_buffer *resp_buf = &req->response;
rpc_status = serializer->serialize_mac_sign_finish_resp(resp_buf, mac, mac_len);
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t mac_verify_finish_handler(void *context, struct call_req* req)
+static rpc_status_t mac_verify_finish_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct mac_provider_serializer *serializer = get_serializer(context, req);
struct mac_provider *this_instance = (struct mac_provider*)context;
@@ -207,13 +204,13 @@
rpc_status = serializer->deserialize_mac_verify_finish_req(req_buf,
&op_handle, &mac, &mac_len);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
psa_status_t psa_status = PSA_ERROR_BAD_STATE;
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_MAC, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_MAC, req->source_id,
op_handle);
if (crypto_context) {
@@ -226,16 +223,16 @@
}
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
}
-static rpc_status_t mac_abort_handler(void *context, struct call_req* req)
+static rpc_status_t mac_abort_handler(void *context, struct rpc_request *req)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_SERIALIZATION_NOT_SUPPORTED;
- struct call_param_buf *req_buf = call_req_get_req_buf(req);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct rpc_buffer *req_buf = &req->request;
const struct mac_provider_serializer *serializer = get_serializer(context, req);
struct mac_provider *this_instance = (struct mac_provider*)context;
@@ -244,7 +241,7 @@
if (serializer)
rpc_status = serializer->deserialize_mac_abort_req(req_buf, &op_handle);
- if (rpc_status == TS_RPC_CALL_ACCEPTED) {
+ if (rpc_status == RPC_SUCCESS) {
/* Return success if operation is no longer active and
* doesn't need aborting.
@@ -253,7 +250,7 @@
struct crypto_context *crypto_context =
crypto_context_pool_find(&this_instance->context_pool,
- CRYPTO_CONTEXT_OP_ID_MAC, call_req_get_caller_id(req),
+ CRYPTO_CONTEXT_OP_ID_MAC, req->source_id,
op_handle);
if (crypto_context) {
@@ -262,7 +259,7 @@
crypto_context_pool_free(&this_instance->context_pool, crypto_context);
}
- call_req_set_opstatus(req, psa_status);
+ req->service_status = psa_status;
}
return rpc_status;
diff --git a/components/service/crypto/provider/extension/mac/mac_provider.h b/components/service/crypto/provider/extension/mac/mac_provider.h
index 5e3cbe2..d987f5a 100644
--- a/components/service/crypto/provider/extension/mac/mac_provider.h
+++ b/components/service/crypto/provider/extension/mac/mac_provider.h
@@ -7,7 +7,7 @@
#ifndef MAC_PROVIDER_H
#define MAC_PROVIDER_H
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
#include <service/common/provider/service_provider.h>
#include <service/crypto/provider/extension/mac/serializer/mac_provider_serializer.h>
#include <service/crypto/provider/crypto_context_pool.h>
diff --git a/components/service/crypto/provider/extension/mac/serializer/mac_provider_serializer.h b/components/service/crypto/provider/extension/mac/serializer/mac_provider_serializer.h
index 3f5e5c6..0ad0465 100644
--- a/components/service/crypto/provider/extension/mac/serializer/mac_provider_serializer.h
+++ b/components/service/crypto/provider/extension/mac/serializer/mac_provider_serializer.h
@@ -10,7 +10,7 @@
#include <stddef.h>
#include <stdint.h>
#include <psa/crypto.h>
-#include <rpc/common/endpoint/rpc_interface.h>
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
/* Provides a common interface for parameter serialization operations
* for the mac service provider.
@@ -18,32 +18,32 @@
struct mac_provider_serializer {
/* Operation: mac_setup */
- rpc_status_t (*deserialize_mac_setup_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_mac_setup_req)(const struct rpc_buffer *req_buf,
psa_key_id_t *key_id,
psa_algorithm_t *alg);
- rpc_status_t (*serialize_mac_setup_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_mac_setup_resp)(struct rpc_buffer *resp_buf,
uint32_t op_handle);
/* Operation: mac_update */
- rpc_status_t (*deserialize_mac_update_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_mac_update_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **data, size_t *data_len);
/* Operation: mac_sign_finish */
- rpc_status_t (*deserialize_mac_sign_finish_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_mac_sign_finish_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
- rpc_status_t (*serialize_mac_sign_finish_resp)(struct call_param_buf *resp_buf,
+ rpc_status_t (*serialize_mac_sign_finish_resp)(struct rpc_buffer *resp_buf,
const uint8_t *mac, size_t mac_len);
/* Operation: mac_verify_finish */
- rpc_status_t (*deserialize_mac_verify_finish_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_mac_verify_finish_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **mac, size_t *mac_len);
/* Operation: mac_abort */
- rpc_status_t (*deserialize_mac_abort_req)(const struct call_param_buf *req_buf,
+ rpc_status_t (*deserialize_mac_abort_req)(const struct rpc_buffer *req_buf,
uint32_t *op_handle);
};
diff --git a/components/service/crypto/provider/extension/mac/serializer/packed-c/packedc_mac_provider_serializer.c b/components/service/crypto/provider/extension/mac/serializer/packed-c/packedc_mac_provider_serializer.c
index fa3a2c9..a82b98d 100644
--- a/components/service/crypto/provider/extension/mac/serializer/packed-c/packedc_mac_provider_serializer.c
+++ b/components/service/crypto/provider/extension/mac/serializer/packed-c/packedc_mac_provider_serializer.c
@@ -11,29 +11,29 @@
#include "packedc_mac_provider_serializer.h"
/* Operation: mac_setup */
-static rpc_status_t deserialize_mac_setup_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_mac_setup_req(const struct rpc_buffer *req_buf,
psa_key_id_t *key_id,
psa_algorithm_t *alg)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_mac_setup_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_mac_setup_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*key_id = recv_msg.key_id;
*alg = recv_msg.alg;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_mac_setup_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_mac_setup_resp(struct rpc_buffer *resp_buf,
uint32_t op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct ts_crypto_mac_setup_out resp_msg;
size_t fixed_len = sizeof(struct ts_crypto_mac_setup_out);
@@ -42,28 +42,28 @@
if (fixed_len <= resp_buf->size) {
memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: mac_update */
-static rpc_status_t deserialize_mac_update_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_mac_update_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
- const uint8_t **data, size_t *data_len)
+ const uint8_t **data, size_t *data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_mac_update_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_mac_update_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -71,16 +71,16 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_MAC_UPDATE_IN_TAG_DATA, &decoded_record)) {
*data = decoded_record.value;
- *data_len = decoded_record.length;
+ *data_length = decoded_record.length;
}
else {
/* Default to a zero length data */
- *data_len = 0;
+ *data_length = 0;
}
}
@@ -88,27 +88,27 @@
}
/* Operation: mac_finish */
-static rpc_status_t deserialize_mac_sign_finish_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_mac_sign_finish_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_mac_sign_finish_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_mac_sign_finish_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_mac_sign_finish_resp(struct call_param_buf *resp_buf,
+static rpc_status_t serialize_mac_sign_finish_resp(struct rpc_buffer *resp_buf,
const uint8_t *mac, size_t mac_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
struct tlv_iterator resp_iter;
struct tlv_record out_record;
@@ -120,28 +120,28 @@
if (tlv_encode(&resp_iter, &out_record)) {
- resp_buf->data_len = tlv_required_space(mac_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = tlv_required_space(mac_len);
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: mac_verify_finish */
-static rpc_status_t deserialize_mac_verify_finish_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_mac_verify_finish_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle,
const uint8_t **mac, size_t *mac_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_mac_verify_finish_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_mac_verify_finish_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
struct tlv_const_iterator req_iter;
struct tlv_record decoded_record;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
@@ -149,7 +149,7 @@
tlv_const_iterator_begin(&req_iter,
(uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ req_buf->data_length - expected_fixed_len);
if (tlv_find_decode(&req_iter, TS_CRYPTO_MAC_SIGN_FINISH_OUT_TAG_MAC, &decoded_record)) {
@@ -166,18 +166,18 @@
}
/* Operation: mac_abort */
-static rpc_status_t deserialize_mac_abort_req(const struct call_param_buf *req_buf,
+static rpc_status_t deserialize_mac_abort_req(const struct rpc_buffer *req_buf,
uint32_t *op_handle)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
struct ts_crypto_mac_abort_in recv_msg;
size_t expected_fixed_len = sizeof(struct ts_crypto_mac_abort_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
memcpy(&recv_msg, req_buf->data, expected_fixed_len);
*op_handle = recv_msg.op_handle;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
diff --git a/components/service/crypto/provider/serializer/crypto_provider_serializer.h b/components/service/crypto/provider/serializer/crypto_provider_serializer.h
index 57364f2..afc2f05 100644
--- a/components/service/crypto/provider/serializer/crypto_provider_serializer.h
+++ b/components/service/crypto/provider/serializer/crypto_provider_serializer.h
@@ -7,10 +7,11 @@
#ifndef CRYPTO_PROVIDER_SERIALIZER_H
#define CRYPTO_PROVIDER_SERIALIZER_H
+#include <psa/crypto.h>
#include <stddef.h>
#include <stdint.h>
-#include <psa/crypto.h>
-#include <rpc/common/endpoint/rpc_interface.h>
+
+#include "components/rpc/common/endpoint/rpc_service_interface.h"
/* Provides a common interface for parameter serialization operations
* for the crypto service provider. Allows alternative serialization
@@ -19,103 +20,104 @@
* implement this interface.
*/
struct crypto_provider_serializer {
-
- /* Returns the maximum deserialized parameter size that could
+ /* Returns the maximum deserialized parameter size that could
* be encoded in a request buffer. Used for determining worst-case
* buffer size without having to actually deserialize the message.
*/
- size_t (*max_deserialised_parameter_size)(const struct call_param_buf *req_buf);
+ size_t (*max_deserialised_parameter_size)(const struct rpc_buffer *req_buf);
- /* Operation: generate_key */
- rpc_status_t (*deserialize_generate_key_req)(const struct call_param_buf *req_buf,
- psa_key_attributes_t *attributes);
+ /* Operation: generate_key */
+ rpc_status_t (*deserialize_generate_key_req)(const struct rpc_buffer *req_buf,
+ psa_key_attributes_t *attributes);
- rpc_status_t (*serialize_generate_key_resp)(struct call_param_buf *resp_buf,
- psa_key_id_t id);
+ rpc_status_t (*serialize_generate_key_resp)(struct rpc_buffer *resp_buf, psa_key_id_t id);
- /* Operation: destroy_key */
- rpc_status_t (*deserialize_destroy_key_req)(const struct call_param_buf *req_buf,
- psa_key_id_t *id);
+ /* Operation: destroy_key */
+ rpc_status_t (*deserialize_destroy_key_req)(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id);
- /* Operation: export_key */
- rpc_status_t (*deserialize_export_key_req)(const struct call_param_buf *req_buf,
- psa_key_id_t *id);
+ /* Operation: export_key */
+ rpc_status_t (*deserialize_export_key_req)(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id);
- rpc_status_t (*serialize_export_key_resp)(struct call_param_buf *resp_buf,
- const uint8_t *data, size_t data_len);
+ rpc_status_t (*serialize_export_key_resp)(struct rpc_buffer *resp_buf, const uint8_t *data,
+ size_t data_len);
- /* Operation: export_public_key */
- rpc_status_t (*deserialize_export_public_key_req)(const struct call_param_buf *req_buf,
- psa_key_id_t *id);
+ /* Operation: export_public_key */
+ rpc_status_t (*deserialize_export_public_key_req)(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id);
- rpc_status_t (*serialize_export_public_key_resp)(struct call_param_buf *resp_buf,
- const uint8_t *data, size_t data_len);
+ rpc_status_t (*serialize_export_public_key_resp)(struct rpc_buffer *resp_buf,
+ const uint8_t *data, size_t data_len);
- /* Operation: import_key */
- rpc_status_t (*deserialize_import_key_req)(const struct call_param_buf *req_buf,
- psa_key_attributes_t *attributes,
- uint8_t *data, size_t *data_len);
+ /* Operation: import_key */
+ rpc_status_t (*deserialize_import_key_req)(const struct rpc_buffer *req_buf,
+ psa_key_attributes_t *attributes, uint8_t *data,
+ size_t *data_len);
- rpc_status_t (*serialize_import_key_resp)(struct call_param_buf *resp_buf,
- psa_key_id_t id);
+ rpc_status_t (*serialize_import_key_resp)(struct rpc_buffer *resp_buf, psa_key_id_t id);
- /* Operation: copy_key */
- rpc_status_t (*deserialize_copy_key_req)(const struct call_param_buf *req_buf,
- psa_key_attributes_t *attributes,
- psa_key_id_t *source_id);
+ /* Operation: copy_key */
+ rpc_status_t (*deserialize_copy_key_req)(const struct rpc_buffer *req_buf,
+ psa_key_attributes_t *attributes,
+ psa_key_id_t *source_id);
- rpc_status_t (*serialize_copy_key_resp)(struct call_param_buf *resp_buf,
- psa_key_id_t target_id);
+ rpc_status_t (*serialize_copy_key_resp)(struct rpc_buffer *resp_buf,
+ psa_key_id_t target_id);
- /* Operation: purge_key */
- rpc_status_t (*deserialize_purge_key_req)(const struct call_param_buf *req_buf,
- psa_key_id_t *id);
+ /* Operation: purge_key */
+ rpc_status_t (*deserialize_purge_key_req)(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id);
- /* Operation: get_key_attributes */
- rpc_status_t (*deserialize_get_key_attributes_req)(const struct call_param_buf *req_buf,
- psa_key_id_t *id);
+ /* Operation: get_key_attributes */
+ rpc_status_t (*deserialize_get_key_attributes_req)(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id);
- rpc_status_t (*serialize_get_key_attributes_resp)(struct call_param_buf *resp_buf,
- const psa_key_attributes_t *attributes);
+ rpc_status_t (*serialize_get_key_attributes_resp)(struct rpc_buffer *resp_buf,
+ const psa_key_attributes_t *attributes);
- /* Operation: sign_hash */
- rpc_status_t (*deserialize_asymmetric_sign_req)(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *hash, size_t *hash_len);
+ /* Operation: sign_hash */
+ rpc_status_t (*deserialize_asymmetric_sign_req)(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *hash, size_t *hash_len);
- rpc_status_t (*serialize_asymmetric_sign_resp)(struct call_param_buf *resp_buf,
- const uint8_t *sig, size_t sig_len);
+ rpc_status_t (*serialize_asymmetric_sign_resp)(struct rpc_buffer *resp_buf,
+ const uint8_t *sig, size_t sig_len);
- /* Operation: verify_hash */
- rpc_status_t (*deserialize_asymmetric_verify_req)(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *hash, size_t *hash_len,
- uint8_t *sig, size_t *sig_len);
+ /* Operation: verify_hash */
+ rpc_status_t (*deserialize_asymmetric_verify_req)(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *hash, size_t *hash_len,
+ uint8_t *sig, size_t *sig_len);
- /* Operation: asymmetric_decrypt */
- rpc_status_t (*deserialize_asymmetric_decrypt_req)(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *ciphertext, size_t *ciphertext_len,
- uint8_t *salt, size_t *salt_len);
+ /* Operation: asymmetric_decrypt */
+ rpc_status_t (*deserialize_asymmetric_decrypt_req)(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *ciphertext,
+ size_t *ciphertext_len, uint8_t *salt,
+ size_t *salt_len);
- rpc_status_t (*serialize_asymmetric_decrypt_resp)(struct call_param_buf *resp_buf,
- const uint8_t *plaintext, size_t plaintext_len);
+ rpc_status_t (*serialize_asymmetric_decrypt_resp)(struct rpc_buffer *resp_buf,
+ const uint8_t *plaintext,
+ size_t plaintext_len);
- /* Operation: asymmetric_encrypt */
- rpc_status_t (*deserialize_asymmetric_encrypt_req)(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *plaintext, size_t *plaintext_len,
- uint8_t *salt, size_t *salt_len);
+ /* Operation: asymmetric_encrypt */
+ rpc_status_t (*deserialize_asymmetric_encrypt_req)(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *plaintext,
+ size_t *plaintext_len, uint8_t *salt,
+ size_t *salt_len);
- rpc_status_t (*serialize_asymmetric_encrypt_resp)(struct call_param_buf *resp_buf,
- const uint8_t *ciphertext, size_t ciphertext_len);
+ rpc_status_t (*serialize_asymmetric_encrypt_resp)(struct rpc_buffer *resp_buf,
+ const uint8_t *ciphertext,
+ size_t ciphertext_len);
- /* Operation: generate_random */
- rpc_status_t (*deserialize_generate_random_req)(const struct call_param_buf *req_buf,
- size_t *size);
+ /* Operation: generate_random */
+ rpc_status_t (*deserialize_generate_random_req)(const struct rpc_buffer *req_buf,
+ size_t *size);
- rpc_status_t (*serialize_generate_random_resp)(struct call_param_buf *resp_buf,
- const uint8_t *output, size_t output_len);
+ rpc_status_t (*serialize_generate_random_resp)(struct rpc_buffer *resp_buf,
+ const uint8_t *output, size_t output_len);
};
#endif /* CRYPTO_PROVIDER_SERIALIZER_H */
diff --git a/components/service/crypto/provider/serializer/packed-c/packedc_crypto_provider_serializer.c b/components/service/crypto/provider/serializer/packed-c/packedc_crypto_provider_serializer.c
index 4a7e59f..2ca39ea 100644
--- a/components/service/crypto/provider/serializer/packed-c/packedc_crypto_provider_serializer.c
+++ b/components/service/crypto/provider/serializer/packed-c/packedc_crypto_provider_serializer.c
@@ -3,708 +3,640 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
+#include "packedc_crypto_provider_serializer.h"
+
#include <common/tlv/tlv.h>
-#include <psa/crypto.h>
#include <protocols/rpc/common/packed-c/status.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/copy_key.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/copy_key.h>
-#include <protocols/service/crypto/packed-c/purge_key.h>
#include <protocols/service/crypto/packed-c/get_key_attributes.h>
+#include <protocols/service/crypto/packed-c/import_key.h>
+#include <protocols/service/crypto/packed-c/key_attributes.h>
+#include <protocols/service/crypto/packed-c/purge_key.h>
#include <protocols/service/crypto/packed-c/sign_hash.h>
#include <protocols/service/crypto/packed-c/verify_hash.h>
-#include "packedc_crypto_provider_serializer.h"
+#include <psa/crypto.h>
+#include <stdlib.h>
+#include <string.h>
+
#include "packedc_key_attributes_translator.h"
/* Returns the maximum possible deserialized parameter size for a packed-c encoded message. */
-static size_t max_deserialised_parameter_size(const struct call_param_buf *req_buf)
+static size_t max_deserialised_parameter_size(const struct rpc_buffer *req_buf)
{
- /*
- * Assume that a deserialized parameter must be the same size or smaller than the
- * entire serialized message.
- */
- return req_buf->data_len;
+ /*
+ * Assume that a deserialized parameter must be the same size or smaller than the
+ * entire serialized message.
+ */
+ return req_buf->data_length;
}
/* Operation: generate_key */
-static rpc_status_t deserialize_generate_key_req(const struct call_param_buf *req_buf,
- psa_key_attributes_t *attributes)
+static rpc_status_t deserialize_generate_key_req(const struct rpc_buffer *req_buf,
+ psa_key_attributes_t *attributes)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_generate_key_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_generate_key_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_generate_key_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_generate_key_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ packedc_crypto_provider_translate_key_attributes_from_proto(attributes,
+ &recv_msg.attributes);
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- packedc_crypto_provider_translate_key_attributes_from_proto(attributes,
- &recv_msg.attributes);
+ rpc_status = RPC_SUCCESS;
+ }
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_generate_key_resp(struct call_param_buf *resp_buf,
- psa_key_id_t id)
+static rpc_status_t serialize_generate_key_resp(struct rpc_buffer *resp_buf, psa_key_id_t id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct ts_crypto_generate_key_out resp_msg;
- size_t fixed_len = sizeof(struct ts_crypto_generate_key_out);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct ts_crypto_generate_key_out resp_msg;
+ size_t fixed_len = sizeof(struct ts_crypto_generate_key_out);
- resp_msg.id = id;
+ resp_msg.id = id;
- if (fixed_len <= resp_buf->size) {
+ if (fixed_len <= resp_buf->size) {
+ memcpy(resp_buf->data, &resp_msg, fixed_len);
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: destroy_key */
-static rpc_status_t deserialize_destroy_key_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_destroy_key_req(const struct rpc_buffer *req_buf, psa_key_id_t *id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_destroy_key_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_destroy_key_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_destroy_key_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_destroy_key_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *id = recv_msg.id;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- *id = recv_msg.id;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: export_key */
-static rpc_status_t deserialize_export_key_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_export_key_req(const struct rpc_buffer *req_buf, psa_key_id_t *id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_export_key_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_export_key_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_export_key_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_export_key_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *id = recv_msg.id;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- *id = recv_msg.id;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_export_key_resp(struct call_param_buf *resp_buf,
- const uint8_t *data, size_t data_len)
+static rpc_status_t serialize_export_key_resp(struct rpc_buffer *resp_buf, const uint8_t *data,
+ size_t data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct tlv_iterator resp_iter;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct tlv_iterator resp_iter;
+ struct tlv_record key_record;
- struct tlv_record key_record;
- key_record.tag = TS_CRYPTO_EXPORT_KEY_OUT_TAG_DATA;
- key_record.length = data_len;
- key_record.value = data;
+ key_record.tag = TS_CRYPTO_EXPORT_KEY_OUT_TAG_DATA;
+ key_record.length = data_length;
+ key_record.value = data;
- tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
+ tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
- if (tlv_encode(&resp_iter, &key_record)) {
+ if (tlv_encode(&resp_iter, &key_record)) {
+ resp_buf->data_length = tlv_required_space(data_length);
+ rpc_status = RPC_SUCCESS;
+ }
- resp_buf->data_len = tlv_required_space(data_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: export_public_key */
-static rpc_status_t deserialize_export_public_key_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_export_public_key_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_export_public_key_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_export_public_key_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_export_public_key_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_export_public_key_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *id = recv_msg.id;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- *id = recv_msg.id;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_export_public_key_resp(struct call_param_buf *resp_buf,
- const uint8_t *data, size_t data_len)
+static rpc_status_t serialize_export_public_key_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *data, size_t data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct tlv_iterator resp_iter;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct tlv_iterator resp_iter;
+ struct tlv_record key_record;
- struct tlv_record key_record;
- key_record.tag = TS_CRYPTO_EXPORT_PUBLIC_KEY_OUT_TAG_DATA;
- key_record.length = data_len;
- key_record.value = data;
+ key_record.tag = TS_CRYPTO_EXPORT_PUBLIC_KEY_OUT_TAG_DATA;
+ key_record.length = data_length;
+ key_record.value = data;
- tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
+ tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
- if (tlv_encode(&resp_iter, &key_record)) {
+ if (tlv_encode(&resp_iter, &key_record)) {
+ resp_buf->data_length = tlv_required_space(data_length);
+ rpc_status = RPC_SUCCESS;
+ }
- resp_buf->data_len = tlv_required_space(data_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: import_key */
-static rpc_status_t deserialize_import_key_req(const struct call_param_buf *req_buf,
- psa_key_attributes_t *attributes, uint8_t *data, size_t *data_len)
+static rpc_status_t deserialize_import_key_req(const struct rpc_buffer *req_buf,
+ psa_key_attributes_t *attributes, uint8_t *data,
+ size_t *data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_import_key_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_import_key_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_import_key_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_import_key_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ struct tlv_const_iterator req_iter;
+ struct tlv_record decoded_record;
- struct tlv_const_iterator req_iter;
- struct tlv_record decoded_record;
+ rpc_status = RPC_SUCCESS;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ packedc_crypto_provider_translate_key_attributes_from_proto(attributes,
+ &recv_msg.attributes);
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- packedc_crypto_provider_translate_key_attributes_from_proto(attributes,
- &recv_msg.attributes);
+ tlv_const_iterator_begin(&req_iter, (uint8_t *)req_buf->data + expected_fixed_len,
+ req_buf->data_length - expected_fixed_len);
- tlv_const_iterator_begin(&req_iter,
- (uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ if (tlv_find_decode(&req_iter, TS_CRYPTO_IMPORT_KEY_IN_TAG_DATA, &decoded_record)) {
+ if (decoded_record.length <= *data_length) {
+ memcpy(data, decoded_record.value, decoded_record.length);
+ *data_length = decoded_record.length;
+ } else {
+ /* Buffer provided too small */
+ return RPC_ERROR_INVALID_REQUEST_BODY;
+ }
+ } else {
+ /* Default for missing parameter */
+ *data_length = 0;
+ }
+ }
- if (tlv_find_decode(&req_iter, TS_CRYPTO_IMPORT_KEY_IN_TAG_DATA, &decoded_record)) {
-
- if (decoded_record.length <= *data_len) {
-
- memcpy(data, decoded_record.value, decoded_record.length);
- *data_len = decoded_record.length;
- }
- else {
- /* Buffer provided too small */
- return TS_RPC_ERROR_INVALID_REQ_BODY;
- }
- }
- else {
- /* Default for missing parameter */
- *data_len = 0;
- }
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_import_key_resp(struct call_param_buf *resp_buf,
- psa_key_id_t id)
+static rpc_status_t serialize_import_key_resp(struct rpc_buffer *resp_buf, psa_key_id_t id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct ts_crypto_import_key_out resp_msg;
- size_t fixed_len = sizeof(struct ts_crypto_import_key_out);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct ts_crypto_import_key_out resp_msg;
+ size_t fixed_len = sizeof(struct ts_crypto_import_key_out);
- resp_msg.id = id;
+ resp_msg.id = id;
- if (fixed_len <= resp_buf->size) {
+ if (fixed_len <= resp_buf->size) {
+ memcpy(resp_buf->data, &resp_msg, fixed_len);
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: copy_key */
-static rpc_status_t deserialize_copy_key_req(const struct call_param_buf *req_buf,
- psa_key_attributes_t *attributes,
- psa_key_id_t *source_id)
+static rpc_status_t deserialize_copy_key_req(const struct rpc_buffer *req_buf,
+ psa_key_attributes_t *attributes,
+ psa_key_id_t *source_id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_copy_key_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_copy_key_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_copy_key_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_copy_key_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ rpc_status = RPC_SUCCESS;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ packedc_crypto_provider_translate_key_attributes_from_proto(attributes,
+ &recv_msg.attributes);
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- packedc_crypto_provider_translate_key_attributes_from_proto(attributes,
- &recv_msg.attributes);
+ *source_id = recv_msg.source_key_id;
+ }
- *source_id = recv_msg.source_key_id;
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_copy_key_resp(struct call_param_buf *resp_buf,
- psa_key_id_t target_id)
+static rpc_status_t serialize_copy_key_resp(struct rpc_buffer *resp_buf, psa_key_id_t target_id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct ts_crypto_copy_key_out resp_msg;
- size_t fixed_len = sizeof(struct ts_crypto_copy_key_out);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct ts_crypto_copy_key_out resp_msg;
+ size_t fixed_len = sizeof(struct ts_crypto_copy_key_out);
- resp_msg.target_key_id = target_id;
+ resp_msg.target_key_id = target_id;
- if (fixed_len <= resp_buf->size) {
+ if (fixed_len <= resp_buf->size) {
+ memcpy(resp_buf->data, &resp_msg, fixed_len);
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: purge_key */
-static rpc_status_t deserialize_purge_key_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_purge_key_req(const struct rpc_buffer *req_buf, psa_key_id_t *id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_purge_key_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_purge_key_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_purge_key_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_purge_key_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *id = recv_msg.id;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- *id = recv_msg.id;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: get_key_attributes */
-static rpc_status_t deserialize_get_key_attributes_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_get_key_attributes_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_get_key_attributes_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_get_key_attributes_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_get_key_attributes_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_get_key_attributes_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *id = recv_msg.id;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- *id = recv_msg.id;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_get_key_attributes_resp(struct call_param_buf *resp_buf,
- const psa_key_attributes_t *attributes)
+static rpc_status_t serialize_get_key_attributes_resp(struct rpc_buffer *resp_buf,
+ const psa_key_attributes_t *attributes)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct ts_crypto_get_key_attributes_out resp_msg;
- size_t fixed_len = sizeof(struct ts_crypto_get_key_attributes_out);
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct ts_crypto_get_key_attributes_out resp_msg;
+ size_t fixed_len = sizeof(struct ts_crypto_get_key_attributes_out);
- packedc_crypto_provider_translate_key_attributes_to_proto(&resp_msg.attributes, attributes);
+ packedc_crypto_provider_translate_key_attributes_to_proto(&resp_msg.attributes, attributes);
- if (fixed_len <= resp_buf->size) {
+ if (fixed_len <= resp_buf->size) {
+ memcpy(resp_buf->data, &resp_msg, fixed_len);
+ resp_buf->data_length = fixed_len;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(resp_buf->data, &resp_msg, fixed_len);
- resp_buf->data_len = fixed_len;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: sign_hash */
-static rpc_status_t deserialize_asymmetric_sign_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *hash, size_t *hash_len)
+static rpc_status_t deserialize_asymmetric_sign_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *hash, size_t *hash_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_sign_hash_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_sign_hash_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_sign_hash_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_sign_hash_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ struct tlv_const_iterator req_iter;
+ struct tlv_record decoded_record;
- struct tlv_const_iterator req_iter;
- struct tlv_record decoded_record;
+ rpc_status = RPC_SUCCESS;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *id = recv_msg.id;
+ *alg = recv_msg.alg;
- *id = recv_msg.id;
- *alg = recv_msg.alg;
+ tlv_const_iterator_begin(&req_iter, (uint8_t *)req_buf->data + expected_fixed_len,
+ req_buf->data_length - expected_fixed_len);
- tlv_const_iterator_begin(&req_iter,
- (uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ if (tlv_find_decode(&req_iter, TS_CRYPTO_SIGN_HASH_IN_TAG_HASH, &decoded_record)) {
+ if (decoded_record.length <= *hash_len) {
+ memcpy(hash, decoded_record.value, decoded_record.length);
+ *hash_len = decoded_record.length;
+ } else {
+ /* Buffer provided too small */
+ return RPC_ERROR_INVALID_REQUEST_BODY;
+ }
+ } else {
+ /* Default to a zero length hash */
+ *hash_len = 0;
+ }
+ }
- if (tlv_find_decode(&req_iter, TS_CRYPTO_SIGN_HASH_IN_TAG_HASH, &decoded_record)) {
-
- if (decoded_record.length <= *hash_len) {
-
- memcpy(hash, decoded_record.value, decoded_record.length);
- *hash_len = decoded_record.length;
- }
- else {
- /* Buffer provided too small */
- return TS_RPC_ERROR_INVALID_REQ_BODY;
- }
- }
- else {
- /* Default to a zero length hash */
- *hash_len = 0;
- }
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_asymmetric_sign_resp(struct call_param_buf *resp_buf,
- const uint8_t *sig, size_t sig_len)
+static rpc_status_t serialize_asymmetric_sign_resp(struct rpc_buffer *resp_buf, const uint8_t *sig,
+ size_t sig_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct tlv_iterator resp_iter;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct tlv_iterator resp_iter;
+ struct tlv_record sig_record;
- struct tlv_record sig_record;
- sig_record.tag = TS_CRYPTO_SIGN_HASH_OUT_TAG_SIGNATURE;
- sig_record.length = sig_len;
- sig_record.value = sig;
+ sig_record.tag = TS_CRYPTO_SIGN_HASH_OUT_TAG_SIGNATURE;
+ sig_record.length = sig_len;
+ sig_record.value = sig;
- tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
+ tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
- if (tlv_encode(&resp_iter, &sig_record)) {
+ if (tlv_encode(&resp_iter, &sig_record)) {
+ resp_buf->data_length = tlv_required_space(sig_len);
+ rpc_status = RPC_SUCCESS;
+ }
- resp_buf->data_len = tlv_required_space(sig_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: verify_hash */
-static rpc_status_t deserialize_asymmetric_verify_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *hash, size_t *hash_len,
- uint8_t *sig, size_t *sig_len)
+static rpc_status_t deserialize_asymmetric_verify_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *hash, size_t *hash_len, uint8_t *sig,
+ size_t *sig_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_verify_hash_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_verify_hash_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_verify_hash_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_verify_hash_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ struct tlv_const_iterator req_iter;
+ struct tlv_record decoded_record;
- struct tlv_const_iterator req_iter;
- struct tlv_record decoded_record;
+ rpc_status = RPC_SUCCESS;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *id = recv_msg.id;
+ *alg = recv_msg.alg;
- *id = recv_msg.id;
- *alg = recv_msg.alg;
+ tlv_const_iterator_begin(&req_iter, (uint8_t *)req_buf->data + expected_fixed_len,
+ req_buf->data_length - expected_fixed_len);
- tlv_const_iterator_begin(&req_iter,
- (uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ if (tlv_find_decode(&req_iter, TS_CRYPTO_VERIFY_HASH_IN_TAG_HASH,
+ &decoded_record)) {
+ if (decoded_record.length <= *hash_len) {
+ memcpy(hash, decoded_record.value, decoded_record.length);
+ *hash_len = decoded_record.length;
+ } else {
+ /* Buffer provided too small */
+ return RPC_ERROR_INVALID_REQUEST_BODY;
+ }
+ } else {
+ /* Default to a zero length hash */
+ *hash_len = 0;
+ }
- if (tlv_find_decode(&req_iter, TS_CRYPTO_VERIFY_HASH_IN_TAG_HASH, &decoded_record)) {
+ if (tlv_find_decode(&req_iter, TS_CRYPTO_VERIFY_HASH_IN_TAG_SIGNATURE,
+ &decoded_record)) {
+ if (decoded_record.length <= *sig_len) {
+ memcpy(sig, decoded_record.value, decoded_record.length);
+ *sig_len = decoded_record.length;
+ } else {
+ /* Buffer provided too small */
+ return RPC_ERROR_INVALID_REQUEST_BODY;
+ }
+ } else {
+ /* Default to a zero length hash */
+ *sig_len = 0;
+ }
+ }
- if (decoded_record.length <= *hash_len) {
-
- memcpy(hash, decoded_record.value, decoded_record.length);
- *hash_len = decoded_record.length;
- }
- else {
- /* Buffer provided too small */
- return TS_RPC_ERROR_INVALID_REQ_BODY;
- }
- }
- else {
- /* Default to a zero length hash */
- *hash_len = 0;
- }
-
- if (tlv_find_decode(&req_iter, TS_CRYPTO_VERIFY_HASH_IN_TAG_SIGNATURE, &decoded_record)) {
-
- if (decoded_record.length <= *sig_len) {
-
- memcpy(sig, decoded_record.value, decoded_record.length);
- *sig_len = decoded_record.length;
- }
- else {
- /* Buffer provided too small */
- return TS_RPC_ERROR_INVALID_REQ_BODY;
- }
- }
- else {
- /* Default to a zero length hash */
- *sig_len = 0;
- }
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: asymmetric_decrypt */
-static rpc_status_t deserialize_asymmetric_decrypt_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *ciphertext, size_t *ciphertext_len,
- uint8_t *salt, size_t *salt_len)
+static rpc_status_t deserialize_asymmetric_decrypt_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *ciphertext, size_t *ciphertext_len,
+ uint8_t *salt, size_t *salt_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_asymmetric_decrypt_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_asymmetric_decrypt_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_asymmetric_decrypt_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_asymmetric_decrypt_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ struct tlv_const_iterator req_iter;
+ struct tlv_record decoded_record;
- struct tlv_const_iterator req_iter;
- struct tlv_record decoded_record;
+ rpc_status = RPC_SUCCESS;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *id = recv_msg.id;
+ *alg = recv_msg.alg;
- *id = recv_msg.id;
- *alg = recv_msg.alg;
+ tlv_const_iterator_begin(&req_iter, (uint8_t *)req_buf->data + expected_fixed_len,
+ req_buf->data_length - expected_fixed_len);
- tlv_const_iterator_begin(&req_iter,
- (uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ if (tlv_find_decode(&req_iter, TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_CIPHERTEXT,
+ &decoded_record)) {
+ if (decoded_record.length <= *ciphertext_len) {
+ memcpy(ciphertext, decoded_record.value, decoded_record.length);
+ *ciphertext_len = decoded_record.length;
+ } else {
+ /* Buffer provided too small */
+ return RPC_ERROR_INVALID_REQUEST_BODY;
+ }
+ } else {
+ /* Default to a zero length hash */
+ *ciphertext_len = 0;
+ }
- if (tlv_find_decode(&req_iter, TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_CIPHERTEXT, &decoded_record)) {
+ if (tlv_find_decode(&req_iter, TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_SALT,
+ &decoded_record)) {
+ if (decoded_record.length <= *salt_len) {
+ memcpy(salt, decoded_record.value, decoded_record.length);
+ *salt_len = decoded_record.length;
+ } else {
+ /* Buffer provided too small */
+ return RPC_ERROR_INVALID_REQUEST_BODY;
+ }
+ } else {
+ /* Default to a zero length hash */
+ *salt_len = 0;
+ }
+ }
- if (decoded_record.length <= *ciphertext_len) {
-
- memcpy(ciphertext, decoded_record.value, decoded_record.length);
- *ciphertext_len = decoded_record.length;
- }
- else {
- /* Buffer provided too small */
- return TS_RPC_ERROR_INVALID_REQ_BODY;
- }
- }
- else {
- /* Default to a zero length hash */
- *ciphertext_len = 0;
- }
-
- if (tlv_find_decode(&req_iter, TS_CRYPTO_ASYMMETRIC_DECRYPT_IN_TAG_SALT, &decoded_record)) {
-
- if (decoded_record.length <= *salt_len) {
-
- memcpy(salt, decoded_record.value, decoded_record.length);
- *salt_len = decoded_record.length;
- }
- else {
- /* Buffer provided too small */
- return TS_RPC_ERROR_INVALID_REQ_BODY;
- }
- }
- else {
- /* Default to a zero length hash */
- *salt_len = 0;
- }
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_asymmetric_decrypt_resp(struct call_param_buf *resp_buf,
- const uint8_t *plaintext, size_t plaintext_len)
+static rpc_status_t serialize_asymmetric_decrypt_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *plaintext,
+ size_t plaintext_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct tlv_iterator resp_iter;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct tlv_iterator resp_iter;
+ struct tlv_record sig_record;
- struct tlv_record sig_record;
- sig_record.tag = TS_CRYPTO_ASYMMETRIC_DECRYPT_OUT_TAG_PLAINTEXT;
- sig_record.length = plaintext_len;
- sig_record.value = plaintext;
+ sig_record.tag = TS_CRYPTO_ASYMMETRIC_DECRYPT_OUT_TAG_PLAINTEXT;
+ sig_record.length = plaintext_len;
+ sig_record.value = plaintext;
- tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
+ tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
- if (tlv_encode(&resp_iter, &sig_record)) {
+ if (tlv_encode(&resp_iter, &sig_record)) {
+ resp_buf->data_length = tlv_required_space(plaintext_len);
+ rpc_status = RPC_SUCCESS;
+ }
- resp_buf->data_len = tlv_required_space(plaintext_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: asymmetric_encrypt */
-static rpc_status_t deserialize_asymmetric_encrypt_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *plaintext, size_t *plaintext_len,
- uint8_t *salt, size_t *salt_len)
+static rpc_status_t deserialize_asymmetric_encrypt_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *plaintext, size_t *plaintext_len,
+ uint8_t *salt, size_t *salt_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_asymmetric_encrypt_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_asymmetric_encrypt_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_asymmetric_encrypt_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_asymmetric_encrypt_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ struct tlv_const_iterator req_iter;
+ struct tlv_record decoded_record;
- struct tlv_const_iterator req_iter;
- struct tlv_record decoded_record;
+ rpc_status = RPC_SUCCESS;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *id = recv_msg.id;
+ *alg = recv_msg.alg;
- *id = recv_msg.id;
- *alg = recv_msg.alg;
+ tlv_const_iterator_begin(&req_iter, (uint8_t *)req_buf->data + expected_fixed_len,
+ req_buf->data_length - expected_fixed_len);
- tlv_const_iterator_begin(&req_iter,
- (uint8_t*)req_buf->data + expected_fixed_len,
- req_buf->data_len - expected_fixed_len);
+ if (tlv_find_decode(&req_iter, TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_PLAINTEXT,
+ &decoded_record)) {
+ if (decoded_record.length <= *plaintext_len) {
+ memcpy(plaintext, decoded_record.value, decoded_record.length);
+ *plaintext_len = decoded_record.length;
+ } else {
+ /* Buffer provided too small */
+ return RPC_ERROR_INVALID_REQUEST_BODY;
+ }
+ } else {
+ /* Default to a zero length hash */
+ *plaintext_len = 0;
+ }
- if (tlv_find_decode(&req_iter, TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_PLAINTEXT, &decoded_record)) {
+ if (tlv_find_decode(&req_iter, TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_SALT,
+ &decoded_record)) {
+ if (decoded_record.length <= *salt_len) {
+ memcpy(salt, decoded_record.value, decoded_record.length);
+ *salt_len = decoded_record.length;
+ } else {
+ /* Buffer provided too small */
+ return RPC_ERROR_INVALID_REQUEST_BODY;
+ }
+ } else {
+ /* Default to a zero length hash */
+ *salt_len = 0;
+ }
+ }
- if (decoded_record.length <= *plaintext_len) {
-
- memcpy(plaintext, decoded_record.value, decoded_record.length);
- *plaintext_len = decoded_record.length;
- }
- else {
- /* Buffer provided too small */
- return TS_RPC_ERROR_INVALID_REQ_BODY;
- }
- }
- else {
- /* Default to a zero length hash */
- *plaintext_len = 0;
- }
-
- if (tlv_find_decode(&req_iter, TS_CRYPTO_ASYMMETRIC_ENCRYPT_IN_TAG_SALT, &decoded_record)) {
-
- if (decoded_record.length <= *salt_len) {
-
- memcpy(salt, decoded_record.value, decoded_record.length);
- *salt_len = decoded_record.length;
- }
- else {
- /* Buffer provided too small */
- return TS_RPC_ERROR_INVALID_REQ_BODY;
- }
- }
- else {
- /* Default to a zero length hash */
- *salt_len = 0;
- }
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_asymmetric_encrypt_resp(struct call_param_buf *resp_buf,
- const uint8_t *ciphertext, size_t ciphertext_len)
+static rpc_status_t serialize_asymmetric_encrypt_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *ciphertext,
+ size_t ciphertext_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct tlv_iterator resp_iter;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct tlv_iterator resp_iter;
+ struct tlv_record sig_record;
- struct tlv_record sig_record;
- sig_record.tag = TS_CRYPTO_ASYMMETRIC_ENCRYPT_OUT_TAG_CIPHERTEXT;
- sig_record.length = ciphertext_len;
- sig_record.value = ciphertext;
+ sig_record.tag = TS_CRYPTO_ASYMMETRIC_ENCRYPT_OUT_TAG_CIPHERTEXT;
+ sig_record.length = ciphertext_len;
+ sig_record.value = ciphertext;
- tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
+ tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
- if (tlv_encode(&resp_iter, &sig_record)) {
+ if (tlv_encode(&resp_iter, &sig_record)) {
+ resp_buf->data_length = tlv_required_space(ciphertext_len);
+ rpc_status = RPC_SUCCESS;
+ }
- resp_buf->data_len = tlv_required_space(ciphertext_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Operation: generate_random */
-static rpc_status_t deserialize_generate_random_req(const struct call_param_buf *req_buf,
- size_t *size)
+static rpc_status_t deserialize_generate_random_req(const struct rpc_buffer *req_buf, size_t *size)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
- struct ts_crypto_generate_random_in recv_msg;
- size_t expected_fixed_len = sizeof(struct ts_crypto_generate_random_in);
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
+ struct ts_crypto_generate_random_in recv_msg;
+ size_t expected_fixed_len = sizeof(struct ts_crypto_generate_random_in);
- if (expected_fixed_len <= req_buf->data_len) {
+ if (expected_fixed_len <= req_buf->data_length) {
+ memcpy(&recv_msg, req_buf->data, expected_fixed_len);
+ *size = recv_msg.size;
+ rpc_status = RPC_SUCCESS;
+ }
- memcpy(&recv_msg, req_buf->data, expected_fixed_len);
- *size = recv_msg.size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
-static rpc_status_t serialize_generate_random_resp(struct call_param_buf *resp_buf,
- const uint8_t *output, size_t output_len)
+static rpc_status_t serialize_generate_random_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *output, size_t output_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
- struct tlv_iterator resp_iter;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
+ struct tlv_iterator resp_iter;
+ struct tlv_record out_record;
- struct tlv_record out_record;
- out_record.tag = TS_CRYPTO_GENERATE_RANDOM_OUT_TAG_RANDOM_BYTES;
- out_record.length = output_len;
- out_record.value = output;
+ out_record.tag = TS_CRYPTO_GENERATE_RANDOM_OUT_TAG_RANDOM_BYTES;
+ out_record.length = output_len;
+ out_record.value = output;
- tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
+ tlv_iterator_begin(&resp_iter, resp_buf->data, resp_buf->size);
- if (tlv_encode(&resp_iter, &out_record)) {
+ if (tlv_encode(&resp_iter, &out_record)) {
+ resp_buf->data_length = tlv_required_space(output_len);
+ rpc_status = RPC_SUCCESS;
+ }
- resp_buf->data_len = tlv_required_space(output_len);
- rpc_status = TS_RPC_CALL_ACCEPTED;
- }
-
- return rpc_status;
+ return rpc_status;
}
/* Singleton method to provide access to the serializer instance */
const struct crypto_provider_serializer *packedc_crypto_provider_serializer_instance(void)
{
- static const struct crypto_provider_serializer instance = {
- max_deserialised_parameter_size,
- deserialize_generate_key_req,
- serialize_generate_key_resp,
- deserialize_destroy_key_req,
- deserialize_export_key_req,
- serialize_export_key_resp,
- deserialize_export_public_key_req,
- serialize_export_public_key_resp,
- deserialize_import_key_req,
- serialize_import_key_resp,
- deserialize_copy_key_req,
- serialize_copy_key_resp,
- deserialize_purge_key_req,
- deserialize_get_key_attributes_req,
- serialize_get_key_attributes_resp,
- deserialize_asymmetric_sign_req,
- serialize_asymmetric_sign_resp,
- deserialize_asymmetric_verify_req,
- deserialize_asymmetric_decrypt_req,
- serialize_asymmetric_decrypt_resp,
- deserialize_asymmetric_encrypt_req,
- serialize_asymmetric_encrypt_resp,
- deserialize_generate_random_req,
- serialize_generate_random_resp
- };
+ static const struct crypto_provider_serializer instance = {
+ max_deserialised_parameter_size, deserialize_generate_key_req,
+ serialize_generate_key_resp, deserialize_destroy_key_req,
+ deserialize_export_key_req, serialize_export_key_resp,
+ deserialize_export_public_key_req, serialize_export_public_key_resp,
+ deserialize_import_key_req, serialize_import_key_resp,
+ deserialize_copy_key_req, serialize_copy_key_resp,
+ deserialize_purge_key_req, deserialize_get_key_attributes_req,
+ serialize_get_key_attributes_resp, deserialize_asymmetric_sign_req,
+ serialize_asymmetric_sign_resp, deserialize_asymmetric_verify_req,
+ deserialize_asymmetric_decrypt_req, serialize_asymmetric_decrypt_resp,
+ deserialize_asymmetric_encrypt_req, serialize_asymmetric_encrypt_resp,
+ deserialize_generate_random_req, serialize_generate_random_resp
+ };
- return &instance;
+ return &instance;
}
diff --git a/components/service/crypto/provider/serializer/protobuf/pb_crypto_provider_serializer.c b/components/service/crypto/provider/serializer/protobuf/pb_crypto_provider_serializer.c
index 6df375d..34cc326 100644
--- a/components/service/crypto/provider/serializer/protobuf/pb_crypto_provider_serializer.c
+++ b/components/service/crypto/provider/serializer/protobuf/pb_crypto_provider_serializer.c
@@ -3,71 +3,71 @@
*
* SPDX-License-Identifier: BSD-3-Clause
*/
-#include <string.h>
-#include <stdlib.h>
+#include "pb_crypto_provider_serializer.h"
+
+#include <pb_decode.h>
+#include <pb_encode.h>
#include <protocols/rpc/common/packed-c/status.h>
+#include <psa/crypto.h>
#include <service/common/serializer/protobuf/pb_helper.h>
-#include <service/crypto/protobuf/generate_key.pb.h>
+#include <service/crypto/protobuf/asymmetric_decrypt.pb.h>
+#include <service/crypto/protobuf/asymmetric_encrypt.pb.h>
#include <service/crypto/protobuf/destroy_key.pb.h>
#include <service/crypto/protobuf/export_key.pb.h>
#include <service/crypto/protobuf/export_public_key.pb.h>
+#include <service/crypto/protobuf/generate_key.pb.h>
+#include <service/crypto/protobuf/generate_random.pb.h>
#include <service/crypto/protobuf/import_key.pb.h>
#include <service/crypto/protobuf/sign_hash.pb.h>
#include <service/crypto/protobuf/verify_hash.pb.h>
-#include <service/crypto/protobuf/asymmetric_decrypt.pb.h>
-#include <service/crypto/protobuf/asymmetric_encrypt.pb.h>
-#include <service/crypto/protobuf/generate_random.pb.h>
-#include <pb_decode.h>
-#include <pb_encode.h>
-#include <psa/crypto.h>
-#include "pb_key_attributes_translator.h"
-#include "pb_crypto_provider_serializer.h"
+#include <stdlib.h>
+#include <string.h>
+#include "pb_key_attributes_translator.h"
/* Returns the maximum possible deserialized parameter size for a protobuf encoded message. */
-static size_t max_deserialised_parameter_size(const struct call_param_buf *req_buf)
+static size_t max_deserialised_parameter_size(const struct rpc_buffer *req_buf)
{
/*
* Assume that a deserialized parameter must be the same size or smaller than the
* entire serialized message.
*/
- return req_buf->data_len;
+ return req_buf->data_length;
}
/* Operation: generate_key */
-static rpc_status_t deserialize_generate_key_req(const struct call_param_buf *req_buf,
- psa_key_attributes_t *attributes)
+static rpc_status_t deserialize_generate_key_req(const struct rpc_buffer *req_buf,
+ psa_key_attributes_t *attributes)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_GenerateKeyIn recv_msg = ts_crypto_GenerateKeyIn_init_default;
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
- if (pb_decode(&istream, ts_crypto_GenerateKeyIn_fields, &recv_msg) && recv_msg.has_attributes) {
-
+ if (pb_decode(&istream, ts_crypto_GenerateKeyIn_fields, &recv_msg) &&
+ recv_msg.has_attributes) {
pb_crypto_provider_translate_key_attributes(attributes, &recv_msg.attributes);
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_generate_key_resp(struct call_param_buf *resp_buf,
- psa_key_id_t id)
+static rpc_status_t serialize_generate_key_resp(struct rpc_buffer *resp_buf, psa_key_id_t id)
{
size_t packed_resp_size;
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
ts_crypto_GenerateKeyOut resp_msg = ts_crypto_GenerateKeyOut_init_default;
resp_msg.id = id;
if (pb_get_encoded_size(&packed_resp_size, ts_crypto_GenerateKeyOut_fields, &resp_msg) &&
- (packed_resp_size <= resp_buf->size)) {
-
- pb_ostream_t ostream = pb_ostream_from_buffer((uint8_t*)resp_buf->data, packed_resp_size);
+ (packed_resp_size <= resp_buf->size)) {
+ pb_ostream_t ostream =
+ pb_ostream_from_buffer((uint8_t *)resp_buf->data, packed_resp_size);
if (pb_encode(&ostream, ts_crypto_GenerateKeyOut_fields, &resp_msg)) {
-
- resp_buf->data_len = packed_resp_size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = packed_resp_size;
+ rpc_status = RPC_SUCCESS;
}
}
@@ -75,60 +75,57 @@
}
/* Operation: destroy_key */
-static rpc_status_t deserialize_destroy_key_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_destroy_key_req(const struct rpc_buffer *req_buf, psa_key_id_t *id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_DestroyKeyIn recv_msg = ts_crypto_DestroyKeyIn_init_default;
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
if (pb_decode(&istream, ts_crypto_DestroyKeyIn_fields, &recv_msg)) {
-
*id = recv_msg.id;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
/* Operation: export_key */
-static rpc_status_t deserialize_export_key_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_export_key_req(const struct rpc_buffer *req_buf, psa_key_id_t *id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_ExportKeyIn recv_msg = ts_crypto_ExportKeyIn_init_default;
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
if (pb_decode(&istream, ts_crypto_ExportKeyIn_fields, &recv_msg)) {
-
*id = recv_msg.id;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_export_key_resp(struct call_param_buf *resp_buf,
- const uint8_t *data, size_t data_len)
+static rpc_status_t serialize_export_key_resp(struct rpc_buffer *resp_buf, const uint8_t *data,
+ size_t data_length)
{
size_t packed_resp_size;
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
ts_crypto_ExportKeyOut resp_msg = ts_crypto_ExportKeyOut_init_default;
- pb_bytes_array_t *key_buffer = pb_malloc_byte_array(data_len);
+ pb_bytes_array_t *key_buffer = pb_malloc_byte_array(data_length);
- memcpy(&key_buffer->bytes, data, data_len);
+ memcpy(&key_buffer->bytes, data, data_length);
resp_msg.data = pb_out_byte_array(key_buffer);
if (pb_get_encoded_size(&packed_resp_size, ts_crypto_ExportKeyOut_fields, &resp_msg) &&
- (packed_resp_size <= resp_buf->size)) {
-
- pb_ostream_t ostream = pb_ostream_from_buffer((uint8_t*)resp_buf->data, packed_resp_size);
+ (packed_resp_size <= resp_buf->size)) {
+ pb_ostream_t ostream =
+ pb_ostream_from_buffer((uint8_t *)resp_buf->data, packed_resp_size);
if (pb_encode(&ostream, ts_crypto_ExportKeyOut_fields, &resp_msg)) {
-
- resp_buf->data_len = packed_resp_size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = packed_resp_size;
+ rpc_status = RPC_SUCCESS;
}
}
@@ -138,42 +135,42 @@
}
/* Operation: export_public_key */
-static rpc_status_t deserialize_export_public_key_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_export_public_key_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_ExportPublicKeyIn recv_msg = ts_crypto_ExportPublicKeyIn_init_default;
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
if (pb_decode(&istream, ts_crypto_ExportPublicKeyIn_fields, &recv_msg)) {
-
*id = recv_msg.id;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_export_public_key_resp(struct call_param_buf *resp_buf,
- const uint8_t *data, size_t data_len)
+static rpc_status_t serialize_export_public_key_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *data, size_t data_length)
{
size_t packed_resp_size;
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
ts_crypto_ExportPublicKeyOut resp_msg = ts_crypto_ExportPublicKeyOut_init_default;
- pb_bytes_array_t *key_buffer = pb_malloc_byte_array(data_len);
+ pb_bytes_array_t *key_buffer = pb_malloc_byte_array(data_length);
resp_msg.data = pb_out_byte_array(key_buffer);
- memcpy(&key_buffer->bytes, data, data_len);
+ memcpy(&key_buffer->bytes, data, data_length);
- if (pb_get_encoded_size(&packed_resp_size, ts_crypto_ExportPublicKeyOut_fields, &resp_msg) &&
- (packed_resp_size <= resp_buf->size)) {
-
- pb_ostream_t ostream = pb_ostream_from_buffer((uint8_t*)resp_buf->data, packed_resp_size);
+ if (pb_get_encoded_size(&packed_resp_size, ts_crypto_ExportPublicKeyOut_fields,
+ &resp_msg) &&
+ (packed_resp_size <= resp_buf->size)) {
+ pb_ostream_t ostream =
+ pb_ostream_from_buffer((uint8_t *)resp_buf->data, packed_resp_size);
if (pb_encode(&ostream, ts_crypto_ExportPublicKeyOut_fields, &resp_msg)) {
-
- resp_buf->data_len = packed_resp_size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = packed_resp_size;
+ rpc_status = RPC_SUCCESS;
}
}
@@ -183,27 +180,27 @@
}
/* Operation: import_key */
-static rpc_status_t deserialize_import_key_req(const struct call_param_buf *req_buf,
- psa_key_attributes_t *attributes, uint8_t *data, size_t *data_len)
+static rpc_status_t deserialize_import_key_req(const struct rpc_buffer *req_buf,
+ psa_key_attributes_t *attributes, uint8_t *data,
+ size_t *data_length)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_ImportKeyIn recv_msg = ts_crypto_ImportKeyIn_init_default;
- pb_bytes_array_t *key_buffer = pb_malloc_byte_array(*data_len);
+ pb_bytes_array_t *key_buffer = pb_malloc_byte_array(*data_length);
recv_msg.data = pb_in_byte_array(key_buffer);
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
if (pb_decode(&istream, ts_crypto_ImportKeyIn_fields, &recv_msg) &&
- recv_msg.has_attributes &&
- (key_buffer->size <= *data_len)) {
-
+ recv_msg.has_attributes && (key_buffer->size <= *data_length)) {
pb_crypto_provider_translate_key_attributes(attributes, &recv_msg.attributes);
memcpy(data, &key_buffer->bytes, key_buffer->size);
- *data_len = key_buffer->size;
+ *data_length = key_buffer->size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
free(key_buffer);
@@ -211,22 +208,20 @@
return rpc_status;
}
-static rpc_status_t serialize_import_key_resp(struct call_param_buf *resp_buf,
- psa_key_id_t id)
+static rpc_status_t serialize_import_key_resp(struct rpc_buffer *resp_buf, psa_key_id_t id)
{
size_t packed_resp_size;
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
ts_crypto_ImportKeyOut resp_msg = ts_crypto_ImportKeyOut_init_default;
resp_msg.id = id;
if (pb_get_encoded_size(&packed_resp_size, ts_crypto_ImportKeyOut_fields, &resp_msg) &&
- (packed_resp_size <= resp_buf->size)) {
-
- pb_ostream_t ostream = pb_ostream_from_buffer((uint8_t*)resp_buf->data, packed_resp_size);
+ (packed_resp_size <= resp_buf->size)) {
+ pb_ostream_t ostream =
+ pb_ostream_from_buffer((uint8_t *)resp_buf->data, packed_resp_size);
if (pb_encode(&ostream, ts_crypto_ImportKeyOut_fields, &resp_msg)) {
-
- resp_buf->data_len = packed_resp_size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = packed_resp_size;
+ rpc_status = RPC_SUCCESS;
}
}
@@ -234,77 +229,75 @@
}
/* Operation: copy_key */
-static rpc_status_t deserialize_copy_key_req(const struct call_param_buf *req_buf,
- psa_key_attributes_t *attributes,
- psa_key_id_t *source_id)
+static rpc_status_t deserialize_copy_key_req(const struct rpc_buffer *req_buf,
+ psa_key_attributes_t *attributes,
+ psa_key_id_t *source_id)
{
(void)req_buf;
(void)attributes;
(void)source_id;
- return TS_RPC_ERROR_INVALID_REQ_BODY;
+ return RPC_ERROR_INVALID_REQUEST_BODY;
}
-static rpc_status_t serialize_copy_key_resp(struct call_param_buf *resp_buf,
- psa_key_id_t target_id)
+static rpc_status_t serialize_copy_key_resp(struct rpc_buffer *resp_buf, psa_key_id_t target_id)
{
(void)resp_buf;
(void)target_id;
- return TS_RPC_ERROR_INTERNAL;
+ return RPC_ERROR_INTERNAL;
}
/* Operation: purge_key */
-static rpc_status_t deserialize_purge_key_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_purge_key_req(const struct rpc_buffer *req_buf, psa_key_id_t *id)
{
(void)req_buf;
(void)id;
- return TS_RPC_ERROR_INVALID_REQ_BODY;
+ return RPC_ERROR_INVALID_REQUEST_BODY;
}
/* Operation: get_key_attributes */
-static rpc_status_t deserialize_get_key_attributes_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id)
+static rpc_status_t deserialize_get_key_attributes_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id)
{
(void)req_buf;
(void)id;
- return TS_RPC_ERROR_INVALID_REQ_BODY;
+ return RPC_ERROR_INVALID_REQUEST_BODY;
}
-static rpc_status_t serialize_get_key_attributes_resp(struct call_param_buf *resp_buf,
- const psa_key_attributes_t *attributes)
+static rpc_status_t serialize_get_key_attributes_resp(struct rpc_buffer *resp_buf,
+ const psa_key_attributes_t *attributes)
{
(void)resp_buf;
(void)attributes;
- return TS_RPC_ERROR_INTERNAL;
+ return RPC_ERROR_INTERNAL;
}
/* Operation: sign_hash */
-static rpc_status_t deserialize_asymmetric_sign_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *hash, size_t *hash_len)
+static rpc_status_t deserialize_asymmetric_sign_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *hash, size_t *hash_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_SignHashIn recv_msg = ts_crypto_SignHashIn_init_default;
pb_bytes_array_t *hash_buffer = pb_malloc_byte_array(*hash_len);
recv_msg.hash = pb_in_byte_array(hash_buffer);
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
if (pb_decode(&istream, ts_crypto_SignHashIn_fields, &recv_msg)) {
-
*id = recv_msg.id;
*alg = recv_msg.alg;
memcpy(hash, &hash_buffer->bytes, hash_buffer->size);
*hash_len = hash_buffer->size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
free(hash_buffer);
@@ -312,11 +305,11 @@
return rpc_status;
}
-static rpc_status_t serialize_asymmetric_sign_resp(struct call_param_buf *resp_buf,
- const uint8_t *sig, size_t sig_len)
+static rpc_status_t serialize_asymmetric_sign_resp(struct rpc_buffer *resp_buf, const uint8_t *sig,
+ size_t sig_len)
{
size_t packed_resp_size;
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
ts_crypto_SignHashOut resp_msg = ts_crypto_SignHashOut_init_default;
pb_bytes_array_t *sig_buffer = pb_malloc_byte_array(sig_len);
@@ -324,13 +317,12 @@
memcpy(&sig_buffer->bytes, sig, sig_len);
if (pb_get_encoded_size(&packed_resp_size, ts_crypto_SignHashOut_fields, &resp_msg) &&
- (packed_resp_size <= resp_buf->size)) {
-
- pb_ostream_t ostream = pb_ostream_from_buffer((uint8_t*)resp_buf->data, packed_resp_size);
+ (packed_resp_size <= resp_buf->size)) {
+ pb_ostream_t ostream =
+ pb_ostream_from_buffer((uint8_t *)resp_buf->data, packed_resp_size);
if (pb_encode(&ostream, ts_crypto_SignHashOut_fields, &resp_msg)) {
-
- resp_buf->data_len = packed_resp_size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = packed_resp_size;
+ rpc_status = RPC_SUCCESS;
}
}
@@ -340,12 +332,12 @@
}
/* Operation: verify_hash */
-static rpc_status_t deserialize_asymmetric_verify_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *hash, size_t *hash_len,
- uint8_t *sig, size_t *sig_len)
+static rpc_status_t deserialize_asymmetric_verify_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *hash, size_t *hash_len, uint8_t *sig,
+ size_t *sig_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_VerifyHashIn recv_msg = ts_crypto_VerifyHashIn_init_default;
pb_bytes_array_t *hash_buffer = pb_malloc_byte_array(*hash_len);
@@ -354,10 +346,10 @@
pb_bytes_array_t *sig_buffer = pb_malloc_byte_array(*sig_len);
recv_msg.signature = pb_in_byte_array(sig_buffer);
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
if (pb_decode(&istream, ts_crypto_VerifyHashIn_fields, &recv_msg)) {
-
*id = recv_msg.id;
*alg = recv_msg.alg;
@@ -367,7 +359,7 @@
memcpy(sig, &sig_buffer->bytes, sig_buffer->size);
*sig_len = sig_buffer->size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
free(hash_buffer);
@@ -377,12 +369,12 @@
}
/* Operation: asymmetric_decrypt */
-static rpc_status_t deserialize_asymmetric_decrypt_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *ciphertext, size_t *ciphertext_len,
- uint8_t *salt, size_t *salt_len)
+static rpc_status_t deserialize_asymmetric_decrypt_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *ciphertext, size_t *ciphertext_len,
+ uint8_t *salt, size_t *salt_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_AsymmetricDecryptIn recv_msg = ts_crypto_AsymmetricDecryptIn_init_default;
pb_bytes_array_t *ciphertext_buffer = pb_malloc_byte_array(*ciphertext_len);
@@ -391,10 +383,10 @@
pb_bytes_array_t *salt_buffer = pb_malloc_byte_array(*salt_len);
recv_msg.salt = pb_in_byte_array(salt_buffer);
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
if (pb_decode(&istream, ts_crypto_AsymmetricDecryptIn_fields, &recv_msg)) {
-
*id = recv_msg.id;
*alg = recv_msg.alg;
@@ -404,13 +396,12 @@
if (salt_buffer->size < *salt_len) {
memcpy(salt, &salt_buffer->bytes, salt_buffer->size);
*salt_len = salt_buffer->size;
- }
- else {
+ } else {
/* Set default for missing optional parameter */
*salt_len = 0;
}
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
free(ciphertext_buffer);
@@ -419,25 +410,26 @@
return rpc_status;
}
-static rpc_status_t serialize_asymmetric_decrypt_resp(struct call_param_buf *resp_buf,
- const uint8_t *plaintext, size_t plaintext_len)
+static rpc_status_t serialize_asymmetric_decrypt_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *plaintext,
+ size_t plaintext_len)
{
size_t packed_resp_size;
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
ts_crypto_AsymmetricDecryptOut resp_msg = ts_crypto_AsymmetricDecryptOut_init_default;
pb_bytes_array_t *plaintext_buffer = pb_malloc_byte_array(plaintext_len);
resp_msg.plaintext = pb_out_byte_array(plaintext_buffer);
memcpy(&plaintext_buffer->bytes, plaintext, plaintext_len);
- if (pb_get_encoded_size(&packed_resp_size, ts_crypto_AsymmetricDecryptOut_fields, &resp_msg) &&
- (packed_resp_size <= resp_buf->size)) {
-
- pb_ostream_t ostream = pb_ostream_from_buffer((uint8_t*)resp_buf->data, packed_resp_size);
+ if (pb_get_encoded_size(&packed_resp_size, ts_crypto_AsymmetricDecryptOut_fields,
+ &resp_msg) &&
+ (packed_resp_size <= resp_buf->size)) {
+ pb_ostream_t ostream =
+ pb_ostream_from_buffer((uint8_t *)resp_buf->data, packed_resp_size);
if (pb_encode(&ostream, ts_crypto_AsymmetricDecryptOut_fields, &resp_msg)) {
-
- resp_buf->data_len = packed_resp_size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = packed_resp_size;
+ rpc_status = RPC_SUCCESS;
}
}
@@ -447,12 +439,12 @@
}
/* Operation: asymmetric_encrypt */
-static rpc_status_t deserialize_asymmetric_encrypt_req(const struct call_param_buf *req_buf,
- psa_key_id_t *id, psa_algorithm_t *alg,
- uint8_t *plaintext, size_t *plaintext_len,
- uint8_t *salt, size_t *salt_len)
+static rpc_status_t deserialize_asymmetric_encrypt_req(const struct rpc_buffer *req_buf,
+ psa_key_id_t *id, psa_algorithm_t *alg,
+ uint8_t *plaintext, size_t *plaintext_len,
+ uint8_t *salt, size_t *salt_len)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_AsymmetricEncryptIn recv_msg = ts_crypto_AsymmetricEncryptIn_init_default;
pb_bytes_array_t *plaintext_buffer = pb_malloc_byte_array(*plaintext_len);
@@ -461,10 +453,10 @@
pb_bytes_array_t *salt_buffer = pb_malloc_byte_array(*salt_len);
recv_msg.salt = pb_in_byte_array(salt_buffer);
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
if (pb_decode(&istream, ts_crypto_AsymmetricEncryptIn_fields, &recv_msg)) {
-
*id = recv_msg.id;
*alg = recv_msg.alg;
@@ -474,13 +466,12 @@
if (salt_buffer->size < *salt_len) {
memcpy(salt, &salt_buffer->bytes, salt_buffer->size);
*salt_len = salt_buffer->size;
- }
- else {
+ } else {
/* Set default for missing optional parameter */
*salt_len = 0;
}
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
free(plaintext_buffer);
@@ -489,25 +480,26 @@
return rpc_status;
}
-static rpc_status_t serialize_asymmetric_encrypt_resp(struct call_param_buf *resp_buf,
- const uint8_t *ciphertext, size_t ciphertext_len)
+static rpc_status_t serialize_asymmetric_encrypt_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *ciphertext,
+ size_t ciphertext_len)
{
size_t packed_resp_size;
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
ts_crypto_AsymmetricEncryptOut resp_msg = ts_crypto_AsymmetricEncryptOut_init_default;
pb_bytes_array_t *ciphertext_buffer = pb_malloc_byte_array(ciphertext_len);
resp_msg.ciphertext = pb_out_byte_array(ciphertext_buffer);
memcpy(&ciphertext_buffer->bytes, ciphertext, ciphertext_len);
- if (pb_get_encoded_size(&packed_resp_size, ts_crypto_AsymmetricEncryptOut_fields, &resp_msg) &&
- (packed_resp_size <= resp_buf->size)) {
-
- pb_ostream_t ostream = pb_ostream_from_buffer((uint8_t*)resp_buf->data, packed_resp_size);
+ if (pb_get_encoded_size(&packed_resp_size, ts_crypto_AsymmetricEncryptOut_fields,
+ &resp_msg) &&
+ (packed_resp_size <= resp_buf->size)) {
+ pb_ostream_t ostream =
+ pb_ostream_from_buffer((uint8_t *)resp_buf->data, packed_resp_size);
if (pb_encode(&ostream, ts_crypto_AsymmetricEncryptOut_fields, &resp_msg)) {
-
- resp_buf->data_len = packed_resp_size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = packed_resp_size;
+ rpc_status = RPC_SUCCESS;
}
}
@@ -517,29 +509,28 @@
}
/* Operation: generate_random */
-static rpc_status_t deserialize_generate_random_req(const struct call_param_buf *req_buf,
- size_t *size)
+static rpc_status_t deserialize_generate_random_req(const struct rpc_buffer *req_buf, size_t *size)
{
- rpc_status_t rpc_status = TS_RPC_ERROR_INVALID_REQ_BODY;
+ rpc_status_t rpc_status = RPC_ERROR_INVALID_REQUEST_BODY;
ts_crypto_GenerateRandomIn recv_msg = ts_crypto_GenerateRandomIn_init_default;
- pb_istream_t istream = pb_istream_from_buffer((const uint8_t*)req_buf->data, req_buf->data_len);
+ pb_istream_t istream =
+ pb_istream_from_buffer((const uint8_t *)req_buf->data, req_buf->data_length);
if (pb_decode(&istream, ts_crypto_GenerateRandomIn_fields, &recv_msg)) {
-
*size = recv_msg.size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ rpc_status = RPC_SUCCESS;
}
return rpc_status;
}
-static rpc_status_t serialize_generate_random_resp(struct call_param_buf *resp_buf,
- const uint8_t *output, size_t output_len)
+static rpc_status_t serialize_generate_random_resp(struct rpc_buffer *resp_buf,
+ const uint8_t *output, size_t output_len)
{
size_t packed_resp_size;
- rpc_status_t rpc_status = TS_RPC_ERROR_INTERNAL;
+ rpc_status_t rpc_status = RPC_ERROR_INTERNAL;
ts_crypto_GenerateRandomOut resp_msg = ts_crypto_GenerateRandomOut_init_default;
pb_bytes_array_t *output_buffer = pb_malloc_byte_array(output_len);
@@ -547,13 +538,12 @@
memcpy(&output_buffer->bytes, output, output_len);
if (pb_get_encoded_size(&packed_resp_size, ts_crypto_GenerateRandomOut_fields, &resp_msg) &&
- (packed_resp_size <= resp_buf->size)) {
-
- pb_ostream_t ostream = pb_ostream_from_buffer((uint8_t*)resp_buf->data, packed_resp_size);
+ (packed_resp_size <= resp_buf->size)) {
+ pb_ostream_t ostream =
+ pb_ostream_from_buffer((uint8_t *)resp_buf->data, packed_resp_size);
if (pb_encode(&ostream, ts_crypto_GenerateRandomOut_fields, &resp_msg)) {
-
- resp_buf->data_len = packed_resp_size;
- rpc_status = TS_RPC_CALL_ACCEPTED;
+ resp_buf->data_length = packed_resp_size;
+ rpc_status = RPC_SUCCESS;
}
}
@@ -566,30 +556,18 @@
const struct crypto_provider_serializer *pb_crypto_provider_serializer_instance(void)
{
static const struct crypto_provider_serializer instance = {
- max_deserialised_parameter_size,
- deserialize_generate_key_req,
- serialize_generate_key_resp,
- deserialize_destroy_key_req,
- deserialize_export_key_req,
- serialize_export_key_resp,
- deserialize_export_public_key_req,
- serialize_export_public_key_resp,
- deserialize_import_key_req,
- serialize_import_key_resp,
- deserialize_copy_key_req,
- serialize_copy_key_resp,
- deserialize_purge_key_req,
- deserialize_get_key_attributes_req,
- serialize_get_key_attributes_resp,
- deserialize_asymmetric_sign_req,
- serialize_asymmetric_sign_resp,
- deserialize_asymmetric_verify_req,
- deserialize_asymmetric_decrypt_req,
- serialize_asymmetric_decrypt_resp,
- deserialize_asymmetric_encrypt_req,
- serialize_asymmetric_encrypt_resp,
- deserialize_generate_random_req,
- serialize_generate_random_resp
+ max_deserialised_parameter_size, deserialize_generate_key_req,
+ serialize_generate_key_resp, deserialize_destroy_key_req,
+ deserialize_export_key_req, serialize_export_key_resp,
+ deserialize_export_public_key_req, serialize_export_public_key_resp,
+ deserialize_import_key_req, serialize_import_key_resp,
+ deserialize_copy_key_req, serialize_copy_key_resp,
+ deserialize_purge_key_req, deserialize_get_key_attributes_req,
+ serialize_get_key_attributes_resp, deserialize_asymmetric_sign_req,
+ serialize_asymmetric_sign_resp, deserialize_asymmetric_verify_req,
+ deserialize_asymmetric_decrypt_req, serialize_asymmetric_decrypt_resp,
+ deserialize_asymmetric_encrypt_req, serialize_asymmetric_encrypt_resp,
+ deserialize_generate_random_req, serialize_generate_random_resp
};
return &instance;