ADC Entropy Source Plugin
Detailed Description
Collect entropy from the ADC on Silicon Labs devices.
The ADC entropy module implements an entropy source plugin module for mbedTLS that can be used in applications needing random numbers or indirectly using mbedTLS modules that depend on the random number generation interfaces of mbed TLS. This module can be compiled by selecting Mbed TLS support for ADC entropy on series-1 devices component. Note that the IADC peripheral is not currently supported.
Data Structures | |
struct | mbedtls_entropy_adc_context |
ADC entropy context structure. | |
Functions | |
void | mbedtls_entropy_adc_init (mbedtls_entropy_adc_context *ctx) |
Initialize an ADC entropy context. | |
int | mbedtls_entropy_adc_set_instance (mbedtls_entropy_adc_context *ctx, unsigned int adc_inst) |
Set and initialize an ADC hardware instance. | |
void | mbedtls_entropy_adc_free (mbedtls_entropy_adc_context *ctx) |
Free ADC entropy context. | |
int | mbedtls_entropy_adc_poll (mbedtls_entropy_adc_context *ctx, unsigned char *output, size_t len, size_t *olen) |
Poll for entropy data. | |
Function Documentation
void mbedtls_entropy_adc_free | ( | mbedtls_entropy_adc_context * | ctx | ) |
Free ADC entropy context.
This function will reset the ADC peripheral and stop the ADC clock. If more than one ENTROPY_ADC contexts are instantiated the user should be aware that one call to mbedtls_entropy_adc_free with any of the ADC entropy contexts will disable the ADC and effectively disable all other calls in the ADC entropy API, except mbedtls_entropy_adc_init and mbedtls_entropy_adc_set_instance which will enable the ADC again. Normally the application will need only one ADC entropy context.
- Parameters
-
[in] ctx
ADC entropy context to be released.
void mbedtls_entropy_adc_init | ( | mbedtls_entropy_adc_context * | ctx | ) |
Initialize an ADC entropy context.
This function will initialize an ADC entropy context. This function will not initialize the ADC hardware instance as an entropy source. The user must call mbedtls_entropy_adc_set_instance in order to initialize the ADC hardware to entropy source mode.
- Parameters
-
[in] ctx
ADC entropy context to be initialized.
int mbedtls_entropy_adc_poll | ( | mbedtls_entropy_adc_context * | ctx, |
unsigned char * | output, |
||
size_t | len, |
||
size_t * | olen |
||
) |
Poll for entropy data.
This function will return entropy data from the ADC and place it into the output buffer. The len parameter tells this function the maximum number of bytes to read.
Note that the number of bytes read from the ADC might differ from the number of bytes requested.
The return value should be used to see if the operation was successful of if an error was encountered while reading the ADC. The content of the olen parameter can be used to check how many bytes were actually read.
- Parameters
-
[in] ctx
ADC entropy context. [out] output
Buffer to fill with entropy data from ADC. [in] len
Maximum number of bytes to fill in output buffer. [out] olen
The actual amount of bytes put into the buffer (Can be 0).
- Returns
- Always 0 for success.
int mbedtls_entropy_adc_set_instance | ( | mbedtls_entropy_adc_context * | ctx, |
unsigned int | adc_inst |
||
) |
Set and initialize an ADC hardware instance.
This function will initialize an ADC hardware instance as an entropy source by starting the ADC clock and initializing registers to prepare collecting entropy in single sample mode. This function assumes that the ADC clock mode is set to SYNC, i.e. the HFPERCLK generates the ADC_CLK.
- Parameters
-
[in] ctx
ADC entropy context. [in] adc_inst
ADC instance number to use.
- Returns
- 0 for success or MBEDTLS_ERR_ENTROPY_SOURCE_FAILED if adc_inst is invalid.