hc
2024-01-04 1543e317f1da31b75942316931e8f491a8920811
kernel/drivers/crypto/nx/nx.c
....@@ -1,20 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /**
23 * Routines supporting the Power 7+ Nest Accelerators driver
34 *
45 * Copyright (C) 2011-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 */
....@@ -255,25 +243,25 @@
255243 * scatterlists based on them.
256244 *
257245 * @nx_ctx: NX crypto context for the lists we're building
258
- * @desc: the block cipher descriptor for the operation
246
+ * @iv: iv data, if the algorithm requires it
259247 * @dst: destination scatterlist
260248 * @src: source scatterlist
261249 * @nbytes: length of data described in the scatterlists
262250 * @offset: number of bytes to fast-forward past at the beginning of
263251 * scatterlists.
264
- * @iv: destination for the iv data, if the algorithm requires it
252
+ * @oiv: destination for the iv data, if the algorithm requires it
265253 *
266
- * This is common code shared by all the AES algorithms. It uses the block
267
- * cipher walk routines to traverse input and output scatterlists, building
254
+ * This is common code shared by all the AES algorithms. It uses the crypto
255
+ * scatterlist walk routines to traverse input and output scatterlists, building
268256 * corresponding NX scatterlists
269257 */
270258 int nx_build_sg_lists(struct nx_crypto_ctx *nx_ctx,
271
- struct blkcipher_desc *desc,
259
+ const u8 *iv,
272260 struct scatterlist *dst,
273261 struct scatterlist *src,
274262 unsigned int *nbytes,
275263 unsigned int offset,
276
- u8 *iv)
264
+ u8 *oiv)
277265 {
278266 unsigned int delta = 0;
279267 unsigned int total = *nbytes;
....@@ -286,8 +274,8 @@
286274 max_sg_len = min_t(u64, max_sg_len,
287275 nx_ctx->ap->databytelen/NX_PAGE_SIZE);
288276
289
- if (iv)
290
- memcpy(iv, desc->info, AES_BLOCK_SIZE);
277
+ if (oiv)
278
+ memcpy(oiv, iv, AES_BLOCK_SIZE);
291279
292280 *nbytes = min_t(u64, *nbytes, nx_ctx->ap->databytelen);
293281
....@@ -523,10 +511,10 @@
523511 return true;
524512 }
525513
526
-static int nx_register_alg(struct crypto_alg *alg, u32 fc, u32 mode)
514
+static int nx_register_skcipher(struct skcipher_alg *alg, u32 fc, u32 mode)
527515 {
528516 return nx_check_props(&nx_driver.viodev->dev, fc, mode) ?
529
- crypto_register_alg(alg) : 0;
517
+ crypto_register_skcipher(alg) : 0;
530518 }
531519
532520 static int nx_register_aead(struct aead_alg *alg, u32 fc, u32 mode)
....@@ -543,10 +531,10 @@
543531 crypto_register_shash(alg) : 0;
544532 }
545533
546
-static void nx_unregister_alg(struct crypto_alg *alg, u32 fc, u32 mode)
534
+static void nx_unregister_skcipher(struct skcipher_alg *alg, u32 fc, u32 mode)
547535 {
548536 if (nx_check_props(NULL, fc, mode))
549
- crypto_unregister_alg(alg);
537
+ crypto_unregister_skcipher(alg);
550538 }
551539
552540 static void nx_unregister_aead(struct aead_alg *alg, u32 fc, u32 mode)
....@@ -581,21 +569,20 @@
581569
582570 memset(&nx_driver.stats, 0, sizeof(struct nx_stats));
583571
584
- rc = NX_DEBUGFS_INIT(&nx_driver);
585
- if (rc)
586
- goto out;
572
+ NX_DEBUGFS_INIT(&nx_driver);
587573
588574 nx_driver.of.status = NX_OKAY;
589575
590
- rc = nx_register_alg(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
576
+ rc = nx_register_skcipher(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
591577 if (rc)
592578 goto out;
593579
594
- rc = nx_register_alg(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC);
580
+ rc = nx_register_skcipher(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC);
595581 if (rc)
596582 goto out_unreg_ecb;
597583
598
- rc = nx_register_alg(&nx_ctr3686_aes_alg, NX_FC_AES, NX_MODE_AES_CTR);
584
+ rc = nx_register_skcipher(&nx_ctr3686_aes_alg, NX_FC_AES,
585
+ NX_MODE_AES_CTR);
599586 if (rc)
600587 goto out_unreg_cbc;
601588
....@@ -647,11 +634,11 @@
647634 out_unreg_gcm:
648635 nx_unregister_aead(&nx_gcm_aes_alg, NX_FC_AES, NX_MODE_AES_GCM);
649636 out_unreg_ctr3686:
650
- nx_unregister_alg(&nx_ctr3686_aes_alg, NX_FC_AES, NX_MODE_AES_CTR);
637
+ nx_unregister_skcipher(&nx_ctr3686_aes_alg, NX_FC_AES, NX_MODE_AES_CTR);
651638 out_unreg_cbc:
652
- nx_unregister_alg(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC);
639
+ nx_unregister_skcipher(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC);
653640 out_unreg_ecb:
654
- nx_unregister_alg(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
641
+ nx_unregister_skcipher(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
655642 out:
656643 return rc;
657644 }
....@@ -718,21 +705,21 @@
718705 NX_MODE_AES_GCM);
719706 }
720707
721
-int nx_crypto_ctx_aes_ctr_init(struct crypto_tfm *tfm)
708
+int nx_crypto_ctx_aes_ctr_init(struct crypto_skcipher *tfm)
722709 {
723
- return nx_crypto_ctx_init(crypto_tfm_ctx(tfm), NX_FC_AES,
710
+ return nx_crypto_ctx_init(crypto_skcipher_ctx(tfm), NX_FC_AES,
724711 NX_MODE_AES_CTR);
725712 }
726713
727
-int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm)
714
+int nx_crypto_ctx_aes_cbc_init(struct crypto_skcipher *tfm)
728715 {
729
- return nx_crypto_ctx_init(crypto_tfm_ctx(tfm), NX_FC_AES,
716
+ return nx_crypto_ctx_init(crypto_skcipher_ctx(tfm), NX_FC_AES,
730717 NX_MODE_AES_CBC);
731718 }
732719
733
-int nx_crypto_ctx_aes_ecb_init(struct crypto_tfm *tfm)
720
+int nx_crypto_ctx_aes_ecb_init(struct crypto_skcipher *tfm)
734721 {
735
- return nx_crypto_ctx_init(crypto_tfm_ctx(tfm), NX_FC_AES,
722
+ return nx_crypto_ctx_init(crypto_skcipher_ctx(tfm), NX_FC_AES,
736723 NX_MODE_AES_ECB);
737724 }
738725
....@@ -759,18 +746,23 @@
759746 {
760747 struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm);
761748
762
- kzfree(nx_ctx->kmem);
749
+ kfree_sensitive(nx_ctx->kmem);
763750 nx_ctx->csbcpb = NULL;
764751 nx_ctx->csbcpb_aead = NULL;
765752 nx_ctx->in_sg = NULL;
766753 nx_ctx->out_sg = NULL;
767754 }
768755
756
+void nx_crypto_ctx_skcipher_exit(struct crypto_skcipher *tfm)
757
+{
758
+ nx_crypto_ctx_exit(crypto_skcipher_ctx(tfm));
759
+}
760
+
769761 void nx_crypto_ctx_aead_exit(struct crypto_aead *tfm)
770762 {
771763 struct nx_crypto_ctx *nx_ctx = crypto_aead_ctx(tfm);
772764
773
- kzfree(nx_ctx->kmem);
765
+ kfree_sensitive(nx_ctx->kmem);
774766 }
775767
776768 static int nx_probe(struct vio_dev *viodev, const struct vio_device_id *id)
....@@ -812,10 +804,12 @@
812804 NX_FC_AES, NX_MODE_AES_GCM);
813805 nx_unregister_aead(&nx_gcm_aes_alg,
814806 NX_FC_AES, NX_MODE_AES_GCM);
815
- nx_unregister_alg(&nx_ctr3686_aes_alg,
816
- NX_FC_AES, NX_MODE_AES_CTR);
817
- nx_unregister_alg(&nx_cbc_aes_alg, NX_FC_AES, NX_MODE_AES_CBC);
818
- nx_unregister_alg(&nx_ecb_aes_alg, NX_FC_AES, NX_MODE_AES_ECB);
807
+ nx_unregister_skcipher(&nx_ctr3686_aes_alg,
808
+ NX_FC_AES, NX_MODE_AES_CTR);
809
+ nx_unregister_skcipher(&nx_cbc_aes_alg, NX_FC_AES,
810
+ NX_MODE_AES_CBC);
811
+ nx_unregister_skcipher(&nx_ecb_aes_alg, NX_FC_AES,
812
+ NX_MODE_AES_ECB);
819813 }
820814
821815 return 0;