crypto_alloc_rng(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’– crypto_alloc_rng(9) πŸ’–

ok so this is a page from the Kernel API Manual β€” it's crypto_alloc_rng(9), and yes it's exactly as iconic as it sounds: it's the one that gets you an RNG handle. bestie, let's get into it ✨


🌸 NAME 🌸

crypto_alloc_rng β€” allocate RNG handle

like, literally that's the whole job. allocate. RNG. handle. periodt πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

struct crypto_rng * crypto_alloc_rng (const char *alg_name , u32 type ,
u32 mask );

that's the whole signature, no cap. three args, one pointer back at you 🫢


πŸ¦‹ ARGUMENTS πŸ¦‹

  • alg_name β€” this is the cra_name / name or the cra_driver_name / driver name of the message digest cipher. yep, you read that right, it says message digest cipher in the source, we don't make the rules we just report them 😭
  • type β€” specifies the type of the cipher. that's it, that's the whole lore.
  • mask β€” specifies the mask for the cipher. it's the vibe check partner of type, fr fr.

✨ DESCRIPTION ✨

okay so what actually happens: this call allocates a cipher handle for a random number generator πŸ”₯ the struct crypto_rng it hands back is the cipher handle you need for literally any subsequent API invocation for that random number generator. so like, hold onto it. it's your main character. πŸ‘‘

here's the tea though: for all random number generators, this call creates a new private copy of the random number generator that does not share a state with other instances. no state sharing. none. everyone gets their own 🧚

the one (1) exception: the "krng" random number generator, which is a kernel crypto API use case for the get_random_bytes function of the /dev/random driver. so that one's special, iykyk 🌈

⭐ RETURN ⭐

  • on success? you get the allocated cipher handle πŸ’– slay.
  • on error? IS_ERR is true, and PTR_ERR returns the error code. so check it, bestie, don't just raw-dog the pointer πŸ™ˆ

πŸ’œ SEE ALSO πŸ’œ

go read these next, they're giving required reading πŸ“š:


okay that's the whole page, you ate that πŸ“ this lil number lives in ./include/crypto and it's dated October 2026 β€” so yeah, from the future, iconic behavior honestly πŸ’€βœ¨ go forth and allocate responsibly, mwah πŸ«ΆπŸ’–

πŸ“¦ where this page comes from