drivers/crypto/hisilicon/hpre/hpre_crypto.c
Source file repositories/reference/linux-study-clean/drivers/crypto/hisilicon/hpre/hpre_crypto.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/crypto/hisilicon/hpre/hpre_crypto.c- Extension
.c- Size
- 44888 bytes
- Lines
- 1898
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/akcipher.hcrypto/dh.hcrypto/ecc_curve.hcrypto/ecdh.hcrypto/rng.hcrypto/internal/akcipher.hcrypto/internal/kpp.hcrypto/internal/rsa.hcrypto/kpp.hcrypto/scatterwalk.hlinux/dma-mapping.hlinux/fips.hlinux/module.hlinux/time.hhpre.h
Detected Declarations
struct hpre_ctxstruct hpre_rsa_ctxstruct hpre_dh_ctxstruct hpre_ecdh_ctxstruct hpre_ctxstruct hpre_asym_requestfunction hpre_align_szfunction hpre_align_pdfunction hpre_dfx_add_req_timefunction hpre_get_data_dma_addrfunction hpre_prepare_dma_buffunction hpre_hw_data_initfunction hpre_hw_data_clr_allfunction hpre_alg_res_post_hffunction hpre_ctx_clearfunction hpre_is_bd_timeoutfunction hpre_dh_cbfunction hpre_rsa_cbfunction hpre_alg_cbfunction hpre_ctx_initfunction hpre_msg_request_setfunction hpre_sendfunction hpre_dh_compute_valuefunction hpre_dh_generate_public_keyfunction hpre_dh_compute_shared_secretfunction hpre_is_dh_params_length_validfunction hpre_dh_set_paramsfunction hpre_dh_clear_ctxfunction hpre_dh_set_secretfunction hpre_dh_max_sizefunction hpre_dh_init_tfmfunction hpre_dh_exit_tfmfunction hpre_rsa_drop_leading_zerosfunction hpre_rsa_key_size_is_supportfunction hpre_rsa_encfunction hpre_rsa_decfunction hpre_rsa_set_nfunction hpre_rsa_set_efunction hpre_rsa_set_dfunction hpre_crt_para_getfunction hpre_rsa_setkey_crtfunction hpre_rsa_clear_ctxfunction hpre_is_crt_keyfunction hpre_rsa_setkeyfunction hpre_rsa_setpubkeyfunction hpre_rsa_setprivkeyfunction hpre_rsa_max_sizefunction hpre_rsa_init_tfm
Annotated Snippet
struct hpre_rsa_ctx {
/* low address: e--->n */
char *pubkey;
dma_addr_t dma_pubkey;
/* low address: d--->n */
char *prikey;
dma_addr_t dma_prikey;
/* low address: dq->dp->q->p->qinv */
char *crt_prikey;
dma_addr_t dma_crt_prikey;
struct crypto_akcipher *soft_tfm;
};
struct hpre_dh_ctx {
/*
* If base is g we compute the public key
* ya = g^xa mod p; [RFC2631 sec 2.1.1]
* else if base if the counterpart public key we
* compute the shared secret
* ZZ = yb^xa mod p; [RFC2631 sec 2.1.1]
* low address: d--->n, please refer to Hisilicon HPRE UM
*/
char *xa_p;
dma_addr_t dma_xa_p;
char *g; /* m */
dma_addr_t dma_g;
struct crypto_kpp *soft_tfm;
};
struct hpre_ecdh_ctx {
/* low address: p->a->k->b */
unsigned char *p;
dma_addr_t dma_p;
/* low address: x->y */
unsigned char *g;
dma_addr_t dma_g;
struct crypto_kpp *soft_tfm;
};
struct hpre_ctx {
struct hisi_qp *qp;
struct device *dev;
struct hpre *hpre;
unsigned int key_sz;
bool crt_g2_mode;
union {
struct hpre_rsa_ctx rsa;
struct hpre_dh_ctx dh;
struct hpre_ecdh_ctx ecdh;
};
/* for ecc algorithms */
unsigned int curve_id;
/* for high performance core */
u8 enable_hpcore;
bool fallback;
};
struct hpre_asym_request {
char *src;
char *dst;
struct hpre_sqe req;
struct hpre_ctx *ctx;
union {
struct akcipher_request *rsa;
struct kpp_request *dh;
struct kpp_request *ecdh;
} areq;
int err;
hpre_cb cb;
struct timespec64 req_time;
};
static inline unsigned int hpre_align_sz(void)
{
return ((crypto_dma_align() - 1) | (HPRE_ALIGN_SZ - 1)) + 1;
}
static inline unsigned int hpre_align_pd(void)
{
return (hpre_align_sz() - 1) & ~(crypto_tfm_ctx_alignment() - 1);
}
static void hpre_dfx_add_req_time(struct hpre_asym_request *hpre_req)
{
struct hpre_ctx *ctx = hpre_req->ctx;
Annotation
- Immediate include surface: `crypto/akcipher.h`, `crypto/dh.h`, `crypto/ecc_curve.h`, `crypto/ecdh.h`, `crypto/rng.h`, `crypto/internal/akcipher.h`, `crypto/internal/kpp.h`, `crypto/internal/rsa.h`.
- Detected declarations: `struct hpre_ctx`, `struct hpre_rsa_ctx`, `struct hpre_dh_ctx`, `struct hpre_ecdh_ctx`, `struct hpre_ctx`, `struct hpre_asym_request`, `function hpre_align_sz`, `function hpre_align_pd`, `function hpre_dfx_add_req_time`, `function hpre_get_data_dma_addr`.
- 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.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.