52#define LOG_MODULE "CSPRNG"
53#define LOG_LEVEL LOG_LEVEL_NONE
56static unsigned read_state_bytes;
69 for(i = 0; i < CSPRNG_SEED_LEN; i++) {
70 seed.
u8[i] ^= new_seed->
u8[i];
74 LOG_DBG_BYTES(seed.
key, CSPRNG_KEY_LEN);
77 LOG_DBG_BYTES(seed.
state, CSPRNG_STATE_LEN);
92 pos = MIN(len, CSPRNG_STATE_LEN - read_state_bytes);
93 memcpy(result, seed.
state + read_state_bytes, pos);
94 read_state_bytes += pos;
99 AES_128.set_key(seed.
key);
100 for(; pos < len; pos += CSPRNG_STATE_LEN) {
101 AES_128.encrypt(seed.
state);
102 read_state_bytes = MIN(len - pos, CSPRNG_STATE_LEN);
103 memcpy(result + pos, seed.
state, read_state_bytes);
Default definitions of C compiler quirk work-arounds.
An OFB-AES-128-based CSPRNG.
void csprng_feed(struct csprng_seed *new_seed)
Mixes a new seed with the current one.
bool csprng_rand(uint8_t *result, unsigned len)
Generates a cryptographic random number.
Header file for the logging system.
This is the structure of a seed.
uint8_t state[CSPRNG_STATE_LEN]
internal state of the CSPRNG
uint8_t key[CSPRNG_KEY_LEN]
AES-128 key of the CSPRNG.
uint8_t u8[CSPRNG_SEED_LEN]
for convenience