crypto/algif_skcipher.c
Source file repositories/reference/linux-study-clean/crypto/algif_skcipher.c
File Facts
- System
- Linux kernel
- Corpus path
crypto/algif_skcipher.c- Extension
.c- Size
- 10175 bytes
- Lines
- 409
- 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/scatterwalk.hcrypto/skcipher.hcrypto/if_alg.hlinux/init.hlinux/list.hlinux/kernel.hlinux/mm.hlinux/module.hlinux/net.hnet/sock.h
Detected Declarations
function Copyrightfunction algif_skcipher_exportfunction _skcipher_recvmsgfunction skcipher_recvmsgfunction skcipher_check_keyfunction skcipher_sendmsg_nokeyfunction skcipher_recvmsg_nokeyfunction skcipher_releasefunction skcipher_setkeyfunction skcipher_sock_destructfunction skcipher_accept_parent_nokeyfunction skcipher_accept_parentfunction algif_skcipher_initfunction algif_skcipher_exitmodule init algif_skcipher_init
Annotated Snippet
static struct proto_ops algif_skcipher_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,
.accept = sock_no_accept,
.release = af_alg_release,
.sendmsg = skcipher_sendmsg,
.recvmsg = skcipher_recvmsg,
.poll = af_alg_poll,
};
static int skcipher_check_key(struct socket *sock)
{
int err = 0;
struct sock *psk;
struct alg_sock *pask;
struct crypto_skcipher *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_skcipher_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 skcipher_sendmsg_nokey(struct socket *sock, struct msghdr *msg,
size_t size)
{
int err;
err = skcipher_check_key(sock);
if (err)
return err;
return skcipher_sendmsg(sock, msg, size);
}
static int skcipher_recvmsg_nokey(struct socket *sock, struct msghdr *msg,
size_t ignored, int flags)
{
int err;
err = skcipher_check_key(sock);
if (err)
return err;
return skcipher_recvmsg(sock, msg, ignored, flags);
}
static struct proto_ops algif_skcipher_ops_nokey = {
.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,
.accept = sock_no_accept,
Annotation
- Immediate include surface: `crypto/scatterwalk.h`, `crypto/skcipher.h`, `crypto/if_alg.h`, `linux/init.h`, `linux/list.h`, `linux/kernel.h`, `linux/mm.h`, `linux/module.h`.
- Detected declarations: `function Copyright`, `function algif_skcipher_export`, `function _skcipher_recvmsg`, `function skcipher_recvmsg`, `function skcipher_check_key`, `function skcipher_sendmsg_nokey`, `function skcipher_recvmsg_nokey`, `function skcipher_release`, `function skcipher_setkey`, `function skcipher_sock_destruct`.
- 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.