drivers/crypto/intel/qat/qat_common/qat_algs.c

Source file repositories/reference/linux-study-clean/drivers/crypto/intel/qat/qat_common/qat_algs.c

File Facts

System
Linux kernel
Corpus path
drivers/crypto/intel/qat/qat_common/qat_algs.c
Extension
.c
Size
41065 bytes
Lines
1349
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.

Dependency Surface

Detected Declarations

Annotated Snippet

struct qat_alg_cd {
	union {
		struct qat_enc { /* Encrypt content desc */
			struct icp_qat_hw_cipher_algo_blk cipher;
			struct icp_qat_hw_auth_algo_blk hash;
		} qat_enc_cd;
		struct qat_dec { /* Decrypt content desc */
			struct icp_qat_hw_auth_algo_blk hash;
			struct icp_qat_hw_cipher_algo_blk cipher;
		} qat_dec_cd;
	};
} __aligned(64);

struct qat_alg_aead_ctx {
	struct qat_alg_cd *enc_cd;
	struct qat_alg_cd *dec_cd;
	dma_addr_t enc_cd_paddr;
	dma_addr_t dec_cd_paddr;
	struct icp_qat_fw_la_bulk_req enc_fw_req;
	struct icp_qat_fw_la_bulk_req dec_fw_req;
	enum icp_qat_hw_auth_algo qat_hash_alg;
	unsigned int hash_digestsize;
	unsigned int hash_blocksize;
	struct qat_crypto_instance *inst;
};

struct qat_alg_skcipher_ctx {
	struct icp_qat_hw_cipher_algo_blk *enc_cd;
	struct icp_qat_hw_cipher_algo_blk *dec_cd;
	dma_addr_t enc_cd_paddr;
	dma_addr_t dec_cd_paddr;
	struct icp_qat_fw_la_bulk_req enc_fw_req;
	struct icp_qat_fw_la_bulk_req dec_fw_req;
	struct qat_crypto_instance *inst;
	struct crypto_skcipher *ftfm;
	struct crypto_cipher *tweak;
	bool fallback;
	int mode;
};

static int qat_alg_do_precomputes(struct icp_qat_hw_auth_algo_blk *hash,
				  struct qat_alg_aead_ctx *ctx,
				  const u8 *auth_key,
				  unsigned int auth_keylen)
{
	switch (ctx->qat_hash_alg) {
	case ICP_QAT_HW_AUTH_ALGO_SHA1: {
		struct hmac_sha1_key key;
		__be32 *istate = (__be32 *)hash->sha.state1;
		__be32 *ostate = (__be32 *)(hash->sha.state1 +
					    round_up(sizeof(key.istate.h), 8));

		hmac_sha1_preparekey(&key, auth_key, auth_keylen);
		for (int i = 0; i < ARRAY_SIZE(key.istate.h); i++) {
			istate[i] = cpu_to_be32(key.istate.h[i]);
			ostate[i] = cpu_to_be32(key.ostate.h[i]);
		}
		memzero_explicit(&key, sizeof(key));
		return 0;
	}
	case ICP_QAT_HW_AUTH_ALGO_SHA256: {
		struct hmac_sha256_key key;
		__be32 *istate = (__be32 *)hash->sha.state1;
		__be32 *ostate = (__be32 *)(hash->sha.state1 +
					    sizeof(key.key.istate.h));

		hmac_sha256_preparekey(&key, auth_key, auth_keylen);
		for (int i = 0; i < ARRAY_SIZE(key.key.istate.h); i++) {
			istate[i] = cpu_to_be32(key.key.istate.h[i]);
			ostate[i] = cpu_to_be32(key.key.ostate.h[i]);
		}
		memzero_explicit(&key, sizeof(key));
		return 0;
	}
	case ICP_QAT_HW_AUTH_ALGO_SHA512: {
		struct hmac_sha512_key key;
		__be64 *istate = (__be64 *)hash->sha.state1;
		__be64 *ostate = (__be64 *)(hash->sha.state1 +
					    sizeof(key.key.istate.h));

		hmac_sha512_preparekey(&key, auth_key, auth_keylen);
		for (int i = 0; i < ARRAY_SIZE(key.key.istate.h); i++) {
			istate[i] = cpu_to_be64(key.key.istate.h[i]);
			ostate[i] = cpu_to_be64(key.key.ostate.h[i]);
		}
		memzero_explicit(&key, sizeof(key));
		return 0;
	}
	default:
		return -EFAULT;

Annotation

Implementation Notes