julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame] | 1 | /* |
Jelle Sels | f237304 | 2022-01-19 13:35:56 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2021-2022, Arm Limited and Contributors. All rights reserved. |
julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | #include <platform/interface/trng.h> |
| 7 | |
| 8 | /* |
| 9 | * A platform trng driver that provides a mock implementation that |
| 10 | * always returns a fixed value. Intended for test purposes only. |
| 11 | */ |
| 12 | static int mock_poll(void *context, unsigned char *output, size_t nbyte, size_t *len) |
| 13 | { |
| 14 | (void)context; |
| 15 | (void)output; |
| 16 | |
| 17 | *len = 0; |
| 18 | |
| 19 | if (nbyte < sizeof(unsigned char) ) |
| 20 | return 0; |
| 21 | |
| 22 | *len = sizeof(unsigned char); |
| 23 | |
| 24 | return 0; |
| 25 | } |
| 26 | |
Jelle Sels | f237304 | 2022-01-19 13:35:56 +0100 | [diff] [blame^] | 27 | int platform_trng_create(struct platform_trng_driver *driver, int instance) |
julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame] | 28 | { |
| 29 | static const struct platform_trng_iface iface = { .poll = mock_poll }; |
| 30 | |
Jelle Sels | f237304 | 2022-01-19 13:35:56 +0100 | [diff] [blame^] | 31 | (void)instance; |
julhal01 | 2c18fbf | 2021-02-01 08:29:28 +0000 | [diff] [blame] | 32 | driver->context = NULL; |
| 33 | driver->iface = &iface; |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | void platform_trng_destroy(struct platform_trng_driver *driver) |
| 39 | { |
| 40 | (void)driver; |
| 41 | } |