drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
Source file repositories/reference/linux-study-clean/drivers/crypto/virtio/virtio_crypto_skcipher_algs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/virtio/virtio_crypto_skcipher_algs.c- Extension
.c- Size
- 17181 bytes
- Lines
- 643
- Domain
- Driver Families
- Bucket
- drivers/crypto
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- 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/engine.hcrypto/internal/skcipher.hcrypto/scatterwalk.hlinux/err.hlinux/scatterlist.huapi/linux/virtio_crypto.hvirtio_crypto_common.h
Detected Declarations
struct virtio_crypto_skcipher_ctxstruct virtio_crypto_sym_requeststruct virtio_crypto_algofunction virtio_crypto_dataq_sym_callbackfunction virtio_crypto_alg_sg_nents_lengthfunction virtio_crypto_alg_validate_keyfunction virtio_crypto_alg_skcipher_init_sessionfunction virtio_crypto_alg_skcipher_close_sessionfunction virtio_crypto_alg_skcipher_init_sessionsfunction virtio_crypto_skcipher_setkeyfunction __virtio_crypto_skcipher_do_reqfunction virtio_crypto_skcipher_encryptfunction virtio_crypto_skcipher_decryptfunction virtio_crypto_skcipher_initfunction virtio_crypto_skcipher_exitfunction virtio_crypto_skcipher_crypt_reqfunction virtio_crypto_skcipher_finalize_reqfunction virtio_crypto_skcipher_algs_registerfunction virtio_crypto_skcipher_algs_unregister
Annotated Snippet
struct virtio_crypto_skcipher_ctx {
struct virtio_crypto *vcrypto;
struct virtio_crypto_sym_session_info enc_sess_info;
struct virtio_crypto_sym_session_info dec_sess_info;
};
struct virtio_crypto_sym_request {
struct virtio_crypto_request base;
/* Cipher or aead */
uint32_t type;
uint8_t *iv;
/* Encryption? */
bool encrypt;
};
struct virtio_crypto_algo {
uint32_t algonum;
uint32_t service;
unsigned int active_devs;
struct skcipher_engine_alg algo;
};
/*
* The algs_lock protects the below global virtio_crypto_active_devs
* and crypto algorithms registion.
*/
static DEFINE_MUTEX(algs_lock);
static void virtio_crypto_skcipher_finalize_req(
struct virtio_crypto_sym_request *vc_sym_req,
struct skcipher_request *req,
int err);
static void virtio_crypto_dataq_sym_callback
(struct virtio_crypto_request *vc_req, int len)
{
struct virtio_crypto_sym_request *vc_sym_req =
container_of(vc_req, struct virtio_crypto_sym_request, base);
struct skcipher_request *ablk_req =
container_of((void *)vc_sym_req, struct skcipher_request,
__ctx);
int error;
/* Finish the encrypt or decrypt process */
if (vc_sym_req->type == VIRTIO_CRYPTO_SYM_OP_CIPHER) {
switch (vc_req->status) {
case VIRTIO_CRYPTO_OK:
error = 0;
break;
case VIRTIO_CRYPTO_INVSESS:
case VIRTIO_CRYPTO_ERR:
error = -EINVAL;
break;
case VIRTIO_CRYPTO_BADMSG:
error = -EBADMSG;
break;
default:
error = -EIO;
break;
}
virtio_crypto_skcipher_finalize_req(vc_sym_req,
ablk_req, error);
}
}
static u64 virtio_crypto_alg_sg_nents_length(struct scatterlist *sg)
{
u64 total = 0;
for (total = 0; sg; sg = sg_next(sg))
total += sg->length;
return total;
}
static int
virtio_crypto_alg_validate_key(int key_len, uint32_t *alg)
{
switch (key_len) {
case AES_KEYSIZE_128:
case AES_KEYSIZE_192:
case AES_KEYSIZE_256:
*alg = VIRTIO_CRYPTO_CIPHER_AES_CBC;
break;
default:
return -EINVAL;
}
return 0;
}
Annotation
- Immediate include surface: `crypto/engine.h`, `crypto/internal/skcipher.h`, `crypto/scatterwalk.h`, `linux/err.h`, `linux/scatterlist.h`, `uapi/linux/virtio_crypto.h`, `virtio_crypto_common.h`.
- Detected declarations: `struct virtio_crypto_skcipher_ctx`, `struct virtio_crypto_sym_request`, `struct virtio_crypto_algo`, `function virtio_crypto_dataq_sym_callback`, `function virtio_crypto_alg_sg_nents_length`, `function virtio_crypto_alg_validate_key`, `function virtio_crypto_alg_skcipher_init_session`, `function virtio_crypto_alg_skcipher_close_session`, `function virtio_crypto_alg_skcipher_init_sessions`, `function virtio_crypto_skcipher_setkey`.
- Atlas domain: Driver Families / drivers/crypto.
- Implementation status: source 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.