Software APIs
dif_csrng_shared.h
Go to the documentation of this file.
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_DIF_DIF_CSRNG_SHARED_H_
6#define OPENTITAN_SW_DEVICE_LIB_DIF_DIF_CSRNG_SHARED_H_
7
14
15/**
16 * @file
17 * Private code shared between the CSRNG and EDN DIFs.
18 */
19
20enum {
21 /**
22 * CSRNG genbits buffer size in uint32_t words.
23 */
25};
26
27/**
28 * Supported CSRNG application commands.
29 * See
30 * https://opentitan.org/book/hw/ip/csrng/doc/theory_of_operation.html#command-header
31 * for details.
32 */
33typedef enum csrng_app_cmd_id {
34 kCsrngAppCmdInstantiate = 1,
35 kCsrngAppCmdReseed = 2,
36 kCsrngAppCmdGenerate = 3,
37 kCsrngAppCmdUpdate = 4,
38 kCsrngAppCmdUninstantiate = 5,
40
41/**
42 * CSRNG application interface command header parameters.
43 */
44typedef struct csrng_app_cmd {
45 /**
46 * Application command.
47 */
49 /**
50 * Entropy source enable.
51 *
52 * Mapped to flag0 in the hardware command interface.
53 */
55 /**
56 * Seed material. Only used in `kCsrngAppCmdInstantiate`, `kCsrngAppCmdReseed`
57 * and `kCsrngAppCmdUpdate` commands.
58 */
60 /**
61 * Generate length. Specified as number of 128bit blocks.
62 */
63 uint32_t generate_len;
65
66/**
67 * This enum type contains all the different command types for
68 * csrng_send_cmd().
69 */
70typedef enum csrng_app_cmd_type {
71 /**
72 * Command issued directly to CSRNG.
73 */
75 /**
76 * Command issued to CSRNG via the SW_CMD_REQ register of the EDN.
77 */
79 /**
80 * Command issued to CSRNG via the GENERATE_CMD register of the EDN.
81 * This type of command will be used in the auto mode of the EDN.
82 */
84 /**
85 * Command issued to CSRNG via the RESEED_CMD register of the EDN.
86 * This type of command will be used in the auto mode of the EDN.
87 */
90
91/**
92 * Builds a CSRNG command header.
93 *
94 * Build a CSRNG command header following the CSRNG specification. The caller is
95 * responsible for verifying the correctness of the parameters passed into this
96 * function.
97 *
98 * @param id CSRNG command ID.
99 * @param entropy_src_enable Entropy source enable flag. Mapped to flag0 in the
100 * command header.
101 * @param cmd_len The overall command lend. It should be set to the number of
102 * seed material words, or zero.
103 * @param generate_len Number of 128bit blocks to request if the command ID is
104 * set to `kCsrngAppCmdGenerate`.
105 * @return CSRNG command header in `uint32_t` format.
106 */
110 uint32_t cmd_len, uint32_t generate_len);
111
112/**
113 * Writes application command `cmd` to the CSRNG_CMD_REQ_REG register.
114 * Returns the result of the operation.
115 */
118 csrng_app_cmd_type_t cmd_type,
119 csrng_app_cmd_t cmd);
120
121#endif // OPENTITAN_SW_DEVICE_LIB_DIF_DIF_CSRNG_SHARED_H_