blob: 1f69396eb8379f0a5ac117920022eee9cdc018e6 [file] [log] [blame]
Julian Hallc02fffb2020-11-23 18:22:06 +01001/*
julhal01c3f4e9a2020-12-15 13:39:01 +00002 * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved.
Julian Hallc02fffb2020-11-23 18:22:06 +01003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef MBED_CRYPTO_PROVIDER_H
8#define MBED_CRYPTO_PROVIDER_H
9
julhal01c3f4e9a2020-12-15 13:39:01 +000010#include <rpc/common/endpoint/rpc_interface.h>
Julian Hallc02fffb2020-11-23 18:22:06 +010011#include <service/common/provider/service_provider.h>
julhal01c3f4e9a2020-12-15 13:39:01 +000012#include <service/crypto/provider/serializer/crypto_provider_serializer.h>
julhal011260f102021-02-15 17:34:08 +000013#include <service/secure_storage/backend/secure_storage_client/secure_storage_client.h>
julhal01c3f4e9a2020-12-15 13:39:01 +000014#include <protocols/rpc/common/packed-c/encoding.h>
Julian Hallc02fffb2020-11-23 18:22:06 +010015
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20struct mbed_crypto_provider
21{
22 struct service_provider base_provider;
julhal01c3f4e9a2020-12-15 13:39:01 +000023 const struct crypto_provider_serializer *serializers[TS_RPC_ENCODING_LIMIT];
julhal011260f102021-02-15 17:34:08 +000024 struct secure_storage_client secure_storage_client;
Julian Hallc02fffb2020-11-23 18:22:06 +010025};
26
27/*
28 * Initializes an instance of the crypto service provider that uses the
29 * Mbed Crypto library to implement crypto operations. Secure storage
30 * for persistent keys needs to be provided by a suitable storage
julhal011260f102021-02-15 17:34:08 +000031 * backend.
Julian Hallc02fffb2020-11-23 18:22:06 +010032 */
julhal01c3f4e9a2020-12-15 13:39:01 +000033struct rpc_interface *mbed_crypto_provider_init(struct mbed_crypto_provider *context,
julhal011260f102021-02-15 17:34:08 +000034 struct rpc_caller *storage_caller,
julhal012c18fbf2021-02-01 08:29:28 +000035 int trng_instance);
Julian Hallc02fffb2020-11-23 18:22:06 +010036
37/*
38 * When operation of the provider is no longer required, this function
39 * frees any resource used by the previously initialized provider instance.
40 */
41void mbed_crypto_provider_deinit(struct mbed_crypto_provider *context);
42
julhal01c3f4e9a2020-12-15 13:39:01 +000043/*
44 * Register a serializer for supportng a particular parameter encoding. At
45 * least one serializer must be registered but additional ones may be registered
46 * to allow alternative parameter serialization schemes to be used to allow
47 * for compatibility with different types of client.
48 */
49void mbed_crypto_provider_register_serializer(struct mbed_crypto_provider *context,
50 unsigned int encoding, const struct crypto_provider_serializer *serializer);
51
Julian Hallc02fffb2020-11-23 18:22:06 +010052#ifdef __cplusplus
53} /* extern "C" */
54#endif
55
56#endif /* MBED_CRYPTO_PROVIDER_H */