crypto/algif_hash.c
Source file repositories/reference/linux-study-clean/crypto/algif_hash.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/algif_hash.c- Extension
.c- Size
- 9841 bytes
- Lines
- 471
- Domain
- Kernel Services
- Bucket
- crypto
- Inferred role
- Kernel Services: operation-table or driver-model contract
- Status
- pattern 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.
- Defines an operation table; this is where Linux turns generic core objects into subsystem-specific behavior.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- 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/hash.hcrypto/if_alg.hlinux/init.hlinux/kernel.hlinux/mm.hlinux/module.hlinux/net.hnet/sock.h
Detected Declarations
struct hash_ctxfunction hash_alloc_resultfunction hash_free_resultfunction hash_sendmsgfunction hash_recvmsgfunction hash_acceptfunction hash_check_keyfunction hash_sendmsg_nokeyfunction hash_recvmsg_nokeyfunction hash_accept_nokeyfunction hash_releasefunction hash_setkeyfunction hash_sock_destructfunction hash_accept_parent_nokeyfunction hash_accept_parentfunction algif_hash_initfunction algif_hash_exitmodule init algif_hash_init
Annotated Snippet
static struct proto_ops algif_hash_ops = {
.family = PF_ALG,
.connect = sock_no_connect,
.socketpair = sock_no_socketpair,
.getname = sock_no_getname,
.ioctl = sock_no_ioctl,
.listen = sock_no_listen,
.shutdown = sock_no_shutdown,
.mmap = sock_no_mmap,
.bind = sock_no_bind,
.release = af_alg_release,
.sendmsg = hash_sendmsg,
.recvmsg = hash_recvmsg,
.accept = hash_accept,
};
static int hash_check_key(struct socket *sock)
{
int err = 0;
struct sock *psk;
struct alg_sock *pask;
struct crypto_ahash *tfm;
struct sock *sk = sock->sk;
struct alg_sock *ask = alg_sk(sk);
lock_sock(sk);
if (!atomic_read(&ask->nokey_refcnt))
goto unlock_child;
psk = ask->parent;
pask = alg_sk(ask->parent);
tfm = pask->private;
err = -ENOKEY;
lock_sock_nested(psk, SINGLE_DEPTH_NESTING);
if (crypto_ahash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
goto unlock;
atomic_dec(&pask->nokey_refcnt);
atomic_set(&ask->nokey_refcnt, 0);
err = 0;
unlock:
release_sock(psk);
unlock_child:
release_sock(sk);
return err;
}
static int hash_sendmsg_nokey(struct socket *sock, struct msghdr *msg,
size_t size)
{
int err;
err = hash_check_key(sock);
if (err)
return err;
return hash_sendmsg(sock, msg, size);
}
static int hash_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
size_t ignored, int flags)
{
int err;
err = hash_check_key(sock);
if (err)
return err;
return hash_recvmsg(sock, msg, ignored, flags);
}
static int hash_accept_nokey(struct socket *sock, struct socket *newsock,
struct proto_accept_arg *arg)
{
int err;
err = hash_check_key(sock);
if (err)
return err;
return hash_accept(sock, newsock, arg);
}
static struct proto_ops algif_hash_ops_nokey = {
Annotation
- Immediate include surface: `crypto/hash.h`, `crypto/if_alg.h`, `linux/init.h`, `linux/kernel.h`, `linux/mm.h`, `linux/module.h`, `linux/net.h`, `net/sock.h`.
- Detected declarations: `struct hash_ctx`, `function hash_alloc_result`, `function hash_free_result`, `function hash_sendmsg`, `function hash_recvmsg`, `function hash_accept`, `function hash_check_key`, `function hash_sendmsg_nokey`, `function hash_recvmsg_nokey`, `function hash_accept_nokey`.
- Atlas domain: Kernel Services / crypto.
- Implementation status: pattern implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.