blob: 9c24581c49f01ec58927490af7b10919142c5291 [file] [log] [blame]
julhal012c18fbf2021-02-01 08:29:28 +00001/*
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_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.
54 * \param device_region Pointer a device region object or NULL if none.
55 *
56 * \return 0 if successful.
57 */
58int platform_trng_create(struct platform_trng_driver *driver,
59 const struct device_region *device_region);
60
61/**
62 * \brief Destroy a driver constructed using the factory method
63 *
64 * \param driver Pointer to driver structure for constructed driver.
65 */
66void platform_trng_destroy(struct platform_trng_driver *driver);
67
68#ifdef __cplusplus
69}
70#endif
71
72#endif /* TS_PLATFORM_INTERFACE_TRNG_H */