include/crypto/rng.h
Source file repositories/reference/linux-study-clean/include/crypto/rng.h
File Facts
- System
- Linux kernel
- Corpus path
include/crypto/rng.h- Extension
.h- Size
- 7362 bytes
- Lines
- 220
- Domain
- Repository Root And Misc
- Bucket
- include
- Inferred role
- Repository Root And Misc: implementation source
- Status
- source implementation candidate
Why This File Exists
Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.
- Top-level or miscellaneous repository surface. Use this as map coverage unless a later manual pass promotes the file into a deeper subsystem dossier.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/atomic.hlinux/container_of.hlinux/crypto.hlinux/fips.hlinux/random.h
Detected Declarations
struct crypto_rngstruct rng_algstruct crypto_rngfunction crypto_stdrng_get_bytesfunction crypto_rng_algfunction crypto_free_rngfunction crypto_rng_generatefunction crypto_rng_get_bytesfunction crypto_rng_seedsize
Annotated Snippet
struct rng_alg {
int (*generate)(struct crypto_rng *tfm,
const u8 *src, unsigned int slen,
u8 *dst, unsigned int dlen);
int (*seed)(struct crypto_rng *tfm, const u8 *seed, unsigned int slen);
void (*set_ent)(struct crypto_rng *tfm, const u8 *data,
unsigned int len);
unsigned int seedsize;
struct crypto_alg base;
};
struct crypto_rng {
struct crypto_tfm base;
};
int __crypto_stdrng_get_bytes(void *buf, unsigned int len);
/**
* crypto_stdrng_get_bytes() - get cryptographically secure random bytes
* @buf: output buffer holding the random numbers
* @len: length of the output buffer
*
* This function fills the caller-allocated buffer with random numbers using the
* normal Linux RNG if fips_enabled=0, or the highest-priority "stdrng"
* algorithm in the crypto_rng subsystem if fips_enabled=1.
*
* Context: May sleep
* Return: 0 function was successful; < 0 if an error occurred
*/
static inline int crypto_stdrng_get_bytes(void *buf, unsigned int len)
{
might_sleep();
if (fips_enabled)
return __crypto_stdrng_get_bytes(buf, len);
return get_random_bytes_wait(buf, len);
}
/**
* DOC: Random number generator API
*
* The random number generator API is used with the ciphers of type
* CRYPTO_ALG_TYPE_RNG (listed as type "rng" in /proc/crypto)
*/
/**
* crypto_alloc_rng() -- allocate RNG handle
* @alg_name: is the cra_name / name or cra_driver_name / driver name of the
* message digest cipher
* @type: specifies the type of the cipher
* @mask: specifies the mask for the cipher
*
* Allocate a cipher handle for a random number generator. The returned struct
* crypto_rng is the cipher handle that is required for any subsequent
* API invocation for that random number generator.
*
* 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. The only exception is the "krng" random number generator which
* is a kernel crypto API use case for the get_random_bytes() function of the
* /dev/random driver.
*
* Return: allocated cipher handle in case of success; IS_ERR() is true in case
* of an error, PTR_ERR() returns the error code.
*/
struct crypto_rng *crypto_alloc_rng(const char *alg_name, u32 type, u32 mask);
static inline struct crypto_tfm *crypto_rng_tfm(struct crypto_rng *tfm)
{
return &tfm->base;
}
static inline struct rng_alg *__crypto_rng_alg(struct crypto_alg *alg)
{
return container_of(alg, struct rng_alg, base);
}
/**
* crypto_rng_alg() - obtain 'struct rng_alg' pointer from RNG handle
* @tfm: RNG handle
*
* Return: Pointer to 'struct rng_alg', derived from @tfm RNG handle
*/
static inline struct rng_alg *crypto_rng_alg(struct crypto_rng *tfm)
{
return __crypto_rng_alg(crypto_rng_tfm(tfm)->__crt_alg);
}
/**
Annotation
- Immediate include surface: `linux/atomic.h`, `linux/container_of.h`, `linux/crypto.h`, `linux/fips.h`, `linux/random.h`.
- Detected declarations: `struct crypto_rng`, `struct rng_alg`, `struct crypto_rng`, `function crypto_stdrng_get_bytes`, `function crypto_rng_alg`, `function crypto_free_rng`, `function crypto_rng_generate`, `function crypto_rng_get_bytes`, `function crypto_rng_seedsize`.
- Atlas domain: Repository Root And Misc / include.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.