CSRNG Device Interface Functions More...
#include <stdint.h>
#include "sw/device/lib/base/macros.h"
#include "sw/device/lib/base/mmio.h"
#include "sw/device/lib/dif/dif_base.h"
#include "csrng_regs.h"
#include "sw/device/lib/dif/autogen/dif_csrng_autogen.h"
Go to the source code of this file.
Data Structures | |
struct | dif_csrng_cmd_status |
The status of the CSRNG block at a particular moment in time. More... | |
struct | dif_csrng_seed_material |
CSRNG common transaction parameters. More... | |
struct | dif_csrng_output_status |
Generated output state. More... | |
struct | dif_csrng_internal_state |
CSRNG internal state. More... | |
Typedefs | |
typedef enum dif_csrng_cmd_status_kind | dif_csrng_cmd_status_kind_t |
This API implements an interface for the CSRNG hardware. More... | |
typedef enum dif_csrng_fifo | dif_csrng_fifo_t |
Enumeration of CSRNG FIFOs, which indicates which part of the hardware produced an error. | |
typedef enum dif_csrng_error | dif_csrng_error_t |
Enumeration of CSRNG FIFO errors. | |
typedef enum dif_csrng_cmd_sts_error | dif_csrng_cmd_sts_t |
Enumeration of CSRNG command status errors. | |
typedef struct dif_csrng_cmd_status | dif_csrng_cmd_status_t |
The status of the CSRNG block at a particular moment in time. | |
typedef enum dif_csrng_entropy_src_toggle | dif_csrng_entropy_src_toggle_t |
CSRNG consume seed from entropy source enable. | |
typedef struct dif_csrng_seed_material | dif_csrng_seed_material_t |
CSRNG common transaction parameters. | |
typedef struct dif_csrng_output_status | dif_csrng_output_status_t |
Generated output state. | |
typedef enum dif_csrng_internal_state_id | dif_csrng_internal_state_id_t |
CSRNG internal state selector ID. | |
typedef struct dif_csrng_internal_state | dif_csrng_internal_state_t |
CSRNG internal state. | |
typedef enum dif_csrng_recoverable_alert | dif_csrng_recoverable_alert_t |
Recoverable alerts emitted by the CSRNG. | |
CSRNG Device Interface Functions
Definition in file dif_csrng.h.
struct dif_csrng_cmd_status |
The status of the CSRNG block at a particular moment in time.
Definition at line 190 of file dif_csrng.h.
Data Fields | ||
---|---|---|
dif_csrng_cmd_sts_t | cmd_sts | The status value CSRNG returns. |
dif_csrng_cmd_status_kind_t | kind | The kind of status the CSRNG is in. |
struct dif_csrng_seed_material |
CSRNG common transaction parameters.
Definition at line 232 of file dif_csrng.h.
Data Fields | ||
---|---|---|
uint32_t | seed_material[kDifCsrngSeedMaterialMaxWordLen] | Seed material used in CSRNG. |
size_t | seed_material_len |
Number of uint32_t words in seed_material . Up to 12 words can be set to initialize the CSRNG. CSRNG will extend the |
struct dif_csrng_output_status |
Generated output state.
Definition at line 248 of file dif_csrng.h.
Data Fields | ||
---|---|---|
bool | fips_mode | Set to true when the cryptographic entropy data available to read is FIPS/CC compliant at the hardware level. |
bool | valid_data |
Set to true when there is cryptographic entropy data available to read using dif_csrng_generate_read() . |
struct dif_csrng_internal_state |
CSRNG internal state.
Definition at line 282 of file dif_csrng.h.
typedef enum dif_csrng_cmd_status_kind dif_csrng_cmd_status_kind_t |
This API implements an interface for the CSRNG hardware.
The API follows the naming conventions used in NIST SP 800-90Ar1:
The seed used for instantiation can either be provided directly in hardware by an entropy source module; or directly by software. See dif_csrng_instantiate()
and dif_csrng_entropy_src
for more details.
The following sequence of operations are required to initialize and generate cryptographic entropy from the CSRNG module:
dif_csrng_init()
dif_csrng_configure()
dif_csrng_instantiate()
dif_csrng_generate_start()
dif_csrng_uninstantiate()
The following functions can be used for reseed and update operations:
The following utility functions are available to poll the state of the hardware:
Please see the following documentation for more information: https://docs.opentitan.org/hw/ip/csrng/doc/
Remaining work:
anonymous enum |
Enumerator | |
---|---|
kDifCsrngSeedMaterialMaxWordLen | Maximum seed material number of uint32_t words supported in CSRNG instantiate and seed commands. |
Definition at line 221 of file dif_csrng.h.
This API implements an interface for the CSRNG hardware.
The API follows the naming conventions used in NIST SP 800-90Ar1:
The seed used for instantiation can either be provided directly in hardware by an entropy source module; or directly by software. See dif_csrng_instantiate()
and dif_csrng_entropy_src
for more details.
The following sequence of operations are required to initialize and generate cryptographic entropy from the CSRNG module:
dif_csrng_init()
dif_csrng_configure()
dif_csrng_instantiate()
dif_csrng_generate_start()
dif_csrng_uninstantiate()
The following functions can be used for reseed and update operations:
The following utility functions are available to poll the state of the hardware:
Please see the following documentation for more information: https://docs.opentitan.org/hw/ip/csrng/doc/
Remaining work:
Definition at line 74 of file dif_csrng.h.
Enumeration of CSRNG command status errors.
Definition at line 160 of file dif_csrng.h.
CSRNG consume seed from entropy source enable.
Definition at line 204 of file dif_csrng.h.
enum dif_csrng_error |
Enumeration of CSRNG FIFO errors.
Definition at line 114 of file dif_csrng.h.
CSRNG internal state selector ID.
Definition at line 264 of file dif_csrng.h.
Recoverable alerts emitted by the CSRNG.
Definition at line 310 of file dif_csrng.h.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_clear_hw_csrng_exceptions | ( | const dif_csrng_t * | csrng | ) |
Clears recorded hardware CSRNG exceptions.
csrng | An CSRNG handle |
Definition at line 302 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_clear_recoverable_alerts | ( | const dif_csrng_t * | csrng | ) |
Clears all recoverable alerts currently recorded in the CSRNG block.
csrng | A CSRNG handle. |
Definition at line 429 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_configure | ( | const dif_csrng_t * | csrng | ) |
Configures CSRNG.
This function should need to be called once for the lifetime of csrng
.
csrng | A CSRNG handle. |
Definition at line 45 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_generate_read | ( | const dif_csrng_t * | csrng, |
uint32_t * | buf, | ||
size_t | len | ||
) |
Reads the output of the last CSRNG generate call.
This function reads len
words out of the CSRNG. This function should be called repeatedly until the number of words requested in dif_csrng_generate_start()
is exhausted. This function will block until len
words are read.
dif_csrng_get_output_status()
can be called before this function to ensure there is data available in the CSRNG output buffer.
csrng | A CSRNG handle. | |
[out] | buf | A buffer to fill with words from the pipeline. |
len | The number of words to read into buf . |
Definition at line 116 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_generate_start | ( | const dif_csrng_t * | csrng, |
size_t | len | ||
) |
Requests cryptographic entropy bits from the CSRNG.
The prediction resistance flag as specified in SP 800-90Ar1 section 10.2.1.1 is not directily supported by the hardware. It is the responsibility of the caller to reseed as needed before calling this function.
The CSRNG accepts generation requests with 128-bit granularity, with a minimum 128-bit request size. This function will increase the size of the request to align it to the nearest 128-bit boundary.
csrng | A CSRNG handle. |
len | Number of uint32_t words to generate. |
len
parameter results in a 128bit block level size greater than 0x800. Definition at line 101 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_get_cmd_force_error | ( | const dif_csrng_t * | csrng, |
dif_csrng_error_t | error | ||
) |
Forces the status registers to indicate a particular error cause.
csrng | An CSRNG handle |
error | The error to force. |
Definition at line 233 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_get_cmd_force_unhealthy_fifo | ( | const dif_csrng_t * | csrng, |
dif_csrng_fifo_t | fifo | ||
) |
Forces the status registers to indicate fifo
as being in an unhealthy state.
csrng | An CSRNG handle |
fifo | The FIFO to mark as unhealthy. |
Definition at line 170 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_get_cmd_interface_status | ( | const dif_csrng_t * | csrng, |
dif_csrng_cmd_status_t * | status | ||
) |
Gets the current command interface status.
This function can be called before or after any of the following functions:
dif_csrng_instantiate()
dif_csrng_reseed()
dif_csrng_update()
dif_csrng_generate_start()
dif_csrng_uninstantiate()
csrng | An CSRNG handle | |
[out] | status | Command interface status. |
Definition at line 142 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_get_hw_csrng_exceptions | ( | const dif_csrng_t * | csrng, |
uint32_t * | exceptions | ||
) |
Returns a bitset indicating which hardware CSRNGs have encountered exceptions.
csrng | An CSRNG handle |
exceptions[out] | The bitset of exception states. |
Definition at line 291 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_get_internal_state | ( | const dif_csrng_t * | csrng, |
dif_csrng_internal_state_id_t | instance_id, | ||
dif_csrng_internal_state_t * | state | ||
) |
Gets the working state of a CSRNG instance.
csrng | A CSRNG handle | |
instance_id | CSRNG instance ID. | |
[out] | state | The working state of a CSRNG instance. |
Definition at line 320 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_get_main_state_machine | ( | const dif_csrng_t * | csrng, |
uint32_t * | state | ||
) |
Returns an opaque blob indicating the main state machine's current state.
csrng | An CSRNG handle |
state[out] | The state machine state as an opaque blob. |
Definition at line 281 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_get_output_status | ( | const dif_csrng_t * | csrng, |
dif_csrng_output_status_t * | status | ||
) |
Gets the current cryptographic entropy output data status.
This function can be used before calling dif_csrng_generate_read()
to check if there is data available to read.
csrng | A CSRNG handle. | |
[out] | status | CSRNG output status. |
Definition at line 311 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_get_recoverable_alerts | ( | const dif_csrng_t * | csrng, |
uint32_t * | alerts | ||
) |
Gets the recoverable alerts currently recorded in the CSRNG block.
This function returns the alerts in a bitset whose indices are given by dif_csrng_recoverable_alert_t
.
csrng | A CSRNG handle. | |
[out] | alerts | Bitset of alerts currently recorded. |
Definition at line 417 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_get_reseed_counter | ( | const dif_csrng_t * | csrng, |
dif_csrng_internal_state_id_t | instance_id, | ||
uint32_t * | reseed_counter | ||
) |
Gets the reseed counter of a CSRNG instance.
csrng | A CSRNG handle | |
instance_id | CSRNG instance ID. | |
[out] | reseed | counter The current reseed counter value of a CSRNG instance. |
Definition at line 363 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_instantiate | ( | const dif_csrng_t * | csrng, |
dif_csrng_entropy_src_toggle_t | entropy_src_enable, | ||
const dif_csrng_seed_material_t * | seed_material | ||
) |
Initializes CSRNG instance with a new seed value.
seed_material
is used as specified in NIST SP 800-90Ar1 section 10.2.1.3.1. See dif_csrng_entropy_src
for details on how this value is mixed with the CSRNG seed.
seed_material
can be NULL, in which case CSRNG will use a zero vector instead.
csrng | A CSRNG handle. |
entropy_src_enable | Entropy source input enable. |
seed_material | Seed initialization parameters. |
Definition at line 63 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_is_locked | ( | const dif_csrng_t * | csrng, |
bool * | is_locked | ||
) |
Checks whether this CSRNG is locked.
csrng | A CSRNG handle. | |
[out] | is_locked | Out-param for the locked state. |
Definition at line 399 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_lock | ( | const dif_csrng_t * | csrng | ) |
Locks out CSRNG functionality.
This function is reentrant: calling it while functionality is locked will have no effect and return kDifCsrngOk
.
csrng | A CSRNG handle. |
Definition at line 391 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_reseed | ( | const dif_csrng_t * | csrng, |
const dif_csrng_seed_material_t * | seed_material | ||
) |
Reseeds CSRNG instance.
When seed_material.seed_material_len
is set to 0, only the entropy source seed is used to reseed the instance, otherwise it will be XOR'ed with the entropy source.
csrng | A CSRNG handle. |
seed_material | Reseed parameters. |
Definition at line 77 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_stop | ( | const dif_csrng_t * | csrng | ) |
Disables the CSRNG module.
csrng | A CSRNG handle. |
Definition at line 407 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_uninstantiate | ( | const dif_csrng_t * | csrng | ) |
Uninstantiates CSRNG.
Resets the CSRNG instance. Values in the CSRNG are zeroed out. This command effectively resets the CSRNG, clearing any errors that it may have encountered due to processing or entropy source errors.
csrng | An CSRNG handle. |
Definition at line 132 of file dif_csrng.c.
OT_WARN_UNUSED_RESULT dif_result_t dif_csrng_update | ( | const dif_csrng_t * | csrng, |
const dif_csrng_seed_material_t * | seed_material | ||
) |
Updates CSRNG state.
This function is similar to dif_csrng_reseed()
, except:
seed_material.seed_material
is used in the update operation.csrng | A CSRNG handle. |
seed_material | Update parameters. |
Definition at line 89 of file dif_csrng.c.