crypto/aead.c
Source file repositories/reference/linux-study-clean/crypto/aead.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/aead.c- Extension
.c- Size
- 7628 bytes
- Lines
- 314
- 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
crypto/internal/aead.hlinux/cryptouser.hlinux/errno.hlinux/init.hlinux/kernel.hlinux/module.hlinux/slab.hlinux/seq_file.hlinux/string.hlinux/string_choices.hnet/netlink.hinternal.h
Detected Declarations
function Copyrightfunction crypto_aead_setkeyfunction crypto_aead_setauthsizefunction crypto_aead_encryptfunction crypto_aead_decryptfunction crypto_aead_exit_tfmfunction crypto_aead_init_tfmfunction crypto_aead_reportfunction crypto_aead_showfunction crypto_aead_free_instancefunction crypto_grab_aeadfunction crypto_has_aeadfunction aead_prepare_algfunction crypto_register_aeadfunction crypto_unregister_aeadfunction crypto_register_aeadsfunction crypto_unregister_aeadsfunction aead_register_instanceexport crypto_aead_setkeyexport crypto_aead_setauthsizeexport crypto_aead_encryptexport crypto_aead_decryptexport crypto_grab_aeadexport crypto_alloc_aeadexport crypto_alloc_sync_aeadexport crypto_has_aeadexport crypto_register_aeadexport crypto_unregister_aeadexport crypto_register_aeadsexport crypto_unregister_aeadsexport aead_register_instance
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* AEAD: Authenticated Encryption with Associated Data
*
* This file provides API support for AEAD algorithms.
*
* Copyright (c) 2007-2015 Herbert Xu <herbert@gondor.apana.org.au>
*/
#include <crypto/internal/aead.h>
#include <linux/cryptouser.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/seq_file.h>
#include <linux/string.h>
#include <linux/string_choices.h>
#include <net/netlink.h>
#include "internal.h"
static int setkey_unaligned(struct crypto_aead *tfm, const u8 *key,
unsigned int keylen)
{
unsigned long alignmask = crypto_aead_alignmask(tfm);
int ret;
u8 *buffer, *alignbuffer;
unsigned long absize;
absize = keylen + alignmask;
buffer = kmalloc(absize, GFP_ATOMIC);
if (!buffer)
return -ENOMEM;
alignbuffer = (u8 *)ALIGN((unsigned long)buffer, alignmask + 1);
memcpy(alignbuffer, key, keylen);
ret = crypto_aead_alg(tfm)->setkey(tfm, alignbuffer, keylen);
kfree_sensitive(buffer);
return ret;
}
int crypto_aead_setkey(struct crypto_aead *tfm,
const u8 *key, unsigned int keylen)
{
unsigned long alignmask = crypto_aead_alignmask(tfm);
int err;
if ((unsigned long)key & alignmask)
err = setkey_unaligned(tfm, key, keylen);
else
err = crypto_aead_alg(tfm)->setkey(tfm, key, keylen);
if (unlikely(err)) {
crypto_aead_set_flags(tfm, CRYPTO_TFM_NEED_KEY);
return err;
}
crypto_aead_clear_flags(tfm, CRYPTO_TFM_NEED_KEY);
return 0;
}
EXPORT_SYMBOL_GPL(crypto_aead_setkey);
int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize)
{
int err;
if ((!authsize && crypto_aead_maxauthsize(tfm)) ||
authsize > crypto_aead_maxauthsize(tfm))
return -EINVAL;
if (crypto_aead_alg(tfm)->setauthsize) {
err = crypto_aead_alg(tfm)->setauthsize(tfm, authsize);
if (err)
return err;
}
tfm->authsize = authsize;
return 0;
}
EXPORT_SYMBOL_GPL(crypto_aead_setauthsize);
int crypto_aead_encrypt(struct aead_request *req)
{
struct crypto_aead *aead = crypto_aead_reqtfm(req);
if (crypto_aead_get_flags(aead) & CRYPTO_TFM_NEED_KEY)
return -ENOKEY;
Annotation
- Immediate include surface: `crypto/internal/aead.h`, `linux/cryptouser.h`, `linux/errno.h`, `linux/init.h`, `linux/kernel.h`, `linux/module.h`, `linux/slab.h`, `linux/seq_file.h`.
- Detected declarations: `function Copyright`, `function crypto_aead_setkey`, `function crypto_aead_setauthsize`, `function crypto_aead_encrypt`, `function crypto_aead_decrypt`, `function crypto_aead_exit_tfm`, `function crypto_aead_init_tfm`, `function crypto_aead_report`, `function crypto_aead_show`, `function crypto_aead_free_instance`.
- 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.