Julian Hall | c02fffb | 2020-11-23 18:22:06 +0100 | [diff] [blame] | 1 | /* |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2020-2021, Arm Limited and Contributors. All rights reserved. |
Julian Hall | c02fffb | 2020-11-23 18:22:06 +0100 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef MBED_CRYPTO_PROVIDER_H |
| 8 | #define MBED_CRYPTO_PROVIDER_H |
| 9 | |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 10 | #include <rpc/common/endpoint/rpc_interface.h> |
Julian Hall | c02fffb | 2020-11-23 18:22:06 +0100 | [diff] [blame] | 11 | #include <service/common/provider/service_provider.h> |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 12 | #include <service/crypto/provider/serializer/crypto_provider_serializer.h> |
julhal01 | 3a4207d | 2021-03-08 13:32:08 +0000 | [diff] [blame] | 13 | #include <service/secure_storage/backend/storage_backend.h> |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 14 | #include <protocols/rpc/common/packed-c/encoding.h> |
Julian Hall | f572896 | 2021-06-24 09:40:23 +0100 | [diff] [blame] | 15 | #include "crypto_context_pool.h" |
Julian Hall | c02fffb | 2020-11-23 18:22:06 +0100 | [diff] [blame] | 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | struct mbed_crypto_provider |
| 22 | { |
| 23 | struct service_provider base_provider; |
Julian Hall | f572896 | 2021-06-24 09:40:23 +0100 | [diff] [blame] | 24 | struct crypto_context_pool context_pool; |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 25 | const struct crypto_provider_serializer *serializers[TS_RPC_ENCODING_LIMIT]; |
Julian Hall | c02fffb | 2020-11-23 18:22:06 +0100 | [diff] [blame] | 26 | }; |
| 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 |
julhal01 | 1260f10 | 2021-02-15 17:34:08 +0000 | [diff] [blame] | 32 | * backend. |
Julian Hall | c02fffb | 2020-11-23 18:22:06 +0100 | [diff] [blame] | 33 | */ |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 34 | struct rpc_interface *mbed_crypto_provider_init(struct mbed_crypto_provider *context, |
julhal01 | 3a4207d | 2021-03-08 13:32:08 +0000 | [diff] [blame] | 35 | struct storage_backend *storage_backend, |
julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame] | 36 | int trng_instance); |
Julian Hall | c02fffb | 2020-11-23 18:22:06 +0100 | [diff] [blame] | 37 | |
| 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 | */ |
| 42 | void mbed_crypto_provider_deinit(struct mbed_crypto_provider *context); |
| 43 | |
julhal01 | c3f4e9a | 2020-12-15 13:39:01 +0000 | [diff] [blame] | 44 | /* |
| 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 | */ |
| 50 | void mbed_crypto_provider_register_serializer(struct mbed_crypto_provider *context, |
| 51 | unsigned int encoding, const struct crypto_provider_serializer *serializer); |
| 52 | |
Julian Hall | c02fffb | 2020-11-23 18:22:06 +0100 | [diff] [blame] | 53 | #ifdef __cplusplus |
| 54 | } /* extern "C" */ |
| 55 | #endif |
| 56 | |
| 57 | #endif /* MBED_CRYPTO_PROVIDER_H */ |