.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /** |
---|
2 | 3 | * Routines supporting the Power 7+ Nest Accelerators driver |
---|
3 | 4 | * |
---|
4 | 5 | * 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. |
---|
18 | 6 | * |
---|
19 | 7 | * Author: Kent Yoder <yoder1@us.ibm.com> |
---|
20 | 8 | */ |
---|
.. | .. |
---|
255 | 243 | * scatterlists based on them. |
---|
256 | 244 | * |
---|
257 | 245 | * @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 |
---|
259 | 247 | * @dst: destination scatterlist |
---|
260 | 248 | * @src: source scatterlist |
---|
261 | 249 | * @nbytes: length of data described in the scatterlists |
---|
262 | 250 | * @offset: number of bytes to fast-forward past at the beginning of |
---|
263 | 251 | * 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 |
---|
265 | 253 | * |
---|
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 |
---|
268 | 256 | * corresponding NX scatterlists |
---|
269 | 257 | */ |
---|
270 | 258 | int nx_build_sg_lists(struct nx_crypto_ctx *nx_ctx, |
---|
271 | | - struct blkcipher_desc *desc, |
---|
| 259 | + const u8 *iv, |
---|
272 | 260 | struct scatterlist *dst, |
---|
273 | 261 | struct scatterlist *src, |
---|
274 | 262 | unsigned int *nbytes, |
---|
275 | 263 | unsigned int offset, |
---|
276 | | - u8 *iv) |
---|
| 264 | + u8 *oiv) |
---|
277 | 265 | { |
---|
278 | 266 | unsigned int delta = 0; |
---|
279 | 267 | unsigned int total = *nbytes; |
---|
.. | .. |
---|
286 | 274 | max_sg_len = min_t(u64, max_sg_len, |
---|
287 | 275 | nx_ctx->ap->databytelen/NX_PAGE_SIZE); |
---|
288 | 276 | |
---|
289 | | - if (iv) |
---|
290 | | - memcpy(iv, desc->info, AES_BLOCK_SIZE); |
---|
| 277 | + if (oiv) |
---|
| 278 | + memcpy(oiv, iv, AES_BLOCK_SIZE); |
---|
291 | 279 | |
---|
292 | 280 | *nbytes = min_t(u64, *nbytes, nx_ctx->ap->databytelen); |
---|
293 | 281 | |
---|
.. | .. |
---|
523 | 511 | return true; |
---|
524 | 512 | } |
---|
525 | 513 | |
---|
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) |
---|
527 | 515 | { |
---|
528 | 516 | return nx_check_props(&nx_driver.viodev->dev, fc, mode) ? |
---|
529 | | - crypto_register_alg(alg) : 0; |
---|
| 517 | + crypto_register_skcipher(alg) : 0; |
---|
530 | 518 | } |
---|
531 | 519 | |
---|
532 | 520 | static int nx_register_aead(struct aead_alg *alg, u32 fc, u32 mode) |
---|
.. | .. |
---|
543 | 531 | crypto_register_shash(alg) : 0; |
---|
544 | 532 | } |
---|
545 | 533 | |
---|
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) |
---|
547 | 535 | { |
---|
548 | 536 | if (nx_check_props(NULL, fc, mode)) |
---|
549 | | - crypto_unregister_alg(alg); |
---|
| 537 | + crypto_unregister_skcipher(alg); |
---|
550 | 538 | } |
---|
551 | 539 | |
---|
552 | 540 | static void nx_unregister_aead(struct aead_alg *alg, u32 fc, u32 mode) |
---|
.. | .. |
---|
581 | 569 | |
---|
582 | 570 | memset(&nx_driver.stats, 0, sizeof(struct nx_stats)); |
---|
583 | 571 | |
---|
584 | | - rc = NX_DEBUGFS_INIT(&nx_driver); |
---|
585 | | - if (rc) |
---|
586 | | - goto out; |
---|
| 572 | + NX_DEBUGFS_INIT(&nx_driver); |
---|
587 | 573 | |
---|
588 | 574 | nx_driver.of.status = NX_OKAY; |
---|
589 | 575 | |
---|
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); |
---|
591 | 577 | if (rc) |
---|
592 | 578 | goto out; |
---|
593 | 579 | |
---|
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); |
---|
595 | 581 | if (rc) |
---|
596 | 582 | goto out_unreg_ecb; |
---|
597 | 583 | |
---|
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); |
---|
599 | 586 | if (rc) |
---|
600 | 587 | goto out_unreg_cbc; |
---|
601 | 588 | |
---|
.. | .. |
---|
647 | 634 | out_unreg_gcm: |
---|
648 | 635 | nx_unregister_aead(&nx_gcm_aes_alg, NX_FC_AES, NX_MODE_AES_GCM); |
---|
649 | 636 | 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); |
---|
651 | 638 | 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); |
---|
653 | 640 | 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); |
---|
655 | 642 | out: |
---|
656 | 643 | return rc; |
---|
657 | 644 | } |
---|
.. | .. |
---|
718 | 705 | NX_MODE_AES_GCM); |
---|
719 | 706 | } |
---|
720 | 707 | |
---|
721 | | -int nx_crypto_ctx_aes_ctr_init(struct crypto_tfm *tfm) |
---|
| 708 | +int nx_crypto_ctx_aes_ctr_init(struct crypto_skcipher *tfm) |
---|
722 | 709 | { |
---|
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, |
---|
724 | 711 | NX_MODE_AES_CTR); |
---|
725 | 712 | } |
---|
726 | 713 | |
---|
727 | | -int nx_crypto_ctx_aes_cbc_init(struct crypto_tfm *tfm) |
---|
| 714 | +int nx_crypto_ctx_aes_cbc_init(struct crypto_skcipher *tfm) |
---|
728 | 715 | { |
---|
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, |
---|
730 | 717 | NX_MODE_AES_CBC); |
---|
731 | 718 | } |
---|
732 | 719 | |
---|
733 | | -int nx_crypto_ctx_aes_ecb_init(struct crypto_tfm *tfm) |
---|
| 720 | +int nx_crypto_ctx_aes_ecb_init(struct crypto_skcipher *tfm) |
---|
734 | 721 | { |
---|
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, |
---|
736 | 723 | NX_MODE_AES_ECB); |
---|
737 | 724 | } |
---|
738 | 725 | |
---|
.. | .. |
---|
759 | 746 | { |
---|
760 | 747 | struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm); |
---|
761 | 748 | |
---|
762 | | - kzfree(nx_ctx->kmem); |
---|
| 749 | + kfree_sensitive(nx_ctx->kmem); |
---|
763 | 750 | nx_ctx->csbcpb = NULL; |
---|
764 | 751 | nx_ctx->csbcpb_aead = NULL; |
---|
765 | 752 | nx_ctx->in_sg = NULL; |
---|
766 | 753 | nx_ctx->out_sg = NULL; |
---|
767 | 754 | } |
---|
768 | 755 | |
---|
| 756 | +void nx_crypto_ctx_skcipher_exit(struct crypto_skcipher *tfm) |
---|
| 757 | +{ |
---|
| 758 | + nx_crypto_ctx_exit(crypto_skcipher_ctx(tfm)); |
---|
| 759 | +} |
---|
| 760 | + |
---|
769 | 761 | void nx_crypto_ctx_aead_exit(struct crypto_aead *tfm) |
---|
770 | 762 | { |
---|
771 | 763 | struct nx_crypto_ctx *nx_ctx = crypto_aead_ctx(tfm); |
---|
772 | 764 | |
---|
773 | | - kzfree(nx_ctx->kmem); |
---|
| 765 | + kfree_sensitive(nx_ctx->kmem); |
---|
774 | 766 | } |
---|
775 | 767 | |
---|
776 | 768 | static int nx_probe(struct vio_dev *viodev, const struct vio_device_id *id) |
---|
.. | .. |
---|
812 | 804 | NX_FC_AES, NX_MODE_AES_GCM); |
---|
813 | 805 | nx_unregister_aead(&nx_gcm_aes_alg, |
---|
814 | 806 | 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); |
---|
819 | 813 | } |
---|
820 | 814 | |
---|
821 | 815 | return 0; |
---|