drivers/crypto/ccree/cc_cipher.c

Source file repositories/reference/linux-study-clean/drivers/crypto/ccree/cc_cipher.c

File Facts

System
Linux kernel
Corpus path
drivers/crypto/ccree/cc_cipher.c
Extension
.c
Size
40726 bytes
Lines
1472
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 cc_user_key_info {
	u8 *key;
	dma_addr_t key_dma_addr;
};

struct cc_hw_key_info {
	enum cc_hw_crypto_key key1_slot;
	enum cc_hw_crypto_key key2_slot;
};

struct cc_cpp_key_info {
	u8 slot;
	enum cc_cpp_alg alg;
};

enum cc_key_type {
	CC_UNPROTECTED_KEY,		/* User key */
	CC_HW_PROTECTED_KEY,		/* HW (FDE) key */
	CC_POLICY_PROTECTED_KEY,	/* CPP key */
	CC_INVALID_PROTECTED_KEY	/* Invalid key */
};

struct cc_cipher_ctx {
	struct cc_drvdata *drvdata;
	int keylen;
	int cipher_mode;
	int flow_mode;
	unsigned int flags;
	enum cc_key_type key_type;
	struct cc_user_key_info user;
	union {
		struct cc_hw_key_info hw;
		struct cc_cpp_key_info cpp;
	};
	struct crypto_shash *shash_tfm;
	struct crypto_skcipher *fallback_tfm;
	bool fallback_on;
};

static void cc_cipher_complete(struct device *dev, void *cc_req, int err);

static inline enum cc_key_type cc_key_type(struct crypto_tfm *tfm)
{
	struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm);

	return ctx_p->key_type;
}

static int validate_keys_sizes(struct cc_cipher_ctx *ctx_p, u32 size)
{
	switch (ctx_p->flow_mode) {
	case S_DIN_to_AES:
		switch (size) {
		case CC_AES_128_BIT_KEY_SIZE:
		case CC_AES_192_BIT_KEY_SIZE:
			if (ctx_p->cipher_mode != DRV_CIPHER_XTS)
				return 0;
			break;
		case CC_AES_256_BIT_KEY_SIZE:
			return 0;
		case (CC_AES_192_BIT_KEY_SIZE * 2):
		case (CC_AES_256_BIT_KEY_SIZE * 2):
			if (ctx_p->cipher_mode == DRV_CIPHER_XTS ||
			    ctx_p->cipher_mode == DRV_CIPHER_ESSIV)
				return 0;
			break;
		default:
			break;
		}
		break;
	case S_DIN_to_DES:
		if (size == DES3_EDE_KEY_SIZE || size == DES_KEY_SIZE)
			return 0;
		break;
	case S_DIN_to_SM4:
		if (size == SM4_KEY_SIZE)
			return 0;
		break;
	default:
		break;
	}
	return -EINVAL;
}

static int validate_data_size(struct cc_cipher_ctx *ctx_p,
			      unsigned int size)
{
	switch (ctx_p->flow_mode) {
	case S_DIN_to_AES:
		switch (ctx_p->cipher_mode) {

Annotation

Implementation Notes