PatchworkOS  966e257
A non-POSIX operating system.
Loading...
Searching...
No Matches
Random Number Generator

Random Number Generator. More...

Collaboration diagram for Random Number Generator:

Detailed Description

Random Number Generator.

The random number generator driver provides functions to generate random numbers for use in the kernel.

See also
RDRAND Instruction

Data Structures

struct  rand_cpu_ctx_t
 CPU random number generator context. More...
 

Functions

void rand_cpu_init (rand_cpu_ctx_t *ctx)
 Initializes the random number generator.
 
uint64_t rand_gen (void *buffer, uint64_t size)
 Fills a buffer with random bytes.
 
uint64_t rdrand_do (uint32_t *value, uint8_t retries)
 Generates a random 32-bit unsigned integer using the RDRAND instruction.
 

Function Documentation

◆ rand_cpu_init()

void rand_cpu_init ( rand_cpu_ctx_t ctx)

Initializes the random number generator.

Definition at line 28 of file rand.c.

Here is the call graph for this function:

◆ rand_gen()

uint64_t rand_gen ( void *  buffer,
uint64_t  size 
)

Fills a buffer with random bytes.

If the RDRAND instruction is available and working, it will be used. Otherwise, a fallback time based RNG will be used.

Parameters
bufferA pointer to the buffer to fill.
sizeThe number of bytes to fill.
Returns
On success, 0. On failure, ERR and errno is set.

Definition at line 61 of file rand.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rdrand_do()

uint64_t rdrand_do ( uint32_t value,
uint8_t  retries 
)
extern

Generates a random 32-bit unsigned integer using the RDRAND instruction.

Parameters
valueA pointer to store the generated random value.
retriesThe number of retries to attempt if RDRAND fails.
Returns
On success, 0. On failure, ERR and errno is set.
Here is the caller graph for this function: