.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /** |
---|
2 | 3 | * AES ECB 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 | */ |
---|
.. | .. |
---|
30 | 18 | #include "nx.h" |
---|
31 | 19 | |
---|
32 | 20 | |
---|
33 | | -static int ecb_aes_nx_set_key(struct crypto_tfm *tfm, |
---|
34 | | - const u8 *in_key, |
---|
35 | | - unsigned int key_len) |
---|
| 21 | +static int ecb_aes_nx_set_key(struct crypto_skcipher *tfm, |
---|
| 22 | + const u8 *in_key, |
---|
| 23 | + unsigned int key_len) |
---|
36 | 24 | { |
---|
37 | | - struct nx_crypto_ctx *nx_ctx = crypto_tfm_ctx(tfm); |
---|
| 25 | + struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm); |
---|
38 | 26 | struct nx_csbcpb *csbcpb = (struct nx_csbcpb *)nx_ctx->csbcpb; |
---|
39 | 27 | |
---|
40 | 28 | nx_ctx_init(nx_ctx, HCOP_FC_AES); |
---|
.. | .. |
---|
62 | 50 | return 0; |
---|
63 | 51 | } |
---|
64 | 52 | |
---|
65 | | -static int ecb_aes_nx_crypt(struct blkcipher_desc *desc, |
---|
66 | | - struct scatterlist *dst, |
---|
67 | | - struct scatterlist *src, |
---|
68 | | - unsigned int nbytes, |
---|
69 | | - int enc) |
---|
| 53 | +static int ecb_aes_nx_crypt(struct skcipher_request *req, |
---|
| 54 | + int enc) |
---|
70 | 55 | { |
---|
71 | | - struct nx_crypto_ctx *nx_ctx = crypto_blkcipher_ctx(desc->tfm); |
---|
| 56 | + struct crypto_skcipher *tfm = crypto_skcipher_reqtfm(req); |
---|
| 57 | + struct nx_crypto_ctx *nx_ctx = crypto_skcipher_ctx(tfm); |
---|
72 | 58 | struct nx_csbcpb *csbcpb = nx_ctx->csbcpb; |
---|
73 | 59 | unsigned long irq_flags; |
---|
74 | 60 | unsigned int processed = 0, to_process; |
---|
.. | .. |
---|
82 | 68 | NX_CPB_FDM(csbcpb) &= ~NX_FDM_ENDE_ENCRYPT; |
---|
83 | 69 | |
---|
84 | 70 | do { |
---|
85 | | - to_process = nbytes - processed; |
---|
| 71 | + to_process = req->cryptlen - processed; |
---|
86 | 72 | |
---|
87 | | - rc = nx_build_sg_lists(nx_ctx, desc, dst, src, &to_process, |
---|
88 | | - processed, NULL); |
---|
| 73 | + rc = nx_build_sg_lists(nx_ctx, NULL, req->dst, req->src, |
---|
| 74 | + &to_process, processed, NULL); |
---|
89 | 75 | if (rc) |
---|
90 | 76 | goto out; |
---|
91 | 77 | |
---|
.. | .. |
---|
95 | 81 | } |
---|
96 | 82 | |
---|
97 | 83 | rc = nx_hcall_sync(nx_ctx, &nx_ctx->op, |
---|
98 | | - desc->flags & CRYPTO_TFM_REQ_MAY_SLEEP); |
---|
| 84 | + req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP); |
---|
99 | 85 | if (rc) |
---|
100 | 86 | goto out; |
---|
101 | 87 | |
---|
.. | .. |
---|
104 | 90 | &(nx_ctx->stats->aes_bytes)); |
---|
105 | 91 | |
---|
106 | 92 | processed += to_process; |
---|
107 | | - } while (processed < nbytes); |
---|
| 93 | + } while (processed < req->cryptlen); |
---|
108 | 94 | |
---|
109 | 95 | out: |
---|
110 | 96 | spin_unlock_irqrestore(&nx_ctx->lock, irq_flags); |
---|
111 | 97 | return rc; |
---|
112 | 98 | } |
---|
113 | 99 | |
---|
114 | | -static int ecb_aes_nx_encrypt(struct blkcipher_desc *desc, |
---|
115 | | - struct scatterlist *dst, |
---|
116 | | - struct scatterlist *src, |
---|
117 | | - unsigned int nbytes) |
---|
| 100 | +static int ecb_aes_nx_encrypt(struct skcipher_request *req) |
---|
118 | 101 | { |
---|
119 | | - return ecb_aes_nx_crypt(desc, dst, src, nbytes, 1); |
---|
| 102 | + return ecb_aes_nx_crypt(req, 1); |
---|
120 | 103 | } |
---|
121 | 104 | |
---|
122 | | -static int ecb_aes_nx_decrypt(struct blkcipher_desc *desc, |
---|
123 | | - struct scatterlist *dst, |
---|
124 | | - struct scatterlist *src, |
---|
125 | | - unsigned int nbytes) |
---|
| 105 | +static int ecb_aes_nx_decrypt(struct skcipher_request *req) |
---|
126 | 106 | { |
---|
127 | | - return ecb_aes_nx_crypt(desc, dst, src, nbytes, 0); |
---|
| 107 | + return ecb_aes_nx_crypt(req, 0); |
---|
128 | 108 | } |
---|
129 | 109 | |
---|
130 | | -struct crypto_alg nx_ecb_aes_alg = { |
---|
131 | | - .cra_name = "ecb(aes)", |
---|
132 | | - .cra_driver_name = "ecb-aes-nx", |
---|
133 | | - .cra_priority = 300, |
---|
134 | | - .cra_flags = CRYPTO_ALG_TYPE_BLKCIPHER, |
---|
135 | | - .cra_blocksize = AES_BLOCK_SIZE, |
---|
136 | | - .cra_alignmask = 0xf, |
---|
137 | | - .cra_ctxsize = sizeof(struct nx_crypto_ctx), |
---|
138 | | - .cra_type = &crypto_blkcipher_type, |
---|
139 | | - .cra_module = THIS_MODULE, |
---|
140 | | - .cra_init = nx_crypto_ctx_aes_ecb_init, |
---|
141 | | - .cra_exit = nx_crypto_ctx_exit, |
---|
142 | | - .cra_blkcipher = { |
---|
143 | | - .min_keysize = AES_MIN_KEY_SIZE, |
---|
144 | | - .max_keysize = AES_MAX_KEY_SIZE, |
---|
145 | | - .setkey = ecb_aes_nx_set_key, |
---|
146 | | - .encrypt = ecb_aes_nx_encrypt, |
---|
147 | | - .decrypt = ecb_aes_nx_decrypt, |
---|
148 | | - } |
---|
| 110 | +struct skcipher_alg nx_ecb_aes_alg = { |
---|
| 111 | + .base.cra_name = "ecb(aes)", |
---|
| 112 | + .base.cra_driver_name = "ecb-aes-nx", |
---|
| 113 | + .base.cra_priority = 300, |
---|
| 114 | + .base.cra_blocksize = AES_BLOCK_SIZE, |
---|
| 115 | + .base.cra_alignmask = 0xf, |
---|
| 116 | + .base.cra_ctxsize = sizeof(struct nx_crypto_ctx), |
---|
| 117 | + .base.cra_module = THIS_MODULE, |
---|
| 118 | + .init = nx_crypto_ctx_aes_ecb_init, |
---|
| 119 | + .exit = nx_crypto_ctx_skcipher_exit, |
---|
| 120 | + .min_keysize = AES_MIN_KEY_SIZE, |
---|
| 121 | + .max_keysize = AES_MAX_KEY_SIZE, |
---|
| 122 | + .setkey = ecb_aes_nx_set_key, |
---|
| 123 | + .encrypt = ecb_aes_nx_encrypt, |
---|
| 124 | + .decrypt = ecb_aes_nx_decrypt, |
---|
149 | 125 | }; |
---|