blob: 0f1daf5bb25d532216ba0be9e32e06f78fc8273f [file] [log] [blame]
julhal012c18fbf2021-02-01 08:29:28 +00001/*
Jelle Selsf2373042022-01-19 13:35:56 +01002 * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved.
julhal012c18fbf2021-02-01 08:29:28 +00003 *
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
19extern "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 */
26struct 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 */
44struct 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.
Jelle Selsf2373042022-01-19 13:35:56 +010054 * \param instance Deployment specific trng instance.
julhal012c18fbf2021-02-01 08:29:28 +000055 *
56 * \return 0 if successful.
57 */
Jelle Selsf2373042022-01-19 13:35:56 +010058int platform_trng_create(struct platform_trng_driver *driver, int instance);
julhal012c18fbf2021-02-01 08:29:28 +000059
60/**
61 * \brief Destroy a driver constructed using the factory method
62 *
63 * \param driver Pointer to driver structure for constructed driver.
64 */
65void platform_trng_destroy(struct platform_trng_driver *driver);
66
67#ifdef __cplusplus
68}
69#endif
70
71#endif /* TS_PLATFORM_INTERFACE_TRNG_H */