TRNG driver implementation for the CC26XX family.
This file should only be included in the board file to fill the TRNG_config struct.
The CC26XX family has a dedicated hardware TRNG based on sampling multiple free running oscillators. With all FROs enabled, the TRNG hardware generates 64 bits of entropy approximately every 5ms. The driver implementation chains multiple 64-bit entropy generation operations together to generate an arbitrary amount of entropy.
The driver keeps a global pool of entropy available to service any requests immediately. If the pool is not sufficiently large or is too depleted to service a request, entropy will be generated until the request is serviced. If there is an ongoing TRNG request that the hardware is generating entropy for, the driver will queue any other requests and work them off in FIFO order.
Requests issued by driver instances with polling return behaviour will preempt any executing requests and be serviced immediately.
After the request queue is emptied, the driver will start an asynchronous operation in the background to refill the depleted entropy pool.
The EIP-75t HW takes 240,000 clock cycles in the default setting to generate one round of output (i.e. 64 bits). This comes to 5ms on a 48MHz clock. The clock cycles per round can be configured to be as low as 2^8 (256) to as high as 2^24 (16,777,216). Entropy re-generation time can be tailored in a trade-off between speed of random number generation and amount of entropy in each of those random numbers.
#include <stdint.h>
#include <stdbool.h>
#include <ti/drivers/Power.h>
#include <ti/drivers/TRNG.h>
#include <ti/drivers/cryptoutils/cryptokey/CryptoKey.h>
#include <ti/drivers/dpl/HwiP.h>
#include <ti/drivers/dpl/SemaphoreP.h>
Go to the source code of this file.
Data Structures | |
struct | TRNGCC26XX_HWAttrs |
TRNGCC26XX Hardware Attributes. More... | |
Macros | |
#define | TRNGCC26XX_SAMPLES_PER_CYCLE_MIN 256 |
Minimum random samples for each entropy generation call. More... | |
#define | TRNGCC26XX_SAMPLES_PER_CYCLE_DEFAULT 240000 |
Default random samples for each entropy generation call. More... | |
#define | TRNGCC26XX_SAMPLES_PER_CYCLE_MAX 16777216 |
Maximum random samples for each entropy generation call. More... | |
#define | TRNGCC26XX_MIN_BYTES_PER_ITERATION (2 * sizeof(uint32_t)) |
Minimum number of bytes provided by the TRNG hardware in one go. More... | |
#define | TRNGCC26XX_ENTROPY_POOL_SIZE (32 / sizeof(uint64_t)) |
Default TRNGCC26XX entropy pool size in 64-bit elements. More... | |
Functions | |
int_fast16_t | TRNGCC26XX_setSamplesPerCycle (TRNG_Handle handle, uint32_t samplesPerCycle) |
Sets the number of entropy generation cycles before the results are returned. More... | |
#define TRNGCC26XX_SAMPLES_PER_CYCLE_MIN 256 |
Minimum random samples for each entropy generation call.
#define TRNGCC26XX_SAMPLES_PER_CYCLE_DEFAULT 240000 |
Default random samples for each entropy generation call.
Set to generate 64 bits of randomness in 5ms with all FROs active.
#define TRNGCC26XX_SAMPLES_PER_CYCLE_MAX 16777216 |
Maximum random samples for each entropy generation call.
#define TRNGCC26XX_MIN_BYTES_PER_ITERATION (2 * sizeof(uint32_t)) |
Minimum number of bytes provided by the TRNG hardware in one go.
Smaller amounts can by requested in driver calls but the full number will always be generated. Part of the generated entropy will simply not be copied back to the target buffer if the requested length is not a multiple of TRNGCC26XX_MIN_BYTES_PER_ITERATION.
#define TRNGCC26XX_ENTROPY_POOL_SIZE (32 / sizeof(uint64_t)) |
Default TRNGCC26XX entropy pool size in 64-bit elements.
By default, the entropy pool is sized to immediately fulfill a 256-bit entropy generation request. If we assume that the TRNG is used infrequently, this should greatly decrease the latency of <= 256-bit requests. This value may be overridden by defining it at the project level and recompiling the driver.
int_fast16_t TRNGCC26XX_setSamplesPerCycle | ( | TRNG_Handle | handle, |
uint32_t | samplesPerCycle | ||
) |
Sets the number of entropy generation cycles before the results are returned.
The default value is set to generate 64 bits of entropy.
handle | A TRNGCC26XX handle returned from TRNGCC26XX_open |
samplesPerCycle | Number of 48MHz clock cycles to sample. Must be between 2^8 and 2^24. |