crypto/api.c
Source file repositories/reference/linux-study-clean/crypto/api.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/api.c- Extension
.c- Size
- 16240 bytes
- Lines
- 688
- Domain
- Kernel Services
- Bucket
- crypto
- Inferred role
- Kernel Services: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/errno.hlinux/jump_label.hlinux/kernel.hlinux/kmod.hlinux/module.hlinux/param.hlinux/sched/signal.hlinux/slab.hlinux/string.hlinux/completion.hinternal.h
Detected Declarations
function crypto_mod_putfunction list_for_each_entryfunction crypto_larval_destroyfunction crypto_larval_killfunction crypto_schedule_testfunction crypto_start_testfunction crypto_probing_notifyfunction crypto_exit_opsfunction crypto_ctxsizefunction crypto_shoot_algfunction crypto_alloc_basefunction crypto_alloc_tfmfunction crypto_destroy_tfmfunction crypto_has_algfunction crypto_req_donefunction crypto_destroy_algexport crypto_alg_listexport crypto_alg_semexport crypto_chainexport crypto_mod_getexport crypto_mod_putexport crypto_larval_allocexport crypto_schedule_testexport crypto_probing_notifyexport crypto_alg_mod_lookupexport crypto_shoot_algexport __crypto_alloc_tfmexport crypto_alloc_baseexport crypto_create_tfm_nodeexport crypto_find_algexport crypto_alloc_tfm_nodeexport crypto_destroy_tfmexport crypto_has_algexport crypto_req_doneexport crypto_destroy_algexport crypto_request_clone
Annotated Snippet
else if (!time_left) {
if (crypto_is_test_larval(larval))
crypto_larval_kill(larval);
alg = ERR_PTR(-ETIMEDOUT);
} else if (!alg || PTR_ERR(alg) == -EEXIST) {
int err = alg ? -EEXIST : -EAGAIN;
/*
* EEXIST is expected because two probes can be scheduled
* at the same time with one using alg_name and the other
* using driver_name. Do a re-lookup but do not retry in
* case we hit a quirk like gcm_base(ctr(aes),...) which
* will never match.
*/
alg = &larval->alg;
alg = crypto_alg_lookup(alg->cra_name, type, mask) ?:
ERR_PTR(err);
} else if (IS_ERR(alg))
;
else if (crypto_is_test_larval(larval) &&
!(alg->cra_flags & CRYPTO_ALG_TESTED))
alg = ERR_PTR(-EAGAIN);
else if (alg->cra_flags & CRYPTO_ALG_FIPS_INTERNAL)
alg = ERR_PTR(-EAGAIN);
else if (!crypto_mod_get(alg))
alg = ERR_PTR(-EAGAIN);
crypto_mod_put(&larval->alg);
if (!IS_ERR(alg) && crypto_is_larval(alg))
goto again;
return alg;
}
static struct crypto_alg *crypto_alg_lookup(const char *name, u32 type,
u32 mask)
{
const u32 fips = CRYPTO_ALG_FIPS_INTERNAL;
struct crypto_alg *alg;
u32 test = 0;
if (!((type | mask) & CRYPTO_ALG_TESTED))
test |= CRYPTO_ALG_TESTED;
down_read(&crypto_alg_sem);
alg = __crypto_alg_lookup(name, (type | test) & ~fips,
(mask | test) & ~fips);
if (alg) {
if (((type | mask) ^ fips) & fips)
mask |= fips;
mask &= fips;
if (!crypto_is_larval(alg) &&
((type ^ alg->cra_flags) & mask)) {
/* Algorithm is disallowed in FIPS mode. */
crypto_mod_put(alg);
alg = ERR_PTR(-ENOENT);
}
} else if (test) {
alg = __crypto_alg_lookup(name, type, mask);
if (alg && !crypto_is_larval(alg)) {
/* Test failed */
crypto_mod_put(alg);
alg = ERR_PTR(-ELIBBAD);
}
}
up_read(&crypto_alg_sem);
return alg;
}
static struct crypto_alg *crypto_larval_lookup(const char *name, u32 type,
u32 mask)
{
struct crypto_alg *alg;
if (!name)
return ERR_PTR(-ENOENT);
type &= ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD);
mask &= ~(CRYPTO_ALG_LARVAL | CRYPTO_ALG_DEAD);
alg = crypto_alg_lookup(name, type, mask);
if (!alg && !(mask & CRYPTO_NOLOAD)) {
request_module("crypto-%s", name);
if (!((type ^ CRYPTO_ALG_NEED_FALLBACK) & mask &
CRYPTO_ALG_NEED_FALLBACK))
request_module("crypto-%s-all", name);
Annotation
- Immediate include surface: `linux/err.h`, `linux/errno.h`, `linux/jump_label.h`, `linux/kernel.h`, `linux/kmod.h`, `linux/module.h`, `linux/param.h`, `linux/sched/signal.h`.
- Detected declarations: `function crypto_mod_put`, `function list_for_each_entry`, `function crypto_larval_destroy`, `function crypto_larval_kill`, `function crypto_schedule_test`, `function crypto_start_test`, `function crypto_probing_notify`, `function crypto_exit_ops`, `function crypto_ctxsize`, `function crypto_shoot_alg`.
- Atlas domain: Kernel Services / crypto.
- Implementation status: integration 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.