STRUCT HWRNG(9)
π struct hwrng(9) π
okay so bestie, welcome to the struct hwrng page from the Kernel API Manual β yes, that's the Hardware Random Number Generator driver, and yes it's exactly as iconic as it sounds π₯
This is the struct you fill out when you want your lil hardware entropy source to be a main character in the kernel. Every field, every callback, every vibe β all here π
β¨ SYNOPSIS β¨
struct hwrng {
const char *name;
int (*init)(struct hwrng *rng);
void (*cleanup)(struct hwrng *rng);
int (*data_present)(struct hwrng *rng, int wait);
int (*data_read)(struct hwrng *rng, u32 *data);
int (*read)(struct hwrng *rng, void *data, size_t max, bool wait);
unsigned long priv;
unsigned short quality;
};
π Members π
okay so let's go field by field, no skipping, periodt π
nameβ the unique RNG name. like a name name, there can only be one, so pick something cute and unique π¦initβ the initialization callback. can beNULL, no pressure π«Άcleanupβ the cleanup callback. also can beNULL, we love an optional bestie β¨data_presentβ callback that figures out if there's data available on the RNG. if it'sNULL, it's assumed there's always data available.*OBSOLETE*π β yeah she's deprecated, noted πdata_readβ read data from the RNG device. returns the number of lower random bytes in"data". must not beNULL. also*OBSOLETE*π β yep, legacy behaviorreadβ the new API, this is the glow-up π drivers can fill up tomaxbytes of data into the buffer. the buffer is aligned for any type, andmaxis a multiple of 4 and>= 32bytes. write that down, it matters πprivβ private data, for use by the RNG driver only. your personal little stash, iykyk πqualityβ estimation of true entropy in the RNG's bitstream, in bits of entropy per 1024 bits of input. valid values:1to1024, or0for maximum. do not mess this up, it's literally the whole vibe check for your entropy β
π SEE ALSO π
- Kernel file
./include/linux/hw_random.hβ go read it, bestie, it's giving source of truth π
okay that's the whole page, you ate that up π sign-off time: this is from ./include/linux, version October 2026, and the page is literally struct hwrng(9). slay, go write a hardware RNG driver ππ§πΈ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms