HRNG#
Introduction#
The Hardware Random Number Generator (HRNG) module provides a mechanism for generating random numbers that are crucial for cryptographic operations, secure communications, and simulations. HRNG supports both true random number generation and pseudo-random number generation modes.
Common use cases include:
Cryptographic Key Generation: Generating keys for encryption algorithms.
Secure Communication: Providing random numbers for session keys and data encryption.
Simulations and Randomization: Generating random inputs for simulations and randomized algorithms.
Configuration#
The HRNG module can be configured using the following parameters:
Modes:
Pseudo-random number: Pseudo-random number rely on mathematical algorithms to generate sequences of numbers that resemble randomness. These algorithms are deterministic, meaning they always produce the same sequence of numbers when initialized with the same starting value, referred to as a seed.
True Random Number : True Random Number create random numbers using physical processes like electronic noise, radioactive decay, or other unpredictable natural events.
The random number generator can be initialized, started, and stopped using the following functions:
Initialize the HRNG : sl_si91x_hrng_init
Start the HRNG : sl_si91x_hrng_start
Get random bytes: sl_si91x_hrng_get_bytes
Stop the HRNG : sl_si91x_hrng_stop
Deinitialize the HRNG : sl_si91x_hrng_deinit
Usage#
To use the HRNG module:
Enable the HRNG peripheral clocks using sl_si91x_hrng_init.
Start the HRNG using sl_si91x_hrng_start.
Retrieve the random numbers using sl_si91x_hrng_get_bytes.
Stop the HRNG using sl_si91x_hrng_stop.
Disable the HRNG peripheral clocks using sl_si91x_hrng_deinit.
Enumerations#
Enumeration for HRNG modes.
Typedefs#
Enumeration for HRNG modes.
Functions#
Initialize the HRNG peripheral.
Start the Hardware Random Number Generator (HRNG).
Retrieve random bytes generated by the HRNG.
Reads random data from the HRNG using the LFSR (Linear-Feedback Shift Register) input latch.
Stop the Hardware Random Number Generator (HRNG).
Disable the HRNG peripheral clocks.
Macros#
Enable clock for HWRNG.
Maximum number of bytes that can be generated by the HWRNG.
Minimum number of bytes that can be generated by the HWRNG.
Enumeration Documentation#
sl_si91x_hrng_mode#
sl_si91x_hrng_mode
Enumeration for HRNG modes.
This enumeration defines the modes in which the Hardware Random Number Generator (HRNG) can operate.
Enumerator | |
---|---|
SL_SI91X_HRNG_TRUE_RANDOM | True random number generation mode. |
SL_SI91X_HRNG_PSEUDO_RANDOM | Pseudo-random number generation mode. |
54
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
Typedef Documentation#
sl_si91x_hrng_mode_t#
typedef enum sl_si91x_hrng_mode sl_si91x_hrng_mode_t
Enumeration for HRNG modes.
This enumeration defines the modes in which the Hardware Random Number Generator (HRNG) can operate.
57
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
Function Documentation#
sl_si91x_hrng_init#
sl_status_t sl_si91x_hrng_init (void )
Initialize the HRNG peripheral.
N/A |
This function initializes the HRNG peripheral, setting up the necessary configurations for random number generation. It must be called before any HRNG functionality can be utilized.
Returns
SL_STATUS_OK - if the initialization was successful.
SL_STATUS_FAIL - if the initialization failed due to an error.
For more information on status codes, see SL STATUS DOCUMENTATION.
76
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
sl_si91x_hrng_start#
sl_status_t sl_si91x_hrng_start (sl_si91x_hrng_mode_t hrng_mode)
Start the Hardware Random Number Generator (HRNG).
[in] | hrng_mode | Mode for random number generation:
|
This function starts the HRNG in the specified mode, allowing either true random or pseudo-random number generation based on the selected mode. It prepares the HRNG hardware to generate random numbers.
Pre-conditions:
The HRNG peripheral clocks must be enabled using sl_si91x_hrng_init.
Returns
SL_STATUS_OK: Successfully started the HRNG.
SL_STATUS_INVALID_PARAMETER: Invalid mode or pointer.
For more information on status codes, see SL STATUS DOCUMENTATION.
100
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
sl_si91x_hrng_get_bytes#
sl_status_t sl_si91x_hrng_get_bytes (uint32_t * random_bytes, uint8_t number_of_bytes)
Retrieve random bytes generated by the HRNG.
[out] | random_bytes | Buffer where the generated random bytes will be stored. |
[in] | number_of_bytes | The number of random bytes to read from the HRNG. The number of bytes must be within the range of 1 to 254. |
This function reads a specified number of random bytes from the HRNG hardware and stores them in the provided buffer. It ensures that the requested number of bytes is fetched from the HRNG peripheral.
Pre-conditions:
The HRNG peripheral clocks must be enabled using sl_si91x_hrng_init.
The HRNG must be started using sl_si91x_hrng_start.
Returns
SL_STATUS_OK: Successfully retrieved the random bytes.
SL_STATUS_INVALID_PARAMETER: Invalid pointer or number of bytes.
SL_STATUS_FAIL: Failed to retrieve random bytes.
For more information on status codes, see SL STATUS DOCUMENTATION.
129
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
sl_si91x_hrng_read_lfsr_input#
sl_status_t sl_si91x_hrng_read_lfsr_input (uint8_t number_of_bytes, uint32_t * random_bytes)
Reads random data from the HRNG using the LFSR (Linear-Feedback Shift Register) input latch.
[in] | number_of_bytes | The number of random bytes to read from the HRNG. The number of bytes must be within the range of 1 to 254. |
[out] | random_bytes | Pointer to an array where the random data will be stored. |
This function reads random data from the HRNG using the LFSR input latch register. It first enables the LFSR, reads the specified number of bytes, and then disables the LFSR. Note
Data is valid only when the LFSR_32_BIT_INPUT_VALID bit is set.
Pre-conditions:
The HRNG peripheral clocks must be enabled using sl_si91x_hrng_init.
The HRNG must be started using sl_si91x_hrng_start.
Returns
SL_STATUS_OK: If the random data was read successfully.
SL_STATUS_FAIL: If there was an error reading the random data.
For more information on status codes, see SL STATUS DOCUMENTATION.
157
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
sl_si91x_hrng_stop#
sl_status_t sl_si91x_hrng_stop (void )
Stop the Hardware Random Number Generator (HRNG).
N/A |
This function disables the HRNG by stopping the random number generation process and halting any ongoing operations within the HRNG peripheral.
Pre-conditions:
The HRNG peripheral clocks must be enabled using sl_si91x_hrng_init.
The HRNG must be started using sl_si91x_hrng_start.
Returns
SL_STATUS_OK: If the HRNG stopped successfully. For more information on status codes, see SL STATUS DOCUMENTATION.
175
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
sl_si91x_hrng_deinit#
sl_status_t sl_si91x_hrng_deinit (void )
Disable the HRNG peripheral clocks.
N/A |
This function disables the HRNG clocks, effectively shutting down the HRNG peripheral to conserve power or halt its operations when not in use.
Pre-conditions:
The HRNG peripheral clocks must be enabled using sl_si91x_hrng_init.
The HRNG must be stopped using sl_si91x_hrng_stop.
Returns
SL_STATUS_OK if the operation was successful. SL_STATUS_FAIL indicates that the operation failed due to an error.
For more information on status codes, see SL STATUS DOCUMENTATION.
194
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
Macro Definition Documentation#
SL_SI91X_HWRNG_CLK_ENABLE#
#define SL_SI91X_HWRNG_CLK_ENABLEValue:
HWRNG_CLK_ENABLE
Enable clock for HWRNG.
44
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
SL_SI91X_HWRNG_MAX_BYTES#
#define SL_SI91X_HWRNG_MAX_BYTESValue:
254
Maximum number of bytes that can be generated by the HWRNG.
46
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h
SL_SI91X_HWRNG_MIN_BYTES#
#define SL_SI91X_HWRNG_MIN_BYTESValue:
1
Minimum number of bytes that can be generated by the HWRNG.
47
of file components/device/silabs/si91x/mcu/drivers/unified_api/inc/sl_si91x_hrng.h