drivers/crypto/ccp/ccp-crypto-aes-cmac.c

Source file repositories/reference/linux-study-clean/drivers/crypto/ccp/ccp-crypto-aes-cmac.c

File Facts

System
Linux kernel
Corpus path
drivers/crypto/ccp/ccp-crypto-aes-cmac.c
Extension
.c
Size
10125 bytes
Lines
403
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

if (!sg) {
			ret = -EINVAL;
			goto e_free;
		}
	}

	if (nbytes) {
		sg = ccp_crypto_sg_table_add(&rctx->data_sg, req->src);
		if (!sg) {
			ret = -EINVAL;
			goto e_free;
		}
	}

	if (need_pad) {
		int pad_length = block_size - (len & (block_size - 1));

		rctx->hash_cnt += pad_length;

		memset(rctx->pad, 0, sizeof(rctx->pad));
		rctx->pad[0] = 0x80;
		sg_init_one(&rctx->pad_sg, rctx->pad, pad_length);
		sg = ccp_crypto_sg_table_add(&rctx->data_sg, &rctx->pad_sg);
		if (!sg) {
			ret = -EINVAL;
			goto e_free;
		}
	}
	if (sg) {
		sg_mark_end(sg);
		sg = rctx->data_sg.sgl;
	}

	/* Initialize the K1/K2 scatterlist */
	if (final)
		cmac_key_sg = (need_pad) ? &ctx->u.aes.k2_sg
					 : &ctx->u.aes.k1_sg;

	memset(&rctx->cmd, 0, sizeof(rctx->cmd));
	INIT_LIST_HEAD(&rctx->cmd.entry);
	rctx->cmd.engine = CCP_ENGINE_AES;
	rctx->cmd.u.aes.type = ctx->u.aes.type;
	rctx->cmd.u.aes.mode = ctx->u.aes.mode;
	rctx->cmd.u.aes.action = CCP_AES_ACTION_ENCRYPT;
	rctx->cmd.u.aes.key = &ctx->u.aes.key_sg;
	rctx->cmd.u.aes.key_len = ctx->u.aes.key_len;
	rctx->cmd.u.aes.iv = &rctx->iv_sg;
	rctx->cmd.u.aes.iv_len = AES_BLOCK_SIZE;
	rctx->cmd.u.aes.src = sg;
	rctx->cmd.u.aes.src_len = rctx->hash_cnt;
	rctx->cmd.u.aes.dst = NULL;
	rctx->cmd.u.aes.cmac_key = cmac_key_sg;
	rctx->cmd.u.aes.cmac_key_len = ctx->u.aes.kn_len;
	rctx->cmd.u.aes.cmac_final = final;

	ret = ccp_crypto_enqueue_request(&req->base, &rctx->cmd);

	return ret;

e_free:
	sg_free_table(&rctx->data_sg);

	return ret;
}

static int ccp_aes_cmac_init(struct ahash_request *req)
{
	struct ccp_aes_cmac_req_ctx *rctx = ahash_request_ctx_dma(req);

	memset(rctx, 0, sizeof(*rctx));

	rctx->null_msg = 1;

	return 0;
}

static int ccp_aes_cmac_update(struct ahash_request *req)
{
	return ccp_do_cmac_update(req, req->nbytes, 0);
}

static int ccp_aes_cmac_final(struct ahash_request *req)
{
	return ccp_do_cmac_update(req, 0, 1);
}

static int ccp_aes_cmac_finup(struct ahash_request *req)
{
	return ccp_do_cmac_update(req, req->nbytes, 1);
}

Annotation

Implementation Notes