|
trng 1.0
trng driver library
|
Implementation of the True Random Number Generator (TRNG) functions. More...
#include "trng.h"
Functions | |
| void | trng_init (void) |
| Initializes the True Random Number Generator (TRNG) module. | |
| void | trng_next_bit (unsigned char bit) |
| Processes a single entropy bit and adds it to the TRNG buffer. | |
| TRNG_Buffer | trng_buffer_status (void) |
| Returns the current fill status of the TRNG buffer. | |
| volatile unsigned char * | trng_buffer (void) |
| Returns a pointer to the internal TRNG buffer. | |
| void | trng_reset (void) |
| Returns a pointer to the internal TRNG buffer. | |
Variables | |
| volatile unsigned char | buffer [10UL] |
| volatile unsigned char | current_buffer_position |
| volatile unsigned char | current_buffer_bit_position |
| volatile unsigned char | first_bit |
| volatile unsigned char | last_bit |
| volatile unsigned char | primary_run |
Implementation of the True Random Number Generator (TRNG) functions.
This file contains the implementation of the TRNG driver functions used to initialize, reset, and manage a True Random Number Generator. It processes entropy bits using a Von Neumann correction algorithm and stores the resulting random data in an internal buffer for later retrieval.
The library is intended for embedded systems requiring nondeterministic random data, such as cryptographic applications, seeding pseudorandom generators, or generating unique identifiers.
| volatile unsigned char * trng_buffer | ( | void | ) |
Returns a pointer to the internal TRNG buffer.
This function provides direct access to the internal memory buffer that stores the corrected random bytes generated by the True Random Number Generator (TRNG). The buffer can be read once the buffer status, retrieved by trng_buffer_status(), indicates that it is full.
| TRNG_Buffer trng_buffer_status | ( | void | ) |
Returns the current fill status of the TRNG buffer.
This function checks the internal TRNG buffer and reports whether it is empty, partially filled, or completely full. It uses internal position counters to determine the current state of the random data storage.
The return value can be one of the following:
| void trng_init | ( | void | ) |
Initializes the True Random Number Generator (TRNG) module.
This function prepares the TRNG module for operation by resetting its internal state and buffer. It should be called once during system initialization before feeding entropy bits using trng_next_bit(). Internally, this function calls trng_reset() to clear all buffer data and reset counters.

| void trng_next_bit | ( | unsigned char | bit | ) |
Processes a single entropy bit and adds it to the TRNG buffer.
This function is called repeatedly with raw entropy bits obtained from a hardware or software noise source. It applies the Von Neumann correction algorithm to remove bias from the input bit sequence and produces unbiased random bits. The corrected bits are packed into the internal TRNG buffer until it reaches the configured size defined by TRNG_BUFFER_SIZE. Once the buffer is full, no further bits are stored until it is reset.
| bit | The next raw entropy bit to process (must be 0 or 1). |
| void trng_reset | ( | void | ) |
Returns a pointer to the internal TRNG buffer.
This function provides direct access to the internal memory buffer that stores the corrected random bytes generated by the True Random Number Generator (TRNG). The buffer can be read once the buffer status, retrieved by trng_buffer_status(), indicates that it is full.

| volatile unsigned char buffer[10UL] |
| volatile unsigned char current_buffer_bit_position |
| volatile unsigned char current_buffer_position |
| volatile unsigned char first_bit |
| volatile unsigned char last_bit |
| volatile unsigned char primary_run |