RANDOM_HARVEST(9)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’– RANDOM_HARVEST(9) β€” gather entropy from the kernel for the entropy device πŸ’–

okay bestie, welcome to this little Kernel Developer’s Manual moment πŸ’…. This is the random_harvest(9) page, and it’s all about feeding β€œrandom-ish” data from kernel land into the entropy device. iconic behavior, honestly ✨


🌸 SYNOPSIS 🌸

#include <sys/types.h>
#include <sys/random.h>

void
random_harvest_direct(void *entropy, u_int size, enum esource source);

void
random_harvest_fast(void *entropy, u_int size, enum esource source);

void
random_harvest_queue(void *entropy, u_int size, enum esource source);

✨ DESCRIPTION ✨

The random_harvest_*() functions are used by device drivers and other kernel processes to pass data that is considered (at least partially) stochastic to the entropy device. No cap, that’s the whole vibe 🫢

The caller should pass a pointer pointing to the β€œrandom” data in entropy. The argument size contains the number of bytes pointed to. The source is chosen from one of the values enumerated in sys/dev/random.h and is used to indicate the source of the entropy ✨

Here’s the variant breakdown, bestie:

  • random_harvest_direct() β€” used for early harvesting before any multitasking is enabled πŸ‘‘
  • random_harvest_fast() β€” used by sources that should not take a performance hit from harvesting, because they’re high-rate sources. Some entropy is sacrificed, but the high rate of supply will compensate for this πŸ’€
  • random_harvest_queue() β€” used for general harvesting and is the default choice for most entropy sources, such as interrupts or console events 🌈

Interrupt harvesting has been in part simplified for the kernel programmer 🧚 If a device driver registers an interrupt handler with BUS_SETUP_INTR(9) or bus_setup_intr(9), then it is only necessary to include the INTR_ENTROPY bit in the flags argument to have that interrupt source be used for entropy harvesting. This should be done wherever practicable πŸ’–

lowkey the INTR_ENTROPY bit is the little shortcut here β€” iykyk ✨

πŸ¦‹ SEE ALSO πŸ¦‹


πŸŽ€ AUTHORS πŸŽ€

The FreeBSD random(4) entropy device and supporting documentation was written by Mark R V Murray πŸ’œ


mwah πŸ’‹ β€” this cute little rewrite is from the Debian copy of the page, dated August 26, 2018. periodt 🫢✨

πŸ“¦ where this page comes from