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