Software APIs
entropy_testutils.h
1// Copyright lowRISC contributors (OpenTitan project).
2// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_ENTROPY_TESTUTILS_H_
6#define OPENTITAN_SW_DEVICE_LIB_TESTING_ENTROPY_TESTUTILS_H_
7
8#include "sw/device/lib/base/status.h"
11
12/**
13 * Initializes the top-specific entropy source with default configuration.
14 *
15 * On Earlgrey, it initializes the entropy_src.
16 * On Darjeeling, this is a no-op.
17 */
19status_t entropy_testutils_entropy_src_init(void);
20
21/**
22 * Initializes the entropy complex in auto-request mode.
23 *
24 * Initializes the entropy source, CSRNG, EDN0, and EDN1 in automatic request
25 * mode, with EDN1 providing highest-quality entropy and EDN0 providing
26 * lower-quality entropy.
27 */
29status_t entropy_testutils_auto_mode_init(void);
30
31/**
32 * Initializes the entropy complex to serve random bits to EDN0 and EDN1.
33 *
34 * Initializes the entropy source, csrng, EDN0 and EDN1 with default boot time
35 * configuration to enable entropy distribution for testing purposes.
36 */
38status_t entropy_testutils_boot_mode_init(void);
39
40/**
41 * Stops EDN instances and CSRNG.
42 *
43 * Stops EDN instances before stopping CSRNG.
44 */
46status_t entropy_testutils_stop_csrng_edn(void);
47
48/**
49 * Stops all entropy complex blocks.
50 *
51 * Stops EDN and CSRNG instances before stopping the entropy source.
52 */
54status_t entropy_testutils_stop_all(void);
55
56/**
57 * Throws test assertion if there are any errors detected in any of the entropy
58 * blocks.
59 *
60 * Note that the encoding of the error codes printed in the log follow the
61 * respective DIF error enum mapping, which may be different to the bit mapping
62 * in the error registers.
63 *
64 * @param csrng CSRNG handle.
65 * @param edn0 EDN0 handle.
66 * @param edn1 EDN1 handle.
67 * @return The result of the operation wrapped on a status_t.
68 */
70status_t entropy_testutils_error_check(const dif_csrng_t *csrng,
71 const dif_edn_t *edn0,
72 const dif_edn_t *edn1);
73
74#endif // OPENTITAN_SW_DEVICE_LIB_TESTING_ENTROPY_TESTUTILS_H_