|
PatchworkOS
|
Random Number Generator. More...
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. | |
Random Number Generator.
The random number generator driver provides functions to generate random numbers for use in the kernel.
| void rand_cpu_init | ( | rand_cpu_ctx_t * | ctx | ) |
Initializes the random number generator.
Definition at line 28 of file rand.c.
References CPUID_ECX_RDRAND, cpuid_feature_info(), ERR, info, LOG_WARN, rdrand_do(), rand_cpu_ctx_t::rdrandAvail, smp_self_unsafe(), and UINT64_MAX.
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.
| buffer | A pointer to the buffer to fill. |
| size | The number of bytes to fill. |
0. On failure, ERR and errno is set. Definition at line 61 of file rand.c.
References buffer, ERR, memcpy(), cpu_t::rand, rand_gen_fallback(), rdrand_do(), rand_cpu_ctx_t::rdrandAvail, smp_put(), and smp_self().
Referenced by key_generate().
Generates a random 32-bit unsigned integer using the RDRAND instruction.
| value | A pointer to store the generated random value. |
| retries | The number of retries to attempt if RDRAND fails. |
0. On failure, ERR and errno is set. Referenced by rand_cpu_init(), and rand_gen().