crypto/shash.c
Source file repositories/reference/linux-study-clean/crypto/shash.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/shash.c- Extension
.c- Size
- 13821 bytes
- Lines
- 549
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/scatterwalk.hlinux/cryptouser.hlinux/err.hlinux/kernel.hlinux/module.hlinux/seq_file.hlinux/string.hnet/netlink.hhash.h
Detected Declarations
function Copyrightfunction crypto_shash_final_nonzerofunction crypto_shash_finup_maxfunction shash_no_setkeyfunction shash_set_needkeyfunction crypto_shash_setkeyfunction __crypto_shash_initfunction crypto_shash_initfunction shash_default_finupfunction crypto_shash_op_and_zerofunction crypto_shash_finupfunction shash_default_digestfunction crypto_shash_digestfunction crypto_shash_tfm_digestfunction __crypto_shash_exportfunction crypto_shash_export_corefunction crypto_shash_exportfunction __crypto_shash_importfunction crypto_shash_import_corefunction crypto_shash_importfunction crypto_shash_exit_tfmfunction crypto_shash_init_tfmfunction crypto_shash_free_instancefunction crypto_shash_reportfunction crypto_shash_showfunction crypto_grab_shashfunction crypto_has_shashfunction hash_prepare_algfunction shash_default_export_corefunction shash_default_import_corefunction shash_prepare_algfunction crypto_register_shashfunction crypto_unregister_shashfunction crypto_register_shashesfunction crypto_unregister_shashesfunction shash_register_instancefunction shash_free_singlespawn_instanceexport shash_no_setkeyexport crypto_shash_setkeyexport crypto_shash_initexport crypto_shash_finupexport crypto_shash_digestexport crypto_shash_tfm_digestexport crypto_shash_export_coreexport crypto_shash_exportexport crypto_shash_import_coreexport crypto_shash_importexport crypto_grab_shash
Annotated Snippet
if (*blenp) {
memcpy(buf + *blenp, data, bs - *blenp);
nbytes = bs;
src = buf;
}
err = crypto_shash_alg(tfm)->update(desc, src, nbytes);
if (err < 0)
return err;
data += nbytes - err - *blenp;
len -= nbytes - err - *blenp;
*blenp = 0;
}
if (*blenp || !out) {
memcpy(buf + *blenp, data, len);
*blenp += len;
if (!out)
return 0;
data = buf;
len = *blenp;
}
finup:
return crypto_shash_op_and_zero(crypto_shash_alg(tfm)->finup, desc,
data, len, out);
}
EXPORT_SYMBOL_GPL(crypto_shash_finup);
static int shash_default_digest(struct shash_desc *desc, const u8 *data,
unsigned int len, u8 *out)
{
return __crypto_shash_init(desc) ?:
crypto_shash_finup(desc, data, len, out);
}
int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
unsigned int len, u8 *out)
{
struct crypto_shash *tfm = desc->tfm;
if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
return -ENOKEY;
return crypto_shash_op_and_zero(crypto_shash_alg(tfm)->digest, desc,
data, len, out);
}
EXPORT_SYMBOL_GPL(crypto_shash_digest);
int crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data,
unsigned int len, u8 *out)
{
SHASH_DESC_ON_STACK(desc, tfm);
desc->tfm = tfm;
return crypto_shash_digest(desc, data, len, out);
}
EXPORT_SYMBOL_GPL(crypto_shash_tfm_digest);
static int __crypto_shash_export(struct shash_desc *desc, void *out,
int (*export)(struct shash_desc *desc,
void *out))
{
struct crypto_shash *tfm = desc->tfm;
u8 *buf = shash_desc_ctx(desc);
unsigned int plen, ss;
plen = crypto_shash_blocksize(tfm) + 1;
ss = crypto_shash_statesize(tfm);
if (crypto_shash_block_only(tfm))
ss -= plen;
if (!export) {
memcpy(out, buf, ss);
return 0;
}
return export(desc, out);
}
int crypto_shash_export_core(struct shash_desc *desc, void *out)
{
return __crypto_shash_export(desc, out,
crypto_shash_alg(desc->tfm)->export_core);
}
EXPORT_SYMBOL_GPL(crypto_shash_export_core);
int crypto_shash_export(struct shash_desc *desc, void *out)
{
struct crypto_shash *tfm = desc->tfm;
Annotation
- Immediate include surface: `crypto/scatterwalk.h`, `linux/cryptouser.h`, `linux/err.h`, `linux/kernel.h`, `linux/module.h`, `linux/seq_file.h`, `linux/string.h`, `net/netlink.h`.
- Detected declarations: `function Copyright`, `function crypto_shash_final_nonzero`, `function crypto_shash_finup_max`, `function shash_no_setkey`, `function shash_set_needkey`, `function crypto_shash_setkey`, `function __crypto_shash_init`, `function crypto_shash_init`, `function shash_default_finup`, `function crypto_shash_op_and_zero`.
- 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.