STRUCT HWRNG(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– 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 be NULL, no pressure 🫢
  • cleanup β€” the cleanup callback. also can be NULL, we love an optional bestie ✨
  • data_present β€” callback that figures out if there's data available on the RNG. if it's NULL, 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 be NULL. also *OBSOLETE* 😭 β€” yep, legacy behavior
  • read β€” the new API, this is the glow-up 😌 drivers can fill up to max bytes of data into the buffer. the buffer is aligned for any type, and max is a multiple of 4 and >= 32 bytes. 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: 1 to 1024, or 0 for 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