safexcel_cipher.c 16.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
/*
 * Copyright (C) 2017 Marvell
 *
 * Antoine Tenart <antoine.tenart@free-electrons.com>
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2. This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */

#include <linux/device.h>
#include <linux/dma-mapping.h>
#include <linux/dmapool.h>

#include <crypto/aes.h>
#include <crypto/skcipher.h>
17
#include <crypto/internal/skcipher.h>
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

#include "safexcel.h"

enum safexcel_cipher_direction {
	SAFEXCEL_ENCRYPT,
	SAFEXCEL_DECRYPT,
};

struct safexcel_cipher_ctx {
	struct safexcel_context base;
	struct safexcel_crypto_priv *priv;

	u32 mode;

	__le32 key[8];
	unsigned int key_len;
};

36
struct safexcel_cipher_req {
37
	enum safexcel_cipher_direction direction;
38 39 40
	bool needs_inv;
};

41 42 43
static void safexcel_skcipher_token(struct safexcel_cipher_ctx *ctx, u8 *iv,
				    struct safexcel_command_desc *cdesc,
				    u32 length)
44 45 46 47 48 49
{
	struct safexcel_token *token;
	unsigned offset = 0;

	if (ctx->mode == CONTEXT_CONTROL_CRYPTO_MODE_CBC) {
		offset = AES_BLOCK_SIZE / sizeof(u32);
50
		memcpy(cdesc->control_data.token, iv, AES_BLOCK_SIZE);
51 52 53 54 55 56 57 58

		cdesc->control_data.options |= EIP197_OPTION_4_TOKEN_IV_CMD;
	}

	token = (struct safexcel_token *)(cdesc->control_data.token + offset);

	token[0].opcode = EIP197_TOKEN_OPCODE_DIRECTION;
	token[0].packet_length = length;
59 60
	token[0].stat = EIP197_TOKEN_STAT_LAST_PACKET |
			EIP197_TOKEN_STAT_LAST_HASH;
61 62 63 64 65
	token[0].instructions = EIP197_TOKEN_INS_LAST |
				EIP197_TOKEN_INS_TYPE_CRYTO |
				EIP197_TOKEN_INS_TYPE_OUTPUT;
}

66 67
static int safexcel_skcipher_aes_setkey(struct crypto_skcipher *ctfm,
					const u8 *key, unsigned int len)
68 69 70
{
	struct crypto_tfm *tfm = crypto_skcipher_tfm(ctfm);
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
71
	struct safexcel_crypto_priv *priv = ctx->priv;
72 73 74 75 76 77 78 79 80
	struct crypto_aes_ctx aes;
	int ret, i;

	ret = crypto_aes_expand_key(&aes, key, len);
	if (ret) {
		crypto_skcipher_set_flags(ctfm, CRYPTO_TFM_RES_BAD_KEY_LEN);
		return ret;
	}

81
	if (priv->version == EIP197 && ctx->base.ctxr_dma) {
82 83 84 85 86
		for (i = 0; i < len / sizeof(u32); i++) {
			if (ctx->key[i] != cpu_to_le32(aes.key_enc[i])) {
				ctx->base.needs_inv = true;
				break;
			}
87 88 89 90 91 92 93 94 95 96 97 98 99
		}
	}

	for (i = 0; i < len / sizeof(u32); i++)
		ctx->key[i] = cpu_to_le32(aes.key_enc[i]);

	ctx->key_len = len;

	memzero_explicit(&aes, sizeof(aes));
	return 0;
}

static int safexcel_context_control(struct safexcel_cipher_ctx *ctx,
100
				    struct crypto_async_request *async,
101
				    struct safexcel_cipher_req *sreq,
102 103 104 105 106
				    struct safexcel_command_desc *cdesc)
{
	struct safexcel_crypto_priv *priv = ctx->priv;
	int ctrl_size;

107 108 109 110 111 112 113
	cdesc->control_data.control0 |= CONTEXT_CONTROL_TYPE_CRYPTO_OUT;

	/* The decryption control type is a combination of the encryption type
	 * and CONTEXT_CONTROL_TYPE_NULL_IN, for all types.
	 */
	if (sreq->direction == SAFEXCEL_DECRYPT)
		cdesc->control_data.control0 |= CONTEXT_CONTROL_TYPE_NULL_IN;
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140

	cdesc->control_data.control0 |= CONTEXT_CONTROL_KEY_EN;
	cdesc->control_data.control1 |= ctx->mode;

	switch (ctx->key_len) {
	case AES_KEYSIZE_128:
		cdesc->control_data.control0 |= CONTEXT_CONTROL_CRYPTO_ALG_AES128;
		ctrl_size = 4;
		break;
	case AES_KEYSIZE_192:
		cdesc->control_data.control0 |= CONTEXT_CONTROL_CRYPTO_ALG_AES192;
		ctrl_size = 6;
		break;
	case AES_KEYSIZE_256:
		cdesc->control_data.control0 |= CONTEXT_CONTROL_CRYPTO_ALG_AES256;
		ctrl_size = 8;
		break;
	default:
		dev_err(priv->dev, "aes keysize not supported: %u\n",
			ctx->key_len);
		return -EINVAL;
	}
	cdesc->control_data.control0 |= CONTEXT_CONTROL_SIZE(ctrl_size);

	return 0;
}

141 142
static int safexcel_handle_req_result(struct safexcel_crypto_priv *priv, int ring,
				      struct crypto_async_request *async,
143 144 145 146
				      struct scatterlist *src,
				      struct scatterlist *dst,
				      unsigned int cryptlen,
				      struct safexcel_cipher_req *sreq,
147
				      bool *should_complete, int *ret)
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
{
	struct safexcel_result_desc *rdesc;
	int ndesc = 0;

	*ret = 0;

	spin_lock_bh(&priv->ring[ring].egress_lock);
	do {
		rdesc = safexcel_ring_next_rptr(priv, &priv->ring[ring].rdr);
		if (IS_ERR(rdesc)) {
			dev_err(priv->dev,
				"cipher: result: could not retrieve the result descriptor\n");
			*ret = PTR_ERR(rdesc);
			break;
		}

		if (rdesc->result_data.error_code) {
			dev_err(priv->dev,
				"cipher: result: result descriptor error (%d)\n",
				rdesc->result_data.error_code);
			*ret = -EIO;
		}

		ndesc++;
	} while (!rdesc->last_seg);

	safexcel_complete(priv, ring);
	spin_unlock_bh(&priv->ring[ring].egress_lock);

177 178 179
	if (src == dst) {
		dma_unmap_sg(priv->dev, src,
			     sg_nents_for_len(src, cryptlen),
180 181
			     DMA_BIDIRECTIONAL);
	} else {
182 183
		dma_unmap_sg(priv->dev, src,
			     sg_nents_for_len(src, cryptlen),
184
			     DMA_TO_DEVICE);
185 186
		dma_unmap_sg(priv->dev, dst,
			     sg_nents_for_len(dst, cryptlen),
187 188 189 190 191 192 193 194
			     DMA_FROM_DEVICE);
	}

	*should_complete = true;

	return ndesc;
}

195 196 197 198 199 200
static int safexcel_aes_send(struct crypto_async_request *base, int ring,
			     struct safexcel_request *request,
			     struct safexcel_cipher_req *sreq,
			     struct scatterlist *src, struct scatterlist *dst,
			     unsigned int cryptlen, u8 *iv, int *commands,
			     int *results)
201
{
202
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(base->tfm);
203 204 205 206
	struct safexcel_crypto_priv *priv = ctx->priv;
	struct safexcel_command_desc *cdesc;
	struct safexcel_result_desc *rdesc;
	struct scatterlist *sg;
207
	int nr_src, nr_dst, n_cdesc = 0, n_rdesc = 0, queued = cryptlen;
208 209
	int i, ret = 0;

210 211 212
	if (src == dst) {
		nr_src = dma_map_sg(priv->dev, src,
				    sg_nents_for_len(src, cryptlen),
213 214 215 216 217
				    DMA_BIDIRECTIONAL);
		nr_dst = nr_src;
		if (!nr_src)
			return -EINVAL;
	} else {
218 219
		nr_src = dma_map_sg(priv->dev, src,
				    sg_nents_for_len(src, cryptlen),
220 221 222 223
				    DMA_TO_DEVICE);
		if (!nr_src)
			return -EINVAL;

224 225
		nr_dst = dma_map_sg(priv->dev, dst,
				    sg_nents_for_len(dst, cryptlen),
226 227
				    DMA_FROM_DEVICE);
		if (!nr_dst) {
228 229
			dma_unmap_sg(priv->dev, src,
				     sg_nents_for_len(src, cryptlen),
230 231 232 233 234 235 236 237 238 239
				     DMA_TO_DEVICE);
			return -EINVAL;
		}
	}

	memcpy(ctx->base.ctxr->data, ctx->key, ctx->key_len);

	spin_lock_bh(&priv->ring[ring].egress_lock);

	/* command descriptors */
240
	for_each_sg(src, sg, nr_src, i) {
241 242 243 244 245 246 247
		int len = sg_dma_len(sg);

		/* Do not overflow the request */
		if (queued - len < 0)
			len = queued;

		cdesc = safexcel_add_cdesc(priv, ring, !n_cdesc, !(queued - len),
248
					   sg_dma_address(sg), len, cryptlen,
249 250 251 252 253 254 255 256 257
					   ctx->base.ctxr_dma);
		if (IS_ERR(cdesc)) {
			/* No space left in the command descriptor ring */
			ret = PTR_ERR(cdesc);
			goto cdesc_rollback;
		}
		n_cdesc++;

		if (n_cdesc == 1) {
258 259
			safexcel_context_control(ctx, base, sreq, cdesc);
			safexcel_skcipher_token(ctx, iv, cdesc, cryptlen);
260 261 262 263 264 265 266 267
		}

		queued -= len;
		if (!queued)
			break;
	}

	/* result descriptors */
268
	for_each_sg(dst, sg, nr_dst, i) {
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283
		bool first = !i, last = (i == nr_dst - 1);
		u32 len = sg_dma_len(sg);

		rdesc = safexcel_add_rdesc(priv, ring, first, last,
					   sg_dma_address(sg), len);
		if (IS_ERR(rdesc)) {
			/* No space left in the result descriptor ring */
			ret = PTR_ERR(rdesc);
			goto rdesc_rollback;
		}
		n_rdesc++;
	}

	spin_unlock_bh(&priv->ring[ring].egress_lock);

284
	request->req = base;
285

286
	*commands = n_cdesc;
287
	*results = n_rdesc;
288 289 290 291 292 293 294 295 296 297 298
	return 0;

rdesc_rollback:
	for (i = 0; i < n_rdesc; i++)
		safexcel_ring_rollback_wptr(priv, &priv->ring[ring].rdr);
cdesc_rollback:
	for (i = 0; i < n_cdesc; i++)
		safexcel_ring_rollback_wptr(priv, &priv->ring[ring].cdr);

	spin_unlock_bh(&priv->ring[ring].egress_lock);

299 300 301
	if (src == dst) {
		dma_unmap_sg(priv->dev, src,
			     sg_nents_for_len(src, cryptlen),
302 303
			     DMA_BIDIRECTIONAL);
	} else {
304 305
		dma_unmap_sg(priv->dev, src,
			     sg_nents_for_len(src, cryptlen),
306
			     DMA_TO_DEVICE);
307 308
		dma_unmap_sg(priv->dev, dst,
			     sg_nents_for_len(dst, cryptlen),
309 310 311 312 313 314 315 316
			     DMA_FROM_DEVICE);
	}

	return ret;
}

static int safexcel_handle_inv_result(struct safexcel_crypto_priv *priv,
				      int ring,
317
				      struct crypto_async_request *base,
318 319
				      bool *should_complete, int *ret)
{
320
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(base->tfm);
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
	struct safexcel_result_desc *rdesc;
	int ndesc = 0, enq_ret;

	*ret = 0;

	spin_lock_bh(&priv->ring[ring].egress_lock);
	do {
		rdesc = safexcel_ring_next_rptr(priv, &priv->ring[ring].rdr);
		if (IS_ERR(rdesc)) {
			dev_err(priv->dev,
				"cipher: invalidate: could not retrieve the result descriptor\n");
			*ret = PTR_ERR(rdesc);
			break;
		}

		if (rdesc->result_data.error_code) {
			dev_err(priv->dev, "cipher: invalidate: result descriptor error (%d)\n",
				rdesc->result_data.error_code);
			*ret = -EIO;
		}

		ndesc++;
	} while (!rdesc->last_seg);

	safexcel_complete(priv, ring);
	spin_unlock_bh(&priv->ring[ring].egress_lock);

	if (ctx->base.exit_inv) {
		dma_pool_free(priv->context_pool, ctx->base.ctxr,
			      ctx->base.ctxr_dma);

		*should_complete = true;

		return ndesc;
	}

357 358
	ring = safexcel_select_ring(priv);
	ctx->base.ring = ring;
359

360
	spin_lock_bh(&priv->ring[ring].queue_lock);
361
	enq_ret = crypto_enqueue_request(&priv->ring[ring].queue, base);
362
	spin_unlock_bh(&priv->ring[ring].queue_lock);
363 364 365 366

	if (enq_ret != -EINPROGRESS)
		*ret = enq_ret;

367 368
	queue_work(priv->ring[ring].workqueue,
		   &priv->ring[ring].work_data.work);
369

370 371 372 373 374
	*should_complete = false;

	return ndesc;
}

375 376 377 378
static int safexcel_skcipher_handle_result(struct safexcel_crypto_priv *priv,
					   int ring,
					   struct crypto_async_request *async,
					   bool *should_complete, int *ret)
379 380 381 382 383 384 385 386 387 388
{
	struct skcipher_request *req = skcipher_request_cast(async);
	struct safexcel_cipher_req *sreq = skcipher_request_ctx(req);
	int err;

	if (sreq->needs_inv) {
		sreq->needs_inv = false;
		err = safexcel_handle_inv_result(priv, ring, async,
						 should_complete, ret);
	} else {
389 390
		err = safexcel_handle_req_result(priv, ring, async, req->src,
						 req->dst, req->cryptlen, sreq,
391 392 393 394 395 396
						 should_complete, ret);
	}

	return err;
}

397
static int safexcel_cipher_send_inv(struct crypto_async_request *base,
398 399 400
				    int ring, struct safexcel_request *request,
				    int *commands, int *results)
{
401
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(base->tfm);
402 403 404
	struct safexcel_crypto_priv *priv = ctx->priv;
	int ret;

405 406
	ret = safexcel_invalidate_cache(base, priv, ctx->base.ctxr_dma, ring,
					request);
407 408 409 410 411 412 413 414 415
	if (unlikely(ret))
		return ret;

	*commands = 1;
	*results = 1;

	return 0;
}

416 417 418
static int safexcel_skcipher_send(struct crypto_async_request *async, int ring,
				  struct safexcel_request *request,
				  int *commands, int *results)
419 420
{
	struct skcipher_request *req = skcipher_request_cast(async);
421
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(req->base.tfm);
422
	struct safexcel_cipher_req *sreq = skcipher_request_ctx(req);
423
	struct safexcel_crypto_priv *priv = ctx->priv;
424 425
	int ret;

426 427
	BUG_ON(priv->version == EIP97 && sreq->needs_inv);

428
	if (sreq->needs_inv)
429 430
		ret = safexcel_cipher_send_inv(async, ring, request, commands,
					       results);
431
	else
432 433
		ret = safexcel_aes_send(async, ring, request, sreq, req->src,
					req->dst, req->cryptlen, req->iv,
434 435 436 437
					commands, results);
	return ret;
}

438 439 440 441
static int safexcel_cipher_exit_inv(struct crypto_tfm *tfm,
				    struct crypto_async_request *base,
				    struct safexcel_cipher_req *sreq,
				    struct safexcel_inv_result *result)
442 443 444
{
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
	struct safexcel_crypto_priv *priv = ctx->priv;
445
	int ring = ctx->base.ring;
446

447
	init_completion(&result->completion);
448

449
	ctx = crypto_tfm_ctx(base->tfm);
450
	ctx->base.exit_inv = true;
451
	sreq->needs_inv = true;
452

453
	spin_lock_bh(&priv->ring[ring].queue_lock);
454
	crypto_enqueue_request(&priv->ring[ring].queue, base);
455
	spin_unlock_bh(&priv->ring[ring].queue_lock);
456

457 458
	queue_work(priv->ring[ring].workqueue,
		   &priv->ring[ring].work_data.work);
459

460
	wait_for_completion(&result->completion);
461

462
	if (result->error) {
463 464
		dev_warn(priv->dev,
			"cipher: sync: invalidate: completion error %d\n",
465 466
			 result->error);
		return result->error;
467 468 469 470 471
	}

	return 0;
}

472
static int safexcel_skcipher_exit_inv(struct crypto_tfm *tfm)
473
{
474
	EIP197_REQUEST_ON_STACK(req, skcipher, EIP197_SKCIPHER_REQ_SIZE);
475
	struct safexcel_cipher_req *sreq = skcipher_request_ctx(req);
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491
	struct safexcel_inv_result result = {};

	memset(req, 0, sizeof(struct skcipher_request));

	skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
				      safexcel_inv_complete, &result);
	skcipher_request_set_tfm(req, __crypto_skcipher_cast(tfm));

	return safexcel_cipher_exit_inv(tfm, &req->base, sreq, &result);
}

static int safexcel_aes(struct crypto_async_request *base,
			struct safexcel_cipher_req *sreq,
			enum safexcel_cipher_direction dir, u32 mode)
{
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(base->tfm);
492
	struct safexcel_crypto_priv *priv = ctx->priv;
493
	int ret, ring;
494

495
	sreq->needs_inv = false;
496
	sreq->direction = dir;
497 498 499
	ctx->mode = mode;

	if (ctx->base.ctxr) {
500
		if (priv->version == EIP197 && ctx->base.needs_inv) {
501 502 503
			sreq->needs_inv = true;
			ctx->base.needs_inv = false;
		}
504 505 506
	} else {
		ctx->base.ring = safexcel_select_ring(priv);
		ctx->base.ctxr = dma_pool_zalloc(priv->context_pool,
507
						 EIP197_GFP_FLAGS(*base),
508 509 510 511 512
						 &ctx->base.ctxr_dma);
		if (!ctx->base.ctxr)
			return -ENOMEM;
	}

513 514 515
	ring = ctx->base.ring;

	spin_lock_bh(&priv->ring[ring].queue_lock);
516
	ret = crypto_enqueue_request(&priv->ring[ring].queue, base);
517
	spin_unlock_bh(&priv->ring[ring].queue_lock);
518

519 520
	queue_work(priv->ring[ring].workqueue,
		   &priv->ring[ring].work_data.work);
521 522 523 524 525 526

	return ret;
}

static int safexcel_ecb_aes_encrypt(struct skcipher_request *req)
{
527 528
	return safexcel_aes(&req->base, skcipher_request_ctx(req),
			    SAFEXCEL_ENCRYPT, CONTEXT_CONTROL_CRYPTO_MODE_ECB);
529 530 531 532
}

static int safexcel_ecb_aes_decrypt(struct skcipher_request *req)
{
533 534
	return safexcel_aes(&req->base, skcipher_request_ctx(req),
			    SAFEXCEL_DECRYPT, CONTEXT_CONTROL_CRYPTO_MODE_ECB);
535 536 537 538 539 540 541 542 543
}

static int safexcel_skcipher_cra_init(struct crypto_tfm *tfm)
{
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
	struct safexcel_alg_template *tmpl =
		container_of(tfm->__crt_alg, struct safexcel_alg_template,
			     alg.skcipher.base);

544 545
	crypto_skcipher_set_reqsize(__crypto_skcipher_cast(tfm),
				    sizeof(struct safexcel_cipher_req));
546

547 548 549 550
	ctx->priv = tmpl->priv;

	ctx->base.send = safexcel_skcipher_send;
	ctx->base.handle_result = safexcel_skcipher_handle_result;
551 552 553
	return 0;
}

554
static int safexcel_cipher_cra_exit(struct crypto_tfm *tfm)
555 556 557 558 559 560 561
{
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);

	memzero_explicit(ctx->key, 8 * sizeof(u32));

	/* context not allocated, skip invalidation */
	if (!ctx->base.ctxr)
562
		return -ENOMEM;
563 564

	memzero_explicit(ctx->base.ctxr->data, 8 * sizeof(u32));
565 566 567 568 569 570 571 572 573 574 575
	return 0;
}

static void safexcel_skcipher_cra_exit(struct crypto_tfm *tfm)
{
	struct safexcel_cipher_ctx *ctx = crypto_tfm_ctx(tfm);
	struct safexcel_crypto_priv *priv = ctx->priv;
	int ret;

	if (safexcel_cipher_cra_exit(tfm))
		return;
576

577
	if (priv->version == EIP197) {
578
		ret = safexcel_skcipher_exit_inv(tfm);
579
		if (ret)
580 581
			dev_warn(priv->dev, "skcipher: invalidation error %d\n",
				 ret);
582 583 584 585
	} else {
		dma_pool_free(priv->context_pool, ctx->base.ctxr,
			      ctx->base.ctxr_dma);
	}
586 587 588 589 590
}

struct safexcel_alg_template safexcel_alg_ecb_aes = {
	.type = SAFEXCEL_ALG_TYPE_SKCIPHER,
	.alg.skcipher = {
591
		.setkey = safexcel_skcipher_aes_setkey,
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613
		.encrypt = safexcel_ecb_aes_encrypt,
		.decrypt = safexcel_ecb_aes_decrypt,
		.min_keysize = AES_MIN_KEY_SIZE,
		.max_keysize = AES_MAX_KEY_SIZE,
		.base = {
			.cra_name = "ecb(aes)",
			.cra_driver_name = "safexcel-ecb-aes",
			.cra_priority = 300,
			.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_ASYNC |
				     CRYPTO_ALG_KERN_DRIVER_ONLY,
			.cra_blocksize = AES_BLOCK_SIZE,
			.cra_ctxsize = sizeof(struct safexcel_cipher_ctx),
			.cra_alignmask = 0,
			.cra_init = safexcel_skcipher_cra_init,
			.cra_exit = safexcel_skcipher_cra_exit,
			.cra_module = THIS_MODULE,
		},
	},
};

static int safexcel_cbc_aes_encrypt(struct skcipher_request *req)
{
614 615
	return safexcel_aes(&req->base, skcipher_request_ctx(req),
			    SAFEXCEL_ENCRYPT, CONTEXT_CONTROL_CRYPTO_MODE_CBC);
616 617 618 619
}

static int safexcel_cbc_aes_decrypt(struct skcipher_request *req)
{
620 621
	return safexcel_aes(&req->base, skcipher_request_ctx(req),
			    SAFEXCEL_DECRYPT, CONTEXT_CONTROL_CRYPTO_MODE_CBC);
622 623 624 625 626
}

struct safexcel_alg_template safexcel_alg_cbc_aes = {
	.type = SAFEXCEL_ALG_TYPE_SKCIPHER,
	.alg.skcipher = {
627
		.setkey = safexcel_skcipher_aes_setkey,
628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
		.encrypt = safexcel_cbc_aes_encrypt,
		.decrypt = safexcel_cbc_aes_decrypt,
		.min_keysize = AES_MIN_KEY_SIZE,
		.max_keysize = AES_MAX_KEY_SIZE,
		.ivsize = AES_BLOCK_SIZE,
		.base = {
			.cra_name = "cbc(aes)",
			.cra_driver_name = "safexcel-cbc-aes",
			.cra_priority = 300,
			.cra_flags = CRYPTO_ALG_TYPE_SKCIPHER | CRYPTO_ALG_ASYNC |
				     CRYPTO_ALG_KERN_DRIVER_ONLY,
			.cra_blocksize = AES_BLOCK_SIZE,
			.cra_ctxsize = sizeof(struct safexcel_cipher_ctx),
			.cra_alignmask = 0,
			.cra_init = safexcel_skcipher_cra_init,
			.cra_exit = safexcel_skcipher_cra_exit,
			.cra_module = THIS_MODULE,
		},
	},
};