blob: 19bc2c2d719298a8aa5eab6c5731594325298a4d [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>
julhal013a4207d2021-03-08 13:32:08 +000013#include <service/secure_storage/backend/storage_backend.h>
julhal01c3f4e9a2020-12-15 13:39:01 +000014#include <protocols/rpc/common/packed-c/encoding.h>
Julian Hallf5728962021-06-24 09:40:23 +010015#include "crypto_context_pool.h"
Julian Hallc02fffb2020-11-23 18:22:06 +010016
17#ifdef __cplusplus
18extern "C" {
19#endif
20
21struct mbed_crypto_provider
22{
23 struct service_provider base_provider;
Julian Hallf5728962021-06-24 09:40:23 +010024 struct crypto_context_pool context_pool;
julhal01c3f4e9a2020-12-15 13:39:01 +000025 const struct crypto_provider_serializer *serializers[TS_RPC_ENCODING_LIMIT];
Julian Hallc02fffb2020-11-23 18:22:06 +010026};
27
28/*
29 * Initializes an instance of the crypto service provider that uses the
30 * Mbed Crypto library to implement crypto operations. Secure storage
31 * for persistent keys needs to be provided by a suitable storage
julhal011260f102021-02-15 17:34:08 +000032 * backend.
Julian Hallc02fffb2020-11-23 18:22:06 +010033 */
julhal01c3f4e9a2020-12-15 13:39:01 +000034struct rpc_interface *mbed_crypto_provider_init(struct mbed_crypto_provider *context,
julhal013a4207d2021-03-08 13:32:08 +000035 struct storage_backend *storage_backend,
julhal012c18fbf2021-02-01 08:29:28 +000036 int trng_instance);
Julian Hallc02fffb2020-11-23 18:22:06 +010037
38/*
39 * When operation of the provider is no longer required, this function
40 * frees any resource used by the previously initialized provider instance.
41 */
42void mbed_crypto_provider_deinit(struct mbed_crypto_provider *context);
43
julhal01c3f4e9a2020-12-15 13:39:01 +000044/*
45 * Register a serializer for supportng a particular parameter encoding. At
46 * least one serializer must be registered but additional ones may be registered
47 * to allow alternative parameter serialization schemes to be used to allow
48 * for compatibility with different types of client.
49 */
50void mbed_crypto_provider_register_serializer(struct mbed_crypto_provider *context,
51 unsigned int encoding, const struct crypto_provider_serializer *serializer);
52
Julian Hallc02fffb2020-11-23 18:22:06 +010053#ifdef __cplusplus
54} /* extern "C" */
55#endif
56
57#endif /* MBED_CRYPTO_PROVIDER_H */