drivers/crypto/inside-secure/eip93/eip93-cipher.c

Source file repositories/reference/linux-study-clean/drivers/crypto/inside-secure/eip93/eip93-cipher.c

File Facts

System
Linux kernel
Corpus path
drivers/crypto/inside-secure/eip93/eip93-cipher.c
Extension
.c
Size
11690 bytes
Lines
414
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

// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (C) 2019 - 2021
 *
 * Richard van Schagen <vschagen@icloud.com>
 * Christian Marangi <ansuelsmth@gmail.com>
 */

#include <crypto/aes.h>
#include <crypto/ctr.h>
#include <crypto/internal/des.h>
#include <linux/dma-mapping.h>

#include "eip93-aes.h"
#include "eip93-cipher.h"
#include "eip93-common.h"
#include "eip93-des.h"
#include "eip93-regs.h"

void eip93_skcipher_handle_result(struct crypto_async_request *async, int err)
{
	struct eip93_crypto_ctx *ctx = crypto_tfm_ctx(async->tfm);
	struct eip93_device *eip93 = ctx->eip93;
	struct skcipher_request *req = skcipher_request_cast(async);
	struct eip93_cipher_reqctx *rctx = skcipher_request_ctx(req);

	eip93_unmap_dma(eip93, rctx, req->src, req->dst);
	eip93_handle_result(eip93, rctx, req->iv);

	skcipher_request_complete(req, err);
}

static int eip93_skcipher_send_req(struct crypto_async_request *async)
{
	struct skcipher_request *req = skcipher_request_cast(async);
	struct eip93_cipher_reqctx *rctx = skcipher_request_ctx(req);
	int err;

	err = check_valid_request(rctx);

	if (err) {
		skcipher_request_complete(req, err);
		return err;
	}

	return eip93_send_req(async, req->iv, rctx);
}

/* Crypto skcipher API functions */
static int eip93_skcipher_cra_init(struct crypto_tfm *tfm)
{
	struct eip93_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
	struct eip93_alg_template *tmpl = container_of(tfm->__crt_alg,
				struct eip93_alg_template, alg.skcipher.base);

	crypto_skcipher_set_reqsize(__crypto_skcipher_cast(tfm),
				    sizeof(struct eip93_cipher_reqctx));

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

	ctx->eip93 = tmpl->eip93;
	ctx->type = tmpl->type;

	ctx->sa_record = kzalloc_obj(*ctx->sa_record);
	if (!ctx->sa_record)
		return -ENOMEM;

	return 0;
}

static void eip93_skcipher_cra_exit(struct crypto_tfm *tfm)
{
	struct eip93_crypto_ctx *ctx = crypto_tfm_ctx(tfm);

	dma_unmap_single(ctx->eip93->dev, ctx->sa_record_base,
			 sizeof(*ctx->sa_record), DMA_TO_DEVICE);
	kfree(ctx->sa_record);
}

static int eip93_skcipher_setkey(struct crypto_skcipher *ctfm, const u8 *key,
				 unsigned int len)
{
	struct crypto_tfm *tfm = crypto_skcipher_tfm(ctfm);
	struct eip93_crypto_ctx *ctx = crypto_tfm_ctx(tfm);
	struct eip93_alg_template *tmpl = container_of(tfm->__crt_alg,
						     struct eip93_alg_template,
						     alg.skcipher.base);
	struct sa_record *sa_record = ctx->sa_record;
	unsigned int keylen = len;
	u32 flags = tmpl->flags;

Annotation

Implementation Notes