julhal01 | ffa98d8 | 2021-01-20 13:51:58 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef TS_PLATFORM_INTERFACE_ENTROPY_H |
| 8 | #define TS_PLATFORM_INTERFACE_ENTROPY_H |
| 9 | |
| 10 | /* |
| 11 | * Interface definintion for a platform entropy driver. A platform provider will |
| 12 | * provide concrete implementations of this interface for each alternative |
| 13 | * implementation supported. |
| 14 | */ |
| 15 | #include <stddef.h> |
| 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 20 | |
| 21 | /* |
| 22 | * Virtual interface for a platform entropy driver. A platform will provide |
| 23 | * one or more concrete implementations of this interface. |
| 24 | */ |
| 25 | struct ts_plat_entropy_iface |
| 26 | { |
| 27 | /** |
| 28 | * \brief Poll for bytes of entropy from a platform entropy source |
| 29 | * |
| 30 | * \param context Platform driver context |
| 31 | * \param output Buffer for output |
| 32 | * \param nbyte Desired number of bytes |
| 33 | * \param len The number of bytes returned (could be zero) |
| 34 | * |
| 35 | * \return 0 if successful. |
| 36 | */ |
| 37 | int (*poll)(void *context, unsigned char *output, size_t nbyte, size_t *len); |
| 38 | }; |
| 39 | |
| 40 | /* |
| 41 | * A platform entropy driver instance. |
| 42 | */ |
| 43 | struct ts_plat_entropy_driver |
| 44 | { |
| 45 | void *context; /**< Opaque driver context */ |
| 46 | const struct ts_plat_entropy_iface *iface; /**< Interface methods */ |
| 47 | }; |
| 48 | |
| 49 | /** |
| 50 | * \brief Factory method to construct a platform specific entropy driver |
| 51 | * |
| 52 | * \param driver Pointer to driver structure to initialize on construction. |
| 53 | * \param config Driver specific configuration or NULL if none. |
| 54 | * |
| 55 | * \return 0 if successful. |
| 56 | */ |
| 57 | int ts_plat_entropy_create(struct ts_plat_entropy_driver *driver, void *config); |
| 58 | |
| 59 | /** |
| 60 | * \brief Destroy a driver constructed using the factory method |
| 61 | * |
| 62 | * \param driver Pointer to driver structure for constructed driver. |
| 63 | */ |
| 64 | void ts_plat_entropy_destroy(struct ts_plat_entropy_driver *driver); |
| 65 | |
| 66 | #ifdef __cplusplus |
| 67 | } |
| 68 | #endif |
| 69 | |
| 70 | #endif /* TS_PLATFORM_INTERFACE_ENTROPY_H */ |