aboutsummaryrefslogtreecommitdiff
path: root/platform/drivers/mock/mock_trng.c
blob: 24b14c0b29d0f201ccd4606e36177d740db0bc38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
#include <platform/interface/trng.h>

/*
 * A platform trng driver that provides a mock implementation that
 * always returns a fixed value.  Intended for test purposes only.
 */
static int mock_poll(void *context, unsigned char *output, size_t nbyte, size_t *len)
{
    (void)context;
    (void)output;

    *len = 0;

    if (nbyte < sizeof(unsigned char) )
        return 0;

    *len = sizeof(unsigned char);

    return 0;
}

int platform_trng_create(struct platform_trng_driver *driver,
                            const struct device_region *device_region)
{
    static const struct platform_trng_iface iface =  { .poll = mock_poll };

    (void)device_region;

    driver->context = NULL;
    driver->iface = &iface;

    return 0;
}

void platform_trng_destroy(struct platform_trng_driver *driver)
{
    (void)driver;
}