hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/drivers/crypto/nx/nx-aes-ccm.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /**
23 * AES CCM routines supporting the Power 7+ Nest Accelerators driver
34 *
45 * Copyright (C) 2012 International Business Machines Inc.
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; version 2 only.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU General Public License
16
- * along with this program; if not, write to the Free Software
17
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
186 *
197 * Author: Kent Yoder <yoder1@us.ibm.com>
208 */
....@@ -339,7 +327,7 @@
339327 }
340328
341329 static int ccm_nx_decrypt(struct aead_request *req,
342
- struct blkcipher_desc *desc,
330
+ u8 *iv,
343331 unsigned int assoclen)
344332 {
345333 struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm);
....@@ -360,7 +348,7 @@
360348 req->src, nbytes + req->assoclen, authsize,
361349 SCATTERWALK_FROM_SG);
362350
363
- rc = generate_pat(desc->info, req, nx_ctx, authsize, nbytes, assoclen,
351
+ rc = generate_pat(iv, req, nx_ctx, authsize, nbytes, assoclen,
364352 csbcpb->cpb.aes_ccm.in_pat_or_b0);
365353 if (rc)
366354 goto out;
....@@ -379,7 +367,7 @@
379367
380368 NX_CPB_FDM(nx_ctx->csbcpb) &= ~NX_FDM_ENDE_ENCRYPT;
381369
382
- rc = nx_build_sg_lists(nx_ctx, desc, req->dst, req->src,
370
+ rc = nx_build_sg_lists(nx_ctx, iv, req->dst, req->src,
383371 &to_process, processed + req->assoclen,
384372 csbcpb->cpb.aes_ccm.iv_or_ctr);
385373 if (rc)
....@@ -393,7 +381,7 @@
393381 /* for partial completion, copy following for next
394382 * entry into loop...
395383 */
396
- memcpy(desc->info, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE);
384
+ memcpy(iv, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE);
397385 memcpy(csbcpb->cpb.aes_ccm.in_pat_or_b0,
398386 csbcpb->cpb.aes_ccm.out_pat_or_mac, AES_BLOCK_SIZE);
399387 memcpy(csbcpb->cpb.aes_ccm.in_s0,
....@@ -417,7 +405,7 @@
417405 }
418406
419407 static int ccm_nx_encrypt(struct aead_request *req,
420
- struct blkcipher_desc *desc,
408
+ u8 *iv,
421409 unsigned int assoclen)
422410 {
423411 struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm);
....@@ -430,7 +418,7 @@
430418
431419 spin_lock_irqsave(&nx_ctx->lock, irq_flags);
432420
433
- rc = generate_pat(desc->info, req, nx_ctx, authsize, nbytes, assoclen,
421
+ rc = generate_pat(iv, req, nx_ctx, authsize, nbytes, assoclen,
434422 csbcpb->cpb.aes_ccm.in_pat_or_b0);
435423 if (rc)
436424 goto out;
....@@ -448,7 +436,7 @@
448436
449437 NX_CPB_FDM(csbcpb) |= NX_FDM_ENDE_ENCRYPT;
450438
451
- rc = nx_build_sg_lists(nx_ctx, desc, req->dst, req->src,
439
+ rc = nx_build_sg_lists(nx_ctx, iv, req->dst, req->src,
452440 &to_process, processed + req->assoclen,
453441 csbcpb->cpb.aes_ccm.iv_or_ctr);
454442 if (rc)
....@@ -462,7 +450,7 @@
462450 /* for partial completion, copy following for next
463451 * entry into loop...
464452 */
465
- memcpy(desc->info, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE);
453
+ memcpy(iv, csbcpb->cpb.aes_ccm.out_ctr, AES_BLOCK_SIZE);
466454 memcpy(csbcpb->cpb.aes_ccm.in_pat_or_b0,
467455 csbcpb->cpb.aes_ccm.out_pat_or_mac, AES_BLOCK_SIZE);
468456 memcpy(csbcpb->cpb.aes_ccm.in_s0,
....@@ -493,67 +481,50 @@
493481 {
494482 struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm);
495483 struct nx_gcm_rctx *rctx = aead_request_ctx(req);
496
- struct blkcipher_desc desc;
497484 u8 *iv = rctx->iv;
498485
499486 iv[0] = 3;
500487 memcpy(iv + 1, nx_ctx->priv.ccm.nonce, 3);
501488 memcpy(iv + 4, req->iv, 8);
502489
503
- desc.info = iv;
504
-
505
- return ccm_nx_encrypt(req, &desc, req->assoclen - 8);
490
+ return ccm_nx_encrypt(req, iv, req->assoclen - 8);
506491 }
507492
508493 static int ccm_aes_nx_encrypt(struct aead_request *req)
509494 {
510
- struct blkcipher_desc desc;
511495 int rc;
512496
513
- desc.info = req->iv;
514
-
515
- rc = crypto_ccm_check_iv(desc.info);
497
+ rc = crypto_ccm_check_iv(req->iv);
516498 if (rc)
517499 return rc;
518500
519
- return ccm_nx_encrypt(req, &desc, req->assoclen);
501
+ return ccm_nx_encrypt(req, req->iv, req->assoclen);
520502 }
521503
522504 static int ccm4309_aes_nx_decrypt(struct aead_request *req)
523505 {
524506 struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(req->base.tfm);
525507 struct nx_gcm_rctx *rctx = aead_request_ctx(req);
526
- struct blkcipher_desc desc;
527508 u8 *iv = rctx->iv;
528509
529510 iv[0] = 3;
530511 memcpy(iv + 1, nx_ctx->priv.ccm.nonce, 3);
531512 memcpy(iv + 4, req->iv, 8);
532513
533
- desc.info = iv;
534
-
535
- return ccm_nx_decrypt(req, &desc, req->assoclen - 8);
514
+ return ccm_nx_decrypt(req, iv, req->assoclen - 8);
536515 }
537516
538517 static int ccm_aes_nx_decrypt(struct aead_request *req)
539518 {
540
- struct blkcipher_desc desc;
541519 int rc;
542520
543
- desc.info = req->iv;
544
-
545
- rc = crypto_ccm_check_iv(desc.info);
521
+ rc = crypto_ccm_check_iv(req->iv);
546522 if (rc)
547523 return rc;
548524
549
- return ccm_nx_decrypt(req, &desc, req->assoclen);
525
+ return ccm_nx_decrypt(req, req->iv, req->assoclen);
550526 }
551527
552
-/* tell the block cipher walk routines that this is a stream cipher by
553
- * setting cra_blocksize to 1. Even using blkcipher_walk_virt_block
554
- * during encrypt/decrypt doesn't solve this problem, because it calls
555
- * blkcipher_walk_done under the covers, which doesn't use walk->blocksize,
556
- * but instead uses this tfm->blocksize. */
557528 struct aead_alg nx_ccm_aes_alg = {
558529 .base = {
559530 .cra_name = "ccm(aes)",